|
| 1 | +package net.authorize.sample.PaypalExpressCheckout; |
| 2 | + |
| 3 | +import java.math.BigDecimal; |
| 4 | + |
| 5 | +import net.authorize.Environment; |
| 6 | +import net.authorize.TransactionType; |
| 7 | +import net.authorize.api.contract.v1.CreateTransactionRequest; |
| 8 | +import net.authorize.api.contract.v1.CreateTransactionResponse; |
| 9 | +import net.authorize.api.contract.v1.MerchantAuthenticationType; |
| 10 | +import net.authorize.api.contract.v1.MessageTypeEnum; |
| 11 | +import net.authorize.api.contract.v1.PayPalType; |
| 12 | +import net.authorize.api.contract.v1.PaymentType; |
| 13 | +import net.authorize.api.contract.v1.TransactionRequestType; |
| 14 | +import net.authorize.api.contract.v1.TransactionTypeEnum; |
| 15 | +import net.authorize.api.controller.CreateTransactionController; |
| 16 | +import net.authorize.api.controller.base.ApiOperationBase; |
| 17 | + |
| 18 | + |
| 19 | +public class AuthorizationAndCaptureContinue |
| 20 | +{ |
| 21 | + public static void run(String apiLoginId, String transactionKey, String TransactionID, String payerID){ |
| 22 | + |
| 23 | + System.out.println("PayPal Authorize Capture-Continue Transaction"); |
| 24 | + |
| 25 | + //Common code to set for all requests |
| 26 | + ApiOperationBase.setEnvironment(Environment.SANDBOX); |
| 27 | + |
| 28 | + // define the merchant information (authentication / transaction id) |
| 29 | + MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ; |
| 30 | + merchantAuthenticationType.setName(apiLoginId); |
| 31 | + merchantAuthenticationType.setTransactionKey(transactionKey); |
| 32 | + ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType); |
| 33 | + |
| 34 | + // Get Transaction Code and Payer ID from the User |
| 35 | + |
| 36 | + |
| 37 | + // Set PayPal type and attributes |
| 38 | + PayPalType payPalType = new PayPalType(); |
| 39 | + payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); |
| 40 | + payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); |
| 41 | + payPalType.setPayerID(payerID); |
| 42 | + |
| 43 | + //standard api call to retrieve response |
| 44 | + PaymentType paymentType = new PaymentType(); |
| 45 | + paymentType.setPayPal(payPalType); |
| 46 | + |
| 47 | + TransactionRequestType transactionRequest = new TransactionRequestType(); |
| 48 | + transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_CONTINUE_TRANSACTION.value().toString()); |
| 49 | + transactionRequest.setPayment(paymentType); |
| 50 | + transactionRequest.setAmount(new BigDecimal("19.45")); |
| 51 | + transactionRequest.setRefTransId(TransactionID); |
| 52 | + |
| 53 | + CreateTransactionRequest request = new CreateTransactionRequest(); |
| 54 | + request.setTransactionRequest(transactionRequest); |
| 55 | + |
| 56 | + // instantiate the controller that will call the service |
| 57 | + CreateTransactionController controller = new CreateTransactionController(request); |
| 58 | + controller.execute(); |
| 59 | + |
| 60 | + // get the response from the service (errors contained if any) |
| 61 | + CreateTransactionResponse response = controller.getApiResponse(); |
| 62 | + |
| 63 | + //validate |
| 64 | + if(response.getMessages().getResultCode() == MessageTypeEnum.OK){ |
| 65 | + if(response.getTransactionResponse() != null){ |
| 66 | + System.out.println("Success, \nMessage : "+response.getTransactionResponse().getMessages().getMessage().get(0).getDescription() ); |
| 67 | + // Get Auth Code By : response.getTransactionResponse().getAuthCode() |
| 68 | + } |
| 69 | + } |
| 70 | + else { |
| 71 | + System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode()+ " " + response.getMessages().getMessage().get(0).getText() ); |
| 72 | + if(response.getTransactionResponse() != null){ |
| 73 | + System.out.println("Transaction Error : "+ response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText()); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments