Skip to content

Commit

Permalink
Merge pull request #19 from shopware/fix-payment-actions
Browse files Browse the repository at this point in the history
Fix payment action types
  • Loading branch information
lernhart authored May 14, 2024
2 parents 9be7711 + f2baf27 commit 11b31ae
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
39 changes: 28 additions & 11 deletions src/Response/PaymentResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

class PaymentResponse
{
public const ACTION_CANCEL = 'cancel';
public const ACTION_FAIL = 'fail';
public const ACTION_PAID = 'paid';
public const ACTION_PAID_PARTIALLY = 'paid_partially';
public const ACTION_PROCESS = 'process';
public const ACTION_PROCESS_UNCONFIRMED = 'process_unconfirmed';
public const ACTION_REFUND = 'refund';
public const ACTION_REMIND = 'remind';
public const ACTION_REOPEN = 'reopen';
public const ACTION_AUTHORIZE = 'authorize';
public const ACTION_CHARGEBACK = 'chargeback';

/**
* @param array<mixed> $data - Data that will be saved on the order to identify the payment
*/
Expand All @@ -24,55 +36,60 @@ public static function validationError(string $message): ResponseInterface

public static function paid(): ResponseInterface
{
return self::createStatusResponse('paid');
return self::createStatusResponse(self::ACTION_PAID);
}

public static function paidPartially(): ResponseInterface
{
return self::createStatusResponse('paid_partially');
return self::createStatusResponse(self::ACTION_PAID_PARTIALLY);
}

public static function cancelled(string $message = ''): ResponseInterface
{
return self::createStatusResponse('cancelled', $message);
return self::createStatusResponse(self::ACTION_CANCEL, $message);
}

public static function failed(string $message = ''): ResponseInterface
{
return self::createStatusResponse('failed', $message);
return self::createStatusResponse(self::ACTION_FAIL, $message);
}

public static function authorize(): ResponseInterface
{
return self::createStatusResponse('authorize');
return self::createStatusResponse(self::ACTION_AUTHORIZE);
}

public static function unconfirmed(): ResponseInterface
{
return self::createStatusResponse('unconfirmed');
return self::createStatusResponse(self::ACTION_PROCESS_UNCONFIRMED);
}

public static function inProgress(): ResponseInterface
{
return self::createStatusResponse('in_progress');
return self::createStatusResponse(self::ACTION_PROCESS);
}

public static function refunded(): ResponseInterface
{
return self::createStatusResponse('refunded');
return self::createStatusResponse(self::ACTION_REFUND);
}

public static function reminded(): ResponseInterface
{
return self::createStatusResponse('reminded');
return self::createStatusResponse(self::ACTION_REMIND);
}

public static function chargeback(): ResponseInterface
{
return self::createStatusResponse('chargeback');
return self::createStatusResponse(self::ACTION_CHARGEBACK);
}

public static function reopen(): ResponseInterface
{
return self::createStatusResponse(self::ACTION_REOPEN);
}

private static function createStatusResponse(string $status, string $message = ''): ResponseInterface
public static function createStatusResponse(string $status, string $message = ''): ResponseInterface

Check warning on line 92 in src/Response/PaymentResponse.php

View workflow job for this annotation

GitHub Actions / unit

Escaped Mutant for Mutator "PublicVisibility": --- Original +++ New @@ @@ { return self::createStatusResponse(self::ACTION_REOPEN); } - public static function createStatusResponse(string $status, string $message = '') : ResponseInterface + protected static function createStatusResponse(string $status, string $message = '') : ResponseInterface { return self::createResponse(array_filter(['status' => $status, 'message' => $message])); }
{
return self::createResponse(array_filter(['status' => $status, 'message' => $message]));
}
Expand Down
16 changes: 11 additions & 5 deletions src/Response/RefundResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,35 @@

class RefundResponse
{
public const ACTION_CANCEL = 'cancel';
public const ACTION_COMPLETE = 'complete';
public const ACTION_FAIL = 'fail';
public const ACTION_PROCESS = 'process';
public const ACTION_REOPEN = 'reopen';

public static function open(): ResponseInterface
{
return self::createStatusResponse('open');
return self::createStatusResponse(self::ACTION_REOPEN);
}

public static function inProgress(): ResponseInterface
{
return self::createStatusResponse('in_progress');
return self::createStatusResponse(self::ACTION_PROCESS);
}

public static function cancelled(): ResponseInterface
{
return self::createStatusResponse('cancelled');
return self::createStatusResponse(self::ACTION_CANCEL);
}

public static function failed(): ResponseInterface
{
return self::createStatusResponse('failed');
return self::createStatusResponse(self::ACTION_FAIL);
}

public static function completed(): ResponseInterface
{
return self::createStatusResponse('completed');
return self::createStatusResponse(self::ACTION_COMPLETE);
}

private static function createStatusResponse(string $status): ResponseInterface
Expand Down
12 changes: 6 additions & 6 deletions tests/Response/PaymentResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function testCancelled(): void
$response = PaymentResponse::cancelled();

static::assertSame(200, $response->getStatusCode());
static::assertSame('{"status":"cancelled"}', $response->getBody()->getContents());
static::assertSame('{"status":"cancel"}', $response->getBody()->getContents());
}

public function testFailed(): void
{
$response = PaymentResponse::failed();

static::assertSame(200, $response->getStatusCode());
static::assertSame('{"status":"failed"}', $response->getBody()->getContents());
static::assertSame('{"status":"fail"}', $response->getBody()->getContents());
}

public function testAuthorize(): void
Expand All @@ -56,31 +56,31 @@ public function testUnconfirmed(): void
$response = PaymentResponse::unconfirmed();

static::assertSame(200, $response->getStatusCode());
static::assertSame('{"status":"unconfirmed"}', $response->getBody()->getContents());
static::assertSame('{"status":"process_unconfirmed"}', $response->getBody()->getContents());
}

public function testInProgress(): void
{
$response = PaymentResponse::inProgress();

static::assertSame(200, $response->getStatusCode());
static::assertSame('{"status":"in_progress"}', $response->getBody()->getContents());
static::assertSame('{"status":"process"}', $response->getBody()->getContents());
}

public function testRefunded(): void
{
$response = PaymentResponse::refunded();

static::assertSame(200, $response->getStatusCode());
static::assertSame('{"status":"refunded"}', $response->getBody()->getContents());
static::assertSame('{"status":"refund"}', $response->getBody()->getContents());
}

public function testReminded(): void
{
$response = PaymentResponse::reminded();

static::assertSame(200, $response->getStatusCode());
static::assertSame('{"status":"reminded"}', $response->getBody()->getContents());
static::assertSame('{"status":"remind"}', $response->getBody()->getContents());
}

public function testChargeback(): void
Expand Down
10 changes: 5 additions & 5 deletions tests/Response/RefundResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testOpen(): void

static::assertSame(200, $response->getStatusCode());
static::assertSame('application/json', $response->getHeaderLine('Content-Type'));
static::assertSame('{"status":"open"}', $response->getBody()->getContents());
static::assertSame('{"status":"reopen"}', $response->getBody()->getContents());
}

public function testInProgress(): void
Expand All @@ -26,7 +26,7 @@ public function testInProgress(): void

static::assertSame(200, $response->getStatusCode());
static::assertSame('application/json', $response->getHeaderLine('Content-Type'));
static::assertSame('{"status":"in_progress"}', $response->getBody()->getContents());
static::assertSame('{"status":"process"}', $response->getBody()->getContents());
}

public function testCancelled(): void
Expand All @@ -35,7 +35,7 @@ public function testCancelled(): void

static::assertSame(200, $response->getStatusCode());
static::assertSame('application/json', $response->getHeaderLine('Content-Type'));
static::assertSame('{"status":"cancelled"}', $response->getBody()->getContents());
static::assertSame('{"status":"cancel"}', $response->getBody()->getContents());
}

public function testFailed(): void
Expand All @@ -44,7 +44,7 @@ public function testFailed(): void

static::assertSame(200, $response->getStatusCode());
static::assertSame('application/json', $response->getHeaderLine('Content-Type'));
static::assertSame('{"status":"failed"}', $response->getBody()->getContents());
static::assertSame('{"status":"fail"}', $response->getBody()->getContents());
}

public function testCompleted(): void
Expand All @@ -53,6 +53,6 @@ public function testCompleted(): void

static::assertSame(200, $response->getStatusCode());
static::assertSame('application/json', $response->getHeaderLine('Content-Type'));
static::assertSame('{"status":"completed"}', $response->getBody()->getContents());
static::assertSame('{"status":"complete"}', $response->getBody()->getContents());
}
}

0 comments on commit 11b31ae

Please sign in to comment.