@@ -13,31 +13,45 @@ to the results of the transaction.
13
13
Autoloading
14
14
-----------------
15
15
16
+ ``` PHP
16
17
require 'vendor/autoload.php';
18
+ ```
17
19
18
20
Setting Merchant Credentials
19
21
----------------------------
20
22
The easiest way to set credentials is to define constants which the SDK uses:
23
+
24
+ ``` PHP
21
25
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
22
26
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
27
+ ```
23
28
24
29
You can also set credentials manually per request like so:
25
30
31
+ ``` PHP
26
32
$sale = new AuthorizeNetAIM("YOUR_API_LOGIN_ID","YOUR_TRANSACTION_KEY");
27
-
33
+ ```
28
34
29
35
Setting the Transaction Post Location
30
36
-------------------------------------
31
37
32
38
To post transactions to the live Authorize.Net gateway:
39
+
40
+ ``` PHP
33
41
define("AUTHORIZENET_SANDBOX", false);
42
+ ```
34
43
35
44
To post transactions to the Authorize.Net test server:
45
+
46
+ ``` PHP
36
47
define("AUTHORIZENET_SANDBOX", true);
48
+ ```
37
49
38
50
You can also set the location manually per request:
39
- $sale->setSandbox(false);
40
51
52
+ ``` PHP
53
+ $sale->setSandbox(false);
54
+ ```
41
55
42
56
Setting Fields
43
57
--------------
@@ -47,17 +61,22 @@ allows you to set these fields in a few different ways depending on your
47
61
preference.
48
62
49
63
Note: to make things easier on the developer, the "x_ " prefix attached to each
50
- field in the AIM API has been removed. Thus, instead of setting $sale->x_card_num,
51
- set $sale->card_num instead.
64
+ field in the AIM API has been removed. Thus, instead of setting ` $sale->x_card_num ` ,
65
+ set ` $sale->card_num ` instead.
52
66
53
67
1.) By Setting Fields Directly:
68
+
69
+ ``` PHP
54
70
$sale = new AuthorizeNetAIM;
55
71
$sale->amount = "1999.99";
56
72
$sale->card_num = '6011000000000012';
57
73
$sale->exp_date = '04/15';
58
74
$response = $sale->authorizeAndCapture();
75
+ ```
59
76
60
77
2.) By Setting Multiple Fields at Once:
78
+
79
+ ``` PHP
61
80
$sale = new AuthorizeNetAIM;
62
81
$sale->setFields(
63
82
array(
@@ -66,12 +85,15 @@ $sale->setFields(
66
85
'exp_date' => '0415'
67
86
)
68
87
);
88
+ ```
69
89
70
90
3.) By Setting Special Items
71
91
72
92
To add line items or set custom fields use the respective functions:
73
93
74
94
Line Items:
95
+
96
+ ``` PHP
75
97
$sale->addLineItem(
76
98
'item1', // Item Id
77
99
'Golf tees', // Item Name
@@ -80,14 +102,19 @@ $sale->addLineItem(
80
102
'5.00', // Item Unit Price
81
103
'N' // Item taxable
82
104
);
105
+ ```
83
106
84
107
Custom Fields:
108
+
109
+ ``` PHP
85
110
$sale->setCustomField("coupon_code", "SAVE2011");
111
+ ```
86
112
87
113
4.) By Passing in Objects
88
114
89
115
Each property will be copied from the object to the AIM request.
90
116
117
+ ``` PHP
91
118
$sale = new AuthorizeNetAIM;
92
119
$customer = (object)array();
93
120
$customer->first_name = "Jane";
104
131
$customer->cust_id = "55";
105
132
$customer->customer_ip = "98.5.5.5";
106
133
$sale->setFields($customer);
134
+ ```
107
135
108
136
Submitting Transactions
109
137
-----------------------
110
138
To submit a transaction call one of the 7 methods:
111
139
112
- -authorizeAndCapture()
113
- -authorizeOnly()
114
- -priorAuthCapture()
115
- -void()
116
- -captureOnly()
117
- -credit()
140
+ ``` PHP
141
+ AuthorizeNetAIM::authorizeAndCapture()
142
+ AuthorizeNetAIM::authorizeOnly()
143
+ AuthorizeNetAIM::priorAuthCapture()
144
+ AuthorizeNetAIM::void()
145
+ AuthorizeNetAIM::captureOnly()
146
+ AuthorizeNetAIM::credit()
147
+ ```
118
148
119
149
Each method has optional parameters which highlight the fields required by the
120
150
Authorize.Net API for that transaction type.
@@ -125,6 +155,7 @@ eCheck
125
155
To submit an electronic check transaction you can set the required fields individually
126
156
or simply use the setECheck method:
127
157
158
+ ``` PHP
128
159
$sale = new AuthorizeNetAIM;
129
160
$sale->amount = "45.00";
130
161
$sale->setECheck(
@@ -136,25 +167,29 @@ $sale->setECheck(
136
167
'WEB' // echeck_type
137
168
);
138
169
$response = $sale->authorizeAndCapture();
139
-
170
+ ```
140
171
141
172
Partial Authorization Transactions
142
173
----------------------------------
143
174
To enable partial authorization transactions set the partial_auth flag
144
175
to true:
145
176
177
+ ``` PHP
146
178
$sale->allow_partial_auth = true;
179
+ ```
147
180
148
181
You should receive a split tender id in the response if a partial auth
149
182
is made:
150
183
184
+ ``` PHP
151
185
$split_tender_id = $response->split_tender_id;
152
-
186
+ ```
153
187
154
188
Itemized Order Information
155
189
--------------------------
156
190
To add itemized order information use the addLineItem method:
157
191
192
+ ``` PHP
158
193
$auth->addLineItem(
159
194
'item1', // Item Id
160
195
'Golf tees', // Item Name
@@ -163,25 +198,27 @@ $auth->addLineItem(
163
198
'5.00', // Item Unit Price
164
199
'N' // Item taxable
165
200
);
166
-
201
+ ```
167
202
168
203
Merchant Defined Fields
169
204
-----------------------
170
205
You can use the setCustomField method to set any custom merchant defined field(s):
171
206
207
+ ``` PHP
172
208
$sale->setCustomField("entrance_source", "Search Engine");
173
209
$sale->setCustomField("coupon_code", "SAVE2011");
174
-
210
+ ```
175
211
176
212
Transaction Response
177
213
--------------------
178
214
When you submit an AIM transaction you receive an AuthorizeNetAIM_Response
179
215
object in return. You can access each name/value pair in the response as
180
216
you would normally expect:
181
217
218
+ ``` PHP
182
219
$response = $sale->authorizeAndCapture();
183
220
$response->response_code;
184
221
$response->response_subcode;
185
222
$response->response_reason_code;
186
223
$response->transaction_id;
187
-
224
+ ```
0 commit comments