| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,102 @@ | |||
| 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 | + // | ||
| 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 | + } | ||
| 97 | + | ||
| 98 | + return response; | ||
| 99 | + | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments