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..0e72ffa --- /dev/null +++ b/src/Message/GlobalRefundRequest.php @@ -0,0 +1,34 @@ +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; + } + + public function getAuthorizationCode() + { + return $this->getParameter('authorizationCode'); + } + + public function setAuthorizationCode($value) + { + return $this->setParameter('authorizationCode', $value); + } +} diff --git a/src/Message/GlobalResponse.php b/src/Message/GlobalResponse.php index 2591eeb..3d93b9d 100644 --- a/src/Message/GlobalResponse.php +++ b/src/Message/GlobalResponse.php @@ -23,7 +23,12 @@ public function isSuccessful() public function getTransactionReference() { - return $this->data['authorization_num']; + return isset($this->data['transaction_tag']) ? $this->data['transaction_tag'] : null; + } + + public function getAuthorizationCode() + { + 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..f186e48 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() @@ -37,7 +43,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 +55,31 @@ 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()); + } + + 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()); + } + + 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()); } } 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, ))); 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']); + } + +} 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=