Skip to content

Commit

Permalink
Merge pull request #7 from ruudk/fix-500-error-handling
Browse files Browse the repository at this point in the history
Handle 503 'Service Temporaily Unavailable' errors
  • Loading branch information
greydnls committed Oct 7, 2014
2 parents 4d49e56 + d28cd64 commit 646a35b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function sendRequest($method, $endpoint, $data = null)
*/
$response = $event['response'];

if ($response->isClientError()) {
if ($response->isError()) {
$event->stopPropagation();
}
});
Expand Down
28 changes: 28 additions & 0 deletions tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,32 @@ public function testSendFailure()
$this->assertNull($response->getRedirectData());
$this->assertSame("The issuer is invalid", $response->getMessage());
}

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

$this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response);
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getRedirectUrl());
$this->assertNull($response->getRedirectData());
$this->assertSame("Issuer failure", $response->getMessage());
}

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

$this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response);
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getRedirectUrl());
$this->assertNull($response->getRedirectData());
$this->assertSame("Payment platform for this payment method temporarily not available", $response->getMessage());
}
}
19 changes: 19 additions & 0 deletions tests/Mock/PurchaseIssuerFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
HTTP/1.1 503 Service Temporarily Unavailable
Server: nginx/1.4.4
Date: Mon, 20 Jan 2014 10:19:39 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 101
Connection: keep-alive
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Max-Age: 300
Cache-Control: no-cache, no-store
Strict-Transport-Security: max-age=31556926; includeSubDomains

{
"error":{
"type":"system",
"message":"Issuer failure",
"field":"issuer"
}
}
18 changes: 18 additions & 0 deletions tests/Mock/PurchaseSystemFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
HTTP/1.1 503 Service Temporarily Unavailable
Server: nginx/1.4.4
Date: Mon, 20 Jan 2014 10:19:39 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 101
Connection: keep-alive
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Max-Age: 300
Cache-Control: no-cache, no-store
Strict-Transport-Security: max-age=31556926; includeSubDomains

{
"error":{
"type":"system",
"message":"Payment platform for this payment method temporarily not available"
}
}

0 comments on commit 646a35b

Please sign in to comment.