diff --git a/src/Message/Response.php b/src/Message/Response.php index 085b00b..8be4967 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -12,19 +12,34 @@ public function isSuccessful() public function getTransactionReference() { - return (isset($this->data['id'])) ? $this->data['id'] : null; + return isset($this->data['id']) ? $this->data['id'] : null; + } + + public function getType() + { + return isset($this->data['type']) ? $this->data['type'] : null; } public function getOrderNumber() { - return (isset($this->data['order_number'])) ? $this->data['order_number'] : null; + return isset($this->data['order_number']) ? $this->data['order_number'] : null; } - public function getMessage() + public function getMessageId() { return isset($this->data['message_id']) ? $this->data['message_id'] : null; } + public function getMessage() + { + return isset($this->data['message']) ? $this->data['message'] : null; + } + + public function getAuthCode() + { + return isset($this->data['auth_code']) ? $this->data['auth_code'] : null; + } + public function getCode() { return isset($this->data['code']) ? $this->data['code'] : null; @@ -34,4 +49,14 @@ public function getCard() { return isset($this->data['card']) ? $this->data['card'] : null; } + + public function getReference() + { + return isset($this->data['reference']) ? $this->data['reference'] : null; + } + + public function getCategory() + { + return isset($this->data['category']) ? $this->data['category'] : null; + } } diff --git a/tests/Message/AuthorizeRequestTest.php b/tests/Message/AuthorizeRequestTest.php index 84e8ac8..3c966d2 100644 --- a/tests/Message/AuthorizeRequestTest.php +++ b/tests/Message/AuthorizeRequestTest.php @@ -17,6 +17,47 @@ public function testEndpoint() $this->assertSame('https://www.beanstream.com/api/v1/payments', $this->request->getEndpoint()); } + public function testSendSuccess() + { + $this->request->setAmount('10.00'); + $this->setMockHttpResponse('AuthorizeSuccess.txt'); + $response = $this->request->send(); + $this->assertTrue($response->isSuccessful()); + $this->assertSame('1000001', $response->getTransactionReference()); + $this->assertSame('1', $response->getOrderNumber()); + $this->assertSame('Approved', $response->getMessage()); + $this->assertSame('1', $response->getMessageId()); + $this->assertSame('TEST', $response->getAuthCode()); + $this->assertSame('PA', $response->getType()); + $this->assertNull($response->getCode()); + $responseCard = $response->getCard(); + $this->assertNotEmpty($responseCard); + $this->assertSame('VI', $responseCard['card_type']); + $this->assertSame('1234', $responseCard['last_four']); + $this->assertSame(0, $responseCard['cvd_match']); + $this->assertSame(0, $responseCard['address_match']); + $this->assertSame(0, $responseCard['postal_result']); + } + + public function testSendError() + { + $this->request->setAmount('10.00'); + $this->setMockHttpResponse('AuthorizeFailure.txt'); + $response = $this->request->send(); + $this->assertSame(49, $response->getCode()); + $this->assertSame(3, $response->getCategory()); + $this->assertSame('Invalid transaction request string', $response->getMessage()); + $this->assertSame('https://www.beanstream.com/docs/errors#49', $response->getReference()); + $this->assertFalse($response->isSuccessful()); + $this->assertNull($response->getTransactionReference()); + $this->assertNull($response->getOrderNumber()); + $this->assertNull($response->getType()); + $this->assertNull($response->getMessageId()); + $this->assertNull($response->getAuthCode()); + $responseCard = $response->getCard(); + $this->assertEmpty($responseCard); + } + public function testMerchantId() { $this->assertSame($this->request, $this->request->setMerchantId('123')); diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 049ec0e..1d1fcef 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -17,6 +17,47 @@ public function testEndpoint() $this->assertSame('https://www.beanstream.com/api/v1/payments', $this->request->getEndpoint()); } + public function testSendSuccess() + { + $this->request->setAmount('10.00'); + $this->setMockHttpResponse('PurchaseSuccess.txt'); + $response = $this->request->send(); + $this->assertTrue($response->isSuccessful()); + $this->assertSame('1000001', $response->getTransactionReference()); + $this->assertSame('1', $response->getOrderNumber()); + $this->assertSame('Approved', $response->getMessage()); + $this->assertSame('1', $response->getMessageId()); + $this->assertSame('TEST', $response->getAuthCode()); + $this->assertSame('P', $response->getType()); + $this->assertNull($response->getCode()); + $responseCard = $response->getCard(); + $this->assertNotEmpty($responseCard); + $this->assertSame('VI', $responseCard['card_type']); + $this->assertSame('1234', $responseCard['last_four']); + $this->assertSame(0, $responseCard['cvd_match']); + $this->assertSame(0, $responseCard['address_match']); + $this->assertSame(0, $responseCard['postal_result']); + } + + public function testSendError() + { + $this->request->setAmount('10.00'); + $this->setMockHttpResponse('PurchaseFailure.txt'); + $response = $this->request->send(); + $this->assertSame(49, $response->getCode()); + $this->assertSame(3, $response->getCategory()); + $this->assertSame('Invalid transaction request string', $response->getMessage()); + $this->assertSame('https://www.beanstream.com/docs/errors#49', $response->getReference()); + $this->assertFalse($response->isSuccessful()); + $this->assertNull($response->getTransactionReference()); + $this->assertNull($response->getOrderNumber()); + $this->assertNull($response->getType()); + $this->assertNull($response->getMessageId()); + $this->assertNull($response->getAuthCode()); + $responseCard = $response->getCard(); + $this->assertEmpty($responseCard); + } + public function testMerchantId() { $this->assertSame($this->request, $this->request->setMerchantId('123')); diff --git a/tests/Message/ResponseTest.php b/tests/Message/ResponseTest.php new file mode 100644 index 0000000..1181e6f --- /dev/null +++ b/tests/Message/ResponseTest.php @@ -0,0 +1,86 @@ +getMockHttpResponse('PurchaseSuccess.txt'); + $response = new Response($this->getMockRequest(), $httpResponse->json()); + $this->assertTrue($response->isSuccessful()); + $this->assertSame('1000001', $response->getTransactionReference()); + $this->assertSame('1', $response->getOrderNumber()); + $this->assertSame('Approved', $response->getMessage()); + $this->assertSame('1', $response->getMessageId()); + $this->assertSame('TEST', $response->getAuthCode()); + $this->assertSame('P', $response->getType()); + $this->assertNull($response->getCode()); + $responseCard = $response->getCard(); + $this->assertNotEmpty($responseCard); + $this->assertSame('VI', $responseCard['card_type']); + $this->assertSame('1234', $responseCard['last_four']); + $this->assertSame(0, $responseCard['cvd_match']); + $this->assertSame(0, $responseCard['address_match']); + $this->assertSame(0, $responseCard['postal_result']); + } + + public function testPurchaseFailure() + { + $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); + $response = new Response($this->getMockRequest(), $httpResponse->json()); + $this->assertSame(49, $response->getCode()); + $this->assertSame(3, $response->getCategory()); + $this->assertSame('Invalid transaction request string', $response->getMessage()); + $this->assertSame('https://www.beanstream.com/docs/errors#49', $response->getReference()); + $this->assertFalse($response->isSuccessful()); + $this->assertNull($response->getTransactionReference()); + $this->assertNull($response->getOrderNumber()); + $this->assertNull($response->getType()); + $this->assertNull($response->getMessageId()); + $this->assertNull($response->getAuthCode()); + $responseCard = $response->getCard(); + $this->assertEmpty($responseCard); + } + + public function testAuthorizeSuccess() + { + $httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt'); + $response = new Response($this->getMockRequest(), $httpResponse->json()); + $this->assertTrue($response->isSuccessful()); + $this->assertSame('1000001', $response->getTransactionReference()); + $this->assertSame('1', $response->getOrderNumber()); + $this->assertSame('Approved', $response->getMessage()); + $this->assertSame('1', $response->getMessageId()); + $this->assertSame('TEST', $response->getAuthCode()); + $this->assertSame('PA', $response->getType()); + $this->assertNull($response->getCode()); + $responseCard = $response->getCard(); + $this->assertNotEmpty($responseCard); + $this->assertSame('VI', $responseCard['card_type']); + $this->assertSame('1234', $responseCard['last_four']); + $this->assertSame(0, $responseCard['cvd_match']); + $this->assertSame(0, $responseCard['address_match']); + $this->assertSame(0, $responseCard['postal_result']); + } + + public function testAuthorizeFailure() + { + $httpResponse = $this->getMockHttpResponse('AuthorizeFailure.txt'); + $response = new Response($this->getMockRequest(), $httpResponse->json()); + $this->assertSame(49, $response->getCode()); + $this->assertSame(3, $response->getCategory()); + $this->assertSame('Invalid transaction request string', $response->getMessage()); + $this->assertSame('https://www.beanstream.com/docs/errors#49', $response->getReference()); + $this->assertFalse($response->isSuccessful()); + $this->assertNull($response->getTransactionReference()); + $this->assertNull($response->getOrderNumber()); + $this->assertNull($response->getType()); + $this->assertNull($response->getMessageId()); + $this->assertNull($response->getAuthCode()); + $responseCard = $response->getCard(); + $this->assertEmpty($responseCard); + } +} diff --git a/tests/Mock/AuthorizeFailure.txt b/tests/Mock/AuthorizeFailure.txt new file mode 100644 index 0000000..6bf36ce --- /dev/null +++ b/tests/Mock/AuthorizeFailure.txt @@ -0,0 +1,9 @@ +HTTP/1.1 400 Bad Request +Content-Type: application/json + +{ + "code":49, + "category":3, + "message":"Invalid transaction request string", + "reference":"https://www.beanstream.com/docs/errors#49" +} diff --git a/tests/Mock/AuthorizeSuccess.txt b/tests/Mock/AuthorizeSuccess.txt new file mode 100644 index 0000000..7313032 --- /dev/null +++ b/tests/Mock/AuthorizeSuccess.txt @@ -0,0 +1,38 @@ +HTTP/1.1 200 OK +Access-Control-Allow-Headers: accept, origin, content-type +Access-Control-Allow-Origin: * +Cache-Control: no-cache +Content-Length: 477 +Content-Type: application/json; charset=utf-8 +Date: Thu, 24 Mar 2016 18:04:30 GMT +Expires: -1 +Pragma: no-cache +Server: Microsoft-IIS/8.5 +X-AspNet-Version: 4.0.30319 +X-Powered-By: ASP.NET + +{ + "id": "1000001", + "approved": "1", + "message_id": "1", + "message": "Approved", + "auth_code": "TEST", + "created": "2016-03-24T11:04:30", + "order_number": "1", + "type": "PA", + "payment_method": "CC", + "card": { + "card_type": "VI", + "last_four": "1234", + "cvd_match": 0, + "address_match": 0, + "postal_result": 0 + }, + "links": [ + { + "rel": "complete", + "href": "https://www.beanstream.com/api/v1/payments/1000001/completions", + "method": "POST" + } + ] +} diff --git a/tests/Mock/PurchaseFailure.txt b/tests/Mock/PurchaseFailure.txt new file mode 100644 index 0000000..6bf36ce --- /dev/null +++ b/tests/Mock/PurchaseFailure.txt @@ -0,0 +1,9 @@ +HTTP/1.1 400 Bad Request +Content-Type: application/json + +{ + "code":49, + "category":3, + "message":"Invalid transaction request string", + "reference":"https://www.beanstream.com/docs/errors#49" +} diff --git a/tests/Mock/PurchaseSuccess.txt b/tests/Mock/PurchaseSuccess.txt new file mode 100644 index 0000000..b0d2228 --- /dev/null +++ b/tests/Mock/PurchaseSuccess.txt @@ -0,0 +1,43 @@ +HTTP/1.1 200 OK +Access-Control-Allow-Headers: accept, origin, content-type +Access-Control-Allow-Origin: * +Cache-Control: no-cache +Content-Length: 477 +Content-Type: application/json; charset=utf-8 +Date: Thu, 24 Mar 2016 18:04:30 GMT +Expires: -1 +Pragma: no-cache +Server: Microsoft-IIS/8.5 +X-AspNet-Version: 4.0.30319 +X-Powered-By: ASP.NET + +{ + "id": "1000001", + "approved": "1", + "message_id": "1", + "message": "Approved", + "auth_code": "TEST", + "created": "2016-03-24T11:04:30", + "order_number": "1", + "type": "P", + "payment_method": "CC", + "card": { + "card_type": "VI", + "last_four": "1234", + "cvd_match": 0, + "address_match": 0, + "postal_result": 0 + }, + "links": [ + { + "rel": "void", + "href": "https://www.beanstream.com/api/v1/payments/1000001/void", + "method": "POST" + }, + { + "rel": "return", + "href": "https://www.beanstream.com/api/v1/payments/1000001/returns", + "method": "POST" + } + ] +}