Skip to content

Commit 800dc49

Browse files
committed
create sample code for Create an Accept Payment Transaction
1 parent e626eec commit 800dc49

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package net.authorize.sample.PaymentTransactions;
2+
3+
import java.math.BigDecimal;
4+
import java.math.RoundingMode;
5+
6+
import net.authorize.Environment;
7+
import net.authorize.api.contract.v1.ANetApiResponse;
8+
import net.authorize.api.contract.v1.CreateTransactionRequest;
9+
import net.authorize.api.contract.v1.CreateTransactionResponse;
10+
import net.authorize.api.contract.v1.OpaqueDataType;
11+
import net.authorize.api.contract.v1.MerchantAuthenticationType;
12+
import net.authorize.api.contract.v1.MessageTypeEnum;
13+
import net.authorize.api.contract.v1.PaymentType;
14+
import net.authorize.api.contract.v1.TransactionRequestType;
15+
import net.authorize.api.contract.v1.TransactionResponse;
16+
import net.authorize.api.contract.v1.TransactionTypeEnum;
17+
import net.authorize.api.controller.CreateTransactionController;
18+
import net.authorize.api.controller.base.ApiOperationBase;
19+
20+
public class CreateAnAcceptPaymentTransaction {
21+
22+
//
23+
// Run this sample from command line with:
24+
// java -jar target/CreateAnAcceptPaymentTransaction-jar-with-dependencies.jar
25+
//
26+
public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
27+
28+
29+
//Common code to set for all requests
30+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
31+
32+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
33+
merchantAuthenticationType.setName(apiLoginId);
34+
merchantAuthenticationType.setTransactionKey(transactionKey);
35+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
36+
37+
// Populate the payment data
38+
PaymentType paymentType = new PaymentType();
39+
OpaqueDataType OpaqueData = new OpaqueDataType();
40+
OpaqueData.setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
41+
OpaqueData.setDataValue("119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9");
42+
paymentType.setOpaqueData(OpaqueData);
43+
44+
// Create the payment transaction request
45+
TransactionRequestType txnRequest = new TransactionRequestType();
46+
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
47+
txnRequest.setPayment(paymentType);
48+
txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
49+
50+
// Make the API Request
51+
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
52+
apiRequest.setTransactionRequest(txnRequest);
53+
CreateTransactionController controller = new CreateTransactionController(apiRequest);
54+
controller.execute();
55+
56+
57+
CreateTransactionResponse response = controller.getApiResponse();
58+
59+
if (response!=null) {
60+
// If API Response is ok, go ahead and check the transaction response
61+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
62+
TransactionResponse result = response.getTransactionResponse();
63+
if(result.getMessages() != null){
64+
System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
65+
System.out.println("Response Code: " + result.getResponseCode());
66+
System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
67+
System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
68+
System.out.println("Auth Code: " + result.getAuthCode());
69+
}
70+
else {
71+
System.out.println("Failed Transaction.");
72+
if(response.getTransactionResponse().getErrors() != null){
73+
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
74+
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
75+
}
76+
}
77+
}
78+
else {
79+
System.out.println("Failed Transaction.");
80+
if(response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null){
81+
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
82+
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
83+
}
84+
else {
85+
System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
86+
System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
87+
}
88+
}
89+
}
90+
else {
91+
System.out.println("Null Response.");
92+
}
93+
94+
return response;
95+
96+
}
97+
98+
99+
100+
}

0 commit comments

Comments
 (0)