Skip to content

Commit 0320c70

Browse files
committed
Conflicts: src/main/java/net/authorize/sample/SampleCode.java
2 parents f6d2c1e + 536a992 commit 0320c70

2 files changed

Lines changed: 68 additions & 24 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package net.authorize.sample.PaypalExpressCheckout;
2+
3+
import java.math.BigDecimal;
4+
import net.authorize.Environment;
5+
import net.authorize.api.contract.v1.*;
6+
import net.authorize.api.controller.base.ApiOperationBase;
7+
import net.authorize.api.controller.CreateTransactionController;
8+
9+
public class AuthorizationOnly {
10+
11+
public static void run(String apiLoginId, String transactionKey) {
12+
System.out.println("PayPal Authorize Only Transaction");
13+
14+
//Common code to set for all requests
15+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
16+
17+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
18+
merchantAuthenticationType.setName(apiLoginId);
19+
merchantAuthenticationType.setTransactionKey(transactionKey);
20+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
21+
22+
PayPalType payPal = new PayPalType();
23+
payPal.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
24+
payPal.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
25+
26+
//standard api call to retrieve response
27+
PaymentType paymentType = new PaymentType();
28+
paymentType.setPayPal(payPal);
29+
30+
TransactionRequestType transactionRequest = new TransactionRequestType();
31+
transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_TRANSACTION.value());
32+
transactionRequest.setPayment(paymentType);
33+
transactionRequest.setAmount(new BigDecimal("19.44"));
34+
35+
CreateTransactionRequest request = new CreateTransactionRequest();
36+
request.setTransactionRequest(transactionRequest);
37+
38+
39+
CreateTransactionController controller = new CreateTransactionController(request);
40+
41+
// call the service
42+
controller.execute();
43+
44+
// get the response from the service
45+
CreateTransactionResponse response = controller.getApiResponse();
46+
MessagesType responseMessage = response.getMessages();
47+
48+
//validate
49+
if (responseMessage.getResultCode().equals(MessageTypeEnum.OK)) {
50+
System.out.println("Message Code : " + responseMessage.getMessage().get(0).getCode() + " | Message Text : " + responseMessage.getMessage().get(0).getText());
51+
if (response.getTransactionResponse() != null) {
52+
System.out.println("Success, Response Code : " + response.getTransactionResponse().getResponseCode() + " | Transaction ID : " + response.getTransactionResponse().getTransId());
53+
}
54+
} else {
55+
System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
56+
if (response.getTransactionResponse() != null) {
57+
System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
58+
}
59+
}
60+
}
61+
}

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

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.authorize.sample.RecurringBilling.*;
1111
import net.authorize.sample.TransactionReporting.*;
1212
import net.authorize.sample.CustomerProfiles.*;
13+
import net.authorize.sample.PaypalExpressCheckout.AuthorizationOnly;
1314

1415
/**
1516
* Created by anetdeveloper on 8/5/15.
@@ -107,8 +108,8 @@ private static void ShowMethods()
107108
System.out.println(" GetHostedProfilePage");
108109
System.out.println(" UpdateCustomerPaymentProfile");
109110
System.out.println(" UpdateCustomerShippingAddress");
111+
System.out.println(" PayPalAuthorizationOnly");
110112
System.out.println(" PayPalAuthorizeOnlyContinue");
111-
System.out.println(" PayPalCredit");
112113
}
113114

114115
private static void RunMethod(String methodName)
@@ -117,7 +118,9 @@ private static void RunMethod(String methodName)
117118
// You can create your own keys in seconds by signing up for a sandbox account here: https://developer.authorize.net/sandbox/
118119
String apiLoginId = "5KP3u95bQpv";
119120
String transactionKey = "4Ktq966gC55GAX7S";
121+
//Update the payedId with which you want to run the sample code
120122
String payerId = "";
123+
//Update the transactionId with which you want to run the sample code
121124
String transactionId = "";
122125

123126
switch (methodName) {
@@ -226,32 +229,12 @@ private static void RunMethod(String methodName)
226229
case "UpdateCustomerShippingAddress":
227230
UpdateCustomerShippingAddress.run(apiLoginId, transactionKey);
228231
break;
232+
case "PayPalAuthorizationOnly":
233+
AuthorizationOnly.run(apiLoginId, transactionKey);
234+
break;
229235
case "PayPalAuthorizeOnlyContinue":
230-
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
231-
System.out.println("Enter transaction ID: ");
232-
try {
233-
transactionId = br.readLine();
234-
} catch (IOException e) {
235-
e.printStackTrace();
236-
}
237-
System.out.println("Enter payer ID: ");
238-
try {
239-
payerId = br.readLine();
240-
} catch (IOException e) {
241-
e.printStackTrace();
242-
}
243236
AuthorizationOnlyContinued.run(apiLoginId, transactionKey, transactionId, payerId);
244237
break;
245-
case "PayPalCredit":
246-
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
247-
System.out.println("Enter transaction ID: ");
248-
try {
249-
transactionId = reader.readLine();
250-
} catch (IOException e){
251-
e.printStackTrace();
252-
}
253-
Credit.run(apiLoginId, transactionKey, transactionId);
254-
break;
255238
default:
256239
ShowUsage();
257240
break;

0 commit comments

Comments
 (0)