Skip to content

Commit

Permalink
Merge pull request #11 from pingdevelopment/master
Browse files Browse the repository at this point in the history
Refund transaction support
  • Loading branch information
greydnls committed Jan 19, 2015
2 parents 233b9c6 + de0ea4a commit 7b51669
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/AIMGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -20,10 +17,10 @@ public function getName()
public function getDefaultParameters()
{
return array(
'apiLoginId' => '',
'apiLoginId' => '',
'transactionKey' => '',
'testMode' => false,
'developerMode' => false,
'testMode' => false,
'developerMode' => false,
);
}

Expand Down Expand Up @@ -76,4 +73,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);
}
}
25 changes: 25 additions & 0 deletions src/Message/AIMRefundRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Omnipay\AuthorizeNet\Message;

/**
* Authorize.Net Refund Request
*/
class AIMRefundRequest extends AbstractRequest
{
protected $action = 'CREDIT';

public function getData()
{
$data = $this->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;
}
}
3 changes: 0 additions & 3 deletions src/SIMGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Omnipay\AuthorizeNet;

use Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest;
use Omnipay\AuthorizeNet\Message\SIMCompleteAuthorizeRequest;

/**
* Authorize.Net SIM Class
*/
Expand Down
33 changes: 33 additions & 0 deletions tests/Message/AIMRefundRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Omnipay\AuthorizeNet\Message;

use Omnipay\Tests\TestCase;

class AIMRefundRequestTest extends TestCase
{
public function setUp()
{
$this->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']);
}
}
28 changes: 28 additions & 0 deletions tests/Message/AIMResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
11 changes: 11 additions & 0 deletions tests/Mock/AIMRefundFailure.txt
Original file line number Diff line number Diff line change
@@ -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|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|
11 changes: 11 additions & 0 deletions tests/Mock/AIMRefundSuccess.txt
Original file line number Diff line number Diff line change
@@ -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|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|

0 comments on commit 7b51669

Please sign in to comment.