1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
|
|
|
|
6
|
|
|
* This file is part of the AuthnetJSON package. |
7
|
|
|
* |
8
|
|
|
* (c) John Conde <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Authnetjson; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Adapter for the Authorize.Net JSON API |
18
|
|
|
* |
19
|
|
|
* @package AuthnetJSON |
20
|
|
|
* @author John Conde <[email protected]> |
21
|
|
|
* @copyright John Conde <[email protected]> |
22
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License, Version 2.0 |
23
|
|
|
* @link https://github.com/stymiee/authnetjson |
24
|
|
|
* @see https://developer.authorize.net/api/reference/ |
25
|
|
|
*/ |
26
|
|
|
class TransactionResponse |
27
|
|
|
{ |
|
|
|
|
28
|
|
|
/** |
|
|
|
|
29
|
|
|
* @var array Transaction response fields to map to values parsed from a transaction response string |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
private static $fieldMap = [ |
|
|
|
|
32
|
|
|
1 => 'ResponseCode', |
|
|
|
|
33
|
|
|
2 => 'ResponseSubcode', |
|
|
|
|
34
|
|
|
3 => 'ResponseReasonCode', |
|
|
|
|
35
|
|
|
4 => 'ResponseReasonText', |
|
|
|
|
36
|
|
|
5 => 'AuthorizationCode', |
|
|
|
|
37
|
|
|
6 => 'AVSResponse', |
|
|
|
|
38
|
|
|
7 => 'TransactionID', |
|
|
|
|
39
|
|
|
8 => 'InvoiceNumber', |
|
|
|
|
40
|
|
|
9 => 'Description', |
|
|
|
|
41
|
|
|
10 => 'Amount', |
|
|
|
|
42
|
|
|
11 => 'Method', |
|
|
|
|
43
|
|
|
12 => 'TransactionType', |
|
|
|
|
44
|
|
|
13 => 'CustomerID', |
|
|
|
|
45
|
|
|
14 => 'FirstName', |
|
|
|
|
46
|
|
|
15 => 'LastName', |
|
|
|
|
47
|
|
|
16 => 'Company', |
|
|
|
|
48
|
|
|
17 => 'Address', |
|
|
|
|
49
|
|
|
18 => 'City', |
|
|
|
|
50
|
|
|
19 => 'State', |
|
|
|
|
51
|
|
|
20 => 'ZipCode', |
|
|
|
|
52
|
|
|
21 => 'Country', |
|
|
|
|
53
|
|
|
22 => 'Phone', |
|
|
|
|
54
|
|
|
23 => 'Fax', |
|
|
|
|
55
|
|
|
24 => 'EmailAddress', |
|
|
|
|
56
|
|
|
25 => 'ShipToFirstName', |
|
|
|
|
57
|
|
|
26 => 'ShipToLastName', |
|
|
|
|
58
|
|
|
27 => 'ShipToCompany', |
|
|
|
|
59
|
|
|
28 => 'ShipToAddress', |
|
|
|
|
60
|
|
|
29 => 'ShipToCity', |
|
|
|
|
61
|
|
|
30 => 'ShipToState', |
|
|
|
|
62
|
|
|
31 => 'ShipToZip', |
|
|
|
|
63
|
|
|
32 => 'ShipToCountry', |
|
|
|
|
64
|
|
|
33 => 'Tax', |
|
|
|
|
65
|
|
|
34 => 'Duty', |
|
|
|
|
66
|
|
|
35 => 'Freight', |
|
|
|
|
67
|
|
|
36 => 'TaxExempt', |
|
|
|
|
68
|
|
|
37 => 'PurchaseOrderNumber', |
|
|
|
|
69
|
|
|
38 => 'MD5Hash', |
|
|
|
|
70
|
|
|
39 => 'CardCodeResponse', |
|
|
|
|
71
|
|
|
40 => 'CardholderAuthenticationVerificationResponse', |
|
|
|
|
72
|
|
|
51 => 'AccountNumber', |
|
|
|
|
73
|
|
|
52 => 'CardType', |
|
|
|
|
74
|
|
|
53 => 'SplitTenderID', |
|
|
|
|
75
|
|
|
54 => 'AmountRequested', |
|
|
|
|
76
|
|
|
55 => 'BalanceOnCard' |
|
|
|
|
77
|
|
|
]; |
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
|
|
|
|
80
|
|
|
* @var array Transaction response fields to map to values parsed from a transaction response string |
|
|
|
|
81
|
|
|
*/ |
82
|
|
|
private $responseArray; |
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Creates out TransactionResponse object and assigns the response variables to an array |
86
|
|
|
* |
87
|
|
|
* @param string $response Comma delimited transaction response string |
|
|
|
|
88
|
|
|
*/ |
89
|
2 |
|
public function __construct(string $response) |
|
|
|
|
90
|
|
|
{ |
|
|
|
|
91
|
2 |
|
$this->responseArray = array_merge([null], explode(',', $response)); |
|
|
|
|
92
|
2 |
|
} |
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Gets the requested value out of the response array using the provided key. The location of that value |
|
|
|
|
96
|
|
|
* can be accessed via it's numerical location in the array (starting at zero) or using the key for that field |
|
|
|
|
97
|
|
|
* as defined by Authorize.Net and mapped in self::$fieldMap. |
98
|
|
|
* |
99
|
|
|
* @param mixed $field Name or key of the transaction field to be retrieved |
|
|
|
|
100
|
|
|
* @return string Transaction field to be retrieved |
|
|
|
|
101
|
|
|
*/ |
102
|
4 |
|
public function getTransactionResponseField($field): ?string |
103
|
|
|
{ |
|
|
|
|
104
|
4 |
|
$value = null; |
|
|
|
|
105
|
4 |
|
if (is_int($field)) { |
106
|
1 |
|
$value = $this->responseArray[$field] ?? $value; |
|
|
|
|
107
|
4 |
|
} elseif ($key = array_search($field, self::$fieldMap, true)) { |
|
|
|
|
108
|
4 |
|
$value = $this->responseArray[$key]; |
109
|
|
|
} |
|
|
|
|
110
|
4 |
|
return $value; |
111
|
|
|
} |
|
|
|
|
112
|
|
|
} |
|
|
|
|
113
|
|
|
|