Skip to content

Commit

Permalink
Added amount to be captured for /payment-requests/{paymentRequestId}/…
Browse files Browse the repository at this point in the history
…capture endpoint
  • Loading branch information
rokas-simonavicius authored and pelanis committed Feb 23, 2023
1 parent 185a822 commit 342bcfd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/CheckoutClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand Down
44 changes: 44 additions & 0 deletions src/Entity/CaptureParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Paysera\Client\CheckoutClient\Entity;

use Evp\Component\Money\Money;
use Paysera\Component\RestClientCommon\Entity\Entity;

class CaptureParameters extends Entity
{
public function __construct(array $data = [])
{
parent::__construct($data);
}

/**
* @return Money|null
*/
public function getCaptureAmount()
{
return $this->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;
}
}

0 comments on commit 342bcfd

Please sign in to comment.