Skip to content

Commit 80ba553

Browse files
Chase Pay Transaction changes in sample code
1 parent 534c6c3 commit 80ba553

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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.CreditCardType;
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 CreateChasePayTransaction {
21+
22+
//
23+
// Run this sample from command line with:
24+
// java -jar target/ChargeCreditCard-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+
CreditCardType creditCard = new CreditCardType();
40+
creditCard.setCardNumber("4111111111111111");
41+
creditCard.setExpirationDate("2020-12");
42+
// Set the token specific info
43+
creditCard.setIsPaymentToken(true);
44+
creditCard.setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA=");
45+
creditCard.setTokenRequestorName("CHASE_PAY");
46+
creditCard.setTokenRequestorId("12345678901");
47+
creditCard.setTokenRequestorEci("07");
48+
creditCard.setCardCode("999");
49+
paymentType.setCreditCard(creditCard);
50+
51+
// Create the payment transaction request
52+
TransactionRequestType txnRequest = new TransactionRequestType();
53+
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
54+
txnRequest.setPayment(paymentType);
55+
txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
56+
//txnRequest.s
57+
// Make the API Request
58+
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
59+
apiRequest.setTransactionRequest(txnRequest);
60+
//apiRequest.setRefId("123456");
61+
CreateTransactionController controller = new CreateTransactionController(apiRequest);
62+
controller.execute();
63+
64+
65+
CreateTransactionResponse response = controller.getApiResponse();
66+
67+
if (response!=null) {
68+
// If API Response is ok, go ahead and check the transaction response
69+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
70+
TransactionResponse result = response.getTransactionResponse();
71+
if (result.getMessages() != null) {
72+
System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
73+
System.out.println("Response Code: " + result.getResponseCode());
74+
System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
75+
System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
76+
System.out.println("Auth Code: " + result.getAuthCode());
77+
}
78+
else {
79+
System.out.println("Failed get Transaction.");
80+
if (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+
}
85+
}
86+
else {
87+
System.out.println("Failed get Transaction.");
88+
if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
89+
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
90+
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
91+
}
92+
else {
93+
System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
94+
System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
95+
}
96+
}
97+
}
98+
else {
99+
System.out.println("Null Response.");
100+
}
101+
102+
return response;
103+
104+
}
105+
106+
107+
108+
}

src/main/java/net/authorize/sample/SampleCode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private static void ShowMethods()
134134
System.out.println(" GetHeldTransactionList");
135135
System.out.println(" ApproveOrDeclineHeldTransaction");
136136
System.out.println(" GetAnAcceptPaymentPage");
137+
System.out.println(" CreateChasePayTransaction");
137138
}
138139

139140
private static void RunMethod(String methodName)
@@ -343,6 +344,9 @@ private static void RunMethod(String methodName)
343344
break;
344345
case "GetAnAcceptPaymentPage":
345346
GetAnAcceptPaymentPage.run(apiLoginId, transactionKey, amount);
347+
break;
348+
case "CreateChasePayTransaction":
349+
CreateChasePayTransaction.run(apiLoginId, transactionKey, amount);
346350
break;
347351
default:
348352
ShowUsage();

0 commit comments

Comments
 (0)