diff --git a/src/Gopay/Service/PreAuthorizedPaymentService.php b/src/Gopay/Service/PreAuthorizedPaymentService.php index d4e28e0..8f21a37 100644 --- a/src/Gopay/Service/PreAuthorizedPaymentService.php +++ b/src/Gopay/Service/PreAuthorizedPaymentService.php @@ -77,6 +77,26 @@ public function payPreAuthorizedInline(PreAuthorizedPayment $payment, $channel, return $response; } + /** + * Capture pre authorized payment via GoPay gateway + * + * @param float $paymentSessionId + * @throws GopayException + * @return void + */ + public function capturePreAuthorized($paymentSessionId) + { + try { + $this->gopay->soap->capturePayment( + $paymentSessionId, + $this->gopay->config->getGopayId(), + $this->gopay->config->getGopaySecretKey() + ); + } catch (Exception $e) { + throw new GopayException($e->getMessage(), 0, $e); + } + } + /** * Cancel pre authorized payment via GoPay gateway * diff --git a/tests/cases/unit/Service/PreAuthorizedPaymentService.phpt b/tests/cases/unit/Service/PreAuthorizedPaymentService.phpt index e583f61..79fc440 100644 --- a/tests/cases/unit/Service/PreAuthorizedPaymentService.phpt +++ b/tests/cases/unit/Service/PreAuthorizedPaymentService.phpt @@ -92,7 +92,6 @@ class PreAuthorizedPaymentServiceTest extends BasePaymentTestCase $gopay->getSoap()->mockery_verify(); } - public function testCancelRecurrent() { $gopay = $this->createGopay(); @@ -130,6 +129,44 @@ class PreAuthorizedPaymentServiceTest extends BasePaymentTestCase $gopay->getSoap()->mockery_verify(); } + + public function testCaptureRecurrent() + { + $gopay = $this->createGopay(); + $service = new PreAuthorizedPaymentService($gopay); + $paymentSessionId = 3000000001; + + $gopay->getSoap() + ->shouldReceive('capturePayment') + ->once() + ->with(Mockery::mustBe($paymentSessionId), Mockery::type('float'), Mockery::type('string')) + ->andReturnUsing(function () { + Assert::truthy(TRUE); + }); + $service->capturePreAuthorized(3000000001); + + $gopay->getSoap()->mockery_verify(); + } + + public function testCaputreRecurrentException() + { + $gopay = $this->createGopay(); + $paymentSessionId = 3000000001; + $exmsg = "Fatal error during paying"; + $service = new PreAuthorizedPaymentService($gopay); + + $gopay->getSoap() + ->shouldReceive('capturePayment') + ->once() + ->with(Mockery::mustBe($paymentSessionId), Mockery::type('float'), Mockery::type('string')) + ->andThrow('Exception', $exmsg); + + Assert::throws(function () use ($service, $paymentSessionId) { + $service->capturePreAuthorized($paymentSessionId); + }, GopayException::class, $exmsg); + + $gopay->getSoap()->mockery_verify(); + } } $test = new PreAuthorizedPaymentServiceTest();