Skip to content

Commit 7fa9d7e

Browse files
author
David Stockton
committed
Fix for BC break of returning messages when asking for codes
Added new getCodeMessage and getAVSCodeMessage methods to AIMResponse class. Updated unit tests to correspond.
1 parent 99327e1 commit 7fa9d7e

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

src/Message/AIMResponse.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ public function __construct(RequestInterface $request, $data)
102102
);
103103

104104
if (isset($response['Response Code']) && isset($response_codes[$response['Response Code']])) {
105-
$response['Response Code'] = $response_codes[$response['Response Code']];
105+
$response['Response Code Message'] = $response_codes[$response['Response Code']];
106106
} else {
107-
$response['Response Code'] = null;
107+
$response['Response Code Message'] = null;
108108
}
109109

110110
if (isset($response['AVS Response']) && isset($avs_response_codes[$response['AVS Response']])) {
111-
$response['AVS Response'] = $avs_response_codes[$response['AVS Response']];
111+
$response['AVS Response Message'] = $avs_response_codes[$response['AVS Response']];
112112
} else {
113-
$response['AVS Response'] = null;
113+
$response['AVS Response Message'] = null;
114114
}
115115

116116
$this->data = $response;
@@ -122,14 +122,19 @@ public function __construct(RequestInterface $request, $data)
122122

123123
public function isSuccessful()
124124
{
125-
return $this->getCode() == 'Approved';
125+
return $this->getCodeMessage() == 'Approved';
126126
}
127127

128128
public function getCode()
129129
{
130130
return $this->data['Response Code'];
131131
}
132132

133+
public function getCodeMessage()
134+
{
135+
return $this->data['Response Code Message'];
136+
}
137+
133138
public function getReasonCode()
134139
{
135140
return $this->data['Response Reason Code'];
@@ -150,6 +155,11 @@ public function getAVSCode()
150155
return $this->data['AVS Response'];
151156
}
152157

158+
public function getAVSCodeMessage()
159+
{
160+
return $this->data['AVS Response Message'];
161+
}
162+
153163
public function getTransactionReference()
154164
{
155165
return $this->data['Transaction ID'];

tests/Message/AIMResponseTest.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public function testAuthorizeSuccess()
2222
$this->assertTrue($response->isSuccessful());
2323
$this->assertSame('2184493132', $response->getTransactionReference());
2424
$this->assertSame('This transaction has been approved.', $response->getMessage());
25-
$this->assertSame('Approved', $response->getCode());
25+
$this->assertSame('1', $response->getCode());
26+
$this->assertSame('Approved', $response->getCodeMessage());
2627
$this->assertSame('1', $response->getReasonCode());
2728
$this->assertSame('GA4OQP', $response->getAuthorizationCode());
28-
$this->assertSame('Address (Street) and five digit ZIP match', $response->getAVSCode());
29+
$this->assertSame('Y', $response->getAVSCode());
30+
$this->assertSame('Address (Street) and five digit ZIP match', $response->getAVSCodeMessage());
2931
}
3032

3133
public function testAuthorizeFailure()
@@ -36,10 +38,12 @@ public function testAuthorizeFailure()
3638
$this->assertFalse($response->isSuccessful());
3739
$this->assertSame('0', $response->getTransactionReference());
3840
$this->assertSame('A valid amount is required.', $response->getMessage());
39-
$this->assertSame('Error', $response->getCode());
41+
$this->assertSame('3', $response->getCode());
42+
$this->assertSame('Error', $response->getCodeMessage());
4043
$this->assertSame('5', $response->getReasonCode());
4144
$this->assertSame('', $response->getAuthorizationCode());
42-
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCode());
45+
$this->assertSame('P', $response->getAVSCode());
46+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
4347
}
4448

4549
public function testCaptureSuccess()
@@ -50,10 +54,12 @@ public function testCaptureSuccess()
5054
$this->assertTrue($response->isSuccessful());
5155
$this->assertSame('2184494531', $response->getTransactionReference());
5256
$this->assertSame('This transaction has been approved.', $response->getMessage());
53-
$this->assertSame('Approved', $response->getCode());
57+
$this->assertSame('1', $response->getCode());
58+
$this->assertSame('Approved', $response->getCodeMessage());
5459
$this->assertSame('1', $response->getReasonCode());
5560
$this->assertSame('F51OYG', $response->getAuthorizationCode());
56-
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCode());
61+
$this->assertSame('P', $response->getAVSCode());
62+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
5763
}
5864

5965
public function testCaptureFailure()
@@ -64,10 +70,12 @@ public function testCaptureFailure()
6470
$this->assertFalse($response->isSuccessful());
6571
$this->assertSame('0', $response->getTransactionReference());
6672
$this->assertSame('The transaction cannot be found.', $response->getMessage());
67-
$this->assertSame('Error', $response->getCode());
73+
$this->assertSame('3', $response->getCode());
74+
$this->assertSame('Error', $response->getCodeMessage());
6875
$this->assertSame('16', $response->getReasonCode());
6976
$this->assertSame('', $response->getAuthorizationCode());
70-
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCode());
77+
$this->assertSame('P', $response->getAVSCode());
78+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
7179
}
7280

7381
public function testPurchaseSuccess()
@@ -78,10 +86,12 @@ public function testPurchaseSuccess()
7886
$this->assertTrue($response->isSuccessful());
7987
$this->assertSame('2184492509', $response->getTransactionReference());
8088
$this->assertSame('This transaction has been approved.', $response->getMessage());
81-
$this->assertSame('Approved', $response->getCode());
89+
$this->assertSame('1', $response->getCode());
90+
$this->assertSame('Approved', $response->getCodeMessage());
8291
$this->assertSame('1', $response->getReasonCode());
8392
$this->assertSame('JE6JM1', $response->getAuthorizationCode());
84-
$this->assertSame('Address (Street) and five digit ZIP match', $response->getAVSCode());
93+
$this->assertSame('Y', $response->getAVSCode());
94+
$this->assertSame('Address (Street) and five digit ZIP match', $response->getAVSCodeMessage());
8595
}
8696

8797
public function testPurchaseFailure()
@@ -92,10 +102,12 @@ public function testPurchaseFailure()
92102
$this->assertFalse($response->isSuccessful());
93103
$this->assertSame('0', $response->getTransactionReference());
94104
$this->assertSame('A valid amount is required.', $response->getMessage());
95-
$this->assertSame('Error', $response->getCode());
105+
$this->assertSame('3', $response->getCode());
106+
$this->assertSame('Error', $response->getCodeMessage());
96107
$this->assertSame('5', $response->getReasonCode());
97108
$this->assertSame('', $response->getAuthorizationCode());
98-
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCode());
109+
$this->assertSame('P', $response->getAVSCode());
110+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
99111
}
100112

101113
public function testRefundSuccess()
@@ -107,9 +119,11 @@ public function testRefundSuccess()
107119
$this->assertTrue($response->isSuccessful());
108120
$this->assertSame('2184492509', $response->getTransactionReference());
109121
$this->assertSame('This transaction has been approved.', $response->getMessage());
110-
$this->assertSame('Approved', $response->getCode());
122+
$this->assertSame('1', $response->getCode());
123+
$this->assertSame('Approved', $response->getCodeMessage());
111124
$this->assertSame('1', $response->getReasonCode());
112-
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCode());
125+
$this->assertSame('P', $response->getAVSCode());
126+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
113127
}
114128

115129
public function testRefundFailure()
@@ -120,9 +134,11 @@ public function testRefundFailure()
120134
$this->assertFalse($response->isSuccessful());
121135
$this->assertSame('0', $response->getTransactionReference());
122136
$this->assertSame('The credit card number is invalid.', $response->getMessage());
123-
$this->assertSame('Error', $response->getCode());
137+
$this->assertSame('3', $response->getCode());
138+
$this->assertSame('Error', $response->getCodeMessage());
124139
$this->assertSame('6', $response->getReasonCode());
125140
$this->assertSame('', $response->getAuthorizationCode());
126-
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCode());
141+
$this->assertSame('P', $response->getAVSCode());
142+
$this->assertSame('AVS not applicable for this transaction', $response->getAVSCodeMessage());
127143
}
128144
}

0 commit comments

Comments
 (0)