Skip to content

Commit

Permalink
PreAuthorized: added capture payment
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jul 6, 2016
1 parent 8600d34 commit c580738
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/Gopay/Service/PreAuthorizedPaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
39 changes: 38 additions & 1 deletion tests/cases/unit/Service/PreAuthorizedPaymentService.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class PreAuthorizedPaymentServiceTest extends BasePaymentTestCase
$gopay->getSoap()->mockery_verify();
}


public function testCancelRecurrent()
{
$gopay = $this->createGopay();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c580738

Please sign in to comment.