Skip to content

Commit ac8462d

Browse files
author
brianmc
committed
merged PR conflicts
2 parents c0f9116 + 5171725 commit ac8462d

3 files changed

Lines changed: 74 additions & 1 deletion

File tree

src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ public static void run(String apiLoginId, String transactionKey) {
5858
}
5959
}
6060
}
61-
}
61+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package net.authorize.sample.PaypalExpressCheckout;
8+
9+
import java.math.BigDecimal;
10+
import net.authorize.api.controller.base.ApiOperationBase;
11+
import net.authorize.api.contract.v1.*;
12+
import net.authorize.api.controller.CreateTransactionController;
13+
import net.authorize.Environment;
14+
15+
/**
16+
*
17+
* @author gnongsie
18+
*/
19+
public class PriorAuthorizationCapture {
20+
public static void run(String apiLoginId, String apiTransactionKey, String transactionId){
21+
System.out.println("Paypal Prior Authorization Transaction");
22+
23+
//Common code to set for all requests
24+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
25+
26+
// Define the merchant information (Authentication / Transaction ID)
27+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
28+
merchantAuthenticationType.setName(apiLoginId);
29+
merchantAuthenticationType.setTransactionKey(apiTransactionKey);
30+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
31+
32+
// Populate the payment data
33+
PayPalType payPalType = new PayPalType();
34+
payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
35+
payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
36+
37+
// Standard api call to retrieve response
38+
PaymentType paymentType = new PaymentType();
39+
paymentType.setPayPal(payPalType);
40+
41+
// Create the payment transaction request
42+
TransactionRequestType transactionRequest = new TransactionRequestType();
43+
transactionRequest.setTransactionType(TransactionTypeEnum.PRIOR_AUTH_CAPTURE_TRANSACTION.value());
44+
transactionRequest.setPayment(paymentType);
45+
transactionRequest.setAmount(BigDecimal.valueOf(19.99));
46+
transactionRequest.setRefTransId(transactionId);
47+
48+
// Make the API Request
49+
CreateTransactionRequest request = new CreateTransactionRequest();
50+
request.setTransactionRequest(transactionRequest);
51+
52+
// Instantiate the contoller that will call the service
53+
CreateTransactionController controller = new CreateTransactionController(request);
54+
controller.execute();
55+
56+
CreateTransactionResponse response = controller.getApiResponse();
57+
58+
// If API Response is ok, go ahead and check the transaction response
59+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK){
60+
if (response.getTransactionResponse() != null){
61+
System.out.println("Success, Auth Code: " + response.getTransactionResponse().getAuthCode());
62+
}
63+
}
64+
else{
65+
System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() +
66+
" " + response.getMessages().getMessage().get(0).getText());
67+
}
68+
}
69+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ private static void ShowMethods()
114114
System.out.println(" PayPalAuthorizationOnly");
115115
System.out.println(" PayPalAuthorizeCaptureContinue");
116116
System.out.println(" PayPalGetDetails");
117+
System.out.println(" PayPalPriorAuthorizationCapture");
117118
}
118119

119120
private static void RunMethod(String methodName)
@@ -247,6 +248,9 @@ private static void RunMethod(String methodName)
247248
break;
248249
case "PayPalGetDetails":
249250
GetDetails.run(apiLoginId, transactionKey);
251+
case "PaypalPriorAuthorizationCapture":
252+
String transactionId = "2241801682"; // Use a valid transaction ID here
253+
PriorAuthorizationCapture.run(apiLoginId, transactionKey, transactionId);
250254
break;
251255
default:
252256
ShowUsage();

0 commit comments

Comments
 (0)