|
1 | | -package PaymentTransactions; |
| 1 | +package net.authorize.sample.PaymentTransactions; |
| 2 | + |
| 3 | +import java.math.BigDecimal; |
| 4 | + |
| 5 | +import net.authorize.Environment; |
| 6 | +import net.authorize.api.contract.v1.*; |
| 7 | +import net.authorize.api.controller.base.ApiOperationBase; |
| 8 | +import net.authorize.api.controller.CreateTransactionController; |
2 | 9 |
|
3 | 10 | public class VoidTransaction { |
4 | 11 |
|
5 | | - public static void main(String apiLoginId, String transactionKey) { |
6 | | - // TODO Auto-generated method stub |
7 | | - System.out.println("Void Transaction Sample"); |
8 | | - |
9 | | - |
10 | | - } |
| 12 | + // |
| 13 | + // Run this sample from command line with: |
| 14 | + // java -jar target/ChargeCreditCard-jar-with-dependencies.jar |
| 15 | + // |
| 16 | + public static void run(String apiLoginId, String transactionKey) { |
| 17 | + |
| 18 | + // Required: |
| 19 | + /* |
| 20 | + * Merchant Authentication |
| 21 | + * * name |
| 22 | + * * transaction key |
| 23 | + * RefTransId |
| 24 | + */ |
| 25 | + |
| 26 | + // Create Transaction Request. |
| 27 | + // Fill in Merchant authentication field. |
| 28 | + // Ref id |
| 29 | + // Transation Reuest |
| 30 | + // TransactionType = voidTransaction |
| 31 | + // refTransId |
| 32 | + |
| 33 | + |
| 34 | + //Common code to set for all requests |
| 35 | + ApiOperationBase.setEnvironment(Environment.SANDBOX); |
| 36 | + |
| 37 | + MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ; |
| 38 | + merchantAuthenticationType.setName("5KP3u95bQpv"); |
| 39 | + merchantAuthenticationType.setTransactionKey("4Ktq966gC55GAX7S"); |
| 40 | + ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType); |
| 41 | + |
| 42 | + // Create the payment transaction request |
| 43 | + TransactionRequestType txnRequest = new TransactionRequestType(); |
| 44 | + txnRequest.setTransactionType(TransactionTypeEnum.VOID_TRANSACTION.value()); |
| 45 | + txnRequest.setRefTransId("2238786428"); |
| 46 | + |
| 47 | + // Make the API Request |
| 48 | + CreateTransactionRequest apiRequest = new CreateTransactionRequest(); |
| 49 | + apiRequest.setTransactionRequest(txnRequest); |
| 50 | + CreateTransactionController controller = new CreateTransactionController(apiRequest); |
| 51 | + controller.execute(); |
| 52 | + |
| 53 | + CreateTransactionResponse response = controller.getApiResponse(); |
| 54 | + |
| 55 | + |
| 56 | + if (response!=null) { |
| 57 | + |
| 58 | + // If API Response is ok, go ahead and check the transaction response |
| 59 | + if (response.getMessages().getResultCode() == MessageTypeEnum.OK) { |
| 60 | + |
| 61 | + TransactionResponse result = response.getTransactionResponse(); |
| 62 | + if (result.getResponseCode().equals("1")) { |
| 63 | + System.out.println(result.getResponseCode()); |
| 64 | + System.out.println("Successfully Voided Transaction"); |
| 65 | + System.out.println(result.getAuthCode()); |
| 66 | + System.out.println(result.getTransId()); |
| 67 | + } |
| 68 | + else |
| 69 | + { |
| 70 | + System.out.println("Failed Transaction"+result.getResponseCode()); |
| 71 | + } |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + System.out.println("Failed Transaction: "+response.getMessages().getResultCode()); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + } |
11 | 80 |
|
12 | 81 | } |
0 commit comments