From 08d23883b533117bba45ce42cdc2aba93c0b4c8f Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Wed, 1 Mar 2017 17:29:59 -0700 Subject: [PATCH 1/4] Implemented the refund and void functionality and created some tests for them. Still need to finish creating the tests. --- src/Gateway.php | 20 ++++++++ src/Message/RefundRequest.php | 35 ++++++++++++++ src/Message/VoidRequest.php | 36 +++++++++++++++ tests/GatewayTest.php | 33 +++++++++++++ tests/Message/RefundRequestTest.php | 72 +++++++++++++++++++++++++++++ tests/Mock/RefundFailure.txt | 9 ++++ tests/Mock/RefundSuccess.txt | 38 +++++++++++++++ 7 files changed, 243 insertions(+) create mode 100644 src/Message/RefundRequest.php create mode 100644 src/Message/VoidRequest.php create mode 100644 tests/Message/RefundRequestTest.php create mode 100644 tests/Mock/RefundFailure.txt create mode 100644 tests/Mock/RefundSuccess.txt diff --git a/src/Gateway.php b/src/Gateway.php index 9b345f3..6864a35 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -82,6 +82,26 @@ public function purchase(array $parameters = array()) return $this->createRequest('\Omnipay\Beanstream\Message\PurchaseRequest', $parameters); } + /** + * @param array $parameters + * + * @return \Omnipay\Beanstream\Message\RefundRequest + */ + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Beanstream\Message\RefundRequest', $parameters); + } + + /** + * @param array $parameters + * + * @return \Omnipay\Beanstream\Message\VoidReqeust + */ + public function void(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Beanstream\Message\VoidRequest', $parameters); + } + /** * @param array $parameters * @return \Omnipay\Beanstream\Message\CreateProfileRequest diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php new file mode 100644 index 0000000..3b17480 --- /dev/null +++ b/src/Message/RefundRequest.php @@ -0,0 +1,35 @@ +validate('amount', 'transactionReference'); + + return array( + 'amount'=>$this->getAmount(), + 'order_number'=>$this->getOrderNumber() + ); + } + + /** + * Get the endpoint for a Refund. This is overwriting the method so we can add the transaction reference dynamically + * + * @return string + */ + public function getEndpoint() + { + return $this->endpoint . '/payments/' . $this->getTransactionReference() . '/returns'; + } +} \ No newline at end of file diff --git a/src/Message/VoidRequest.php b/src/Message/VoidRequest.php new file mode 100644 index 0000000..421fc28 --- /dev/null +++ b/src/Message/VoidRequest.php @@ -0,0 +1,36 @@ +validate('amount', 'transactionReference'); + + return array( + 'amount'=>$this->getAmount() + ); + } + + /** + * Get the endpoint for a Void. This is overwriting the method so we can add the transaction reference dynamically + * + * @return string + */ + public function getEndpoint() + { + return $this->endpoint . '/payments/' . $this->getTransactionReference() . '/void'; + } +} \ No newline at end of file diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index d15aec3..97b0552 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -4,6 +4,9 @@ class GatewayTest extends GatewayTestCase { + /** @var Gateway */ + protected $gateway; + public function setUp() { parent::setUp(); @@ -181,4 +184,34 @@ public function testDeleteProfileCard() $this->assertSame(2, $request->getCardId()); $this->assertSame('DELETE', $request->getHttpMethod()); } + + public function testRefund() + { + $request = $this->gateway->refund( + array( + 'transactionReference'=>1, + 'amount'=> 10.00 + ) + ); + $this->assertInstanceOf('Omnipay\Beanstream\Message\RefundRequest', $request); + $this->assertSame(1, $request->getTransactionReference()); + $this->assertSame('10.00', $request->getAmount()); + $this->assertSame('POST', $request->getHttpMethod()); + $this->assertSame('https://www.beanstream.com/api/v1/payments/1/returns', $request->getEndpoint()); + } + + public function testVoid() + { + $request = $this->gateway->void( + array( + 'transactionReference'=>1, + 'amount'=> 10.00 + ) + ); + $this->assertInstanceOf('Omnipay\Beanstream\Message\VoidRequest', $request); + $this->assertSame(1, $request->getTransactionReference()); + $this->assertSame('10.00', $request->getAmount()); + $this->assertSame('POST', $request->getHttpMethod()); + $this->assertSame('https://www.beanstream.com/api/v1/payments/1/void', $request->getEndpoint()); + } } diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php new file mode 100644 index 0000000..def92e2 --- /dev/null +++ b/tests/Message/RefundRequestTest.php @@ -0,0 +1,72 @@ +request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'amount'=>10.00, + 'transactionReference'=>1000001 + ) + ); + } + + public function testEndpoint() + { + $this->assertSame('https://www.beanstream.com/api/v1/payments/1000001/returns', $this->request->getEndpoint()); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('RefundSuccess.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('R', $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->setMockHttpResponse('RefundFailure.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); + } +} \ No newline at end of file diff --git a/tests/Mock/RefundFailure.txt b/tests/Mock/RefundFailure.txt new file mode 100644 index 0000000..6bf36ce --- /dev/null +++ b/tests/Mock/RefundFailure.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/RefundSuccess.txt b/tests/Mock/RefundSuccess.txt new file mode 100644 index 0000000..9fe8da5 --- /dev/null +++ b/tests/Mock/RefundSuccess.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": "R", + "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" + } + ] +} From 02cdb4d50e345995c03911a4e546e0e7a3d74db4 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Thu, 2 Mar 2017 09:50:31 -0700 Subject: [PATCH 2/4] Finished creation of the tests for Void and Refund. Implemented the capture functionality and created tests for it as well. --- src/Gateway.php | 10 ++++ src/Message/CaptureRequest.php | 27 +++++++++ tests/GatewayTest.php | 36 ++++++++++-- tests/Message/CaptureRequestTest.php | 84 ++++++++++++++++++++++++++++ tests/Message/VoidRequestTest.php | 84 ++++++++++++++++++++++++++++ tests/Mock/CaptureFailure.txt | 9 +++ tests/Mock/CaptureSuccess.txt | 38 +++++++++++++ tests/Mock/VoidFailure.txt | 9 +++ tests/Mock/VoidSuccess.txt | 38 +++++++++++++ 9 files changed, 329 insertions(+), 6 deletions(-) create mode 100644 src/Message/CaptureRequest.php create mode 100644 tests/Message/CaptureRequestTest.php create mode 100644 tests/Message/VoidRequestTest.php create mode 100644 tests/Mock/CaptureFailure.txt create mode 100644 tests/Mock/CaptureSuccess.txt create mode 100644 tests/Mock/VoidFailure.txt create mode 100644 tests/Mock/VoidSuccess.txt diff --git a/src/Gateway.php b/src/Gateway.php index 6864a35..1a6ca10 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -102,6 +102,16 @@ public function void(array $parameters = array()) return $this->createRequest('\Omnipay\Beanstream\Message\VoidRequest', $parameters); } + /** + * @param array $parameters + * + * @return \Omnipay\Beanstream\Message\CaptureRequest + */ + public function capture(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Beanstream\Message\CaptureRequest', $parameters); + } + /** * @param array $parameters * @return \Omnipay\Beanstream\Message\CreateProfileRequest diff --git a/src/Message/CaptureRequest.php b/src/Message/CaptureRequest.php new file mode 100644 index 0000000..30dc1ab --- /dev/null +++ b/src/Message/CaptureRequest.php @@ -0,0 +1,27 @@ +endpoint . '/payments/' . $this->getTransactionReference() . '/completions'; + } +} \ No newline at end of file diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 97b0552..f330efc 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -185,33 +185,57 @@ public function testDeleteProfileCard() $this->assertSame('DELETE', $request->getHttpMethod()); } + /** + * Test the creation of a RefundRequest object + */ public function testRefund() { $request = $this->gateway->refund( array( - 'transactionReference'=>1, + 'transactionReference'=>100, 'amount'=> 10.00 ) ); $this->assertInstanceOf('Omnipay\Beanstream\Message\RefundRequest', $request); - $this->assertSame(1, $request->getTransactionReference()); + $this->assertSame(100, $request->getTransactionReference()); $this->assertSame('10.00', $request->getAmount()); $this->assertSame('POST', $request->getHttpMethod()); - $this->assertSame('https://www.beanstream.com/api/v1/payments/1/returns', $request->getEndpoint()); + $this->assertSame('https://www.beanstream.com/api/v1/payments/100/returns', $request->getEndpoint()); } + /** + * Test the creation of a VoidRequest object + */ public function testVoid() { $request = $this->gateway->void( array( - 'transactionReference'=>1, + 'transactionReference'=>100, 'amount'=> 10.00 ) ); $this->assertInstanceOf('Omnipay\Beanstream\Message\VoidRequest', $request); - $this->assertSame(1, $request->getTransactionReference()); + $this->assertSame(100, $request->getTransactionReference()); $this->assertSame('10.00', $request->getAmount()); $this->assertSame('POST', $request->getHttpMethod()); - $this->assertSame('https://www.beanstream.com/api/v1/payments/1/void', $request->getEndpoint()); + $this->assertSame('https://www.beanstream.com/api/v1/payments/100/void', $request->getEndpoint()); + } + + /** + * Test the creation of a CaptureRequest object + */ + public function testCapture() + { + $request = $this->gateway->capture( + array( + 'transactionReference'=>100, + 'amount'=>10.00 + ) + ); + $this->assertInstanceOf('Omnipay\Beanstream\Message\CaptureRequest', $request); + $this->assertSame(100, $request->getTransactionReference()); + $this->assertSame('10.00', $request->getAmount()); + $this->assertSame('POST', $request->getHttpMethod()); + $this->assertSame('https://www.beanstream.com/api/v1/payments/100/completions', $request->getEndpoint()); } } diff --git a/tests/Message/CaptureRequestTest.php b/tests/Message/CaptureRequestTest.php new file mode 100644 index 0000000..265a354 --- /dev/null +++ b/tests/Message/CaptureRequestTest.php @@ -0,0 +1,84 @@ +request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'amount'=>10.00, + 'transactionReference'=>1000001 + ) + ); + } + + /** + * Test the correct endpoint is being generated + */ + public function testEndpoint() + { + $this->assertSame('https://www.beanstream.com/api/v1/payments/1000001/completions', $this->request->getEndpoint()); + } + + /** + * Test that the send and response object works correctly on success + */ + public function testSendSuccess() + { + $this->setMockHttpResponse('CaptureSuccess.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('PC', $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']); + } + + /** + * Test that the send and response object works correctly on failure + */ + public function testSendError() + { + $this->setMockHttpResponse('CaptureFailure.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); + } +} \ No newline at end of file diff --git a/tests/Message/VoidRequestTest.php b/tests/Message/VoidRequestTest.php new file mode 100644 index 0000000..37df61e --- /dev/null +++ b/tests/Message/VoidRequestTest.php @@ -0,0 +1,84 @@ +request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'amount'=>10.00, + 'transactionReference'=>1000001 + ) + ); + } + + /** + * Test that the endpoint is being generated correctly + */ + public function testEndpoint() + { + $this->assertSame('https://www.beanstream.com/api/v1/payments/1000001/void', $this->request->getEndpoint()); + } + + /** + * Test that the send function and response object are working correctly on success + */ + public function testSendSuccess() + { + $this->setMockHttpResponse('VoidSuccess.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('V', $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']); + } + + /** + * Test that the send function and response object are working correctly on failure + */ + public function testSendError() + { + $this->setMockHttpResponse('VoidFailure.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); + } +} \ No newline at end of file diff --git a/tests/Mock/CaptureFailure.txt b/tests/Mock/CaptureFailure.txt new file mode 100644 index 0000000..6bf36ce --- /dev/null +++ b/tests/Mock/CaptureFailure.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/CaptureSuccess.txt b/tests/Mock/CaptureSuccess.txt new file mode 100644 index 0000000..733c4b6 --- /dev/null +++ b/tests/Mock/CaptureSuccess.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": "PC", + "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/VoidFailure.txt b/tests/Mock/VoidFailure.txt new file mode 100644 index 0000000..6bf36ce --- /dev/null +++ b/tests/Mock/VoidFailure.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/VoidSuccess.txt b/tests/Mock/VoidSuccess.txt new file mode 100644 index 0000000..0c22722 --- /dev/null +++ b/tests/Mock/VoidSuccess.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": "V", + "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" + } + ] +} From da772b6c5748594bd60b5c5592b138af6e322cbe Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Thu, 2 Mar 2017 12:06:57 -0700 Subject: [PATCH 3/4] Updated the message tests for capture and void so they are using the correct type code that beanstream uses. This commit also has an integration test class added for testing actual transactions with beanstream. --- .gitignore | 1 + tests/IntegrationTest.php | 165 +++++++++++++++++++++++++++ tests/Message/CaptureRequestTest.php | 2 +- tests/Message/VoidRequestTest.php | 2 +- tests/Mock/CaptureSuccess.txt | 2 +- tests/Mock/VoidSuccess.txt | 2 +- 6 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 tests/IntegrationTest.php diff --git a/.gitignore b/.gitignore index 8a282a5..9af5c19 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock composer.phar phpunit.xml +/tests/Mock/myCredentials.json \ No newline at end of file diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php new file mode 100644 index 0000000..fa09b64 --- /dev/null +++ b/tests/IntegrationTest.php @@ -0,0 +1,165 @@ +", + * "apiPasscode":"" + * } + * + * If that file does not exist or is not formatted in this way, all tests in this class will be skipped. + * + * @package Omnipay\Beanstream\tests + */ +class IntegrationTest extends GatewayTestCase +{ + /** @var Gateway */ + protected $gateway; + + /** + * Check for the credentials file. Skips the test if the credentials file is missing or not setup correctly. Otherwise, + * instantiates the gateway and sets up the credentials. + */ + public function setUp() + { + $merchantId = ''; + $apiPasscode = ''; + $credentialsFilePath = dirname(__FILE__) . '/Mock/myCredentials.json'; + + if(file_exists($credentialsFilePath)) { + $credentialsJson = file_get_contents($credentialsFilePath); + if($credentialsJson) { + $credentials = json_decode($credentialsJson); + $merchantId = $credentials->merchantId; + $apiPasscode = $credentials->apiPasscode; + } + } + + if(empty($merchantId) || empty($apiPasscode)) { + $this->markTestSkipped(); + } else { + $this->gateway = new Gateway(); + $this->gateway->setMerchantId($merchantId); + $this->gateway->setApiPasscode($apiPasscode); + } + } + + /** + * Test an Authorize call followed by a capture call for that transaction + */ + public function testAuthCapture() + { + $card = $this->getValidCard(); + $card['number'] = '4030000010001234'; + $card['cvv'] = '123'; + $authResponse = $this->gateway->authorize( + array( + 'amount'=>10.00, + 'card'=>$card, + 'payment_method'=>'card' + ) + )->send(); + $this->assertTrue($authResponse->isSuccessful()); + $this->assertSame('Approved', $authResponse->getMessage()); + + $captureResponse = $this->gateway->capture( + array( + 'transactionReference'=>$authResponse->getTransactionReference(), + 'amount'=>10.00 + ) + )->send(); + + $this->assertTrue($captureResponse->isSuccessful()); + $this->assertSame('Approved', $captureResponse->getMessage()); + } + + /** + * Test a failed purchase transaction. The card number used below is a special one for Beanstream that always declines. + */ + public function testFailedPurchase() + { + $card = $this->getValidCard(); + $card['number'] = '4003050500040005'; + $card['cvv'] = '123'; + $purchaseResponse = $this->gateway->purchase( + array( + 'amount'=>10.00, + 'card'=>$card, + 'payment_method'=>'card' + ) + )->send(); + + $this->assertFalse($purchaseResponse->isSuccessful()); + $this->assertSame('DECLINE', $purchaseResponse->getMessage()); + } + + /** + * Test a purchase call followed by a refund call for that purchase + */ + public function testPurchaseRefund() + { + $card = $this->getValidCard(); + $card['number'] = '4030000010001234'; + $card['cvv'] = '123'; + $purchaseResponse = $this->gateway->purchase( + array( + 'amount'=>20.00, + 'card'=>$card, + 'payment_method'=>'card' + ) + )->send(); + + $this->assertTrue($purchaseResponse->isSuccessful()); + $this->assertSame('Approved', $purchaseResponse->getMessage()); + + $refundResponse = $this->gateway->refund( + array( + 'amount'=>20.00, + 'transactionReference'=>$purchaseResponse->getTransactionReference() + ) + )->send(); + + $this->assertTrue($refundResponse->isSuccessful()); + $this->assertSame('Approved', $refundResponse->getMessage()); + } + + /** + * Test a purchase call followed by a void call for that purchase + */ + public function testPurchaseVoid() + { + $card = $this->getValidCard(); + $card['number'] = '4030000010001234'; + $card['cvv'] = '123'; + $purchaseResponse = $this->gateway->purchase( + array( + 'amount'=>20.00, + 'card'=>$card, + 'payment_method'=>'card' + ) + )->send(); + + $this->assertTrue($purchaseResponse->isSuccessful()); + $this->assertSame('Approved', $purchaseResponse->getMessage()); + + $voidResponse = $this->gateway->void( + array( + 'amount'=>20.00, + 'transactionReference'=>$purchaseResponse->getTransactionReference() + ) + )->send(); + + $this->assertTrue($voidResponse->isSuccessful()); + $this->assertSame('Approved', $voidResponse->getMessage()); + } +} \ No newline at end of file diff --git a/tests/Message/CaptureRequestTest.php b/tests/Message/CaptureRequestTest.php index 265a354..653f271 100644 --- a/tests/Message/CaptureRequestTest.php +++ b/tests/Message/CaptureRequestTest.php @@ -50,7 +50,7 @@ public function testSendSuccess() $this->assertSame('Approved', $response->getMessage()); $this->assertSame('1', $response->getMessageId()); $this->assertSame('TEST', $response->getAuthCode()); - $this->assertSame('PC', $response->getType()); + $this->assertSame('PAC', $response->getType()); $this->assertNull($response->getCode()); $responseCard = $response->getCard(); $this->assertNotEmpty($responseCard); diff --git a/tests/Message/VoidRequestTest.php b/tests/Message/VoidRequestTest.php index 37df61e..27f1b49 100644 --- a/tests/Message/VoidRequestTest.php +++ b/tests/Message/VoidRequestTest.php @@ -50,7 +50,7 @@ public function testSendSuccess() $this->assertSame('Approved', $response->getMessage()); $this->assertSame('1', $response->getMessageId()); $this->assertSame('TEST', $response->getAuthCode()); - $this->assertSame('V', $response->getType()); + $this->assertSame('VP', $response->getType()); $this->assertNull($response->getCode()); $responseCard = $response->getCard(); $this->assertNotEmpty($responseCard); diff --git a/tests/Mock/CaptureSuccess.txt b/tests/Mock/CaptureSuccess.txt index 733c4b6..f0d827f 100644 --- a/tests/Mock/CaptureSuccess.txt +++ b/tests/Mock/CaptureSuccess.txt @@ -19,7 +19,7 @@ X-Powered-By: ASP.NET "auth_code": "TEST", "created": "2016-03-24T11:04:30", "order_number": "1", - "type": "PC", + "type": "PAC", "payment_method": "CC", "card": { "card_type": "VI", diff --git a/tests/Mock/VoidSuccess.txt b/tests/Mock/VoidSuccess.txt index 0c22722..1de849a 100644 --- a/tests/Mock/VoidSuccess.txt +++ b/tests/Mock/VoidSuccess.txt @@ -19,7 +19,7 @@ X-Powered-By: ASP.NET "auth_code": "TEST", "created": "2016-03-24T11:04:30", "order_number": "1", - "type": "V", + "type": "VP", "payment_method": "CC", "card": { "card_type": "VI", From 5ade4ce5c546bd49ecdda54a319ee3305f8e0cc9 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Tue, 7 Mar 2017 14:06:59 -0700 Subject: [PATCH 4/4] Updated some formatting to be more PSR2 compliant --- src/Message/CaptureRequest.php | 2 +- src/Message/RefundRequest.php | 2 +- src/Message/VoidRequest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Message/CaptureRequest.php b/src/Message/CaptureRequest.php index 30dc1ab..53db11e 100644 --- a/src/Message/CaptureRequest.php +++ b/src/Message/CaptureRequest.php @@ -24,4 +24,4 @@ public function getEndpoint() { return $this->endpoint . '/payments/' . $this->getTransactionReference() . '/completions'; } -} \ No newline at end of file +} diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 3b17480..4bcaf70 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -32,4 +32,4 @@ public function getEndpoint() { return $this->endpoint . '/payments/' . $this->getTransactionReference() . '/returns'; } -} \ No newline at end of file +} diff --git a/src/Message/VoidRequest.php b/src/Message/VoidRequest.php index 421fc28..3c87b8d 100644 --- a/src/Message/VoidRequest.php +++ b/src/Message/VoidRequest.php @@ -33,4 +33,4 @@ public function getEndpoint() { return $this->endpoint . '/payments/' . $this->getTransactionReference() . '/void'; } -} \ No newline at end of file +}