From 572122b4be1c1db78bba6aceb4bf6211afdcbca2 Mon Sep 17 00:00:00 2001 From: dwoodmansee Date: Thu, 22 Oct 2015 16:45:07 -0400 Subject: [PATCH 1/6] Add refund support for Global Gateway --- src/GlobalGateway.php | 5 ++++ src/Message/GlobalRefundRequest.php | 46 +++++++++++++++++++++++++++++ src/Message/GlobalResponse.php | 5 ++++ 3 files changed, 56 insertions(+) create mode 100644 src/Message/GlobalRefundRequest.php diff --git a/src/GlobalGateway.php b/src/GlobalGateway.php index 51cc91f..71a1457 100644 --- a/src/GlobalGateway.php +++ b/src/GlobalGateway.php @@ -61,4 +61,9 @@ public function setPassword($value) { return $this->setParameter('password', $value); } + + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\FirstData\Message\GlobalRefundRequest', $parameters); + } } diff --git a/src/Message/GlobalRefundRequest.php b/src/Message/GlobalRefundRequest.php new file mode 100644 index 0000000..60fddb8 --- /dev/null +++ b/src/Message/GlobalRefundRequest.php @@ -0,0 +1,46 @@ +setTransactionType($this->action); + $data = $this->getBaseData('DoDirectPayment'); + + $this->validate('amount', 'transactionReference', 'authorizationCode'); + + $data['amount'] = $this->getAmount(); + $data['currency_code'] = $this->getCurrency(); + $data['transaction_tag'] = $this->getTransactionReference(); + $data['authorization_num'] = $this->getAuthorizationCode(); + + $data['client_ip'] = $this->getClientIp(); + return $data; + } + + + /** + * Get the transaction ID. + * + * @return string + */ + public function getAuthorizationCode() + { + return $this->getParameter('authorizationCode'); + } + + /** + * Sets the transaction ID. + * + * @param string $value + * @return AbstractRequest Provides a fluent interface + */ + public function setAuthorizationCode($value) + { + return $this->setParameter('authorizationCode', $value); + } +} diff --git a/src/Message/GlobalResponse.php b/src/Message/GlobalResponse.php index 2591eeb..d8edfd2 100644 --- a/src/Message/GlobalResponse.php +++ b/src/Message/GlobalResponse.php @@ -22,6 +22,11 @@ public function isSuccessful() } public function getTransactionReference() + { + return $this->data['transaction_tag']; + } + + public function getAuthorizationCode() { return $this->data['authorization_num']; } From 20ecb4ae1614f63ef5ce13917bd5c0b8ad410df2 Mon Sep 17 00:00:00 2001 From: dwoodmansee Date: Thu, 22 Oct 2015 18:16:20 -0400 Subject: [PATCH 2/6] remove setAuthorizationCode function, add transaction_tag to purchase test cases --- src/Message/GlobalRefundRequest.php | 17 ----------------- src/Message/GlobalResponse.php | 4 ++-- tests/GlobalGatewayTest.php | 6 ++++-- tests/Message/GlobalPurchaseResponseTest.php | 9 +++++++-- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/Message/GlobalRefundRequest.php b/src/Message/GlobalRefundRequest.php index 60fddb8..016f987 100644 --- a/src/Message/GlobalRefundRequest.php +++ b/src/Message/GlobalRefundRequest.php @@ -22,25 +22,8 @@ public function getData() return $data; } - - /** - * Get the transaction ID. - * - * @return string - */ public function getAuthorizationCode() { return $this->getParameter('authorizationCode'); } - - /** - * Sets the transaction ID. - * - * @param string $value - * @return AbstractRequest Provides a fluent interface - */ - public function setAuthorizationCode($value) - { - return $this->setParameter('authorizationCode', $value); - } } diff --git a/src/Message/GlobalResponse.php b/src/Message/GlobalResponse.php index d8edfd2..3d93b9d 100644 --- a/src/Message/GlobalResponse.php +++ b/src/Message/GlobalResponse.php @@ -23,12 +23,12 @@ public function isSuccessful() public function getTransactionReference() { - return $this->data['transaction_tag']; + return isset($this->data['transaction_tag']) ? $this->data['transaction_tag'] : null; } public function getAuthorizationCode() { - return $this->data['authorization_num']; + return isset($this->data['authorization_num']) ? $this->data['authorization_num'] : null; } public function getMessage() diff --git a/tests/GlobalGatewayTest.php b/tests/GlobalGatewayTest.php index 701cab6..e937903 100644 --- a/tests/GlobalGatewayTest.php +++ b/tests/GlobalGatewayTest.php @@ -37,7 +37,8 @@ public function testPurchaseSuccess() $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); - $this->assertEquals('ET181147', $response->getTransactionReference()); + $this->assertEquals('28513493', $response->getTransactionReference()); + $this->assertEquals('ET181147', $response->getAuthorizationCode()); } public function testAuthorizeSuccess() @@ -48,6 +49,7 @@ public function testAuthorizeSuccess() $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); - $this->assertEquals('ET181147', $response->getTransactionReference()); + $this->assertEquals('28513493', $response->getTransactionReference()); + $this->assertEquals('ET181147', $response->getAuthorizationCode()); } } diff --git a/tests/Message/GlobalPurchaseResponseTest.php b/tests/Message/GlobalPurchaseResponseTest.php index 9ead59b..dfef6da 100644 --- a/tests/Message/GlobalPurchaseResponseTest.php +++ b/tests/Message/GlobalPurchaseResponseTest.php @@ -15,11 +15,13 @@ public function testPurchaseSuccess() 'exact_message' => 'Transaction Normal', 'reference_no' => 'abc123', 'authorization_num' => 'auth1234', + 'transaction_tag' => 'tag1234', 'transaction_approved' => 1, ))); $this->assertTrue($response->isSuccessful()); - $this->assertEquals('auth1234', $response->getTransactionReference()); + $this->assertEquals('auth1234', $response->getAuthorizationCode()); + $this->assertEquals('tag1234', $response->getTransactionReference()); $this->assertSame('Transaction Normal', $response->getMessage()); $this->assertEquals('00', $response->getCode()); } @@ -32,11 +34,13 @@ public function testPurchaseError() 'exact_message' => 'Invalid Credit Card Number', 'reference_no' => 'abc123', 'authorization_num' => 'auth1234', + 'transaction_tag' => 'tag1234', 'transaction_approved' => 0, ))); $this->assertFalse($response->isSuccessful()); - $this->assertEquals('auth1234', $response->getTransactionReference()); + $this->assertEquals('auth1234', $response->getAuthorizationCode()); + $this->assertEquals('tag1234', $response->getTransactionReference()); $this->assertSame('Invalid Credit Card Number', $response->getMessage()); $this->assertEquals('22', $response->getCode()); } @@ -48,6 +52,7 @@ public function testBankError() 'exact_resp_code' => 00, 'reference_no' => 'abc123', 'authorization_num' => '', + 'transaction_tag' => '', 'transaction_approved' => 0, ))); From 6ab10a1565ef7736db4ad61f462be76edf7ee98d Mon Sep 17 00:00:00 2001 From: dwoodmansee Date: Thu, 22 Oct 2015 18:59:58 -0400 Subject: [PATCH 3/6] fix getAuthorizationCode, begin refund test coverage --- src/Message/GlobalRefundRequest.php | 6 ++++++ tests/GlobalGatewayTest.php | 20 ++++++++++++++++++++ tests/Mock/RefundError.txt | 5 +++++ tests/Mock/RefundSuccess.txt | 5 +++++ 4 files changed, 36 insertions(+) create mode 100644 tests/Mock/RefundError.txt create mode 100644 tests/Mock/RefundSuccess.txt diff --git a/src/Message/GlobalRefundRequest.php b/src/Message/GlobalRefundRequest.php index 016f987..ef612da 100644 --- a/src/Message/GlobalRefundRequest.php +++ b/src/Message/GlobalRefundRequest.php @@ -26,4 +26,10 @@ public function getAuthorizationCode() { return $this->getParameter('authorizationCode'); } + + public function setAuthorizationCode($value) + { + return $this->setParameter('authorizationCode', $value); + } + } diff --git a/tests/GlobalGatewayTest.php b/tests/GlobalGatewayTest.php index e937903..67c6398 100644 --- a/tests/GlobalGatewayTest.php +++ b/tests/GlobalGatewayTest.php @@ -21,6 +21,12 @@ public function setUp() 'currency' => 'USD', 'testMode' => true, ); + + $this->refundOptions = array( + 'amount' => 13.00, + 'transactionReference' => '28513493', + 'authorizationCode' => 'ET181147' + ); } public function testProperties() @@ -52,4 +58,18 @@ public function testAuthorizeSuccess() $this->assertEquals('28513493', $response->getTransactionReference()); $this->assertEquals('ET181147', $response->getAuthorizationCode()); } + + + public function testRefundSuccess() + { + $this->setMockHttpResponse('RefundSuccess.txt'); + + $response = $this->gateway->refund($this->refundOptions)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertEquals('28513493', $response->getTransactionReference()); + $this->assertEquals('ET181147', $response->getAuthorizationCode()); + } + } diff --git a/tests/Mock/RefundError.txt b/tests/Mock/RefundError.txt new file mode 100644 index 0000000..1d9dea4 --- /dev/null +++ b/tests/Mock/RefundError.txt @@ -0,0 +1,5 @@ +HTTP/1.1 201 OK +Date: Tue, 11 Feb 2014 02:34:58 GMT +Content-type: text/html; charset=utf-8 + +account_number=&amount=13.0&amount_requested=&authorization=&authorization_num=&avs=&bank_id=&bank_message=&bank_resp_code=&bank_resp_code_2=&card_cost=&cardholder_name=&cavv=&cavv_algorithm=&cavv_response=&cc_expiry=9999&cc_number=&cc_verification_str1=&cc_verification_str2=&check_number=&check_type=&clerk_id=&client_email=&client_ip=&correlation_id=&credit_card_type=&ctr=¤cy_code=USD¤t_balance=&customer_id_number=&customer_id_type=&customer_name=&customer_ref=&cvd_presence_ind=0&cvv2=&date_of_birth=&device_id=&ean=&ecommerce_flag=&error_description=&error_number=&exact_message=Invalid+Refund&exact_resp_code=64&fraud_suspected=&gateway_id=AF8163-05&gift_card_amount=&gross_amount_currency_id=&language=&logon_message=&merchant_address=426+Market+St&merchant_city=Chattenooga&merchant_country=United+States&merchant_name=PriceWaiter+DEMO0243&merchant_postal=37402&merchant_province=Tennessee&merchant_url=https%3A%2F%2Fwww.pricewaiter.com%2F&message=&micr=&pan=&partial_redemption=0&password=&payer_id=&previous_balance=&reference_3=&reference_no=order2®istration_date=®istration_no=&release_type=&retrieval_ref_no=&secure_auth_required=&secure_auth_result=&sequence_no=000056&success=&surcharge_amount=&tax1_amount=&tax1_number=&tax2_amount=&tax2_number=×tamp=&track1=&track2=&transaction_approved=0&transaction_error=1&transaction_tag=28513493&transaction_type=34&transarmor_token=&user_name=&vip=&virtual_card=&xid=&zip_code= diff --git a/tests/Mock/RefundSuccess.txt b/tests/Mock/RefundSuccess.txt new file mode 100644 index 0000000..57b19d6 --- /dev/null +++ b/tests/Mock/RefundSuccess.txt @@ -0,0 +1,5 @@ +HTTP/1.1 201 OK +Date: Tue, 11 Feb 2014 02:34:58 GMT +Content-type: text/html; charset=utf-8 + +account_number=&amount=13.0&amount_requested=&authorization=&authorization_num=ET181147&avs=&bank_id=&bank_message=Approved&bank_resp_code=100&bank_resp_code_2=&card_cost=&cardholder_name=Example+User&cavv=&cavv_algorithm=&cavv_response=&cc_expiry=0318&cc_number=%23%23%23%23%23%23%23%23%23%23%23%231111&cc_verification_str1=&cc_verification_str2=&check_number=&check_type=&clerk_id=&client_email=&client_ip=&correlation_id=&credit_card_type=Visa&ctr=¤cy_code=USD¤t_balance=&customer_id_number=&customer_id_type=&customer_name=&customer_ref=&cvd_presence_ind=0&cvv2=&date_of_birth=&device_id=&ean=&ecommerce_flag=&error_description=&error_number=&exact_message=Transaction+Normal&exact_resp_code=00&fraud_suspected=&gateway_id=AF8163-05&gift_card_amount=&gross_amount_currency_id=&language=&logon_message=&merchant_address=426+Market+St&merchant_city=Chattenooga&merchant_country=United+States&merchant_name=PriceWaiter+DEMO0243&merchant_postal=37402&merchant_province=Tennessee&merchant_url=https%3A%2F%2Fwww.pricewaiter.com%2F&message=&micr=&pan=&partial_redemption=0&password=&payer_id=&previous_balance=&reference_3=&reference_no=order2®istration_date=®istration_no=&release_type=&retrieval_ref_no=7775501&secure_auth_required=&secure_auth_result=&sequence_no=000056&success=&surcharge_amount=&tax1_amount=&tax1_number=&tax2_amount=&tax2_number=×tamp=&track1=&track2=&transaction_approved=1&transaction_error=0&transaction_tag=28513493&transaction_type=34&transarmor_token=&user_name=&vip=&virtual_card=&xid=&zip_code= From 08a3d908151d698cfacb3794df7a35a09484057e Mon Sep 17 00:00:00 2001 From: dwoodmansee Date: Thu, 22 Oct 2015 19:09:23 -0400 Subject: [PATCH 4/6] fix setAuthorizationCode, psr2 issue --- src/Message/GlobalRefundRequest.php | 1 - tests/GlobalGatewayTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Message/GlobalRefundRequest.php b/src/Message/GlobalRefundRequest.php index ef612da..0e72ffa 100644 --- a/src/Message/GlobalRefundRequest.php +++ b/src/Message/GlobalRefundRequest.php @@ -31,5 +31,4 @@ public function setAuthorizationCode($value) { return $this->setParameter('authorizationCode', $value); } - } diff --git a/tests/GlobalGatewayTest.php b/tests/GlobalGatewayTest.php index 67c6398..447e89c 100644 --- a/tests/GlobalGatewayTest.php +++ b/tests/GlobalGatewayTest.php @@ -71,5 +71,4 @@ public function testRefundSuccess() $this->assertEquals('28513493', $response->getTransactionReference()); $this->assertEquals('ET181147', $response->getAuthorizationCode()); } - } From 88b855a727f04f0df4c5bd2ad3881bc071a514b5 Mon Sep 17 00:00:00 2001 From: dwoodmansee Date: Thu, 22 Oct 2015 19:14:54 -0400 Subject: [PATCH 5/6] add refund error test --- tests/GlobalGatewayTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/GlobalGatewayTest.php b/tests/GlobalGatewayTest.php index 447e89c..f186e48 100644 --- a/tests/GlobalGatewayTest.php +++ b/tests/GlobalGatewayTest.php @@ -59,7 +59,6 @@ public function testAuthorizeSuccess() $this->assertEquals('ET181147', $response->getAuthorizationCode()); } - public function testRefundSuccess() { $this->setMockHttpResponse('RefundSuccess.txt'); @@ -71,4 +70,16 @@ public function testRefundSuccess() $this->assertEquals('28513493', $response->getTransactionReference()); $this->assertEquals('ET181147', $response->getAuthorizationCode()); } + + public function testRefundError() + { + $this->setMockHttpResponse('RefundError.txt'); + + $response = $this->gateway->refund($this->refundOptions)->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertEquals('28513493', $response->getTransactionReference()); + $this->assertEquals('', $response->getAuthorizationCode()); + } } From 4bc8155725b443c32f4bb27ca5e5d3a23210bfa8 Mon Sep 17 00:00:00 2001 From: dwoodmansee Date: Thu, 22 Oct 2015 19:22:22 -0400 Subject: [PATCH 6/6] test coverage for GlobalRefundRequest --- tests/Message/GlobalRefundRequestTest.php | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/Message/GlobalRefundRequestTest.php diff --git a/tests/Message/GlobalRefundRequestTest.php b/tests/Message/GlobalRefundRequestTest.php new file mode 100644 index 0000000..23fe810 --- /dev/null +++ b/tests/Message/GlobalRefundRequestTest.php @@ -0,0 +1,27 @@ +getHttpClient(), $this->getHttpRequest()); + $request->initialize( + array( + 'amount' => 13.00, + 'transactionReference' => '28513493', + 'authorizationCode' => 'ET181147' + ) + ); + + $data = $request->getData(); + $this->assertEquals('34', $data['transaction_type']); + $this->assertEquals('28513493', $data['transaction_tag']); + $this->assertEquals('ET181147', $data['authorization_num']); + } + +}