forked from AuthorizeNet/sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
638 lines (525 loc) · 27.5 KB
/
README
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
Authorize.Net Java SDK
======================
The Java SDK is meant to offer an alternate object-oriented model of
development with the Authorize.net APIs (Version 3.1). The SDK is based
entirely off the name-value pair API, but performs the core payment activities
(such as error handling/parsing, network communication, and data encoding)
behind the scenes. Providing the end developer with this, allows the developer
to start integrating immediately without having to write out a mass of boiler
plate code.
The SDK can be used with AIM (Advanced Integration Method), SIM (Server
Integration Method), & DPM (Direct Post Method). While each integration
method may share common components of the SDK, the delivery of the payment
information for each is slightly different. Take SIM for example. Rather than
provide the boiler plate code for making an HTTP POST (like what is done with
AIM), the SIM component offers a utility method in the Transaction object
called createSecureRedirectForm(...) which builds out a HTML FORM and returns
it as a string for display on the page. While this is offered in the SDK as a
helper method, the developer is also able to create their own FORM
programmatically as
well.
Prerequisites
=============
* JDK 1.5.0 or higher
* Ant 1.6.2 or higher (build SDK only)
* Maven 2.2.0 or higher (build SDK only)
Note: Support for building the SDK with either Ant or Maven has bee made.
Please see the respective build processes below. All initial jars
and docs were built with Ant however.
Dependencies
============
The SDK is offered with very few dependencies.
* commons-logging-1.1.1.jar : logging
* log4j-1.2.16.jar : logging
* httpclient-4.0.1.jar : http communication with the payment gateway
* httpcore-4.0.1.jar : http communication with the payment gateway
* junit-4.8.2.jar : unit testing
Build process
==============
* Note: To properly run the unit tests, please reference the
anet_java_sdk.properties.example file, which is a simple properties file that
holds the API credentials for testing the SDK.
Build the SDK with Ant
----------------------
To compile the SDK and create a jar...
$ ant jar
To run the unit tests...
$ ant unit-test
To create the javadocs...
$ ant javadoc
Build the SDK with Maven
------------------------
To compile the SDK and create a jar...
$ mvn clean package
Test Code - Advanced Integration Method (AIM)
=============================================
There are some sample unit tests that are located in the test directory. They
capture basic auth/capture (product purchase) functionality, which most
integrations are looking to get started with.
A simple auth/capture can be performed with the following code (JSP) :
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.util.Map" %>
<%@ page import="net.authorize.Environment" %>
<%@ page import="net.authorize.Merchant" %>
<%@ page import="net.authorize.TransactionType" %>
<%@ page import="net.authorize.aim.Result" %>
<%@ page import="net.authorize.aim.Transaction" %>
<%@ page import="net.authorize.data.*" %>
<%@ page import="net.authorize.data.creditcard.*" %>
<%
String apiLoginID = "YOUR_API_LOGIN_ID";
String transactionKey = "YOUR_TRANSACTION_KEY";
Merchant merchant = Merchant.createMerchant(Environment.SANDBOX,
apiLoginID, transactionKey);
// create credit card
CreditCard creditCard = CreditCard.createCreditCard();
creditCard.setCreditCardNumber("4111 1111 1111 1111");
creditCard.setExpirationMonth("12");
creditCard.setExpirationYear("2015");
// create transaction
Transaction authCaptureTransaction = merchant.createAIMTransaction(
TransactionType.AUTH_CAPTURE, new BigDecimal(1.99));
authCaptureTransaction.setCreditCard(creditCard);
Result<Transaction> result = (Result<Transaction>)merchant
.postTransaction(authCaptureTransaction);
if(result.isApproved()) {
out.println("Approved!</br>");
out.println("Transaction Id: " + result.getTarget().getTransactionId());
} else if (result.isDeclined()) {
out.println("Declined.</br>");
out.println(result.getReasonResponseCode() + " : " + result.getResponseText());
} else {
out.println("Error.</br>");
out.println(result.getReasonResponseCode() + " : " + result.getResponseText());
}
%>
Test Code - Advanced Integration Method (AIM) + Card Present
============================================================
There are some sample unit tests that are located in the test directory. Similar
to the AIM test, however they leverage the Card Present API.
A simple auth/capture can be performed with the following code (JSP) :
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.util.Map" %>
<%@ page import="net.authorize.Environment" %>
<%@ page import="net.authorize.Merchant" %>
<%@ page import="net.authorize.TransactionType" %>
<%@ page import="net.authorize.aim.cardpresent.Result" %>
<%@ page import="net.authorize.aim.Transaction" %>
<%@ page import="net.authorize.data.*" %>
<%@ page import="net.authorize.data.creditcard.*" %>
<%
String apiLoginID = "YOUR_API_LOGIN_ID";
String transactionKey = "YOUR_TRANSACTION_KEY";
String MD5Value = "MD5_VALUE";
Merchant merchant = Merchant.createMerchant(Environment.SANDBOX,
apiLoginID, transactionKey);
merchant.setDeviceType(net.authorize.DeviceType.VIRTUAL_TERMINAL);
merchant.setMarketType(net.authorize.MarketType.RETAIL);
merchant.setMD5Value(MD5Value);
// create credit card
CreditCard creditCard = CreditCard.createCreditCard();
creditCard.setCardType(CardType.VISA);
creditCard.setTrack1("%B4111111111111111^CARDUSER/JOHN^1803101000000000020000831000000?");
creditCard.setTrack2(";4111111111111111=1803101000020000831?");
// create transaction
Transaction authCaptureTransaction = merchant.createAIMTransaction(
TransactionType.AUTH_CAPTURE, new BigDecimal(1.99));
authCaptureTransaction.setCreditCard(creditCard);
Result<Transaction> result = (Result<Transaction>)merchant
.postTransaction(authCaptureTransaction);
if(result.isApproved()) {
out.println("Approved!</br>");
out.println("Transaction Id: " + result.getTransId());
} else if (result.isDeclined()) {
out.println("Declined.</br>");
out.println(result.getResponseReasonCodes().get(0) + " : " +
result.getResponseReasonCodes().get(0).getReasonText());
} else {
out.println("Error.</br>");
out.println(result.getResponseReasonCodes().get(0) + " : " +
result.getResponseReasonCodes().get(0).getReasonText());
}
%>
Test Code - Server Integration Method (SIM)
===========================================
The SDK implementation for SIM is fairly concise. To easily create a finger-
print for your form POST, you can reference the following code :
Fingerprint fingerprint = Fingerprint.createFingerprint(
"YOUR_API_LOGIN_ID",
"YOUR_TRANSACTION_KEY",
1234567890,
"AMOUNT");
String x_fp_sequence = fingerprint.getSequence();
String x_fp_timestamp = fingerprint.getTimeStamp();
String x_fp_hash = fingerprint.getFingerprintHash();
Parsing a Relay Response is performed by using the ResponseParser class.
It takes as it's only method parameter a pipe (|) delimited string
that represents the transaction response passed to the merchant by
Authorize.net.
HashMap<ResponseField, String> responseMap =
ResponseParser.parseResponseString(responseString);
Setting up the necessary data containers and getting a form that can be
displayed directly on the page can be performed via the following code (JSP) :
<%@ page import="net.authorize.sim.*" %>
<%@ page import="net.authorize.sim.button.*" %>
<%@ page import="net.authorize.data.*" %>
<%@ page import="net.authorize.data.creditcard.*" %>
<%
String apiLoginID = "YOUR_API_LOGIN_ID";
String transactionKey = "YOUR_TRANSACTION_KEY";
String amount = "1.99";
Fingerprint fingerprint = Fingerprint.createFingerprint(
apiLoginID,
transactionKey,
1234567890,
amount);
long x_fp_sequence = fingerprint.getSequence();
long x_fp_timestamp = fingerprint.getTimeStamp();
String x_fp_hash = fingerprint.getFingerprintHash();
%>
<FORM NAME='formName' ID='formID' ACTION='https://test.authorize.net/gateway/transact.dll' METHOD='POST'>
<INPUT TYPE='HIDDEN' NAME='x_login' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(apiLoginID)%>'>
<INPUT TYPE='HIDDEN' NAME='x_fp_sequence' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(Long.toString(x_fp_sequence))%>'>
<INPUT TYPE='HIDDEN' NAME='x_fp_timestamp' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(Long.toString(x_fp_timestamp))%>'>
<INPUT TYPE='HIDDEN' NAME='x_fp_hash' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(x_fp_hash)%>'>
<INPUT TYPE='HIDDEN' NAME='x_version' VALUE='3.1'>
<INPUT TYPE='HIDDEN' NAME='x_method' VALUE='CC'>
<INPUT TYPE='HIDDEN' NAME='x_type' VALUE='AUTH_CAPTURE'>
<INPUT TYPE='TEXT' NAME='x_amount' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(amount)%>'>
<INPUT TYPE='HIDDEN' NAME='x_show_form' VALUE='payment_form'>
<INPUT TYPE='HIDDEN' NAME='x_test_request' VALUE='FALSE'>
<INPUT TYPE='SUBMIT' NAME='submit_button' VALUE='Submit' CLASS='null'>
</FORM>
If you were to load this JSP in your browser and hit submit, you should be taken
to a page on the Authorize.Net servers that contains a form asking for payment
information to be submitted.
Test Code - Direct Post Method (DPM)
====================================
* This method is implemented via three code snippets. First, create the page
that will host the form that will be submitted. We're calling this form.jsp,
and you will be required to enter in your API_LOGIN_ID, TRANSACTION_KEY, and
your public facing MERCHANT_HOST domain name. Note, you may want to alter the
relayResponseUrl and place the jsp in a separate webapp container of your
choosing.
========
form.jsp
========
<%@ page import="net.authorize.sim.*" %>
<%
String apiLoginId = "YOUR_API_LOGIN_ID";
String transactionKey = "YOUR_TRANSACTION_KEY";
String relayResponseUrl = "http://MERCHANT_HOST/relay_response.jsp";
String amount = "1.99";
Fingerprint fingerprint = Fingerprint.createFingerprint(
apiLoginId,
transactionKey,
1234567890, // random sequence used for the finger print creation
amount);
long x_fp_sequence = fingerprint.getSequence();
long x_fp_timestamp = fingerprint.getTimeStamp();
String x_fp_hash = fingerprint.getFingerprintHash();
%>
<FORM NAME='secure_redirect_form' ID='secure_redirect_form_id' ACTION='https://test.authorize.net/gateway/transact.dll' METHOD='POST'>
<label>CreditCardNumber</label><input type='text' class='text' name='x_card_num' size='15'></input>
<label>Exp.</label><input type='text' class='text' name='x_exp_date' size='4'></input>
<label>Amount</label><input type='text' class='text' name='x_amount' size='9' readonly value='<%=net.authorize.util.StringUtils.sanitizeString(amount)%>'></input>
<INPUT TYPE='HIDDEN' NAME='x_invoice_num' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(Long.toString(System.currentTimeMillis()))%>'>
<INPUT TYPE='HIDDEN' NAME='x_relay_url' VALUE='<%=relayResponseUrl%>'>
<INPUT TYPE='HIDDEN' NAME='x_login' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(apiLoginId)%>'>
<INPUT TYPE='HIDDEN' NAME='x_fp_sequence' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(Long.toString(x_fp_sequence))%>'>
<INPUT TYPE='HIDDEN' NAME='x_fp_timestamp' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(Long.toString(x_fp_timestamp))%>'>
<INPUT TYPE='HIDDEN' NAME='x_fp_hash' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(x_fp_hash)%>'>
<INPUT TYPE='HIDDEN' NAME='x_version' VALUE='3.1'>
<INPUT TYPE='HIDDEN' NAME='x_method' VALUE='CC'>
<INPUT TYPE='HIDDEN' NAME='x_type' VALUE='AUTH_CAPTURE'>
<INPUT TYPE='HIDDEN' NAME='x_amount' VALUE='<%=net.authorize.util.StringUtils.sanitizeString(amount)%>'>
<INPUT TYPE='HIDDEN' NAME='x_test_request' VALUE='FALSE'>
<INPUT TYPE='HIDDEN' NAME='notes' VALUE='extra hot please'>
<INPUT TYPE='SUBMIT' NAME='buy_button' VALUE='BUY'>
</FORM>
* Create a page that will receive the response. We're calling this
relay_response.jsp (referenced in the form above by the relayResponseUrl).
Once again, you will be required to enter in your API_LOGIN_ID and your public
facing MERCHANT_HOST domain name. Additionally, you will have to provide your
MD5_HASH_KEY. Unless you have explicitly set this in the merchant interface:
Account > Settings > Security Settings > MD5-Hash, leave this as an empty
string.
==================
relay_response.jsp
==================
<%@ page import="java.util.Map" %>
<%@ page import="net.authorize.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--
var referrer = document.referrer;
if (referrer.substr(0,7)=="http://") referrer = referrer.substr(7);
if (referrer.substr(0,8)=="https://") referrer = referrer.substr(8);
if(referrer && referrer.indexOf(document.location.hostname) != 0) {
<%
String apiLoginId = "YOUR_API_LOGIN_ID";
String receiptPageUrl = "http://MERCHANT_HOST/order_receipt.jsp";
/*
* Leave the MD5HashKey as is - empty string, unless you have explicitly set it in the merchant interface:
* Account > Settings > Security Settings > MD5-Hash
*/
String MD5HashKey = "";
net.authorize.sim.Result result = net.authorize.sim.Result.createResult(apiLoginId, MD5HashKey, request.getParameterMap());
// perform Java server side processing...
// ...
// build receipt url buffer
StringBuffer receiptUrlBuffer = new StringBuffer(receiptPageUrl);
if(result != null) {
receiptUrlBuffer.append("?");
receiptUrlBuffer.append(ResponseField.RESPONSE_CODE.getFieldName()).append("=");
receiptUrlBuffer.append(result.getResponseCode().getCode());
receiptUrlBuffer.append("&");
receiptUrlBuffer.append(ResponseField.RESPONSE_REASON_CODE.getFieldName()).append("=");
receiptUrlBuffer.append(result.getReasonResponseCode().getResponseReasonCode());
receiptUrlBuffer.append("&");
receiptUrlBuffer.append(ResponseField.RESPONSE_REASON_TEXT.getFieldName()).append("=");
receiptUrlBuffer.append(result.getResponseMap().get(ResponseField.RESPONSE_REASON_TEXT.getFieldName()));
if(result.isApproved()) {
receiptUrlBuffer.append("&").append(ResponseField.TRANSACTION_ID.getFieldName()).append("=");
receiptUrlBuffer.append(result.getResponseMap().get(ResponseField.TRANSACTION_ID.getFieldName()));
}
}
%>
// Use Javascript to redirect the page to the receipt redirect url. If Javascript is not
// available, then the <meta> refresh tag will handle the redirect.
document.location = "<%=receiptUrlBuffer.toString()%>";
}
//-->
</script>
<noscript><meta http-equiv="refresh" content="0;url=<%=receiptUrlBuffer.toString()%>"></noscript>
</body>
</html>
* Create a page, called order_receipt.jsp, that will host the receipt
information. This is what the user will finally see.
=================
order_receipt.jsp
=================
<%@ page import="java.util.Map" %>
<%@ page import="net.authorize.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<h1>Your Receipt Page</h1></br>
<%
// Show the confirmation data
Map<String, String[]> requestParameterMap = request.getParameterMap();
if(requestParameterMap != null && requestParameterMap.containsKey(ResponseField.RESPONSE_CODE.getFieldName())) {
String transactionId = "";
if(requestParameterMap.containsKey(ResponseField.TRANSACTION_ID.getFieldName())) {
transactionId = requestParameterMap.get(ResponseField.TRANSACTION_ID.getFieldName())[0];
}
// 1 means we have a successful transaction
if("1".equals(requestParameterMap.get(ResponseField.RESPONSE_CODE.getFieldName())[0])) {
%>
<h2>Success!</h2>
<h3>Your transaction ID:</h3>
<div><%=net.authorize.util.StringUtils.sanitizeString(transactionId)%></div>
<%
} else {
%>
<h2>Error!</h2>
<h3><%=net.authorize.util.StringUtils.sanitizeString(
requestParameterMap.get(ResponseField.RESPONSE_REASON_TEXT.getFieldName())[0])%></h3>
<table>
<tr>
<td>response code</td>
<td><%=net.authorize.util.StringUtils.sanitizeString(
requestParameterMap.get(ResponseField.RESPONSE_CODE.getFieldName())[0])%></td>
</tr>
<tr>
<td>response reason code</td>
<td><%=net.authorize.util.StringUtils.sanitizeString(requestParameterMap.get(ResponseField.RESPONSE_REASON_CODE.getFieldName())[0])%></td>
</tr>
</table>
</div>
<%
}
}
%>
</body>
</html>
Upon loading form.jsp and following the steps, you should have been able to
successfully enter in your credit card information hit submit and receive a
success or error message that is hosted on your merchant server.
Test Code - Automated Recurring Billing (ARB)
=============================================
There are some sample unit tests that are located in the test directory. They
capture basic create/update/cancel/get subscription recurring billing requests.
A simple subscription creation can be performed with the following code (JSP) :
<%@ page import="java.math.BigDecimal" %>
<%@ page import="net.authorize.Merchant" %>
<%@ page import="net.authorize.Environment" %>
<%@ page import="net.authorize.Transaction" %>
<%@ page import="net.authorize.arb.*" %>
<%@ page import="net.authorize.xml.Message" %>
<%@ page import="net.authorize.data.xml.*" %>
<%@ page import="net.authorize.data.arb.*" %>
<%@ page import="net.authorize.data.creditcard.CreditCard" %>
<%
String apiLoginID = "YOUR_API_LOGIN_ID";
String transactionKey = "YOUR_TRANSACTION_KEY";
Merchant merchant = Merchant.createMerchant(Environment.SANDBOX,
apiLoginID, transactionKey);
PaymentSchedule new_schedule = PaymentSchedule.createPaymentSchedule();
new_schedule.setIntervalLength(1);
new_schedule.setSubscriptionUnit(SubscriptionUnitType.MONTHS);
new_schedule.setStartDate("2019-01-01");
new_schedule.setTotalOccurrences(7);
new_schedule.setTrialOccurrences(0);
// Create a new credit card
//
CreditCard credit_card = CreditCard.createCreditCard();
credit_card.setCreditCardNumber("4111 1111 1111 1111");
credit_card.setExpirationDate("2029-07");
// Create a billing info
//
Address billing_info = Address.createAddress();
billing_info.setFirstName("Test " + System.currentTimeMillis());
billing_info.setLastName("Tester");
// Create a customer and specify billing info
//
Customer customer = Customer.createCustomer();
customer.setBillTo(billing_info);
// Create a subscription and specify payment, schedule and customer
//
Subscription subscription = Subscription.createSubscription();
subscription.setPayment(Payment.createPayment(credit_card));
subscription.setSchedule(new_schedule);
subscription.setCustomer(customer);
subscription.setAmount(new BigDecimal(6.00));
subscription.setTrialAmount(Transaction.ZERO_AMOUNT);
subscription.setRefId("REF:" + System.currentTimeMillis());
subscription.setName("Demo Subscription " + System.currentTimeMillis());
net.authorize.arb.Transaction transaction =
merchant.createARBTransaction(TransactionType.CREATE_SUBSCRIPTION,
subscription);
Result<Transaction> result = (Result<Transaction>)merchant.postTransaction(transaction);
out.println("Result Code: " + (result.getResultCode() != null ? result.getResultCode() : "No result code") + "<br/>");
out.println("Result Subscription Id: " + result.getResultSubscriptionId() + "<br/>");
for(int i = 0; i < result.getMessages().size(); i++){
Message message = (Message)result.getMessages().get(i);
out.println("Message code/text: " + message.getCode() + " - " + message.getText() + "<br/>");
}
%>
Test Code - Customer Information Manager (CIM)
==============================================
There are some sample unit tests that are located in the test directory. They
capture requests that create, delete, get, and update customer profile
information, including payment and address information.
A simple customer profile can be created with the following code (JSP) :
<%@ page import="net.authorize.Merchant" %>
<%@ page import="net.authorize.Environment" %>
<%@ page import="net.authorize.Transaction" %>
<%@ page import="net.authorize.cim.*" %>
<%@ page import="net.authorize.data.cim.*" %>
<%@ page import="net.authorize.data.xml.*" %>
<%@ page import="net.authorize.xml.Message" %>
<%@ page import="net.authorize.data.creditcard.CreditCard" %>
<%
String apiLoginID = "YOUR_API_LOGIN_ID";
String transactionKey = "YOUR_TRANSACTION_KEY";
Merchant merchant = Merchant.createMerchant(Environment.SANDBOX,
apiLoginID, transactionKey);
CustomerProfile customerProfile = CustomerProfile.createCustomerProfile();
customerProfile.setDescription("Customer A");
customerProfile.setMerchantCustomerId("123456789");
customerProfile.setEmail("[email protected]");
Address billingInfo = Address.createAddress();
billingInfo.setFirstName("Joe");
billingInfo.setLastName("Test");
billingInfo.setCompany("CompanyA");
billingInfo.setAddress("123 Street");
billingInfo.setCity("AnyCity");
billingInfo.setState("CA");
billingInfo.setCountry("US");
billingInfo.setZipPostalCode("90123");
billingInfo.setPhoneNumber("415-555-1212");
billingInfo.setFaxNumber("415-555-1313");
CreditCard creditCard = CreditCard.createCreditCard();
creditCard.setCreditCardNumber("4111111111111111");
creditCard.setExpirationDate("2029-07");
PaymentProfile paymentProfile = PaymentProfile.createPaymentProfile();
paymentProfile.setBillTo(billingInfo);
paymentProfile.addPayment(Payment.createPayment(creditCard));
paymentProfile.setCustomerType(CustomerType.INDIVIDUAL);
// Create a new customer profile
net.authorize.cim.Transaction transaction =
merchant.createCIMTransaction(TransactionType.CREATE_CUSTOMER_PROFILE);
transaction.setRefId(Long.toString(System.currentTimeMillis()));
transaction.setCustomerProfile(customerProfile);
transaction.addPaymentProfile(paymentProfile);
transaction.setValidationMode(ValidationModeType.TEST_MODE);
Result<Transaction> result = (Result<Transaction>)merchant.postTransaction(transaction);
out.println("Result Code: " + (result.getResultCode() != null ? result.getResultCode() : "No result code") + "<br>");
if(result.getCustomerProfileId() != null){
out.println("Result customerProfile Id: " + result.getCustomerProfileId() + "<br>");
}
for(int i = 0; i < result.getMessages().size(); i++){
Message message = (Message)result.getMessages().get(i);
out.println(message.getCode() + " - " + message.getText() + "<br>");
}
%>
Test Code - Transaction Details
===============================
There are some sample unit tests that are located in the test directory. They
capture requests that retrieve transaction data that was processed by Authorize.Net.
A simple batch list request can be created with the following code (JSP) :
<%@ page import="net.authorize.Merchant" %>
<%@ page import="net.authorize.Environment" %>
<%@ page import="net.authorize.Transaction" %>
<%@ page import="net.authorize.reporting.*" %>
<%
String apiLoginID = "YOUR_API_LOGIN_ID";
String transactionKey = "YOUR_TRANSACTION_KEY";
Merchant merchant = Merchant.createMerchant(Environment.SANDBOX,
apiLoginID, transactionKey);
net.authorize.reporting.Transaction transaction = merchant.createReportingTransaction(net.authorize.reporting.TransactionType.GET_SETTLED_BATCH_LIST);
net.authorize.data.xml.reporting.ReportingDetails reportingDetails = net.authorize.data.xml.reporting.ReportingDetails.createReportingDetails();
reportingDetails.setBatchIncludeStatistics(true);
transaction.setReportingDetails(reportingDetails);
Result<Transaction> result = (Result<Transaction>)merchant.postTransaction(transaction);
out.println("Result Code: " + (result.getResultCode() != null ? result.getResultCode() : "No result code") + "<br>");
for(net.authorize.data.xml.reporting.BatchDetails batchDetail : result.getReportingDetails().getBatchDetailsList()) {
out.println("<hr/>");
out.println("* id: " + batchDetail.getBatchId() + "<br>");
out.println("* settlementState: " + batchDetail.getSettlementState().value() + "<br>");
out.println("* local settlementTime: " + batchDetail.getSettlementTimeLocal().toString() + "<br>");
out.println("* UTC settlementTime: " + batchDetail.getSettlementTimeUTC().toString() + "<br>");
out.println("* paymentMethod: " + batchDetail.getPaymentMethod() + "<br>");
for(net.authorize.data.xml.reporting.BatchStatistics batchStat :batchDetail.getBatchStatisticsList()) {
out.println("<table>");
out.println("<tr><td>accountType</td><td>" + batchStat.getAccountType()+"</td>");
out.println("<tr><td>chargeAmount</td><td>" + batchStat.getChargeAmount()+"</td>");
out.println("<tr><td>chargebackAmount</td><td>" + batchStat.getChargebackAmount()+"</td>");
out.println("<tr><td>chargebackCount</td><td>" + batchStat.getChargebackCount()+"</td>");
out.println("<tr><td>chargeChargebackAmount</td><td>" + batchStat.getChargeChargebackAmount()+"</td>");
out.println("<tr><td>chargeChargebackCount</td><td>" + batchStat.getChargeChargebackCount()+"</td>");
out.println("<tr><td>chargeCount</td><td>" + batchStat.getChargeCount()+"</td>");
out.println("<tr><td>chargeReturnedItemsAmount</td><td>" + batchStat.getChargeReturnedItemsAmount()+"</td>");
out.println("<tr><td>chargeReturnedItemsCount</td><td>" +batchStat.getChargeReturnedItemsCount()+"</td>");
out.println("<tr><td>correctionNoticeCount</td><td>" + batchStat.getCorrectionNoticeCount()+"</td>");
out.println("<tr><td>declineCount</td><td>" + batchStat.getDeclineCount()+"</td>");
out.println("<tr><td>errorCount</td><td>" +batchStat.getErrorCount()+"</td>");
out.println("<tr><td>refundAmount</td><td>" + batchStat.getRefundAmount()+"</td>");
out.println("<tr><td>refundCount</td><td>" + batchStat.getRefundCount()+"</td>");
out.println("<tr><td>refundChargebackAmount</td><td>" + batchStat.getRefundChargebackAmount()+"</td>");
out.println("<tr><td>refundReturnedItemsAmount</td><td>" + batchStat.getRefundReturnedItemsAmount()+"</td>");
out.println("<tr><td>refundReturnedItemsCount</td><td>" + batchStat.getRefundReturnedItemsCount()+"</td>");
out.println("<tr><td>returnedItemAmount</td><td>" + batchStat.getReturnedItemAmount()+"</td>");
out.println("<tr><td>returnedItemCount</td><td>" + batchStat.getReturnedItemCount()+"</td>");
out.println("<tr><td>voidCount</td><td>" + batchStat.getVoidCount()+"</td>");
out.println("</table>");
}
}
%>