Skip to content

Commit

Permalink
Fix partial capture (#85)
Browse files Browse the repository at this point in the history
* Fix partial capture of payment
Add items as required param in captured payment

* Modify test
  • Loading branch information
zingon authored May 6, 2021
1 parent 74c5166 commit 87a32c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/Service/PaymentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,21 @@ public function refundPayment($id, float $amount, ?array $items = null, ?array $
}

/**
* @param int|float $id
* @param int|float $id
* @param float|null $amount
* @param mixed[]|null $items
*/
public function capturePayment($id, ?float $amount = null): Response
public function capturePayment($id, ?float $amount = null, ?array $items = null): Response
{
$data = [];

if ($amount !== null) {
$data['amount'] = round($amount * 100);
if ($amount === null || $items === null) {
return $this->makeRequest('POST', 'payments/payment/' . $id . '/capture');
}

$data = array_merge(
['amount' => round($amount * 100)],
['items' => $items]
);

return $this->makeRequest('POST', 'payments/payment/' . $id . '/capture', $data);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/cases/unit/Service/PaymentService.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ test(function (): void {
->makePartial()
->shouldAllowMockingProtectedMethods();
$service->shouldReceive('makeRequest')
->with('POST', 'payments/payment/10001/capture', ['amount' => 3150.])
->with('POST', 'payments/payment/10001/capture')
->andReturn($response);

Assert::type(Response::class, $service->capturePayment(10001, 31.5));
Assert::type(Response::class, $service->capturePayment(10001));
});

0 comments on commit 87a32c0

Please sign in to comment.