From dc7b5f9419ddb9b72b6657dd865b907104990403 Mon Sep 17 00:00:00 2001 From: Bojan Zelic Date: Wed, 16 Jul 2014 17:23:36 -0700 Subject: [PATCH 1/5] Added Refund support --- src/AIMGateway.php | 5 +++++ src/Message/AIMRefundRequest.php | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/Message/AIMRefundRequest.php diff --git a/src/AIMGateway.php b/src/AIMGateway.php index 990c5928..e91a49a5 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -76,4 +76,9 @@ public function void(array $parameters = array()) { return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMVoidRequest', $parameters); } + + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters); + } } diff --git a/src/Message/AIMRefundRequest.php b/src/Message/AIMRefundRequest.php new file mode 100644 index 00000000..6f339e2e --- /dev/null +++ b/src/Message/AIMRefundRequest.php @@ -0,0 +1,24 @@ +getBaseData('RefundTransaction'); + + $this->validate('amount', 'transactionReference'); + + $data['x_trans_id'] = $this->getTransactionReference(); + $data['x_card_num'] = $this->getCard()->getNumber(); + $data['x_exp_date'] = $this->getCard()->getExpiryDate('my'); + $data['x_amount'] = $this->getAmount(); + + return $data; + } +} From d04ab99fb81f75ab376908038dda24282efa3220 Mon Sep 17 00:00:00 2001 From: Peter Adams Date: Tue, 6 Jan 2015 19:50:43 -0700 Subject: [PATCH 2/5] Reformatted using PSR-4 settings --- src/Message/AIMRefundRequest.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Message/AIMRefundRequest.php b/src/Message/AIMRefundRequest.php index 6f339e2e..654c9c55 100644 --- a/src/Message/AIMRefundRequest.php +++ b/src/Message/AIMRefundRequest.php @@ -7,18 +7,19 @@ */ class AIMRefundRequest extends AbstractRequest { - protected $action = 'CREDIT'; - public function getData() - { - $data = $this->getBaseData('RefundTransaction'); + protected $action = 'CREDIT'; - $this->validate('amount', 'transactionReference'); + public function getData() + { + $data = $this->getBaseData('RefundTransaction'); - $data['x_trans_id'] = $this->getTransactionReference(); - $data['x_card_num'] = $this->getCard()->getNumber(); - $data['x_exp_date'] = $this->getCard()->getExpiryDate('my'); - $data['x_amount'] = $this->getAmount(); + $this->validate('amount', 'transactionReference'); - return $data; - } + $data['x_trans_id'] = $this->getTransactionReference(); + $data['x_card_num'] = $this->getCard()->getNumber(); + $data['x_exp_date'] = $this->getCard()->getExpiryDate('my'); + $data['x_amount'] = $this->getAmount(); + + return $data; + } } From 6239b16213907d9a9f38c734f0b63f6c608fc350 Mon Sep 17 00:00:00 2001 From: Peter Adams Date: Tue, 6 Jan 2015 20:00:46 -0700 Subject: [PATCH 3/5] Fixed indentation issues for AIM and SIM Gateway classes --- src/AIMGateway.php | 20 +++++++++++++++----- src/SIMGateway.php | 13 ++++++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/AIMGateway.php b/src/AIMGateway.php index e91a49a5..e078f10e 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -59,26 +59,36 @@ public function setDeveloperMode($value) public function authorize(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest', $parameters); + return $this->createRequest( + '\Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest', $parameters + ); } public function capture(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\CaptureRequest', $parameters); + return $this->createRequest( + '\Omnipay\AuthorizeNet\Message\CaptureRequest', $parameters + ); } public function purchase(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMPurchaseRequest', $parameters); + return $this->createRequest( + '\Omnipay\AuthorizeNet\Message\AIMPurchaseRequest', $parameters + ); } public function void(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMVoidRequest', $parameters); + return $this->createRequest( + '\Omnipay\AuthorizeNet\Message\AIMVoidRequest', $parameters + ); } public function refund(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters); + return $this->createRequest( + '\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters + ); } } diff --git a/src/SIMGateway.php b/src/SIMGateway.php index 1ef4b4af..8640f3d7 100644 --- a/src/SIMGateway.php +++ b/src/SIMGateway.php @@ -35,17 +35,24 @@ public function setHashSecret($value) public function authorize(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters); + return $this->createRequest( + '\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters + ); } public function completeAuthorize(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\SIMCompleteAuthorizeRequest', $parameters); + return $this->createRequest( + '\Omnipay\AuthorizeNet\Message\SIMCompleteAuthorizeRequest', + $parameters + ); } public function purchase(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters); + return $this->createRequest( + '\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters + ); } public function completePurchase(array $parameters = array()) From 2f1429644f8c9da8a1f960f1a5cda7abb281508f Mon Sep 17 00:00:00 2001 From: Bojan Zelic Date: Sun, 18 Jan 2015 16:23:26 -0700 Subject: [PATCH 4/5] Added Refund Unit Tests --- tests/Message/AIMRefundRequestTest.php | 33 ++++++++++++++++++++++++++ tests/Message/AIMResponseTest.php | 28 ++++++++++++++++++++++ tests/Mock/AIMRefundFailure.txt | 11 +++++++++ tests/Mock/AIMRefundSuccess.txt | 11 +++++++++ 4 files changed, 83 insertions(+) create mode 100644 tests/Message/AIMRefundRequestTest.php create mode 100644 tests/Mock/AIMRefundFailure.txt create mode 100644 tests/Mock/AIMRefundSuccess.txt diff --git a/tests/Message/AIMRefundRequestTest.php b/tests/Message/AIMRefundRequestTest.php new file mode 100644 index 00000000..7f4671d6 --- /dev/null +++ b/tests/Message/AIMRefundRequestTest.php @@ -0,0 +1,33 @@ +request = new AIMRefundRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'amount' => '12.00', + 'transactionReference' => '60O2UZ', + 'currency' => 'USD', + 'card' => $this->getValidCard(), + ) + ); + } + + public function testGetData() + { + $data = $this->request->getData(); + + $card = $this->getValidCard(); + + $this->assertSame('CREDIT', $data['x_type']); + $this->assertSame('60O2UZ', $data['x_trans_id']); + $this->assertSame($card['number'], $data['x_card_num']); + $this->assertSame('12.00', $data['x_amount']); + } +} diff --git a/tests/Message/AIMResponseTest.php b/tests/Message/AIMResponseTest.php index 98ed2b81..7466f896 100644 --- a/tests/Message/AIMResponseTest.php +++ b/tests/Message/AIMResponseTest.php @@ -97,4 +97,32 @@ public function testPurchaseFailure() $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); } + + public function testRefundSuccess() + { + $httpResponse = $this->getMockHttpResponse('AIMRefundSuccess.txt'); + + $response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody()); + + $this->assertTrue($response->isSuccessful()); + $this->assertSame('2184492509', $response->getTransactionReference()); + $this->assertSame('This transaction has been approved.', $response->getMessage()); + $this->assertSame('1', $response->getCode()); + $this->assertSame('1', $response->getReasonCode()); + $this->assertSame('P', $response->getAVSCode()); + } + + public function testRefundFailure() + { + $httpResponse = $this->getMockHttpResponse('AIMRefundFailure.txt'); + $response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody()); + + $this->assertFalse($response->isSuccessful()); + $this->assertSame('0', $response->getTransactionReference()); + $this->assertSame('The credit card number is invalid.', $response->getMessage()); + $this->assertSame('3', $response->getCode()); + $this->assertSame('6', $response->getReasonCode()); + $this->assertSame('', $response->getAuthorizationCode()); + $this->assertSame('P', $response->getAVSCode()); + } } diff --git a/tests/Mock/AIMRefundFailure.txt b/tests/Mock/AIMRefundFailure.txt new file mode 100644 index 00000000..3872e035 --- /dev/null +++ b/tests/Mock/AIMRefundFailure.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Date: Sat, 18 Jan 2015 04:25:47 GMT +Server: Microsoft-IIS/6.0 +X-Powered-By: ASP.NET +Content-Type: text/html +Content-Length: 307 +Cache-Control: private, must-revalidate, max-age=0 +Expires: Tue, 01 Jan 1980 00:00:00 GMT + +|3|,|1|,|6|,|The credit card number is invalid.|,||,|P|,|0|,||,||,|12.00|,|CC|,|credit|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|A391717AA20018B2BCED3118EB0415C3|,||,||,||,||,||,||,||,||,||,||,||,||,|XXXX7898|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,| \ No newline at end of file diff --git a/tests/Mock/AIMRefundSuccess.txt b/tests/Mock/AIMRefundSuccess.txt new file mode 100644 index 00000000..8147b8ab --- /dev/null +++ b/tests/Mock/AIMRefundSuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Date: Sat, 18 Jan 2015 04:00:47 GMT +Server: Microsoft-IIS/6.0 +X-Powered-By: ASP.NET +Content-Type: text/html +Content-Length: 307 +Cache-Control: private, must-revalidate, max-age=0 +Expires: Tue, 01 Jan 1980 00:00:00 GMT + +|1|,|1|,|1|,|This transaction has been approved.|,||,|P|,|2184492509|,||,||,|12.00|,|CC|,|credit|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|7ECF5CE3C94D33E55BB9D08EFFACEC21|,||,||,||,||,||,||,||,||,||,||,||,||,|XXXX1111|,|Visa|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,| \ No newline at end of file From de0ea4ad9990b29f32c5b8d97a9af07f65f14e23 Mon Sep 17 00:00:00 2001 From: Peter Adams Date: Mon, 19 Jan 2015 09:21:48 -0700 Subject: [PATCH 5/5] Fixed formatting issues --- src/AIMGateway.php | 29 ++++++++--------------------- src/SIMGateway.php | 16 +++------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/AIMGateway.php b/src/AIMGateway.php index e078f10e..a8327a02 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -2,9 +2,6 @@ namespace Omnipay\AuthorizeNet; -use Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest; -use Omnipay\AuthorizeNet\Message\AIMPurchaseRequest; -use Omnipay\AuthorizeNet\Message\CaptureRequest; use Omnipay\Common\AbstractGateway; /** @@ -20,10 +17,10 @@ public function getName() public function getDefaultParameters() { return array( - 'apiLoginId' => '', + 'apiLoginId' => '', 'transactionKey' => '', - 'testMode' => false, - 'developerMode' => false, + 'testMode' => false, + 'developerMode' => false, ); } @@ -59,36 +56,26 @@ public function setDeveloperMode($value) public function authorize(array $parameters = array()) { - return $this->createRequest( - '\Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest', $parameters - ); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest', $parameters); } public function capture(array $parameters = array()) { - return $this->createRequest( - '\Omnipay\AuthorizeNet\Message\CaptureRequest', $parameters - ); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\CaptureRequest', $parameters); } public function purchase(array $parameters = array()) { - return $this->createRequest( - '\Omnipay\AuthorizeNet\Message\AIMPurchaseRequest', $parameters - ); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMPurchaseRequest', $parameters); } public function void(array $parameters = array()) { - return $this->createRequest( - '\Omnipay\AuthorizeNet\Message\AIMVoidRequest', $parameters - ); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMVoidRequest', $parameters); } public function refund(array $parameters = array()) { - return $this->createRequest( - '\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters - ); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters); } } diff --git a/src/SIMGateway.php b/src/SIMGateway.php index 8640f3d7..bb384101 100644 --- a/src/SIMGateway.php +++ b/src/SIMGateway.php @@ -2,9 +2,6 @@ namespace Omnipay\AuthorizeNet; -use Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest; -use Omnipay\AuthorizeNet\Message\SIMCompleteAuthorizeRequest; - /** * Authorize.Net SIM Class */ @@ -35,24 +32,17 @@ public function setHashSecret($value) public function authorize(array $parameters = array()) { - return $this->createRequest( - '\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters - ); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters); } public function completeAuthorize(array $parameters = array()) { - return $this->createRequest( - '\Omnipay\AuthorizeNet\Message\SIMCompleteAuthorizeRequest', - $parameters - ); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\SIMCompleteAuthorizeRequest', $parameters); } public function purchase(array $parameters = array()) { - return $this->createRequest( - '\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters - ); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters); } public function completePurchase(array $parameters = array())