From 342bcfd7b23b8131028ecc3d8bba4e8d7c7e5f50 Mon Sep 17 00:00:00 2001 From: Rokas Simonavicius Date: Thu, 16 Feb 2023 10:43:24 +0200 Subject: [PATCH] Added amount to be captured for /payment-requests/{paymentRequestId}/capture endpoint --- CHANGELOG.md | 4 +++ src/CheckoutClient.php | 5 ++-- src/Entity/CaptureParameters.php | 44 ++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/Entity/CaptureParameters.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c10e9ff..627449a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.0 - 2023-02-16 +### Added +- Amount to be captured for `/payment-requests/{paymentRequestId}/capture` endpoint + ## 2.1.0 - 2020-12-04 ### Changed - evp/money version increased up to ^2.0 diff --git a/src/CheckoutClient.php b/src/CheckoutClient.php index 2ebb720..7e31d2c 100644 --- a/src/CheckoutClient.php +++ b/src/CheckoutClient.php @@ -6,7 +6,6 @@ use Fig\Http\Message\RequestMethodInterface; use Paysera\Component\RestClientCommon\Client\ApiClient; use Paysera\Component\RestClientCommon\Entity\Filter; -use Evp\Component\Money\Money; class CheckoutClient { @@ -147,12 +146,12 @@ public function authorizePaymentRequest($id, Entities\AuthorizationParameters $a * @param string $id * @return Entities\PaymentRequest */ - public function capturePaymentRequest($id) + public function capturePaymentRequest($id, Entities\CaptureParameters $captureParameters = null) { $request = $this->apiClient->createRequest( RequestMethodInterface::METHOD_PUT, sprintf('payment-requests/%s/capture', urlencode($id)), - null + $captureParameters ); $data = $this->apiClient->makeRequest($request); diff --git a/src/Entity/CaptureParameters.php b/src/Entity/CaptureParameters.php new file mode 100644 index 0000000..94590de --- /dev/null +++ b/src/Entity/CaptureParameters.php @@ -0,0 +1,44 @@ +get('capture_amount') !== null + ? new Money($this->get('capture_amount')['amount'], $this->get('capture_amount')['currency']) + : null + ; + } + + /** + * @param Money|null $captureAmount + * + * @return self + */ + public function setCaptureAmount(Money $captureAmount = null) + { + if ($captureAmount === null) { + $this->set('capture_amount', null); + } else { + $this->set('capture_amount', [ + 'amount' => $captureAmount->getAmount(), + 'currency' => $captureAmount->getCurrency() + ]); + } + + return $this; + } +}