Skip to content

Commit d468a27

Browse files
committed
AuthorizationAndCaptureContinue.java added to samples
1 parent 536a992 commit d468a27

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}

src/main/java/net/authorize/sample/SampleCode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.authorize.sample.RecurringBilling.*;
1010
import net.authorize.sample.TransactionReporting.*;
1111
import net.authorize.sample.CustomerProfiles.*;
12+
import net.authorize.sample.PaypalExpressCheckout.AuthorizationAndCaptureContinue;
1213
import net.authorize.sample.PaypalExpressCheckout.AuthorizationOnly;
1314

1415
/**
@@ -108,6 +109,7 @@ private static void ShowMethods()
108109
System.out.println(" UpdateCustomerPaymentProfile");
109110
System.out.println(" UpdateCustomerShippingAddress");
110111
System.out.println(" PayPalAuthorizationOnly");
112+
System.out.println(" PayPalAuthorizeCaptureContinue");
111113
}
112114

113115
private static void RunMethod(String methodName)
@@ -116,6 +118,10 @@ private static void RunMethod(String methodName)
116118
// You can create your own keys in seconds by signing up for a sandbox account here: https://developer.authorize.net/sandbox/
117119
String apiLoginId = "5KP3u95bQpv";
118120
String transactionKey = "4Ktq966gC55GAX7S";
121+
122+
//Set transactionID and payerID here for some function calls
123+
String transactionID = "";
124+
String payerID = "";
119125

120126
switch (methodName) {
121127
case "VisaCheckoutDecrypt":
@@ -226,6 +232,9 @@ private static void RunMethod(String methodName)
226232
case "PayPalAuthorizationOnly":
227233
AuthorizationOnly.run(apiLoginId, transactionKey);
228234
break;
235+
case "PayPalAuthorizeCaptureContinue":
236+
AuthorizationAndCaptureContinue.run(apiLoginId, transactionKey, transactionID, payerID);
237+
break;
229238
default:
230239
ShowUsage();
231240
break;

0 commit comments

Comments
 (0)