Skip to content

Commit dabc031

Browse files
author
David Stockton
committed
Merge branch 'master' into acicali/master
2 parents e9c3f8b + 7b51669 commit dabc031

File tree

7 files changed

+116
-9
lines changed

7 files changed

+116
-9
lines changed

src/AIMGateway.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Omnipay\AuthorizeNet;
44

5-
use Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest;
6-
use Omnipay\AuthorizeNet\Message\AIMPurchaseRequest;
7-
use Omnipay\AuthorizeNet\Message\CaptureRequest;
85
use Omnipay\Common\AbstractGateway;
96

107
/**
@@ -20,10 +17,10 @@ public function getName()
2017
public function getDefaultParameters()
2118
{
2219
return array(
23-
'apiLoginId' => '',
20+
'apiLoginId' => '',
2421
'transactionKey' => '',
25-
'testMode' => false,
26-
'developerMode' => false,
22+
'testMode' => false,
23+
'developerMode' => false,
2724
);
2825
}
2926

@@ -76,4 +73,9 @@ public function void(array $parameters = array())
7673
{
7774
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMVoidRequest', $parameters);
7875
}
76+
77+
public function refund(array $parameters = array())
78+
{
79+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters);
80+
}
7981
}

src/Message/AIMRefundRequest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
/**
6+
* Authorize.Net Refund Request
7+
*/
8+
class AIMRefundRequest extends AbstractRequest
9+
{
10+
protected $action = 'CREDIT';
11+
12+
public function getData()
13+
{
14+
$data = $this->getBaseData('RefundTransaction');
15+
16+
$this->validate('amount', 'transactionReference');
17+
18+
$data['x_trans_id'] = $this->getTransactionReference();
19+
$data['x_card_num'] = $this->getCard()->getNumber();
20+
$data['x_exp_date'] = $this->getCard()->getExpiryDate('my');
21+
$data['x_amount'] = $this->getAmount();
22+
23+
return $data;
24+
}
25+
}

src/SIMGateway.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Omnipay\AuthorizeNet;
44

5-
use Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest;
6-
use Omnipay\AuthorizeNet\Message\SIMCompleteAuthorizeRequest;
7-
85
/**
96
* Authorize.Net SIM Class
107
*/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class AIMRefundRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new AIMRefundRequest($this->getHttpClient(), $this->getHttpRequest());
12+
$this->request->initialize(
13+
array(
14+
'amount' => '12.00',
15+
'transactionReference' => '60O2UZ',
16+
'currency' => 'USD',
17+
'card' => $this->getValidCard(),
18+
)
19+
);
20+
}
21+
22+
public function testGetData()
23+
{
24+
$data = $this->request->getData();
25+
26+
$card = $this->getValidCard();
27+
28+
$this->assertSame('CREDIT', $data['x_type']);
29+
$this->assertSame('60O2UZ', $data['x_trans_id']);
30+
$this->assertSame($card['number'], $data['x_card_num']);
31+
$this->assertSame('12.00', $data['x_amount']);
32+
}
33+
}

tests/Message/AIMResponseTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,32 @@ public function testPurchaseFailure()
9797
$this->assertSame('', $response->getAuthorizationCode());
9898
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCode());
9999
}
100+
101+
public function testRefundSuccess()
102+
{
103+
$httpResponse = $this->getMockHttpResponse('AIMRefundSuccess.txt');
104+
105+
$response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody());
106+
107+
$this->assertTrue($response->isSuccessful());
108+
$this->assertSame('2184492509', $response->getTransactionReference());
109+
$this->assertSame('This transaction has been approved.', $response->getMessage());
110+
$this->assertSame('1', $response->getCode());
111+
$this->assertSame('1', $response->getReasonCode());
112+
$this->assertSame('P', $response->getAVSCode());
113+
}
114+
115+
public function testRefundFailure()
116+
{
117+
$httpResponse = $this->getMockHttpResponse('AIMRefundFailure.txt');
118+
$response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody());
119+
120+
$this->assertFalse($response->isSuccessful());
121+
$this->assertSame('0', $response->getTransactionReference());
122+
$this->assertSame('The credit card number is invalid.', $response->getMessage());
123+
$this->assertSame('3', $response->getCode());
124+
$this->assertSame('6', $response->getReasonCode());
125+
$this->assertSame('', $response->getAuthorizationCode());
126+
$this->assertSame('P', $response->getAVSCode());
127+
}
100128
}

tests/Mock/AIMRefundFailure.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HTTP/1.1 200 OK
2+
Connection: close
3+
Date: Sat, 18 Jan 2015 04:25:47 GMT
4+
Server: Microsoft-IIS/6.0
5+
X-Powered-By: ASP.NET
6+
Content-Type: text/html
7+
Content-Length: 307
8+
Cache-Control: private, must-revalidate, max-age=0
9+
Expires: Tue, 01 Jan 1980 00:00:00 GMT
10+
11+
|3|,|1|,|6|,|The credit card number is invalid.|,||,|P|,|0|,||,||,|12.00|,|CC|,|credit|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|A391717AA20018B2BCED3118EB0415C3|,||,||,||,||,||,||,||,||,||,||,||,||,|XXXX7898|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|

tests/Mock/AIMRefundSuccess.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HTTP/1.1 200 OK
2+
Connection: close
3+
Date: Sat, 18 Jan 2015 04:00:47 GMT
4+
Server: Microsoft-IIS/6.0
5+
X-Powered-By: ASP.NET
6+
Content-Type: text/html
7+
Content-Length: 307
8+
Cache-Control: private, must-revalidate, max-age=0
9+
Expires: Tue, 01 Jan 1980 00:00:00 GMT
10+
11+
|1|,|1|,|1|,|This transaction has been approved.|,||,|P|,|2184492509|,||,||,|12.00|,|CC|,|credit|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|7ECF5CE3C94D33E55BB9D08EFFACEC21|,||,||,||,||,||,||,||,||,||,||,||,||,|XXXX1111|,|Visa|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|

0 commit comments

Comments
 (0)