Skip to content

Commit 2b0dc30

Browse files
committed
Add support for hosted purchases being in 'pending' state (WIP)
1 parent ee1a50f commit 2b0dc30

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Message/CompletePurchaseResponse.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
*/
1010
class CompletePurchaseResponse extends AbstractResponse
1111
{
12+
/**
13+
* Is the response pending?
14+
*
15+
* @return boolean
16+
*/
17+
public function isPending()
18+
{
19+
return $this->data->createdPaymentOutput->payment->statusOutput->statusCategory == 'PENDING_PAYMENT';
20+
}
21+
1222
/**
1323
* Is the response successful?
1424
*
@@ -46,6 +56,7 @@ public function getMessage()
4656
*/
4757
public function getCardReference()
4858
{
49-
return $this->data->createdPaymentOutput->payment->paymentOutput->cardPaymentMethodSpecificOutput->token ?? null;
59+
return $this->data->createdPaymentOutput->payment->paymentOutput->cardPaymentMethodSpecificOutput->token
60+
?? null;
5061
}
5162
}

tests/GatewayTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,31 @@ public function testCompletePurchaseSuccess()
5353

5454
$response = $this->gateway->completePurchase($options)->send();
5555

56+
$this->assertFalse($response->isPending());
5657
$this->assertTrue($response->isSuccessful());
5758
$this->assertFalse($response->isRedirect());
5859
$this->assertSame('1234567890_0', $response->getTransactionReference());
5960
$this->assertSame('PENDING_CAPTURE', $response->getMessage());
6061
$this->assertSame('12345678-90ab-cdef-1234-567890abcdef', $response->getCardReference());
6162
}
6263

64+
public function testCompletePurchasePending()
65+
{
66+
// @todo - make mock response
67+
$this->setMockHttpResponse('HostedCompletePurchasePending.txt');
68+
69+
$options = array_merge($this->options, ['hostedCheckoutId' => '0000000001']);
70+
71+
$response = $this->gateway->completePurchase($options)->send();
72+
73+
$this->assertTrue($response->isPending());
74+
$this->assertFalse($response->isSuccessful());
75+
$this->assertFalse($response->isRedirect());
76+
$this->assertSame('1234567890_0', $response->getTransactionReference());
77+
$this->assertSame('REDIRECTED', $response->getMessage());
78+
$this->assertSame('12345678-90ab-cdef-1234-567890abcdef', $response->getCardReference());
79+
}
80+
6381
public function testCompletePurchaseFailure()
6482
{
6583
$this->setMockHttpResponse('HostedCompletePurchaseFailure.txt');
@@ -68,6 +86,7 @@ public function testCompletePurchaseFailure()
6886

6987
$response = $this->gateway->completePurchase($options)->send();
7088

89+
$this->assertFalse($response->isPending());
7190
$this->assertFalse($response->isSuccessful());
7291
$this->assertFalse($response->isRedirect());
7392
$this->assertSame('1234567890_0', $response->getTransactionReference());

0 commit comments

Comments
 (0)