|
19 | 19 |
|
20 | 20 | public class CreateChasePayTransaction { |
21 | 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) { |
| 22 | + // |
| 23 | + // Run this sample from command line with: |
| 24 | + // |
| 25 | + public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) { |
| 26 | + |
| 27 | + // Common code to set for all requests |
| 28 | + ApiOperationBase.setEnvironment(Environment.SANDBOX); |
| 29 | + |
| 30 | + MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType(); |
| 31 | + merchantAuthenticationType.setName(apiLoginId); |
| 32 | + merchantAuthenticationType.setTransactionKey(transactionKey); |
| 33 | + ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType); |
| 34 | + |
| 35 | + // Populate the payment data |
| 36 | + PaymentType paymentType = new PaymentType(); |
| 37 | + CreditCardType creditCard = new CreditCardType(); |
| 38 | + creditCard.setCardNumber("4111111111111111"); |
| 39 | + creditCard.setExpirationDate("2020-12"); |
| 40 | + // Set the token specific info |
| 41 | + creditCard.setIsPaymentToken(true); |
| 42 | + creditCard.setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA="); |
| 43 | + creditCard.setTokenRequestorName("CHASE_PAY"); |
| 44 | + creditCard.setTokenRequestorId("12345678901"); |
| 45 | + creditCard.setTokenRequestorEci("07"); |
| 46 | + creditCard.setCardCode("999"); |
| 47 | + paymentType.setCreditCard(creditCard); |
| 48 | + |
| 49 | + // Create the payment transaction request |
| 50 | + TransactionRequestType txnRequest = new TransactionRequestType(); |
| 51 | + txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value()); |
| 52 | + txnRequest.setPayment(paymentType); |
| 53 | + txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING)); |
| 54 | + // Make the API Request |
| 55 | + CreateTransactionRequest apiRequest = new CreateTransactionRequest(); |
| 56 | + apiRequest.setTransactionRequest(txnRequest); |
| 57 | + CreateTransactionController controller = new CreateTransactionController(apiRequest); |
| 58 | + controller.execute(); |
| 59 | + |
| 60 | + CreateTransactionResponse response = controller.getApiResponse(); |
| 61 | + |
| 62 | + if (response != null) { |
| 63 | + // If API Response is ok, go ahead and check the transaction response |
| 64 | + if (response.getMessages().getResultCode() == MessageTypeEnum.OK) { |
| 65 | + TransactionResponse result = response.getTransactionResponse(); |
| 66 | + if (result.getMessages() != null) { |
| 67 | + System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId()); |
| 68 | + System.out.println("Response Code: " + result.getResponseCode()); |
| 69 | + System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode()); |
| 70 | + System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription()); |
| 71 | + System.out.println("Auth Code: " + result.getAuthCode()); |
| 72 | + } else { |
| 73 | + System.out.println("Failed get Transaction."); |
| 74 | + if (response.getTransactionResponse().getErrors() != null) { |
| 75 | + System.out.println("Error Code: " |
| 76 | + + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode()); |
| 77 | + System.out.println("Error message: " |
| 78 | + + response.getTransactionResponse().getErrors().getError().get(0).getErrorText()); |
| 79 | + } |
| 80 | + } |
| 81 | + } else { |
| 82 | + System.out.println("Failed get Transaction."); |
| 83 | + if (response.getTransactionResponse() != null |
| 84 | + && response.getTransactionResponse().getErrors() != null) { |
| 85 | + System.out.println("Error Code: " |
| 86 | + + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode()); |
| 87 | + System.out.println("Error message: " |
| 88 | + + response.getTransactionResponse().getErrors().getError().get(0).getErrorText()); |
| 89 | + } else { |
| 90 | + System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode()); |
| 91 | + System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText()); |
| 92 | + } |
| 93 | + } |
| 94 | + } else { |
| 95 | + System.out.println("Null Response."); |
| 96 | + } |
27 | 97 |
|
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 | 98 | return response; |
103 | 99 |
|
104 | | - } |
105 | | - |
106 | | - |
| 100 | + } |
107 | 101 |
|
108 | 102 | } |
0 commit comments