-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthorizeNet_AIM_9.inc
208 lines (182 loc) · 7.41 KB
/
AuthorizeNet_AIM_9.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?lasso
define authorizenet_aim_9(
AIMParams::map,
-testdeveloper::boolean=true,
-testrequest::boolean=false) => {
if(local_defined('testrequest')) => {
#testrequest -> isnota(::boolean) ? return 'testrequest is not boolean'
}
/*
==================
CONFIGURATION
==================
Configuration includes configuring the Authorize.Net website Merchant Interface, setting values in this tag, and passing values into this tag as a map of key/values.
In the Authorize.Net Merchant Interface, obtain your transaction key.
Account > Settings > API Login ID and Transaction Key
You will enter your transaction key below.
Next configure the response delimiter character.
Account > Settings > Direct Response
Use a pipe and no encapsulation characters:
Delimited Response: (X) Yes ( ) No
Default Field Separator | (pipe) or [ ]
Field Encapsulation Character [blank] or [ ]
If you do not use the above settings then you must change the corresponding values as defined elsewhere in this tag.
Now enter configuration values for this tag below.
You can choose to either set configuration values in this tag below or pass them in as values in the map of AIM parameters. Any values passed into this tag will override their corresponding values entered below.
*/
// Your API login ID for the payment gateway account
local(x_login) = 'ENTER_YOUR_LOGIN'
// Your transaction key obtained from the Merchant Interface
local(x_tran_key) = 'ENTER_YOUR_TRANSACTION_KEY'
// Most transaction types will be AUTH_CAPTURE.
// See the AIM Guide for other types and further requirements.
local(x_type) = 'AUTH_CAPTURE'
// If any of the following values have not been passed into this tag via the map of AIM parameters, then insert the configured values above.
#AIMParams -> find('x_login') == void ? #AIMParams -> insert('x_login'=#x_login)
#AIMParams -> find('x_tran_key') == void ? #AIMParams -> insert('x_tran_key'=#x_tran_key)
#AIMParams -> find('x_type') == void ? #AIMParams -> insert('x_type'=#x_type)
// Initialize variables
local(
CurrentParam = null,
AIMParamArray = array,
AIMParamstring = string,
AIMURL = string,
AIMResult = string,
AIMResultArray = array,
AIMResultLabelArray = array,
AIMCurrentResultLabel = null,
output = null,
)
/*
The following URL will be used to send your POST parameters to Authorize.Net. 'test' is used for testing your developer x_login and x_tran_key values, whereas 'secure' is used for testing your merchant account values.
Note that you can still submit test transactions to 'secure' either by setting the Authorize.Net merchant interface to TEST MODE or by submitting a transaction with the parameter 'x_test_request'='TRUE'.
*/
if(#testdeveloper == true) => {
#AIMURL = 'https://test.authorize.net/gateway/transact.dll'
else
#AIMURL = 'https://secure2.authorize.net/gateway/transact.dll'
}
if(#testrequest == true) => {
// Send a test transaction request to the designated server.
#AIMParams -> insert('x_test_request' = 'TRUE')
else
// Rely upon the TEST MODE configuration in the Authorize.Net Merchant Interface. Omitting -testrequest is equivalent to setting it to 'FALSE'.
#AIMParams -> insert('x_test_request' = 'FALSE')
}
/*
The following commented parameters should be set through the merchant web interface on Authorize.Net and are placed here for reference only. However, if you set a parameter in Authorize.Net, comment it below; and if you do not set a parameter in Authorize.Net, then uncomment it here. In other words, define parameters in one and only one place.
*/
// #AIMParams -> insert('x_test_request'='FALSE')
// #AIMParams -> insert('x_version'='3.1')
// #AIMParams -> insert('x_delim_data'='TRUE')
#AIMParams -> insert('x_relay_response'='FALSE') // Do not change
#AIMParams -> forEachPair => {
#AIMParamArray -> insert(#1 -> first = #1 -> second)
}
// The first 68 result labels are reserved by the AIM gateway for version 3.1. Do not alter their order or names.
local(aimresultlabels) = array(
'x_response_code',
'x_response_subcode',
'x_response_reason_code',
'x_response_reason_text',
'x_approval_code',
'x_avs_result_code',
'x_transaction_id',
'x_invoice_num',
'x_description',
'x_amount',
'x_method',
'x_type',
'x_cust_id',
'x_first_name',
'x_last_name',
'x_company',
'x_address',
'x_city',
'x_state',
'x_zip',
'x_country',
'x_phone',
'x_fax',
'x_email',
'x_ship_to_first_name',
'x_ship_to_last_name',
'x_ship_to_company',
'x_ship_to_address',
'x_ship_to_city',
'x_ship_to_state',
'x_ship_to_zip',
'x_ship_to_country',
'x_tax',
'x_duty',
'x_freight',
'x_tax_exempt',
'x_po_num',
'x_MD5_hash',
'x_card_code',
'x_cavv_resp_code',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'x_acct_number_last4',
'x_card_type',
'x_split_tender_id',
'x_prepaid_requested_amount',
'x_prepaid_balance_on_card',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
// The following labels are optionally defined by the merchant and echoed by the AIM gateway. If you do not add them here, they will not be echoed by the AIM Results Array and not added to the #output.
'x_comments',
'x_another_example')
// Send parameters to Authorize.Net. Cross fingers.
#AIMResult = string(include_url(#AIMURL, -postparams = #AIMParamArray))
/*
The character used in the following split must be the same as the character you use in your Authorize.Net settings:
Account > Settings > Direct Response > Direct Response Delimiter
*/
#AIMResultArray = #AIMResult -> split('|')
if(#AIMResultArray -> size == 1) => {
// uh-oh. There was a failure. Check your configuration in the Merchant Interface or in this tag.
#output = #AIMResult
else
// Yippee! The gateway returned a response we can parse to determine whether the transaction was successful or has failed.
#output = map
local(counter) = 0
with current_result in #AIMResultArray do => {
#counter += 1
if(#aimresultlabels -> size > #counter) => {
// We are within the range of defined results labels.
local(current_label) = #aimresultlabels -> get(#counter)
if(#current_result != '') => {
#output -> insert(#current_label = #current_result)
}
else
// We are outside the range of defined results labels, and so we create ennumerated labels.
local(current_label = 'x_out_of_range_label_' + #counter)
if(#current_result != '') => {
#output -> insert(#current_label = #current_result)
}
}
}
}
return #output
}
?>