|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Easily interact with the Authorize.Net AIM API. |
|
4
|
|
|
* |
|
5
|
|
|
* |
|
6
|
|
|
* Example Authorize and Capture Transaction against the Sandbox: |
|
7
|
|
|
* <code> |
|
8
|
|
|
* <?php require_once 'AuthorizeNet.php' |
|
9
|
|
|
* $sale = new AuthorizeNetAIM; |
|
10
|
|
|
* $sale->setFields( |
|
11
|
|
|
* array( |
|
12
|
|
|
* 'amount' => '4.99', |
|
13
|
|
|
* 'card_num' => '411111111111111', |
|
14
|
|
|
* 'exp_date' => '0515' |
|
15
|
|
|
* ) |
|
16
|
|
|
* ); |
|
17
|
|
|
* $response = $sale->authorizeAndCapture(); |
|
18
|
|
|
* if ($response->approved) { |
|
19
|
|
|
* echo "Sale successful!"; } else { |
|
20
|
|
|
* echo $response->error_message; |
|
21
|
|
|
* } |
|
22
|
|
|
* ?> |
|
23
|
|
|
* </code> |
|
24
|
|
|
* |
|
25
|
|
|
* Note: To send requests to the live gateway, either define this: |
|
26
|
|
|
* define("AUTHORIZENET_SANDBOX", false); |
|
27
|
|
|
* -- OR -- |
|
28
|
|
|
* $sale = new AuthorizeNetAIM; |
|
29
|
|
|
* $sale->setSandbox(false); |
|
30
|
|
|
* |
|
31
|
|
|
* @package AuthorizeNet |
|
32
|
|
|
* @subpackage AuthorizeNetAIM |
|
33
|
|
|
* @link http://www.authorize.net/support/AIM_guide.pdf AIM Guide |
|
34
|
|
|
*/ |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Builds and sends an AuthorizeNet AIM Request. |
|
39
|
|
|
* |
|
40
|
|
|
* @package AuthorizeNet |
|
41
|
|
|
* @subpackage AuthorizeNetAIM |
|
42
|
|
|
*/ |
|
43
|
|
|
class AuthorizeNetAIM extends AuthorizeNetRequest |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
|
|
const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; |
|
47
|
|
|
const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Holds all the x_* name/values that will be posted in the request. |
|
51
|
|
|
* Default values are provided for best practice fields. |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $_x_post_fields = array( |
|
54
|
|
|
"version" => "3.1", |
|
55
|
|
|
"delim_char" => ",", |
|
56
|
|
|
"delim_data" => "TRUE", |
|
57
|
|
|
"relay_response" => "FALSE", |
|
58
|
|
|
"encap_char" => "|", |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Only used if merchant wants to send multiple line items about the charge. |
|
63
|
|
|
*/ |
|
64
|
|
|
private $_additional_line_items = array(); |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Only used if merchant wants to send custom fields. |
|
68
|
|
|
*/ |
|
69
|
|
|
private $_custom_fields = array(); |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Checks to make sure a field is actually in the API before setting. |
|
73
|
|
|
* Set to false to skip this check. |
|
74
|
|
|
*/ |
|
75
|
|
|
public $verify_x_fields = true; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* A list of all fields in the AIM API. |
|
79
|
|
|
* Used to warn user if they try to set a field not offered in the API. |
|
80
|
|
|
*/ |
|
81
|
|
|
private $_all_aim_fields = array("address","allow_partial_auth","amount", |
|
82
|
|
|
"auth_code","authentication_indicator", "bank_aba_code","bank_acct_name", |
|
83
|
|
|
"bank_acct_num","bank_acct_type","bank_check_number","bank_name", |
|
84
|
|
|
"card_code","card_num","cardholder_authentication_value","city","company", |
|
85
|
|
|
"country","cust_id","customer_ip","delim_char","delim_data","description", |
|
86
|
|
|
"duplicate_window","duty","echeck_type","email","email_customer", |
|
87
|
|
|
"encap_char","exp_date","fax","first_name","footer_email_receipt", |
|
88
|
|
|
"freight","header_email_receipt","invoice_num","last_name","line_item", |
|
89
|
|
|
"login","method","phone","po_num","recurring_billing","relay_response", |
|
90
|
|
|
"ship_to_address","ship_to_city","ship_to_company","ship_to_country", |
|
91
|
|
|
"ship_to_first_name","ship_to_last_name","ship_to_state","ship_to_zip", |
|
92
|
|
|
"split_tender_id","state","tax","tax_exempt","test_request","tran_key", |
|
93
|
|
|
"trans_id","type","version","zip" |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Do an AUTH_CAPTURE transaction. |
|
98
|
|
|
* |
|
99
|
|
|
* Required "x_" fields: card_num, exp_date, amount |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $amount The dollar amount to charge |
|
102
|
|
|
* @param string $card_num The credit card number |
|
103
|
|
|
* @param string $exp_date CC expiration date |
|
104
|
|
|
* |
|
105
|
|
|
* @return AuthorizeNetAIM_Response |
|
106
|
|
|
*/ |
|
107
|
24 |
|
public function authorizeAndCapture($amount = false, $card_num = false, $exp_date = false) |
|
108
|
|
|
{ |
|
109
|
24 |
|
($amount ? $this->amount = $amount : null); |
|
|
|
|
|
|
110
|
24 |
|
($card_num ? $this->card_num = $card_num : null); |
|
|
|
|
|
|
111
|
24 |
|
($exp_date ? $this->exp_date = $exp_date : null); |
|
|
|
|
|
|
112
|
24 |
|
$this->type = "AUTH_CAPTURE"; |
|
|
|
|
|
|
113
|
24 |
|
return $this->_sendRequest(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Do a PRIOR_AUTH_CAPTURE transaction. |
|
118
|
|
|
* |
|
119
|
|
|
* Required "x_" field: trans_id(The transaction id of the prior auth, unless split |
|
120
|
|
|
* tender, then set x_split_tender_id manually.) |
|
121
|
|
|
* amount (only if lesser than original auth) |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $trans_id Transaction id to charge |
|
124
|
|
|
* @param string $amount Dollar amount to charge if lesser than auth |
|
125
|
|
|
* |
|
126
|
|
|
* @return AuthorizeNetAIM_Response |
|
127
|
|
|
*/ |
|
128
|
2 |
|
public function priorAuthCapture($trans_id = false, $amount = false) |
|
129
|
|
|
{ |
|
130
|
2 |
|
($trans_id ? $this->trans_id = $trans_id : null); |
|
|
|
|
|
|
131
|
2 |
|
($amount ? $this->amount = $amount : null); |
|
|
|
|
|
|
132
|
2 |
|
$this->type = "PRIOR_AUTH_CAPTURE"; |
|
|
|
|
|
|
133
|
2 |
|
return $this->_sendRequest(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Do an AUTH_ONLY transaction. |
|
138
|
|
|
* |
|
139
|
|
|
* Required "x_" fields: card_num, exp_date, amount |
|
140
|
|
|
* |
|
141
|
|
|
* @param string $amount The dollar amount to charge |
|
142
|
|
|
* @param string $card_num The credit card number |
|
143
|
|
|
* @param string $exp_date CC expiration date |
|
144
|
|
|
* |
|
145
|
|
|
* @return AuthorizeNetAIM_Response |
|
146
|
|
|
*/ |
|
147
|
5 |
|
public function authorizeOnly($amount = false, $card_num = false, $exp_date = false) |
|
148
|
|
|
{ |
|
149
|
5 |
|
($amount ? $this->amount = $amount : null); |
|
|
|
|
|
|
150
|
5 |
|
($card_num ? $this->card_num = $card_num : null); |
|
|
|
|
|
|
151
|
5 |
|
($exp_date ? $this->exp_date = $exp_date : null); |
|
|
|
|
|
|
152
|
5 |
|
$this->type = "AUTH_ONLY"; |
|
|
|
|
|
|
153
|
5 |
|
return $this->_sendRequest(); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Do a VOID transaction. |
|
158
|
|
|
* |
|
159
|
|
|
* Required "x_" field: trans_id(The transaction id of the prior auth, unless split |
|
160
|
|
|
* tender, then set x_split_tender_id manually.) |
|
161
|
|
|
* |
|
162
|
|
|
* @param string $trans_id Transaction id to void |
|
163
|
|
|
* |
|
164
|
|
|
* @return AuthorizeNetAIM_Response |
|
165
|
|
|
*/ |
|
166
|
4 |
|
public function void($trans_id = false) |
|
167
|
|
|
{ |
|
168
|
4 |
|
($trans_id ? $this->trans_id = $trans_id : null); |
|
|
|
|
|
|
169
|
4 |
|
$this->type = "VOID"; |
|
|
|
|
|
|
170
|
4 |
|
return $this->_sendRequest(); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Do a CAPTURE_ONLY transaction. |
|
175
|
|
|
* |
|
176
|
|
|
* Required "x_" fields: auth_code, amount, card_num , exp_date |
|
177
|
|
|
* |
|
178
|
|
|
* @param string $auth_code The auth code |
|
179
|
|
|
* @param string $amount The dollar amount to charge |
|
180
|
|
|
* @param string $card_num The last 4 of credit card number |
|
181
|
|
|
* @param string $exp_date CC expiration date |
|
182
|
|
|
* |
|
183
|
|
|
* @return AuthorizeNetAIM_Response |
|
184
|
|
|
*/ |
|
185
|
|
|
public function captureOnly($auth_code = false, $amount = false, $card_num = false, $exp_date = false) |
|
186
|
|
|
{ |
|
187
|
|
|
($auth_code ? $this->auth_code = $auth_code : null); |
|
|
|
|
|
|
188
|
|
|
($amount ? $this->amount = $amount : null); |
|
|
|
|
|
|
189
|
|
|
($card_num ? $this->card_num = $card_num : null); |
|
|
|
|
|
|
190
|
|
|
($exp_date ? $this->exp_date = $exp_date : null); |
|
|
|
|
|
|
191
|
|
|
$this->type = "CAPTURE_ONLY"; |
|
|
|
|
|
|
192
|
|
|
return $this->_sendRequest(); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Do a CREDIT transaction. |
|
197
|
|
|
* |
|
198
|
|
|
* Required "x_" fields: trans_id, amount, card_num (just the last 4) |
|
199
|
|
|
* |
|
200
|
|
|
* @param string $trans_id Transaction id to credit |
|
201
|
|
|
* @param string $amount The dollar amount to credit |
|
202
|
|
|
* @param string $card_num The last 4 of credit card number |
|
203
|
|
|
* |
|
204
|
|
|
* @return AuthorizeNetAIM_Response |
|
205
|
|
|
*/ |
|
206
|
|
|
public function credit($trans_id = false, $amount = false, $card_num = false) |
|
207
|
|
|
{ |
|
208
|
|
|
($trans_id ? $this->trans_id = $trans_id : null); |
|
|
|
|
|
|
209
|
|
|
($amount ? $this->amount = $amount : null); |
|
|
|
|
|
|
210
|
|
|
($card_num ? $this->card_num = $card_num : null); |
|
|
|
|
|
|
211
|
|
|
$this->type = "CREDIT"; |
|
|
|
|
|
|
212
|
|
|
return $this->_sendRequest(); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Alternative syntax for setting x_ fields. |
|
217
|
|
|
* |
|
218
|
|
|
* Usage: $sale->method = "echeck"; |
|
219
|
|
|
* |
|
220
|
|
|
* @param string $name |
|
221
|
|
|
* @param string $value |
|
222
|
|
|
*/ |
|
223
|
29 |
|
public function __set($name, $value) |
|
224
|
|
|
{ |
|
225
|
29 |
|
$this->setField($name, $value); |
|
226
|
29 |
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Quickly set multiple fields. |
|
230
|
|
|
* |
|
231
|
|
|
* Note: The prefix x_ will be added to all fields. If you want to set a |
|
232
|
|
|
* custom field without the x_ prefix, use setCustomField or setCustomFields. |
|
233
|
|
|
* |
|
234
|
|
|
* @param array $fields Takes an array or object. |
|
235
|
|
|
*/ |
|
236
|
21 |
|
public function setFields($fields) |
|
237
|
|
|
{ |
|
238
|
21 |
|
$array = (array)$fields; |
|
239
|
21 |
|
foreach ($array as $key => $value) { |
|
240
|
21 |
|
$this->setField($key, $value); |
|
241
|
|
|
} |
|
242
|
20 |
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Quickly set multiple custom fields. |
|
246
|
|
|
* |
|
247
|
|
|
* @param array $fields |
|
248
|
|
|
*/ |
|
249
|
1 |
|
public function setCustomFields($fields) |
|
250
|
|
|
{ |
|
251
|
1 |
|
$array = (array)$fields; |
|
252
|
1 |
|
foreach ($array as $key => $value) { |
|
253
|
1 |
|
$this->setCustomField($key, $value); |
|
254
|
|
|
} |
|
255
|
1 |
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* Add a line item. |
|
259
|
|
|
* |
|
260
|
|
|
* @param string $item_id |
|
261
|
|
|
* @param string $item_name |
|
262
|
|
|
* @param string $item_description |
|
263
|
|
|
* @param string $item_quantity |
|
264
|
|
|
* @param string $item_unit_price |
|
265
|
|
|
* @param string $item_taxable |
|
266
|
|
|
*/ |
|
267
|
2 |
|
public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
|
|
|
|
|
268
|
|
|
{ |
|
269
|
2 |
|
$line_item = ""; |
|
270
|
2 |
|
$delimiter = ""; |
|
271
|
2 |
|
foreach (func_get_args() as $key => $value) { |
|
272
|
2 |
|
$line_item .= $delimiter . $value; |
|
273
|
2 |
|
$delimiter = "<|>"; |
|
274
|
|
|
} |
|
275
|
2 |
|
$this->_additional_line_items[] = $line_item; |
|
276
|
2 |
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Use ECHECK as payment type. |
|
280
|
|
|
*/ |
|
281
|
1 |
|
public function setECheck($bank_aba_code, $bank_acct_num, $bank_acct_type, $bank_name, $bank_acct_name, $echeck_type = 'WEB') |
|
282
|
|
|
{ |
|
283
|
1 |
|
$this->setFields( |
|
284
|
|
|
array( |
|
285
|
1 |
|
'method' => 'echeck', |
|
286
|
1 |
|
'bank_aba_code' => $bank_aba_code, |
|
287
|
1 |
|
'bank_acct_num' => $bank_acct_num, |
|
288
|
1 |
|
'bank_acct_type' => $bank_acct_type, |
|
289
|
1 |
|
'bank_name' => $bank_name, |
|
290
|
1 |
|
'bank_acct_name' => $bank_acct_name, |
|
291
|
1 |
|
'echeck_type' => $echeck_type, |
|
292
|
|
|
) |
|
293
|
|
|
); |
|
294
|
1 |
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Set an individual name/value pair. This will append x_ to the name |
|
298
|
|
|
* before posting. |
|
299
|
|
|
* |
|
300
|
|
|
* @param string $name |
|
301
|
|
|
* @param string $value |
|
302
|
|
|
*/ |
|
303
|
30 |
|
public function setField($name, $value) |
|
304
|
|
|
{ |
|
305
|
30 |
|
if ($this->verify_x_fields) { |
|
306
|
25 |
|
if (in_array($name, $this->_all_aim_fields)) { |
|
307
|
25 |
|
$this->_x_post_fields[$name] = $value; |
|
308
|
|
|
} else { |
|
309
|
1 |
|
throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
310
|
25 |
|
To set a custom field use setCustomField('field','value') instead."); |
|
311
|
|
|
} |
|
312
|
|
|
} else { |
|
313
|
5 |
|
$this->_x_post_fields[$name] = $value; |
|
314
|
|
|
} |
|
315
|
30 |
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* Set a custom field. Note: the x_ prefix will not be added to |
|
319
|
|
|
* your custom field if you use this method. |
|
320
|
|
|
* |
|
321
|
|
|
* @param string $name |
|
322
|
|
|
* @param string $value |
|
323
|
|
|
*/ |
|
324
|
4 |
|
public function setCustomField($name, $value) |
|
325
|
|
|
{ |
|
326
|
4 |
|
$this->_custom_fields[$name] = $value; |
|
327
|
4 |
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Unset an x_ field. |
|
331
|
|
|
* |
|
332
|
|
|
* @param string $name Field to unset. |
|
333
|
|
|
*/ |
|
334
|
1 |
|
public function unsetField($name) |
|
335
|
|
|
{ |
|
336
|
1 |
|
unset($this->_x_post_fields[$name]); |
|
337
|
1 |
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* |
|
341
|
|
|
* |
|
342
|
|
|
* @param string $response |
|
343
|
|
|
* |
|
344
|
|
|
* @return AuthorizeNetAIM_Response |
|
345
|
|
|
*/ |
|
346
|
24 |
|
protected function _handleResponse($response) |
|
347
|
|
|
{ |
|
348
|
24 |
|
return new AuthorizeNetAIM_Response($response, $this->_x_post_fields['delim_char'], $this->_x_post_fields['encap_char'], $this->_custom_fields); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @return string |
|
353
|
|
|
*/ |
|
354
|
29 |
|
protected function _getPostUrl() |
|
355
|
|
|
{ |
|
356
|
29 |
|
return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* Converts the x_post_fields array into a string suitable for posting. |
|
361
|
|
|
*/ |
|
362
|
29 |
|
protected function _setPostString() |
|
363
|
|
|
{ |
|
364
|
29 |
|
$this->_x_post_fields['login'] = $this->_api_login; |
|
365
|
29 |
|
$this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
366
|
29 |
|
$this->_post_string = ""; |
|
367
|
29 |
|
foreach ($this->_x_post_fields as $key => $value) { |
|
368
|
29 |
|
$this->_post_string .= "x_$key=" . urlencode($value) . "&"; |
|
369
|
|
|
} |
|
370
|
|
|
// Add line items |
|
371
|
29 |
|
foreach ($this->_additional_line_items as $key => $value) { |
|
372
|
2 |
|
$this->_post_string .= "x_line_item=" . urlencode($value) . "&"; |
|
373
|
|
|
} |
|
374
|
|
|
// Add custom fields |
|
375
|
29 |
|
foreach ($this->_custom_fields as $key => $value) { |
|
376
|
4 |
|
$this->_post_string .= "$key=" . urlencode($value) . "&"; |
|
377
|
|
|
} |
|
378
|
29 |
|
$this->_post_string = rtrim($this->_post_string, "& "); |
|
379
|
29 |
|
} |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* Parses an AuthorizeNet AIM Response. |
|
384
|
|
|
* |
|
385
|
|
|
* @package AuthorizeNet |
|
386
|
|
|
* @subpackage AuthorizeNetAIM |
|
387
|
|
|
*/ |
|
388
|
|
|
class AuthorizeNetAIM_Response extends AuthorizeNetResponse |
|
|
|
|
|
|
389
|
|
|
{ |
|
390
|
|
|
private $_response_array = array(); // An array with the split response. |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* Constructor. Parses the AuthorizeNet response string. |
|
394
|
|
|
* |
|
395
|
|
|
* @param string $response The response from the AuthNet server. |
|
396
|
|
|
* @param string $delimiter The delimiter used (default is ",") |
|
397
|
|
|
* @param string $encap_char The encap_char used (default is "|") |
|
398
|
|
|
* @param array $custom_fields Any custom fields set in the request. |
|
399
|
|
|
*/ |
|
400
|
25 |
|
public function __construct($response, $delimiter, $encap_char, $custom_fields) |
|
401
|
|
|
{ |
|
402
|
25 |
|
if ($response) { |
|
403
|
|
|
|
|
404
|
|
|
// Split Array |
|
405
|
25 |
|
$this->response = $response; |
|
406
|
25 |
|
if ($encap_char) { |
|
407
|
25 |
|
$this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
408
|
|
|
} else { |
|
409
|
|
|
$this->_response_array = explode($delimiter, $response); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* If AuthorizeNet doesn't return a delimited response. |
|
414
|
|
|
*/ |
|
415
|
25 |
|
if (count($this->_response_array) < 10) { |
|
416
|
1 |
|
$this->approved = false; |
|
417
|
1 |
|
$this->error = true; |
|
418
|
1 |
|
$this->error_message = "Unrecognized response from AuthorizeNet: $response"; |
|
|
|
|
|
|
419
|
1 |
|
return; |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
|
|
423
|
|
|
|
|
424
|
|
|
// Set all fields |
|
425
|
24 |
|
$this->response_code = $this->_response_array[0]; |
|
426
|
24 |
|
$this->response_subcode = $this->_response_array[1]; |
|
427
|
24 |
|
$this->response_reason_code = $this->_response_array[2]; |
|
428
|
24 |
|
$this->response_reason_text = $this->_response_array[3]; |
|
429
|
24 |
|
$this->authorization_code = $this->_response_array[4]; |
|
430
|
24 |
|
$this->avs_response = $this->_response_array[5]; |
|
431
|
24 |
|
$this->transaction_id = $this->_response_array[6]; |
|
432
|
24 |
|
$this->invoice_number = $this->_response_array[7]; |
|
433
|
24 |
|
$this->description = $this->_response_array[8]; |
|
434
|
24 |
|
$this->amount = $this->_response_array[9]; |
|
435
|
24 |
|
$this->method = $this->_response_array[10]; |
|
436
|
24 |
|
$this->transaction_type = $this->_response_array[11]; |
|
437
|
24 |
|
$this->customer_id = $this->_response_array[12]; |
|
438
|
24 |
|
$this->first_name = $this->_response_array[13]; |
|
439
|
24 |
|
$this->last_name = $this->_response_array[14]; |
|
440
|
24 |
|
$this->company = $this->_response_array[15]; |
|
441
|
24 |
|
$this->address = $this->_response_array[16]; |
|
442
|
24 |
|
$this->city = $this->_response_array[17]; |
|
443
|
24 |
|
$this->state = $this->_response_array[18]; |
|
444
|
24 |
|
$this->zip_code = $this->_response_array[19]; |
|
445
|
24 |
|
$this->country = $this->_response_array[20]; |
|
446
|
24 |
|
$this->phone = $this->_response_array[21]; |
|
447
|
24 |
|
$this->fax = $this->_response_array[22]; |
|
448
|
24 |
|
$this->email_address = $this->_response_array[23]; |
|
449
|
24 |
|
$this->ship_to_first_name = $this->_response_array[24]; |
|
450
|
24 |
|
$this->ship_to_last_name = $this->_response_array[25]; |
|
451
|
24 |
|
$this->ship_to_company = $this->_response_array[26]; |
|
452
|
24 |
|
$this->ship_to_address = $this->_response_array[27]; |
|
453
|
24 |
|
$this->ship_to_city = $this->_response_array[28]; |
|
454
|
24 |
|
$this->ship_to_state = $this->_response_array[29]; |
|
455
|
24 |
|
$this->ship_to_zip_code = $this->_response_array[30]; |
|
456
|
24 |
|
$this->ship_to_country = $this->_response_array[31]; |
|
457
|
24 |
|
$this->tax = $this->_response_array[32]; |
|
458
|
24 |
|
$this->duty = $this->_response_array[33]; |
|
459
|
24 |
|
$this->freight = $this->_response_array[34]; |
|
460
|
24 |
|
$this->tax_exempt = $this->_response_array[35]; |
|
461
|
24 |
|
$this->purchase_order_number= $this->_response_array[36]; |
|
462
|
24 |
|
$this->md5_hash = $this->_response_array[37]; |
|
463
|
24 |
|
$this->card_code_response = $this->_response_array[38]; |
|
464
|
24 |
|
$this->cavv_response = $this->_response_array[39]; |
|
465
|
24 |
|
$this->account_number = $this->_response_array[50]; |
|
466
|
24 |
|
$this->card_type = $this->_response_array[51]; |
|
467
|
24 |
|
$this->split_tender_id = $this->_response_array[52]; |
|
468
|
24 |
|
$this->requested_amount = $this->_response_array[53]; |
|
469
|
24 |
|
$this->balance_on_card = $this->_response_array[54]; |
|
470
|
|
|
|
|
471
|
24 |
|
$this->approved = ($this->response_code == self::APPROVED); |
|
472
|
24 |
|
$this->declined = ($this->response_code == self::DECLINED); |
|
473
|
24 |
|
$this->error = ($this->response_code == self::ERROR); |
|
474
|
24 |
|
$this->held = ($this->response_code == self::HELD); |
|
475
|
|
|
|
|
476
|
|
|
// Set custom fields |
|
477
|
24 |
|
if ($count = count($custom_fields)) { |
|
478
|
4 |
|
$custom_fields_response = array_slice($this->_response_array, -$count, $count); |
|
479
|
4 |
|
$i = 0; |
|
480
|
4 |
|
foreach ($custom_fields as $key => $value) { |
|
481
|
4 |
|
$this->$key = $custom_fields_response[$i]; |
|
482
|
4 |
|
$i++; |
|
483
|
|
|
} |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
24 |
|
if ($this->error) { |
|
487
|
2 |
|
$this->error_message = "AuthorizeNet Error: |
|
488
|
2 |
|
Response Code: ".$this->response_code." |
|
489
|
2 |
|
Response Subcode: ".$this->response_subcode." |
|
490
|
2 |
|
Response Reason Code: ".$this->response_reason_code." |
|
491
|
2 |
|
Response Reason Text: ".$this->response_reason_text." |
|
492
|
24 |
|
"; |
|
493
|
|
|
} |
|
494
|
|
|
} else { |
|
495
|
|
|
$this->approved = false; |
|
496
|
|
|
$this->error = true; |
|
497
|
|
|
$this->error_message = "Error connecting to AuthorizeNet"; |
|
498
|
|
|
} |
|
499
|
24 |
|
} |
|
500
|
|
|
|
|
501
|
|
|
} |
|
502
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.