Skip to content

Commit dde369f

Browse files
committed
Merge pull request thephpleague#15 from dstockto/acicali/master
Fix for unit tests for thephpleague#13
2 parents e2e813b + 7fa9d7e commit dde369f

File tree

2 files changed

+134
-9
lines changed

2 files changed

+134
-9
lines changed

src/Message/AIMResponse.php

Lines changed: 117 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,106 @@ class AIMResponse extends AbstractResponse
1414
public function __construct(RequestInterface $request, $data)
1515
{
1616
$this->request = $request;
17-
$this->data = explode('|,|', substr($data, 1, -1));
17+
$rawFields = substr($data, 1, - 1);
18+
if ($rawFields !== false) {
19+
$temp = explode('|,|', $rawFields);
20+
} else {
21+
$temp = array();
22+
}
23+
24+
$response_fields = array(
25+
'Response Code',
26+
'Response Subcode',
27+
'Response Reason Code',
28+
'Response Reason Text',
29+
'Authorization Code',
30+
'AVS Response',
31+
'Transaction ID',
32+
'Invoice Number',
33+
'Description',
34+
'Amount',
35+
'Method',
36+
'Transaction Type',
37+
'Customer ID',
38+
'First Name',
39+
'Last Name',
40+
'Company',
41+
'Address',
42+
'City',
43+
'State',
44+
'ZIP Code',
45+
'Country',
46+
'Phone',
47+
'Fax',
48+
'Email Address',
49+
'Ship To First Name',
50+
'Ship To Last Name',
51+
'Ship To Company',
52+
'Ship To Address',
53+
'Ship To City',
54+
'Ship To State',
55+
'Ship To ZIP Code',
56+
'Ship To Country',
57+
'Tax',
58+
'Duty',
59+
'Freight',
60+
'Tax Exempt',
61+
'Purchase Order Number',
62+
'MD5 Hash',
63+
'Card Code Response',
64+
'Cardholder Authentication Verification Response',
65+
'Account Number',
66+
'Card Type',
67+
'Split Tender ID',
68+
'Requested Amount',
69+
'Balance On Card'
70+
);
71+
72+
$response = array();
73+
74+
foreach ($response_fields as $field) {
75+
$responseField = array_shift($temp);
76+
if (!is_null($responseField)) {
77+
$response[$field] = $responseField;
78+
}
79+
}
80+
81+
$response_codes = array(
82+
1 => 'Approved',
83+
2 => 'Declined',
84+
3 => 'Error',
85+
4 => 'Held for Review'
86+
);
87+
88+
$avs_response_codes = array(
89+
'A' => 'Address (Street) matches, ZIP does not',
90+
'B' => 'Address information not provided for AVS check',
91+
'E' => 'AVS error',
92+
'G' => 'Non-U.S. Card Issuing Bank',
93+
'N' => 'No Match on Address (Street) or ZIP',
94+
'P' => 'AVS not applicable for this transaction',
95+
'R' => 'Retry?System unavailable or timed out',
96+
'S' => 'Service not supported by issuer',
97+
'U' => 'Address information is unavailable',
98+
'W' => 'Nine digit ZIP matches, Address (Street) does not',
99+
'X' => 'Address (Street) and nine digit ZIP match',
100+
'Y' => 'Address (Street) and five digit ZIP match',
101+
'Z' => 'Five digit ZIP matches, Address (Street) does not'
102+
);
103+
104+
if (isset($response['Response Code']) && isset($response_codes[$response['Response Code']])) {
105+
$response['Response Code Message'] = $response_codes[$response['Response Code']];
106+
} else {
107+
$response['Response Code Message'] = null;
108+
}
109+
110+
if (isset($response['AVS Response']) && isset($avs_response_codes[$response['AVS Response']])) {
111+
$response['AVS Response Message'] = $avs_response_codes[$response['AVS Response']];
112+
} else {
113+
$response['AVS Response Message'] = null;
114+
}
115+
116+
$this->data = $response;
18117

19118
if (count($this->data) < 10) {
20119
throw new InvalidResponseException();
@@ -23,36 +122,46 @@ public function __construct(RequestInterface $request, $data)
23122

24123
public function isSuccessful()
25124
{
26-
return '1' === $this->getCode();
125+
return $this->getCodeMessage() == 'Approved';
27126
}
28127

29128
public function getCode()
30129
{
31-
return $this->data[0];
130+
return $this->data['Response Code'];
131+
}
132+
133+
public function getCodeMessage()
134+
{
135+
return $this->data['Response Code Message'];
32136
}
33137

34138
public function getReasonCode()
35139
{
36-
return $this->data[2];
140+
return $this->data['Response Reason Code'];
37141
}
38142

39143
public function getMessage()
40144
{
41-
return $this->data[3];
145+
return $this->data['Response Reason Text'];
42146
}
43147

44148
public function getAuthorizationCode()
45149
{
46-
return $this->data[4];
150+
return $this->data['Authorization Code'];
47151
}
48152

49153
public function getAVSCode()
50154
{
51-
return $this->data[5];
155+
return $this->data['AVS Response'];
156+
}
157+
158+
public function getAVSCodeMessage()
159+
{
160+
return $this->data['AVS Response Message'];
52161
}
53162

54163
public function getTransactionReference()
55164
{
56-
return $this->data[6];
165+
return $this->data['Transaction ID'];
57166
}
58167
}

tests/Message/AIMResponseTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class AIMResponseTest extends TestCase
88
{
99
/**
10-
* @expectedException Omnipay\Common\Exception\InvalidResponseException
10+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
1111
*/
1212
public function testConstructEmpty()
1313
{
@@ -23,9 +23,11 @@ public function testAuthorizeSuccess()
2323
$this->assertSame('2184493132', $response->getTransactionReference());
2424
$this->assertSame('This transaction has been approved.', $response->getMessage());
2525
$this->assertSame('1', $response->getCode());
26+
$this->assertSame('Approved', $response->getCodeMessage());
2627
$this->assertSame('1', $response->getReasonCode());
2728
$this->assertSame('GA4OQP', $response->getAuthorizationCode());
2829
$this->assertSame('Y', $response->getAVSCode());
30+
$this->assertSame('Address (Street) and five digit ZIP match', $response->getAVSCodeMessage());
2931
}
3032

3133
public function testAuthorizeFailure()
@@ -37,9 +39,11 @@ public function testAuthorizeFailure()
3739
$this->assertSame('0', $response->getTransactionReference());
3840
$this->assertSame('A valid amount is required.', $response->getMessage());
3941
$this->assertSame('3', $response->getCode());
42+
$this->assertSame('Error', $response->getCodeMessage());
4043
$this->assertSame('5', $response->getReasonCode());
4144
$this->assertSame('', $response->getAuthorizationCode());
4245
$this->assertSame('P', $response->getAVSCode());
46+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
4347
}
4448

4549
public function testCaptureSuccess()
@@ -51,9 +55,11 @@ public function testCaptureSuccess()
5155
$this->assertSame('2184494531', $response->getTransactionReference());
5256
$this->assertSame('This transaction has been approved.', $response->getMessage());
5357
$this->assertSame('1', $response->getCode());
58+
$this->assertSame('Approved', $response->getCodeMessage());
5459
$this->assertSame('1', $response->getReasonCode());
5560
$this->assertSame('F51OYG', $response->getAuthorizationCode());
5661
$this->assertSame('P', $response->getAVSCode());
62+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
5763
}
5864

5965
public function testCaptureFailure()
@@ -65,9 +71,11 @@ public function testCaptureFailure()
6571
$this->assertSame('0', $response->getTransactionReference());
6672
$this->assertSame('The transaction cannot be found.', $response->getMessage());
6773
$this->assertSame('3', $response->getCode());
74+
$this->assertSame('Error', $response->getCodeMessage());
6875
$this->assertSame('16', $response->getReasonCode());
6976
$this->assertSame('', $response->getAuthorizationCode());
7077
$this->assertSame('P', $response->getAVSCode());
78+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
7179
}
7280

7381
public function testPurchaseSuccess()
@@ -79,9 +87,11 @@ public function testPurchaseSuccess()
7987
$this->assertSame('2184492509', $response->getTransactionReference());
8088
$this->assertSame('This transaction has been approved.', $response->getMessage());
8189
$this->assertSame('1', $response->getCode());
90+
$this->assertSame('Approved', $response->getCodeMessage());
8291
$this->assertSame('1', $response->getReasonCode());
8392
$this->assertSame('JE6JM1', $response->getAuthorizationCode());
8493
$this->assertSame('Y', $response->getAVSCode());
94+
$this->assertSame('Address (Street) and five digit ZIP match', $response->getAVSCodeMessage());
8595
}
8696

8797
public function testPurchaseFailure()
@@ -93,9 +103,11 @@ public function testPurchaseFailure()
93103
$this->assertSame('0', $response->getTransactionReference());
94104
$this->assertSame('A valid amount is required.', $response->getMessage());
95105
$this->assertSame('3', $response->getCode());
106+
$this->assertSame('Error', $response->getCodeMessage());
96107
$this->assertSame('5', $response->getReasonCode());
97108
$this->assertSame('', $response->getAuthorizationCode());
98109
$this->assertSame('P', $response->getAVSCode());
110+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
99111
}
100112

101113
public function testRefundSuccess()
@@ -108,8 +120,10 @@ public function testRefundSuccess()
108120
$this->assertSame('2184492509', $response->getTransactionReference());
109121
$this->assertSame('This transaction has been approved.', $response->getMessage());
110122
$this->assertSame('1', $response->getCode());
123+
$this->assertSame('Approved', $response->getCodeMessage());
111124
$this->assertSame('1', $response->getReasonCode());
112125
$this->assertSame('P', $response->getAVSCode());
126+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
113127
}
114128

115129
public function testRefundFailure()
@@ -121,8 +135,10 @@ public function testRefundFailure()
121135
$this->assertSame('0', $response->getTransactionReference());
122136
$this->assertSame('The credit card number is invalid.', $response->getMessage());
123137
$this->assertSame('3', $response->getCode());
138+
$this->assertSame('Error', $response->getCodeMessage());
124139
$this->assertSame('6', $response->getReasonCode());
125140
$this->assertSame('', $response->getAuthorizationCode());
126141
$this->assertSame('P', $response->getAVSCode());
142+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
127143
}
128144
}

0 commit comments

Comments
 (0)