|
| 1 | +package net.authorize.sample.FraudManagement; |
| 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.AfdsTransactionEnum; |
| 9 | +import net.authorize.api.contract.v1.CreateTransactionRequest; |
| 10 | +import net.authorize.api.contract.v1.CreateTransactionResponse; |
| 11 | +import net.authorize.api.contract.v1.CreditCardType; |
| 12 | +import net.authorize.api.contract.v1.HeldTransactionRequestType; |
| 13 | +import net.authorize.api.contract.v1.MerchantAuthenticationType; |
| 14 | +import net.authorize.api.contract.v1.MessageTypeEnum; |
| 15 | +import net.authorize.api.contract.v1.PaymentType; |
| 16 | +import net.authorize.api.contract.v1.TransactionRequestType; |
| 17 | +import net.authorize.api.contract.v1.TransactionResponse; |
| 18 | +import net.authorize.api.contract.v1.TransactionTypeEnum; |
| 19 | +import net.authorize.api.contract.v1.UpdateHeldTransactionRequest; |
| 20 | +import net.authorize.api.contract.v1.UpdateHeldTransactionResponse; |
| 21 | +import net.authorize.api.controller.CreateTransactionController; |
| 22 | +import net.authorize.api.controller.UpdateHeldTransactionController; |
| 23 | +import net.authorize.api.controller.base.ApiOperationBase; |
| 24 | + |
| 25 | +public class ApproveOrDeclineHeldTransaction { |
| 26 | + |
| 27 | + public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionId) { |
| 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 | + |
| 38 | + // Create the payment transaction request |
| 39 | + HeldTransactionRequestType txnRequest = new HeldTransactionRequestType(); |
| 40 | + txnRequest.setAction(AfdsTransactionEnum.APPROVE); |
| 41 | + txnRequest.setRefTransId("60012148613"); |
| 42 | + |
| 43 | + // Make the API Request |
| 44 | + UpdateHeldTransactionRequest apiRequest = new UpdateHeldTransactionRequest(); |
| 45 | + apiRequest.setHeldTransactionRequest(txnRequest); |
| 46 | + UpdateHeldTransactionController controller = new UpdateHeldTransactionController(apiRequest); |
| 47 | + controller.execute(); |
| 48 | + |
| 49 | + |
| 50 | + UpdateHeldTransactionResponse response = controller.getApiResponse(); |
| 51 | + |
| 52 | + if (response!=null) { |
| 53 | + // If API Response is ok, go ahead and check the transaction response |
| 54 | + if (response.getMessages().getResultCode() == MessageTypeEnum.OK) { |
| 55 | + TransactionResponse result = response.getTransactionResponse(); |
| 56 | + if(result.getMessages() != null){ |
| 57 | + System.out.println("Successfully updated transaction with Transaction ID: " + result.getTransId()); |
| 58 | + System.out.println("Response Code: " + result.getResponseCode()); |
| 59 | + System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode()); |
| 60 | + System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription()); |
| 61 | + System.out.println("Auth Code: " + result.getAuthCode()); |
| 62 | + } |
| 63 | + else { |
| 64 | + System.out.println("Failed while updating transaction."); |
| 65 | + if(response.getTransactionResponse().getErrors() != null){ |
| 66 | + System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode()); |
| 67 | + System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText()); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + else { |
| 72 | + System.out.println("Failed while updating transaction."); |
| 73 | + if(response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null){ |
| 74 | + System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode()); |
| 75 | + System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText()); |
| 76 | + } |
| 77 | + else { |
| 78 | + System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode()); |
| 79 | + System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText()); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + else { |
| 84 | + System.out.println("Null Response."); |
| 85 | + } |
| 86 | + |
| 87 | + return response; |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +} |
0 commit comments