@@ -14,7 +14,90 @@ 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+ $ temp = explode ('|,| ' , substr ($ data , 1 , -1 ));
18+
19+ $ response_fields = array (
20+ 'Response Code ' ,
21+ 'Response Subcode ' ,
22+ 'Response Reason Code ' ,
23+ 'Response Reason Text ' ,
24+ 'Authorization Code ' ,
25+ 'AVS Response ' ,
26+ 'Transaction ID ' ,
27+ 'Invoice Number ' ,
28+ 'Description ' ,
29+ 'Amount ' ,
30+ 'Method ' ,
31+ 'Transaction Type ' ,
32+ 'Customer ID ' ,
33+ 'First Name ' ,
34+ 'Last Name ' ,
35+ 'Company ' ,
36+ 'Address ' ,
37+ 'City ' ,
38+ 'State ' ,
39+ 'ZIP Code ' ,
40+ 'Country ' ,
41+ 'Phone ' ,
42+ 'Fax ' ,
43+ 'Email Address ' ,
44+ 'Ship To First Name ' ,
45+ 'Ship To Last Name ' ,
46+ 'Ship To Company ' ,
47+ 'Ship To Address ' ,
48+ 'Ship To City ' ,
49+ 'Ship To State ' ,
50+ 'Ship To ZIP Code ' ,
51+ 'Ship To Country ' ,
52+ 'Tax ' ,
53+ 'Duty ' ,
54+ 'Freight ' ,
55+ 'Tax Exempt ' ,
56+ 'Purchase Order Number ' ,
57+ 'MD5 Hash ' ,
58+ 'Card Code Response ' ,
59+ 'Cardholder Authentication Verification Response ' ,
60+ 'Account Number ' ,
61+ 'Card Type ' ,
62+ 'Split Tender ID ' ,
63+ 'Requested Amount ' ,
64+ 'Balance On Card '
65+ );
66+
67+ $ response = array ();
68+
69+ foreach ($ response_fields as $ field )
70+ {
71+ $ response [$ field ] = array_shift ($ temp );
72+ }
73+
74+ $ response_codes = array (
75+ 1 => 'Approved ' ,
76+ 2 => 'Declined ' ,
77+ 3 => 'Error ' ,
78+ 4 => 'Held for Review '
79+ );
80+
81+ $ avs_response_codes = array (
82+ 'A ' => 'Address (Street) matches, ZIP does not ' ,
83+ 'B ' => 'Address information not provided for AVS check ' ,
84+ 'E ' => 'AVS error ' ,
85+ 'G ' => 'Non-U.S. Card Issuing Bank ' ,
86+ 'N ' => 'No Match on Address (Street) or ZIP ' ,
87+ 'P ' => 'AVS not applicable for this transaction ' ,
88+ 'R ' => 'Retry?System unavailable or timed out ' ,
89+ 'S ' => 'Service not supported by issuer ' ,
90+ 'U ' => 'Address information is unavailable ' ,
91+ 'W ' => 'Nine digit ZIP matches, Address (Street) does not ' ,
92+ 'X ' => 'Address (Street) and nine digit ZIP match ' ,
93+ 'Y ' => 'Address (Street) and five digit ZIP match ' ,
94+ 'Z ' => 'Five digit ZIP matches, Address (Street) does not '
95+ );
96+
97+ $ response ['Response Code ' ] = $ response_codes [$ response ['Response Code ' ]];
98+ $ response ['AVS Response ' ] = $ avs_response_codes [$ response ['AVS Response ' ]];
99+
100+ $ this ->data = $ response ;
18101
19102 if (count ($ this ->data ) < 10 ) {
20103 throw new InvalidResponseException ();
@@ -23,36 +106,36 @@ public function __construct(RequestInterface $request, $data)
23106
24107 public function isSuccessful ()
25108 {
26- return ' 1 ' === $ this ->getCode ();
109+ return $ this ->getCode () == ' Approved ' ;
27110 }
28111
29112 public function getCode ()
30113 {
31- return $ this ->data [0 ];
114+ return $ this ->data [' Response Code ' ];
32115 }
33116
34117 public function getReasonCode ()
35118 {
36- return $ this ->data [2 ];
119+ return $ this ->data [' Response Reason Code ' ];
37120 }
38121
39122 public function getMessage ()
40123 {
41- return $ this ->data [3 ];
124+ return $ this ->data [' Response Reason Text ' ];
42125 }
43126
44127 public function getAuthorizationCode ()
45128 {
46- return $ this ->data [4 ];
129+ return $ this ->data [' Authorization Code ' ];
47130 }
48131
49132 public function getAVSCode ()
50133 {
51- return $ this ->data [5 ];
134+ return $ this ->data [' AVS Response ' ];
52135 }
53136
54137 public function getTransactionReference ()
55138 {
56- return $ this ->data [6 ];
139+ return $ this ->data [' Transaction ID ' ];
57140 }
58141}
0 commit comments