From d28cd64ba86b45d7e08c60ec442a24fafe612ff6 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Wed, 23 Jul 2014 12:28:22 +0200 Subject: [PATCH] Handle 503 'Service Temporaily Unavailable' errors --- src/Message/AbstractRequest.php | 2 +- tests/Message/PurchaseRequestTest.php | 28 +++++++++++++++++++++++++++ tests/Mock/PurchaseIssuerFailure.txt | 19 ++++++++++++++++++ tests/Mock/PurchaseSystemFailure.txt | 18 +++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/Mock/PurchaseIssuerFailure.txt create mode 100644 tests/Mock/PurchaseSystemFailure.txt diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 4ce6e4a..529f7c6 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -26,7 +26,7 @@ protected function sendRequest($method, $endpoint, $data = null) */ $response = $event['response']; - if ($response->isClientError()) { + if ($response->isError()) { $event->stopPropagation(); } }); diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index f659c9c..7a980d1 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -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()); + } } diff --git a/tests/Mock/PurchaseIssuerFailure.txt b/tests/Mock/PurchaseIssuerFailure.txt new file mode 100644 index 0000000..4c34eeb --- /dev/null +++ b/tests/Mock/PurchaseIssuerFailure.txt @@ -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" + } +} diff --git a/tests/Mock/PurchaseSystemFailure.txt b/tests/Mock/PurchaseSystemFailure.txt new file mode 100644 index 0000000..3de75a8 --- /dev/null +++ b/tests/Mock/PurchaseSystemFailure.txt @@ -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" + } +}