diff --git a/composer.json b/composer.json index d42a310..6a8a625 100755 --- a/composer.json +++ b/composer.json @@ -6,8 +6,9 @@ "require": { "php": ">=7.4|^8.0", "ext-json": "*", - "marc-mabe/php-enum": "^4.3", "guzzlehttp/guzzle": "^6.0|^7.0", + "marc-mabe/php-enum": "^4.3", + "symfony/property-access": "^5.4|^6.0|^6.4", "symfony/serializer": "^5.4|^6.0" }, "require-dev": { diff --git a/src/PayPo/Request/Transaction/CancelRequest.php b/src/PayPo/Request/Transaction/CancelRequest.php new file mode 100644 index 0000000..639ad15 --- /dev/null +++ b/src/PayPo/Request/Transaction/CancelRequest.php @@ -0,0 +1,32 @@ +status = OrderStatusEnum::CANCELED; + $this->transactionUuid = $transactionUuid; + } + + public function getHttpMethod(): string + { + return self::HTTP_METHOD; + } + + public function getUrl(): string + { + return self::ENDPOINT . '/' . $this->transactionUuid; + } +} diff --git a/src/PayPo/Service/Order.php b/src/PayPo/Service/Order.php index f3bcb26..d9b042d 100644 --- a/src/PayPo/Service/Order.php +++ b/src/PayPo/Service/Order.php @@ -7,6 +7,7 @@ use Answear\PayPo\Exception\BadResponseException; use Answear\PayPo\Exception\PrepareRequestException; use Answear\PayPo\Exception\ServiceUnavailable; +use Answear\PayPo\Request\Transaction\CancelRequest; use Answear\PayPo\Request\Transaction\ConfirmRequest; use Answear\PayPo\Request\Transaction\CreateRequest; use Answear\PayPo\Request\Transaction\RefundRequest; @@ -89,6 +90,18 @@ public function refund(string $transactionUuid, int $amount): Response return $this->handleRequest($request, Response::class); } + /** + * @throws ServiceUnavailable + * @throws PrepareRequestException + * @throws BadResponseException + */ + public function cancel(string $transactionUuid): ConfirmResponse + { + $request = new CancelRequest($transactionUuid); + + return $this->handleRequest($request, ConfirmResponse::class); + } + /** * @return object|mixed * diff --git a/tests/Integration/Request/Transaction/CancelTest.php b/tests/Integration/Request/Transaction/CancelTest.php new file mode 100644 index 0000000..f7abd58 --- /dev/null +++ b/tests/Integration/Request/Transaction/CancelTest.php @@ -0,0 +1,54 @@ +expectException(ConfigurationException::class); + + $client = $this->createMock(Client::class); + $this->getOrderService(new PayPoClient($client))->cancel($transactionUuid); + } + + public function provideDataForRequest(): iterable + { + $this->setUpConfiguration(); + + yield [ + self::TRANSACTION_UUID, + '{"status":"CANCELED"}', + [ + 'code' => '200', + 'statusDescription' => 'Transaction updated successfully', + ], + ]; + } + + protected function sendAndAssert(PayPoClient $client, $request, array $apiResponse): void + { + self::assertSame(self::TRANSACTION_UUID, $request); + + $response = $this->getOrderService($client)->cancel($request); + + self::assertSame($apiResponse['code'], $response->code); + self::assertSame($apiResponse['statusDescription'], $response->statusDescription); + } +}