Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Context/Order/OrderTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ public function getOrder(): Order
\assert(\is_array($this->data['order']));
return new Order($this->data['order']);
}

/**
* @return array<mixed>
*/
public function getValidationData(): array
{
\assert(\is_array($this->data['validationData']));
return $this->data['validationData'];
}
}
14 changes: 14 additions & 0 deletions src/Response/PaymentResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,30 @@
return self::createStatusResponse(self::ACTION_REOPEN);
}

/**
* @param self::ACTION_* $status
*/
public static function createStatusResponse(string $status, string $message = ''): ResponseInterface
{
return self::createResponse(array_filter(['status' => $status, 'message' => $message]));
}

/**
* @deprecated tag:v5.0.0 - Will be removed and is replaced by {@see self::redirectUrl}
*/
public static function redirect(string $url): ResponseInterface
{
return self::createResponse(['redirectUrl' => $url]);
}

/**
* @param self::ACTION_* $status
*/
public static function redirectUrl(string $status, string $url): ResponseInterface
{
return self::createResponse(array_filter(['status' => $status, 'redirectUrl' => $url]));

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

View workflow job for this annotation

GitHub Actions / unit

Escaped Mutant for Mutator "UnwrapArrayFilter": @@ @@ */ public static function redirectUrl(string $status, string $url): ResponseInterface { - return self::createResponse(array_filter(['status' => $status, 'redirectUrl' => $url])); + return self::createResponse(['status' => $status, 'redirectUrl' => $url]); } /** * @param array<mixed> $data
}

/**
* @param array<mixed> $data
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/Context/Order/OrderTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function testConstruct(): void
'customFields' => [
'key' => 'value',
],
'validationData' => [
'key' => 'value'
]
]);

static::assertSame('transaction-id', $orderTransaction->getId());
Expand All @@ -39,5 +42,7 @@ public function testConstruct(): void
static::assertSame('order-id', $orderTransaction->getOrder()->getId());
static::assertArrayHasKey('key', $orderTransaction->getCustomFields());
static::assertSame('value', $orderTransaction->getCustomFields()['key']);
static::assertArrayHasKey('key', $orderTransaction->getValidationData());
static::assertSame('value', $orderTransaction->getValidationData()['key']);
}
}
11 changes: 11 additions & 0 deletions tests/Response/PaymentResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,22 @@ public function testValidateError(): void
static::assertSame('{"message":"error"}', $response->getBody()->getContents());
}

/**
* @deprecated tag:v5.0.0 - Will be removed
*/
public function testRedirect(): void
{
$response = PaymentResponse::redirect('https://example.com');

static::assertSame(200, $response->getStatusCode());
static::assertSame('{"redirectUrl":"https:\/\/example.com"}', $response->getBody()->getContents());
}

public function testRedirectUrl(): void
{
$response = PaymentResponse::redirectUrl(PaymentResponse::ACTION_PROCESS, 'https://example.com');

static::assertSame(200, $response->getStatusCode());
static::assertSame('{"status":"process","redirectUrl":"https:\/\/example.com"}', $response->getBody()->getContents());
}
}
Loading