Skip to content

Commit 4cbcf7d

Browse files
committed
+Credit
1 parent 96974cf commit 4cbcf7d

3 files changed

Lines changed: 92 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ public static void run(String apiLoginId, String transactionKey, String transact
5858
if (result.getResponseCode().equals("1")) {
5959
System.out.println(result.getResponseCode());
6060
System.out.println("Successful PayPal Transaction");
61-
System.out.println("Reference Transaction ID: " + result.getRefTransID());
62-
System.out.println(result.getMessages().getMessage().get(0).getDescription());
61+
//System.out.println("Reference Transaction ID: " + result.getRefTransID());
62+
System.out.println("Description: "+result.getMessages().getMessage().get(0).getDescription());
6363
}
6464
else
6565
{
6666
System.out.println(result.getResponseCode());
67-
System.out.println("Failed Transaction: "+result.getErrors().getError().get(0).getErrorText());
67+
System.out.println("Failed Transaction Description: "+result.getErrors().getError().get(0).getErrorText());
6868
}
6969
}
7070
else
7171
{
72-
System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
72+
System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
7373
System.out.println("Error Code: "+response.getMessages().getMessage().get(0).getCode());
7474
}
7575
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package net.authorize.sample.PaypalExpressCheckout;
2+
3+
import java.math.BigDecimal;
4+
5+
import net.authorize.Environment;
6+
import net.authorize.api.contract.v1.*;
7+
import net.authorize.api.controller.base.ApiOperationBase;
8+
import net.authorize.api.controller.CreateTransactionController;
9+
10+
public class Credit {
11+
12+
public static void run(String apiLoginId, String transactionKey, String transactionId) {
13+
14+
System.out.println("PayPal Credit Transaction");
15+
//Common code to set for all requests
16+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
17+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
18+
merchantAuthenticationType.setName(apiLoginId);
19+
merchantAuthenticationType.setTransactionKey(transactionKey);
20+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
21+
22+
// Populate PayPal Transaction Data
23+
PayPalType payPalType = new PayPalType();
24+
payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
25+
payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
26+
27+
// Populate the payment data
28+
PaymentType paymentType = new PaymentType();
29+
paymentType.setPayPal(payPalType);
30+
31+
// Create the payment transaction request
32+
TransactionRequestType txnRequest = new TransactionRequestType();
33+
txnRequest.setTransactionType(TransactionTypeEnum.REFUND_TRANSACTION.value());
34+
txnRequest.setPayment(paymentType);
35+
txnRequest.setAmount(new BigDecimal(500.00));
36+
txnRequest.setRefTransId(transactionId);
37+
38+
// Make the API Request
39+
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
40+
apiRequest.setTransactionRequest(txnRequest);
41+
CreateTransactionController controller = new CreateTransactionController(apiRequest);
42+
controller.execute();
43+
44+
45+
CreateTransactionResponse response = controller.getApiResponse();
46+
47+
if (response!=null) {
48+
49+
// If API Response is ok, go ahead and check the transaction response
50+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
51+
52+
TransactionResponse result = response.getTransactionResponse();
53+
if (result.getResponseCode().equals("1")) {
54+
System.out.println(result.getResponseCode());
55+
System.out.println("Successful PayPal Transaction");
56+
//System.out.println("Reference Transaction ID: " + result.getRefTransID());
57+
System.out.println(result.getMessages().getMessage().get(0).getDescription());
58+
}
59+
else
60+
{
61+
System.out.println("Transaction Error: "+result.getErrors().getError().get(0).getErrorCode()+" "+result.getErrors().getError().get(0).getErrorText());
62+
63+
}
64+
}
65+
else
66+
{
67+
System.out.println("Error: "+response.getMessages().getMessage().get(0).getCode()+ " " + response.getMessages().getMessage().get(0).getText());
68+
69+
}
70+
}
71+
72+
}
73+
74+
75+
76+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ private static void ShowMethods()
107107
System.out.println(" GetHostedProfilePage");
108108
System.out.println(" UpdateCustomerPaymentProfile");
109109
System.out.println(" PayPalAuthorizeOnlyContinue");
110+
System.out.println(" PayPalCredit");
111+
110112
}
111113

112114
private static void RunMethod(String methodName)
@@ -240,6 +242,16 @@ private static void RunMethod(String methodName)
240242
AuthorizationOnlyContinued.run(apiLoginId, transactionKey, transactionId, payerId);
241243

242244
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;
243255
default:
244256
ShowUsage();
245257
break;

0 commit comments

Comments
 (0)