Skip to content

Commit

Permalink
Fix CompletePurchase response always returning success
Browse files Browse the repository at this point in the history
  • Loading branch information
amacneil committed Dec 22, 2013
1 parent 5c59146 commit a175c9d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/Omnipay/Mollie/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ public function isSuccessful()
return false;
}

return 'error' !== (string) $this->data->item['type'];
if (isset($this->data->item)) {
return 'error' !== (string) $this->data->item['type'];
} elseif (isset($this->data->order->status)) {
return 'Success' === (string) $this->data->order->status;
}

return true;
}

public function isRedirect()
Expand Down Expand Up @@ -63,6 +69,8 @@ public function getCode()
{
if (isset($this->data->item)) {
return (string) $this->data->item->errorcode;
} elseif (isset($this->data->order->status)) {
return (string) $this->data->order->status;
}
}

Expand Down
28 changes: 23 additions & 5 deletions tests/Omnipay/Mollie/Message/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ public function testGetData()
$this->assertSame('abc123', $data['transaction_id']);
}

/*
* We need a Mollie test account to record some responses to completePurchase()
* and test CompletePurchaseRequest::send()
* Pull requests welcome!
*/
public function testSendSuccess()
{
$this->setMockHttpResponse('CompletePurchaseSuccess.txt');
$response = $this->request->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('3be9b120ea75fe6807571f5f649cad6d', $response->getTransactionReference());
$this->assertSame('This iDEAL-order has successfuly been payed for, and this is the first time you check it.', $response->getMessage());
$this->assertSame('Success', $response->getCode());
}

public function testSendFailure()
{
$this->setMockHttpResponse('CompletePurchaseFailure.txt');
$response = $this->request->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('d0feefce2a1ae5a05d24a10d364bc281', $response->getTransactionReference());
$this->assertSame('This iDEAL-order wasn\'t payed for, or was already checked by you. (We give payed=true only once, for your protection)', $response->getMessage());
$this->assertSame('CheckedBefore', $response->getCode());
}
}
19 changes: 19 additions & 0 deletions tests/Omnipay/Mollie/Mock/CompletePurchaseFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
HTTP/1.1 200 OK
Server: nginx/1.4.4
Date: Sat, 21 Dec 2013 23:22:46 GMT
Content-Type: text/xml
Content-Length: 393
Connection: keep-alive
Vary: Accept-Encoding

<?xml version="1.0"?>
<response>
<order>
<transaction_id>d0feefce2a1ae5a05d24a10d364bc281</transaction_id>
<amount>40150</amount>
<currency>EUR</currency>
<payed>false</payed>
<message>This iDEAL-order wasn't payed for, or was already checked by you. (We give payed=true only once, for your protection)</message>
<status>CheckedBefore</status>
</order>
</response>
24 changes: 24 additions & 0 deletions tests/Omnipay/Mollie/Mock/CompletePurchaseSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
HTTP/1.1 200 OK
Server: nginx/1.4.4
Date: Sat, 21 Dec 2013 23:36:50 GMT
Content-Type: text/xml
Content-Length: 540
Connection: keep-alive
Vary: Accept-Encoding

<?xml version="1.0"?>
<response>
<order>
<transaction_id>3be9b120ea75fe6807571f5f649cad6d</transaction_id>
<amount>40150</amount>
<currency>EUR</currency>
<payed>true</payed>
<message>This iDEAL-order has successfuly been payed for, and this is the first time you check it.</message>
<status>Success</status>
<consumer>
<consumerName>T. TEST</consumerName>
<consumerAccount>NL17RABO0213698412</consumerAccount>
<consumerCity>NOT PROVIDED</consumerCity>
</consumer>
</order>
</response>

0 comments on commit a175c9d

Please sign in to comment.