diff --git a/.gitignore b/.gitignore
index dca07322..f067f9e7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+# Compiled class file
*.class
# Mobile Tools for Java (J2ME)
@@ -11,6 +12,10 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+# Ignore Mac DS_Store files
+.DS_Store
+
/logs/
/target/
+/bin/
diff --git a/.travis.yml b/.travis.yml
index 1d29ab7f..fca8ffae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,17 @@
language:
java
+
+dist: trusty
sudo:
false
jdk:
- - oraclejdk8
- - oraclejdk7
- - openjdk7
+ - oraclejdk8
+ - oraclejdk9
+ - openjdk7
+
+matrix:
+ allow_failures:
+ - jdk: oraclejdk9
diff --git a/README.md b/README.md
index 454f0095..91b398f6 100644
--- a/README.md
+++ b/README.md
@@ -1,26 +1,47 @@
-# Sample Java Code for Authorize.Net
-[]
-(https://travis-ci.org/AuthorizeNet/sample-code-java)
+# Java Sample Code for the Authorize.Net SDK
+[](https://travis-ci.org/AuthorizeNet/sample-code-java)
-This repository contains working code samples which demonstrate Java integration with the Authorize.Net Java SDK
-The samples are organized just like our API, which you can also try out directly here: http://developer.authorize.net/api/reference
+This repository contains working code samples which demonstrate Java integration with the [Authorize.Net Java SDK](https://www.github.com/AuthorizeNet/sdk-java).
+The samples are organized into categories and common usage examples, just like our [API Reference Guide](http://developer.authorize.net/api/reference). Our API Reference Guide is an interactive reference for the Authorize.Net API. It explains the request and response parameters for each API method and has embedded code windows to allow you to send actual requests right within the API Reference Guide.
-##Using the Sample Code
-The samples are all completely independent and self-contained so you can look at them to get a gist of how the method works, you can use the snippets to try in your own sample project, or you can run each sample from the command line.
+## Using the Sample Code
-##Running the Samples
- Clone this repository.
- Run "mvn package" in the root directory to create the SampleCode console app.
- Then run a sample directly by name:
-````
+The samples are all completely independent and self-contained. You can analyze them to get an understanding of how a particular method works, or you can use the snippets as a starting point for your own project.
+
+You can also run each sample directly from the command line.
+
+## Running the Samples From the Command Line
+* Clone this repository:
+```
+ $ git clone https://github.com/AuthorizeNet/sample-code-java.git
+```
+* Run "mvn package" in the root directory to create the SampleCode console app.
+* Run the individual samples by name. For example:
+```
> java -jar target/SampleCode.jar [CodeSampleName]
-````
+```
e.g.
-````
+```
> java -jar target/SampleCode.jar ChargeCreditCard
-````
-Running SampleCode without a parameter will give you the list of sample names. Handy or what!
+```
+Running SampleCode without a parameter will give you the list of sample names.
+
+**NOTE : You can update to your Sandbox credentials in SampleCode.java**
+
+**For using behind proxy**
+
+Please set the JAVA environment proxy using a similar code :
+```
+ System.setProperty(Constants.HTTPS_USE_PROXY, "true");
+ System.setProperty(Constants.HTTPS_PROXY_HOST, "127.0.0.1");
+ System.setProperty(Constants.HTTPS_PROXY_PORT, "8888");
+```
+**For using proxy authentication**
-*PLEASE NOTE THIS PROJECT IS CURRENTLY UNDER DEVELOPMENT*
+Please set the JAVA environment proxy credentials using a similar code :
+```
+ System.setProperty(Constants.HTTPS_PROXY_USERNAME, "exampleUsername");
+ System.setProperty(Constants.HTTPS_PROXY_PASSWORD, "examplePassword");
+```
diff --git a/pom.xml b/pom.xml
index dc4c0c44..f456c3e3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,49 +1,80 @@
- 4.0.0
- net.authorize.sample
- SampleCode
- jar
- 1.0
- SampleCode
- http://maven.apache.org
-
-
- net.authorize
- anet-java-sdk
- 1.8.6
-
-
-
-
-
- maven-compiler-plugin
-
- 1.7
- 1.7
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- 2.4.1
-
-
- package
-
- shade
-
-
- SampleCode
-
-
- net.authorize.sample.SampleCode
-
-
-
-
-
-
-
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ 2.0.5
+
+ 4.0.0
+ net.authorize.sample
+ SampleCode
+ jar
+ 1.0
+ SampleCode
+ http://maven.apache.org
+
+
+ net.authorize
+ anet-java-sdk
+ 3.0.0
+
+
+ junit
+ junit
+ 4.13.1
+
+
+
+
+
+ maven-compiler-plugin
+ 3.7.0
+
+ 9
+ 9
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 2.4.1
+
+ false
+
+
+ *:*
+
+ **/Log4j2Plugins.dat
+
+
+
+
+
+
+ package
+
+ shade
+
+
+ SampleCode
+
+
+ net.authorize.sample.SampleCode
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.9
+
+
+ **/*.java
+
+
+
+
+
diff --git a/src/main/java/net/authorize/sample/AcceptSuite/CreateAnAcceptPaymentTransaction.java b/src/main/java/net/authorize/sample/AcceptSuite/CreateAnAcceptPaymentTransaction.java
new file mode 100644
index 00000000..a4b551ff
--- /dev/null
+++ b/src/main/java/net/authorize/sample/AcceptSuite/CreateAnAcceptPaymentTransaction.java
@@ -0,0 +1,100 @@
+package net.authorize.sample.AcceptSuite;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.OpaqueDataType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class CreateAnAcceptPaymentTransaction {
+
+ //
+ // Run this sample from command line with:
+ // java -jar target/CreateAnAcceptPaymentTransaction-jar-with-dependencies.jar
+ //
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
+
+
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ // Populate the payment data
+ PaymentType paymentType = new PaymentType();
+ OpaqueDataType OpaqueData = new OpaqueDataType();
+ OpaqueData.setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
+ OpaqueData.setDataValue("119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9");
+ paymentType.setOpaqueData(OpaqueData);
+
+ // Create the payment transaction request
+ TransactionRequestType txnRequest = new TransactionRequestType();
+ txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
+ txnRequest.setPayment(paymentType);
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+
+ // Make the API Request
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(txnRequest);
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+
+
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+
+ }
+
+
+
+}
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetHostedProfilePage.java b/src/main/java/net/authorize/sample/AcceptSuite/GetAcceptCustomerProfilePage.java
similarity index 87%
rename from src/main/java/net/authorize/sample/CustomerProfiles/GetHostedProfilePage.java
rename to src/main/java/net/authorize/sample/AcceptSuite/GetAcceptCustomerProfilePage.java
index 258f6801..b9ff5fa7 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/GetHostedProfilePage.java
+++ b/src/main/java/net/authorize/sample/AcceptSuite/GetAcceptCustomerProfilePage.java
@@ -1,4 +1,4 @@
-package net.authorize.sample.CustomerProfiles;
+package net.authorize.sample.AcceptSuite;
import net.authorize.Environment;
import net.authorize.api.contract.v1.*;
@@ -8,9 +8,9 @@
import net.authorize.api.controller.GetHostedProfilePageController;
import net.authorize.api.controller.base.ApiOperationBase;
-public class GetHostedProfilePage {
+public class GetAcceptCustomerProfilePage {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -27,7 +27,7 @@ public static void run(String apiLoginId, String transactionKey) {
alist.getSetting().add(setting);
GetHostedProfilePageRequest apiRequest = new GetHostedProfilePageRequest();
- apiRequest.setCustomerProfileId("YourProfileID");
+ apiRequest.setCustomerProfileId(customerProfileId);
apiRequest.setHostedProfileSettings(alist);
GetHostedProfilePageController controller = new GetHostedProfilePageController(apiRequest);
@@ -50,5 +50,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to get hosted profile page: " + response.getMessages().getResultCode());
}
}
+ return response;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/net/authorize/sample/AcceptSuite/GetAnAcceptPaymentPage.java b/src/main/java/net/authorize/sample/AcceptSuite/GetAnAcceptPaymentPage.java
new file mode 100644
index 00000000..5b3f9394
--- /dev/null
+++ b/src/main/java/net/authorize/sample/AcceptSuite/GetAnAcceptPaymentPage.java
@@ -0,0 +1,66 @@
+package net.authorize.sample.AcceptSuite;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.controller.GetHostedPaymentPageController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class GetAnAcceptPaymentPage {
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
+
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ // Create the payment transaction request
+ TransactionRequestType txnRequest = new TransactionRequestType();
+ txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+
+ SettingType setting1 = new SettingType();
+ setting1.setSettingName("hostedPaymentButtonOptions");
+ setting1.setSettingValue("{\"text\": \"Pay\"}");
+
+ SettingType setting2 = new SettingType();
+ setting2.setSettingName("hostedPaymentOrderOptions");
+ setting2.setSettingValue("{\"show\": false}");
+
+ ArrayOfSetting alist = new ArrayOfSetting();
+ alist.getSetting().add(setting1);
+ alist.getSetting().add(setting2);
+
+ GetHostedPaymentPageRequest apiRequest = new GetHostedPaymentPageRequest();
+ apiRequest.setTransactionRequest(txnRequest);
+ apiRequest.setHostedPaymentSettings(alist);
+
+ GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
+ controller.execute();
+
+ GetHostedPaymentPageResponse response = new GetHostedPaymentPageResponse();
+ response = controller.getApiResponse();
+
+ if (response!=null) {
+
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+
+ System.out.println(response.getMessages().getMessage().get(0).getCode());
+ System.out.println(response.getMessages().getMessage().get(0).getText());
+
+ System.out.println(response.getToken());
+ }
+ else
+ {
+ System.out.println("Failed to get hosted payment page: " + response.getMessages().getResultCode());
+ }
+ }
+ return response;
+ }
+}
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerPaymentProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerPaymentProfile.java
index 23a1263d..94edc17d 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerPaymentProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerPaymentProfile.java
@@ -4,21 +4,13 @@
import net.authorize.api.contract.v1.*;
import net.authorize.api.contract.v1.MerchantAuthenticationType;
-import net.authorize.api.controller.base.ApiOperationBase;
-
-import net.authorize.Transaction;
-import net.authorize.api.controller.CreateCustomerProfileController;
-import net.authorize.api.controller.CreateCustomerProfileFromTransactionController;
import net.authorize.api.controller.CreateCustomerPaymentProfileController;
import net.authorize.api.controller.base.ApiOperationBase;
-import net.authorize.cim.Result;
-import net.authorize.cim.TransactionType;
-import net.authorize.cim.ValidationModeType;
//author @krgupta
public class CreateCustomerPaymentProfile {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -27,13 +19,10 @@ public static void run(String apiLoginId, String transactionKey) {
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- String customerprofileId = "36374423" ;
-
-
//private String getPaymentDetails(MerchantAuthenticationType merchantAuthentication, String customerprofileId, ValidationModeEnum validationMode) {
CreateCustomerPaymentProfileRequest apiRequest = new CreateCustomerPaymentProfileRequest();
apiRequest.setMerchantAuthentication(merchantAuthenticationType);
- apiRequest.setCustomerProfileId(customerprofileId);
+ apiRequest.setCustomerProfileId(customerProfileId);
//customer address
CustomerAddressType customerAddress = new CustomerAddressType();
@@ -49,8 +38,8 @@ public static void run(String apiLoginId, String transactionKey) {
//credit card details
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4111111111111111");
- creditCard.setExpirationDate("2023-12");
- creditCard.setCardCode("");
+ creditCard.setExpirationDate("2035-12");
+ creditCard.setCardCode("122");
CustomerPaymentProfileType profile = new CustomerPaymentProfileType();
profile.setBillTo(customerAddress);
@@ -60,26 +49,27 @@ public static void run(String apiLoginId, String transactionKey) {
profile.setPayment(payment);
apiRequest.setPaymentProfile(profile);
-
- CreateCustomerPaymentProfileController controller = new CreateCustomerPaymentProfileController(apiRequest);
- controller.execute();
+
+ CreateCustomerPaymentProfileController controller = new CreateCustomerPaymentProfileController(apiRequest);
+ controller.execute();
CreateCustomerPaymentProfileResponse response = new CreateCustomerPaymentProfileResponse();
response = controller.getApiResponse();
-
if (response!=null) {
-
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
+
System.out.println(response.getCustomerPaymentProfileId());
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
- System.out.println(response.getValidationDirectResponse());
+ if (response.getValidationDirectResponse() != null)
+ System.out.println(response.getValidationDirectResponse());
}
else
{
System.out.println("Failed to create customer payment profile: " + response.getMessages().getResultCode());
}
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java
index be3168c0..8880e1b6 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java
@@ -7,53 +7,77 @@
import net.authorize.api.controller.base.ApiOperationBase;
public class CreateCustomerProfile {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String eMail) {
- public static void run(String apiLoginId, String transactionKey) {
-
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
-
+ // Set the request to operate in either the sandbox or production environment
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ // Create object with merchant authentication details
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+ // Populate the payment data
CreditCardType creditCard = new CreditCardType();
- creditCard.setCardNumber("4111111111111111");
- creditCard.setExpirationDate("1220");
-
- PaymentType paymentType = new PaymentType();
- paymentType.setCreditCard(creditCard);
+ creditCard.setCardNumber("4111111111111111");
+ creditCard.setExpirationDate("1235");
+ PaymentType paymentType = new PaymentType();
+ paymentType.setCreditCard(creditCard);
- CustomerPaymentProfileType customerPaymentProfileType = new CustomerPaymentProfileType();
- customerPaymentProfileType.setCustomerType(CustomerTypeEnum.INDIVIDUAL);
- customerPaymentProfileType.setPayment(paymentType);
+ // Set payment profile data
+ CustomerPaymentProfileType customerPaymentProfileType = new CustomerPaymentProfileType();
+ customerPaymentProfileType.setCustomerType(CustomerTypeEnum.INDIVIDUAL);
+ customerPaymentProfileType.setPayment(paymentType);
+ // Set customer profile data
CustomerProfileType customerProfileType = new CustomerProfileType();
- customerProfileType.setMerchantCustomerId("Merchant_Customer_ID");
- customerProfileType.setDescription("Profile description here");
- customerProfileType.setEmail("customer-profile-email@here.com");
+ customerProfileType.setMerchantCustomerId("M_" + eMail);
+ customerProfileType.setDescription("Profile description for " + eMail);
+ customerProfileType.setEmail(eMail);
customerProfileType.getPaymentProfiles().add(customerPaymentProfileType);
+ // Create the API request and set the parameters for this specific request
CreateCustomerProfileRequest apiRequest = new CreateCustomerProfileRequest();
+ apiRequest.setMerchantAuthentication(merchantAuthenticationType);
apiRequest.setProfile(customerProfileType);
apiRequest.setValidationMode(ValidationModeEnum.TEST_MODE);
+
+ // Call the controller
CreateCustomerProfileController controller = new CreateCustomerProfileController(apiRequest);
controller.execute();
- CreateCustomerProfileResponse response = controller.getApiResponse();
- if (response!=null) {
-
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ // Get the response
+ CreateCustomerProfileResponse response = new CreateCustomerProfileResponse();
+ response = controller.getApiResponse();
+
+ // Parse the response to determine results
+ if (response!=null) {
+ // If API Response is OK, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getCustomerProfileId());
- System.out.println(response.getCustomerPaymentProfileIdList().getNumericString().get(0));
- System.out.println(response.getCustomerShippingAddressIdList().getNumericString().get(0));
- System.out.println(response.getValidationDirectResponseList().getString().get(0));
+ if (!response.getCustomerPaymentProfileIdList().getNumericString().isEmpty()) {
+ System.out.println(response.getCustomerPaymentProfileIdList().getNumericString().get(0));
+ }
+ if (!response.getCustomerShippingAddressIdList().getNumericString().isEmpty()) {
+ System.out.println(response.getCustomerShippingAddressIdList().getNumericString().get(0));
+ }
+ if (!response.getValidationDirectResponseList().getString().isEmpty()) {
+ System.out.println(response.getValidationDirectResponseList().getString().get(0));
+ }
}
else
{
System.out.println("Failed to create customer profile: " + response.getMessages().getResultCode());
}
+ } else {
+ // Display the error code and message when response is null
+ ANetApiResponse errorResponse = controller.getErrorResponse();
+ System.out.println("Failed to get response");
+ if (!errorResponse.getMessages().getMessage().isEmpty()) {
+ System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
+ }
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfileFromTransaction.java b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfileFromTransaction.java
index 33da4ac1..3e3ae284 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfileFromTransaction.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfileFromTransaction.java
@@ -1,16 +1,27 @@
package net.authorize.sample.CustomerProfiles;
-import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
import java.math.BigDecimal;
+import java.math.RoundingMode;
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateCustomerProfileFromTransactionRequest;
+import net.authorize.api.contract.v1.CreateCustomerProfileResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.CreditCardType;
+import net.authorize.api.contract.v1.CustomerDataType;
+import net.authorize.api.contract.v1.CustomerProfileBaseType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
import net.authorize.api.controller.CreateCustomerProfileFromTransactionController;
import net.authorize.api.controller.CreateTransactionController;
import net.authorize.api.controller.base.ApiOperationBase;
public class CreateCustomerProfileFromTransaction {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount, String email) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -19,11 +30,9 @@ public static void run(String apiLoginId, String transactionKey) {
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- String customerprofileId = "36374423" ;
-
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4111111111111111");
- creditCard.setExpirationDate("0616");
+ creditCard.setExpirationDate("0635");
PaymentType paymentType = new PaymentType();
paymentType.setCreditCard(creditCard);
@@ -31,10 +40,10 @@ public static void run(String apiLoginId, String transactionKey) {
TransactionRequestType requestInternal = new TransactionRequestType();
requestInternal.setTransactionType("authOnlyTransaction");
requestInternal.setPayment(paymentType);
- requestInternal.setAmount(new BigDecimal(System.currentTimeMillis() % 100));
+ requestInternal.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
CustomerDataType customer = new CustomerDataType();
- customer.setEmail(System.currentTimeMillis()+"@b.bla");
+ customer.setEmail(email);
requestInternal.setCustomer(customer);
CreateTransactionRequest request = new CreateTransactionRequest();
@@ -45,14 +54,26 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
+ CustomerProfileBaseType customerProfile = new CustomerProfileBaseType();
+ customerProfile.setMerchantCustomerId("123213");
+ customerProfile.setEmail("johnsnow@castleblack.com");
+ customerProfile.setDescription("This is a sample customer profile");
+
CreateCustomerProfileFromTransactionRequest transaction_request = new CreateCustomerProfileFromTransactionRequest();
transaction_request.setTransId(response.getTransactionResponse().getTransId());
+ // You can either specify the customer information in form of customerProfileBaseType object
+ transaction_request.setCustomer(customerProfile);
+ // OR
+ // You can just provide the customer Profile ID
+ // transaction_request.setCustomerProfileId("1232132");
+
CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(transaction_request);
createProfileController.execute();
CreateCustomerProfileResponse customer_response = createProfileController.getApiResponse();
- if(customer_response != null) {
+ if (customer_response != null) {
System.out.println(transaction_request.getTransId());
}
+ return customer_response;
}
}
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerShippingAddress.java b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerShippingAddress.java
index b4f339e1..b3187096 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerShippingAddress.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerShippingAddress.java
@@ -8,7 +8,7 @@
public class CreateCustomerShippingAddress {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -28,7 +28,7 @@ public static void run(String apiLoginId, String transactionKey) {
customerAddressType.setPhoneNumber("000-000-0000");
CreateCustomerShippingAddressRequest apiRequest = new CreateCustomerShippingAddressRequest();
- apiRequest.setCustomerProfileId("10000");
+ apiRequest.setCustomerProfileId(customerProfileId);
apiRequest.setAddress(customerAddressType);
CreateCustomerShippingAddressController controller = new CreateCustomerShippingAddressController(apiRequest);
@@ -48,6 +48,7 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to create customer shipping address: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerPaymentProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerPaymentProfile.java
index 3a501d68..684206a6 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerPaymentProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerPaymentProfile.java
@@ -10,7 +10,8 @@
public class DeleteCustomerPaymentProfile {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId,
+ String customerPaymentProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -20,8 +21,8 @@ public static void run(String apiLoginId, String transactionKey) {
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
DeleteCustomerPaymentProfileRequest apiRequest = new DeleteCustomerPaymentProfileRequest();
- apiRequest.setCustomerProfileId("10000");
- apiRequest.setCustomerPaymentProfileId("20000");
+ apiRequest.setCustomerProfileId(customerProfileId);
+ apiRequest.setCustomerPaymentProfileId(customerPaymentProfileId);
DeleteCustomerPaymentProfileController controller = new DeleteCustomerPaymentProfileController(apiRequest);
controller.execute();
@@ -41,5 +42,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to delete customer payment profile: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerProfile.java
index 54d04601..6eb49847 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerProfile.java
@@ -10,7 +10,7 @@
public class DeleteCustomerProfile {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -20,7 +20,7 @@ public static void run(String apiLoginId, String transactionKey) {
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
DeleteCustomerProfileRequest apiRequest = new DeleteCustomerProfileRequest();
- apiRequest.setCustomerProfileId("10000");
+ apiRequest.setCustomerProfileId(customerProfileId);
DeleteCustomerProfileController controller = new DeleteCustomerProfileController(apiRequest);
controller.execute();
@@ -40,5 +40,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to delete customer profile: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerShippingAddress.java b/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerShippingAddress.java
index fe0e5510..2f5c4ead 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerShippingAddress.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/DeleteCustomerShippingAddress.java
@@ -10,7 +10,8 @@
public class DeleteCustomerShippingAddress {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId,
+ String customerAddressId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -20,8 +21,8 @@ public static void run(String apiLoginId, String transactionKey) {
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
DeleteCustomerShippingAddressRequest apiRequest = new DeleteCustomerShippingAddressRequest();
- apiRequest.setCustomerProfileId("10000");
- apiRequest.setCustomerAddressId("30000");
+ apiRequest.setCustomerProfileId(customerProfileId);
+ apiRequest.setCustomerAddressId(customerAddressId);
DeleteCustomerShippingAddressController controller = new DeleteCustomerShippingAddressController(apiRequest);
controller.execute();
@@ -41,5 +42,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to delete customer shipping address: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfile.java
index c945ff62..022f5d38 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfile.java
@@ -10,7 +10,8 @@
public class GetCustomerPaymentProfile {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId,
+ String customerPaymentProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -20,8 +21,8 @@ public static void run(String apiLoginId, String transactionKey) {
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
GetCustomerPaymentProfileRequest apiRequest = new GetCustomerPaymentProfileRequest();
- apiRequest.setCustomerProfileId("10000");
- apiRequest.setCustomerPaymentProfileId("20000");
+ apiRequest.setCustomerProfileId(customerProfileId);
+ apiRequest.setCustomerPaymentProfileId(customerPaymentProfileId);
GetCustomerPaymentProfileController controller = new GetCustomerPaymentProfileController(apiRequest);
controller.execute();
@@ -51,11 +52,17 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println(response.getPaymentProfile().getPayment().getCreditCard().getCardNumber());
System.out.println(response.getPaymentProfile().getPayment().getCreditCard().getExpirationDate());
- }
- else
- {
+
+ if ((response.getPaymentProfile().getSubscriptionIds() != null) && (response.getPaymentProfile().getSubscriptionIds().getSubscriptionId() != null) &&
+ (!response.getPaymentProfile().getSubscriptionIds().getSubscriptionId().isEmpty())) {
+ System.out.println("List of subscriptions:");
+ for (String subscriptionid : response.getPaymentProfile().getSubscriptionIds().getSubscriptionId())
+ System.out.println(subscriptionid);
+ }
+ } else {
System.out.println("Failed to get customer payment profile: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfileList.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfileList.java
index 1cc8b547..f55c204e 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfileList.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfileList.java
@@ -7,19 +7,18 @@
import net.authorize.api.controller.base.ApiOperationBase;
import net.authorize.api.controller.*;
-public class GetCustomerPaymentProfileList
-{
- public static void run(String apiLoginId,String transactionKey)
- {
+public class GetCustomerPaymentProfileList {
+ public static ANetApiResponse run(String apiLoginId,String transactionKey) {
+
+ // Set the request to operate in either the sandbox or production environment
ApiOperationBase.setEnvironment(Environment.SANDBOX);
- // Giving the merchant authentication information
+ // Create object with merchant authentication details
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- //Setting the paging
+ // Setting the paging
Paging paging = new Paging();
paging.setLimit(100);
paging.setOffset(1);
@@ -33,55 +32,57 @@ public static void run(String apiLoginId,String transactionKey)
// Setting the searchType
CustomerPaymentProfileSearchTypeEnum searchType = CustomerPaymentProfileSearchTypeEnum.CARDS_EXPIRING_IN_MONTH;
- // Making the API request
+ // Create the API request and set the parameters for this specific request
GetCustomerPaymentProfileListRequest apiRequest = new GetCustomerPaymentProfileListRequest();
+ apiRequest.setMerchantAuthentication(merchantAuthenticationType);
apiRequest.setPaging(paging);
apiRequest.setSearchType(searchType);
apiRequest.setSorting(sorting);
apiRequest.setMonth("2020-12");
- // Calling the controller
+ // Call the controller
GetCustomerPaymentProfileListController controller = new GetCustomerPaymentProfileListController(apiRequest);
controller.execute();
- // Getting the response
+
+ // Get the response
GetCustomerPaymentProfileListResponse response = new GetCustomerPaymentProfileListResponse();
response = controller.getApiResponse();
- // Checking id the response is not null then printing the details
- if(response != null)
- {
- if(response.getMessages().getResultCode() == MessageTypeEnum.OK)
- {
+
+ // Parse the response to determine results
+ if (response != null) {
+ // If API Response is OK, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println("Successfully got customer payment profile list");
System.out.println("Message Code:" + response.getMessages().getMessage().get(0).getCode());
System.out.println("Message Text:" + response.getMessages().getMessage().get(0).getText());
System.out.println("Total Number of Results in the Results Set:" + response.getTotalNumInResultSet());
List arr = response.getPaymentProfiles().getPaymentProfile();
- for(CustomerPaymentProfileListItemType element : arr)
- {
+ for (CustomerPaymentProfileListItemType element : arr) {
System.out.println();
- if(element.getBillTo()!=null)
+ if (element.getBillTo()!=null) {
System.out.println("Customer name : "+element.getBillTo().getFirstName()+" "+element.getBillTo().getLastName());
+ }
System.out.println("Credit card number: "+element.getPayment().getCreditCard().getCardNumber());
System.out.println("Customer Profile ID : "+element.getCustomerProfileId());
System.out.println("Customer Payment Profile ID : "+element.getCustomerPaymentProfileId());
}
- }
- else
- {
- // When the error occurs
+ } else {
+ // Displaying the error code and message when error occurs
System.out.println("Failed to get customer payment profile list");
- if(!response.getMessages().getMessage().isEmpty())
+ if (!response.getMessages().getMessage().isEmpty()) {
System.out.println("Error: "+response.getMessages().getMessage().get(0).getCode()+" "+ response.getMessages().getMessage().get(0).getText());
+ }
}
- }
- else
- {
- // Displaying the error code and message when response is null
+ } else {
+ // Display the error code and message when response is null
ANetApiResponse errorResponse = controller.getErrorResponse();
System.out.println("Failed to get response");
- if(!errorResponse.getMessages().getMessage().isEmpty())
+ if (!errorResponse.getMessages().getMessage().isEmpty()) {
System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
+ }
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfile.java
index b4d9d12b..0169c33d 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfile.java
@@ -10,7 +10,7 @@
public class GetCustomerProfile {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -20,7 +20,7 @@ public static void run(String apiLoginId, String transactionKey) {
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
GetCustomerProfileRequest apiRequest = new GetCustomerProfileRequest();
- apiRequest.setCustomerProfileId("10000");
+ apiRequest.setCustomerProfileId("1929820324"); //customerProfileId);
GetCustomerProfileController controller = new GetCustomerProfileController(apiRequest);
controller.execute();
@@ -30,7 +30,7 @@ public static void run(String apiLoginId, String transactionKey) {
if (response!=null) {
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
@@ -40,37 +40,49 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println(response.getProfile().getEmail());
System.out.println(response.getProfile().getCustomerProfileId());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getFirstName());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getLastName());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getCompany());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getAddress());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getCity());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getState());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getZip());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getCountry());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getPhoneNumber());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getFaxNumber());
+ if ((!response.getProfile().getPaymentProfiles().isEmpty()) &&
+ (response.getProfile().getPaymentProfiles().get(0).getBillTo() != null)) {
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getFirstName());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getLastName());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getCompany());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getAddress());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getCity());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getState());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getZip());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getCountry());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getPhoneNumber());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getBillTo().getFaxNumber());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getCustomerPaymentProfileId());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getCustomerPaymentProfileId());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getPayment().getCreditCard().getCardNumber());
- System.out.println(response.getProfile().getPaymentProfiles().get(0).getPayment().getCreditCard().getExpirationDate());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getPayment().getCreditCard().getCardNumber());
+ System.out.println(response.getProfile().getPaymentProfiles().get(0).getPayment().getCreditCard().getExpirationDate());
+ }
- System.out.println(response.getProfile().getShipToList().get(0).getFirstName());
- System.out.println(response.getProfile().getShipToList().get(0).getLastName());
- System.out.println(response.getProfile().getShipToList().get(0).getCompany());
- System.out.println(response.getProfile().getShipToList().get(0).getAddress());
- System.out.println(response.getProfile().getShipToList().get(0).getCity());
- System.out.println(response.getProfile().getShipToList().get(0).getState());
- System.out.println(response.getProfile().getShipToList().get(0).getZip());
- System.out.println(response.getProfile().getShipToList().get(0).getCountry());
- System.out.println(response.getProfile().getShipToList().get(0).getPhoneNumber());
- System.out.println(response.getProfile().getShipToList().get(0).getFaxNumber());
- }
- else
- {
+ if (!response.getProfile().getShipToList().isEmpty()) {
+ System.out.println(response.getProfile().getShipToList().get(0).getFirstName());
+ System.out.println(response.getProfile().getShipToList().get(0).getLastName());
+ System.out.println(response.getProfile().getShipToList().get(0).getCompany());
+ System.out.println(response.getProfile().getShipToList().get(0).getAddress());
+ System.out.println(response.getProfile().getShipToList().get(0).getCity());
+ System.out.println(response.getProfile().getShipToList().get(0).getState());
+ System.out.println(response.getProfile().getShipToList().get(0).getZip());
+ System.out.println(response.getProfile().getShipToList().get(0).getCountry());
+ System.out.println(response.getProfile().getShipToList().get(0).getPhoneNumber());
+ System.out.println(response.getProfile().getShipToList().get(0).getFaxNumber());
+ }
+
+ if ((response.getSubscriptionIds() != null) && (response.getSubscriptionIds().getSubscriptionId() != null) &&
+ (!response.getSubscriptionIds().getSubscriptionId().isEmpty())) {
+ System.out.println("List of subscriptions:");
+ for (String subscriptionid : response.getSubscriptionIds().getSubscriptionId())
+ System.out.println(subscriptionid);
+ }
+
+ } else {
System.out.println("Failed to get customer profile: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfileIds.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfileIds.java
index cf08aa12..6e25d51c 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfileIds.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfileIds.java
@@ -10,7 +10,7 @@
public class GetCustomerProfileIds {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -34,7 +34,7 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
- for(int i =0; i < response.getIds().getNumericString().size(); i++) {
+ for (int i =0; i < response.getIds().getNumericString().size(); i++) {
System.out.println(response.getIds().getNumericString().get(i));
}
@@ -44,5 +44,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to get customer payment profile: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerShippingAddress.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerShippingAddress.java
index 06a36a8c..e5f63005 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerShippingAddress.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerShippingAddress.java
@@ -10,7 +10,8 @@
public class GetCustomerShippingAddress {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId,
+ String customerAddressId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -20,8 +21,8 @@ public static void run(String apiLoginId, String transactionKey) {
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
GetCustomerShippingAddressRequest apiRequest = new GetCustomerShippingAddressRequest();
- apiRequest.setCustomerProfileId("10000");
- apiRequest.setCustomerAddressId("30000");
+ apiRequest.setCustomerProfileId(customerProfileId);
+ apiRequest.setCustomerAddressId(customerAddressId);
GetCustomerShippingAddressController controller = new GetCustomerShippingAddressController(apiRequest);
controller.execute();
@@ -48,11 +49,17 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println(response.getAddress().getFaxNumber());
System.out.println(response.getAddress().getCustomerAddressId());
- }
- else
- {
+
+ if ((response.getSubscriptionIds() != null) && (response.getSubscriptionIds().getSubscriptionId() != null) &&
+ (!response.getSubscriptionIds().getSubscriptionId().isEmpty())) {
+ System.out.println("List of subscriptions:");
+ for (String subscriptionid : response.getSubscriptionIds().getSubscriptionId())
+ System.out.println(subscriptionid);
+ }
+ } else {
System.out.println("Failed to get customer shipping address: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerPaymentProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerPaymentProfile.java
index 4aab3ddf..de859f97 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerPaymentProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerPaymentProfile.java
@@ -7,7 +7,7 @@
public class UpdateCustomerPaymentProfile {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId, String customerPaymentProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -30,18 +30,18 @@ public static void run(String apiLoginId, String transactionKey) {
//credit card details
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4111111111111111");
- creditCard.setExpirationDate("2023-12");
+ creditCard.setExpirationDate("2035-12");
PaymentType paymentType = new PaymentType();
paymentType.setCreditCard(creditCard);
CustomerPaymentProfileExType customer = new CustomerPaymentProfileExType();
customer.setPayment(paymentType);
- customer.setCustomerPaymentProfileId("20000");
+ customer.setCustomerPaymentProfileId(customerPaymentProfileId);
customer.setBillTo(customerAddress);
UpdateCustomerPaymentProfileRequest apiRequest = new UpdateCustomerPaymentProfileRequest();
- apiRequest.setCustomerProfileId("10000");
+ apiRequest.setCustomerProfileId(customerProfileId);
apiRequest.setPaymentProfile(customer);
apiRequest.setValidationMode(ValidationModeEnum.LIVE_MODE);
@@ -63,5 +63,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to update customer payment profile: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerProfile.java
index b37613bc..ef888414 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerProfile.java
@@ -7,7 +7,7 @@
public class UpdateCustomerProfile {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -16,11 +16,12 @@ public static void run(String apiLoginId, String transactionKey) {
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- CustomerProfileExType customer = new CustomerProfileExType();
+ CustomerProfileInfoExType customer = new CustomerProfileInfoExType();
customer.setMerchantCustomerId("custId123");
customer.setDescription("some description");
customer.setEmail("newaddress@example.com");
- customer.setCustomerProfileId("10000");
+ customer.setCustomerProfileId(customerProfileId);
+ customer.setProfileType(CustomerProfileTypeEnum.REGULAR);
UpdateCustomerProfileRequest apiRequest = new UpdateCustomerProfileRequest();
apiRequest.setProfile(customer);
@@ -43,5 +44,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to update customer profile: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerShippingAddress.java b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerShippingAddress.java
index 3ca064cb..a266df5e 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerShippingAddress.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerShippingAddress.java
@@ -7,7 +7,7 @@
public class UpdateCustomerShippingAddress {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileID, String customerAddressId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -25,10 +25,10 @@ public static void run(String apiLoginId, String transactionKey) {
customer.setZip("98004");
customer.setCountry("USA");
customer.setPhoneNumber("000-000-0000");
- customer.setCustomerAddressId("30000");
+ customer.setCustomerAddressId(customerAddressId);
UpdateCustomerShippingAddressRequest apiRequest = new UpdateCustomerShippingAddressRequest();
- apiRequest.setCustomerProfileId("10000");
+ apiRequest.setCustomerProfileId(customerProfileID);
apiRequest.setAddress(customer);
UpdateCustomerShippingAddressController controller = new UpdateCustomerShippingAddressController(apiRequest);
@@ -49,5 +49,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to update customer shipping address: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/ValidateCustomerPaymentProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/ValidateCustomerPaymentProfile.java
index 4700fb01..55e70e1a 100644
--- a/src/main/java/net/authorize/sample/CustomerProfiles/ValidateCustomerPaymentProfile.java
+++ b/src/main/java/net/authorize/sample/CustomerProfiles/ValidateCustomerPaymentProfile.java
@@ -7,8 +7,8 @@
public class ValidateCustomerPaymentProfile {
- public static void run(String apiLoginId, String transactionKey) {
-
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId, String customerPaymentProfileId) {
+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
@@ -17,13 +17,16 @@ public static void run(String apiLoginId, String transactionKey) {
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
ValidateCustomerPaymentProfileRequest apiRequest = new ValidateCustomerPaymentProfileRequest();
- apiRequest.setCustomerProfileId("10000");
- apiRequest.setCustomerPaymentProfileId("20000");
+ apiRequest.setCustomerProfileId(customerProfileId);
+ apiRequest.setCustomerPaymentProfileId(customerPaymentProfileId);
apiRequest.setValidationMode(ValidationModeEnum.LIVE_MODE);
+ apiRequest.setCardCode("122");
+ apiRequest.setCustomerShippingAddressId("1");
+
- ValidateCustomerPaymentProfileController controller = new ValidateCustomerPaymentProfileController(apiRequest);
+ ValidateCustomerPaymentProfileController controller = new ValidateCustomerPaymentProfileController(apiRequest);
controller.execute();
-
+
ValidateCustomerPaymentProfileResponse response = new ValidateCustomerPaymentProfileResponse();
response = controller.getApiResponse();
@@ -40,5 +43,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to validate customer payment profile: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/FraudManagement/ApproveOrDeclineHeldTransaction.java b/src/main/java/net/authorize/sample/FraudManagement/ApproveOrDeclineHeldTransaction.java
new file mode 100644
index 00000000..7afab2ac
--- /dev/null
+++ b/src/main/java/net/authorize/sample/FraudManagement/ApproveOrDeclineHeldTransaction.java
@@ -0,0 +1,88 @@
+package net.authorize.sample.FraudManagement;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.AfdsTransactionEnum;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.CreditCardType;
+import net.authorize.api.contract.v1.HeldTransactionRequestType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
+import net.authorize.api.contract.v1.UpdateHeldTransactionRequest;
+import net.authorize.api.contract.v1.UpdateHeldTransactionResponse;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.UpdateHeldTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class ApproveOrDeclineHeldTransaction {
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionId) {
+
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+
+ // Create the payment transaction request
+ HeldTransactionRequestType txnRequest = new HeldTransactionRequestType();
+ txnRequest.setAction(AfdsTransactionEnum.APPROVE);
+ txnRequest.setRefTransId("60012148613");
+
+ // Make the API Request
+ UpdateHeldTransactionRequest apiRequest = new UpdateHeldTransactionRequest();
+ apiRequest.setHeldTransactionRequest(txnRequest);
+ UpdateHeldTransactionController controller = new UpdateHeldTransactionController(apiRequest);
+ controller.execute();
+
+
+ UpdateHeldTransactionResponse response = controller.getApiResponse();
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully updated transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ } else {
+ System.out.println("Failed while updating transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ } else {
+ System.out.println("Failed while updating transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ } else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+ }
+
+
+
+}
diff --git a/src/main/java/net/authorize/sample/FraudManagement/GetHeldTransactionList.java b/src/main/java/net/authorize/sample/FraudManagement/GetHeldTransactionList.java
new file mode 100644
index 00000000..6089d973
--- /dev/null
+++ b/src/main/java/net/authorize/sample/FraudManagement/GetHeldTransactionList.java
@@ -0,0 +1,65 @@
+package net.authorize.sample.FraudManagement;
+
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.GetSettledBatchListController;
+import net.authorize.api.controller.GetUnsettledTransactionListController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+//author @krgupta
+public class GetHeldTransactionList{
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ GetUnsettledTransactionListRequest getRequest = new GetUnsettledTransactionListRequest();
+ getRequest.setMerchantAuthentication(merchantAuthenticationType);
+ getRequest.setStatus(TransactionGroupStatusEnum.PENDING_APPROVAL);
+
+ Paging paging = new Paging();
+ paging.setLimit(100);
+ paging.setOffset(1);
+
+ getRequest.setPaging(paging);
+
+ TransactionListSorting sorting = new TransactionListSorting();
+ sorting.setOrderBy(TransactionListOrderFieldEnum.ID);
+ sorting.setOrderDescending(true);
+
+ getRequest.setSorting(sorting);
+
+ GetUnsettledTransactionListController controller = new GetUnsettledTransactionListController(getRequest);
+ controller.execute();
+ GetUnsettledTransactionListResponse getResponse = controller.getApiResponse();
+
+ if (getResponse!=null) {
+
+ if (getResponse.getMessages().getResultCode() == MessageTypeEnum.OK) {
+
+ System.out.println(getResponse.getMessages().getMessage().get(0).getCode());
+ System.out.println(getResponse.getMessages().getMessage().get(0).getText());
+ getResponse.getTransactions();
+
+ ArrayOfTransactionSummaryType txnList = getResponse.getTransactions();
+ if (txnList != null) {
+ System.out.println("List of Suspicious Transactions :");
+ for (TransactionSummaryType txn : txnList.getTransaction()) {
+ System.out.println(txn.getTransId());
+ }
+ }
+ }
+ else
+ {
+ System.out.println("Failed to get unsettled transaction list: " + getResponse.getMessages().getResultCode());
+ }
+ }
+ return getResponse;
+
+ }
+}
diff --git a/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnAcceptTransaction.java b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnAcceptTransaction.java
new file mode 100644
index 00000000..cb0769df
--- /dev/null
+++ b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnAcceptTransaction.java
@@ -0,0 +1,73 @@
+package net.authorize.sample.MobileInAppTransactions;
+
+import java.math.BigDecimal;
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class CreateAnAcceptTransaction
+{
+ public static ANetApiResponse run(String apiLoginId, String transactionKey)
+ {
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ // Giving the merchant authentication information
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+ // Setting the payment
+ OpaqueDataType op = new OpaqueDataType();
+ op.setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
+ op.setDataValue("9471471570959063005001");
+ PaymentType paymentOne = new PaymentType();
+ paymentOne.setOpaqueData(op);
+ // Setting the transaction
+ TransactionRequestType transactionRequest = new TransactionRequestType();
+ transactionRequest.setAmount(new BigDecimal("131"));
+ transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
+ transactionRequest.setPayment(paymentOne);
+ // Making the api request
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(transactionRequest);
+ // Creating the controller
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+ // Getting the response
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth code : " + result.getAuthCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ } else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+ }
+}
diff --git a/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnAndroidPayTransaction.java b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnAndroidPayTransaction.java
new file mode 100644
index 00000000..0f1287d0
--- /dev/null
+++ b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnAndroidPayTransaction.java
@@ -0,0 +1,78 @@
+package net.authorize.sample.MobileInAppTransactions;
+
+import java.math.BigDecimal;
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class CreateAnAndroidPayTransaction {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ // Giving the merchant authentication information
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+ // Setting the payment
+ OpaqueDataType op = new OpaqueDataType();
+ op.setDataDescriptor("COMMON.ANDROID.INAPP.PAYMENT");
+ op.setDataValue(
+ "eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxOTNkMWJhZDlkZGNiNjBhNzk1IiwiZXBoZW1lcmFsUHVibGljS2V5IjoiTUlJQlN6Q0NBUU1HQnlxR1NNNDlBZ0V3Z2ZjQ0FRRXdMQVlIS29aSXpqMEJBUUloQVBcL1wvXC9cLzhBQUFBQkFBQUFBQUFBQUFBQUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL01Gc0VJUFwvXC9cL1wvOEFBQUFCQUFBQUFBQUFBQUFBQUFBQVwvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cLzhCQ0JheGpYWXFqcVQ1N1BydlZWMm1JYThaUjBHc014VHNQWTd6ancrSjlKZ1N3TVZBTVNkTmdpRzV3U1RhbVo0NFJPZEpyZUJuMzZRQkVFRWF4ZlI4dUVzUWtmNHZPYmxZNlJBOG5jRGZZRXQ2ek9nOUtFNVJkaVl3cFpQNDBMaVwvaHBcL200N242MHA4RDU0V0s4NHpWMnN4WHM3THRrQm9ONzlSOVFJaEFQXC9cL1wvXC84QUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cLys4NXZxdHB4ZWVoUE81eXNMOFl5VlJBZ0VCQTBJQUJHbStnc2wwUFpGVFwva0RkVVNreHd5Zm84SnB3VFFRekJtOWxKSm5tVGw0REdVdkFENEdzZUdqXC9wc2hCWjBLM1RldXFEdFwvdERMYkUrOFwvbTB5Q21veHc9IiwicHVibGljS2V5SGFzaCI6IlwvYmI5Q05DMzZ1QmhlSEZQYm1vaEI3T28xT3NYMkora0pxdjQ4ek9WVmlRPSJ9LCJzaWduYXR1cmUiOiJNSUlEUWdZSktvWklodmNOQVFjQ29JSURNekNDQXk4Q0FRRXhDekFKQmdVckRnTUNHZ1VBTUFzR0NTcUdTSWIzRFFFSEFhQ0NBaXN3Z2dJbk1JSUJsS0FEQWdFQ0FoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQXdKekVsTUNNR0ExVUVBeDRjQUdNQWFBQnRBR0VBYVFCQUFIWUFhUUJ6QUdFQUxnQmpBRzhBYlRBZUZ3MHhOREF4TURFd05qQXdNREJhRncweU5EQXhNREV3TmpBd01EQmFNQ2N4SlRBakJnTlZCQU1lSEFCakFHZ0FiUUJoQUdrQVFBQjJBR2tBY3dCaEFDNEFZd0J2QUcwd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFOQzgra2d0Z212V0YxT3pqZ0ROcmpURUJSdW9cLzVNS3ZsTTE0NnBBZjdHeDQxYmxFOXc0ZklYSkFEN0ZmTzdRS2pJWFlOdDM5ckx5eTd4RHdiXC81SWtaTTYwVFoyaUkxcGo1NVVjOGZkNGZ6T3BrM2Z0WmFRR1hOTFlwdEcxZDlWN0lTODJPdXA5TU1vMUJQVnJYVFBITmNzTTk5RVBVblBxZGJlR2M4N20wckFnTUJBQUdqWERCYU1GZ0dBMVVkQVFSUk1FK0FFSFpXUHJXdEpkN1laNDMxaENnN1lGU2hLVEFuTVNVd0l3WURWUVFESGh3QVl3Qm9BRzBBWVFCcEFFQUFkZ0JwQUhNQVlRQXVBR01BYndCdGdoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQURnWUVBYlVLWUNrdUlLUzlRUTJtRmNNWVJFSW0ybCtYZzhcL0pYditHQlZRSmtPS29zY1k0aU5ERkFcL2JRbG9nZjlMTFU4NFRId05SbnN2VjNQcnY3UlRZODFncTBkdEM4elljQWFBa0NISUkzeXFNbko0QU91NkVPVzlrSmsyMzJnU0U3V2xDdEhiZkxTS2Z1U2dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0=");
+ PaymentType paymentOne = new PaymentType();
+ paymentOne.setOpaqueData(op);
+ // Setting the transaction
+ TransactionRequestType transactionRequest = new TransactionRequestType();
+ transactionRequest.setAmount(new BigDecimal("131"));
+ transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
+ transactionRequest.setPayment(paymentOne);
+ // Making the api request
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(transactionRequest);
+ // Creating the controller
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+ // Getting the response
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response != null) {
+ // If API Response is ok, go ahead and check the transaction
+ // response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth code : " + result.getAuthCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: "
+ + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: "
+ + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null
+ && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: "
+ + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: "
+ + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ } else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+ }
+}
diff --git a/src/main/java/net/authorize/sample/ApplePayTransactions/CreateAnApplePayTransaction.java b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnApplePayTransaction.java
similarity index 69%
rename from src/main/java/net/authorize/sample/ApplePayTransactions/CreateAnApplePayTransaction.java
rename to src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnApplePayTransaction.java
index 959b2e83..f75feae4 100644
--- a/src/main/java/net/authorize/sample/ApplePayTransactions/CreateAnApplePayTransaction.java
+++ b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnApplePayTransaction.java
@@ -1,15 +1,14 @@
-package net.authorize.sample.ApplePayTransactions;
+package net.authorize.sample.MobileInAppTransactions;
import java.math.BigDecimal;
import net.authorize.Environment;
-import net.authorize.TransactionType;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.CreateTransactionController;
import net.authorize.api.controller.base.ApiOperationBase;
public class CreateAnApplePayTransaction
{
- public static void run(String apiLoginId, String transactionKey)
+ public static ANetApiResponse run(String apiLoginId, String transactionKey)
{
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -37,29 +36,38 @@ public static void run(String apiLoginId, String transactionKey)
controller.execute();
// Getting the response
CreateTransactionResponse response = controller.getApiResponse();
- if(response!=null)
- {
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK)
- {
- if (response.getTransactionResponse() != null)
- {
- TransactionResponse result = response.getTransactionResponse();
- System.out.println("Successful: Create an ApplePay Transaction");
- System.out.println("Response Code : " + result.getResponseCode());
- System.out.println("Transaction ID : " + result.getTransId());
- System.out.println("Auth code : " + result.getAuthCode());
- }
- }
- else
- {
- System.out.println("Failed: Create ApplePay Transaction");
- if(!response.getMessages().getMessage().isEmpty())
- System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
-
- if (response.getTransactionResponse() != null)
- if(!response.getTransactionResponse().getErrors().getError().isEmpty())
- System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
- }
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth code : " + result.getAuthCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ } else {
+ System.out.println("Null Response.");
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateGooglePayTransaction.java b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateGooglePayTransaction.java
new file mode 100644
index 00000000..112c6a0f
--- /dev/null
+++ b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateGooglePayTransaction.java
@@ -0,0 +1,100 @@
+package net.authorize.sample.MobileInAppTransactions;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+import java.math.BigDecimal;
+
+public class CreateGooglePayTransaction {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ OpaqueDataType opaqueData = new OpaqueDataType();
+ opaqueData.setDataDescriptor("COMMON.GOOGLE.INAPP.PAYMENT");
+ opaqueData.setDataValue("1234567890ABCDEF1111AAAA2222BBBB3333CCCC4444DDDD5555EEEE6666FFFF7777888899990000");
+
+ PaymentType paymentType = new PaymentType();
+ paymentType.setOpaqueData(opaqueData);
+
+ LineItemType lineItem = new LineItemType();
+ lineItem.setItemId("1");
+ lineItem.setName("vase");
+ lineItem.setDescription("Cannes logo");
+ lineItem.setQuantity(BigDecimal.valueOf(18));
+ lineItem.setUnitPrice(BigDecimal.valueOf(45.00));
+
+ ArrayOfLineItem lineItems = new ArrayOfLineItem();
+ lineItems.getLineItem().add(lineItem);
+
+ ExtendedAmountType tax = new ExtendedAmountType();
+ tax.setAmount(BigDecimal.valueOf(amount));
+ tax.setName("level2 tax name");
+ tax.setDescription("level2 tax");
+
+ UserField userField = new UserField();
+ TransactionRequestType.UserFields userFields = new TransactionRequestType.UserFields();
+
+ userField.setName("UserDefinedFieldName1");
+ userField.setValue("UserDefinedFieldValue1");
+ userFields.getUserField().add(userField);
+
+ userField.setName("UserDefinedFieldName2");
+ userField.setValue("UserDefinedFieldValue2");
+ userFields.getUserField().add(userField);
+
+ TransactionRequestType transactionRequest = new TransactionRequestType();
+ transactionRequest.setAmount(BigDecimal.valueOf(amount));
+ transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
+ transactionRequest.setPayment(paymentType);
+ transactionRequest.setLineItems(lineItems);
+ transactionRequest.setTax(tax);
+ transactionRequest.setUserFields(userFields);
+
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(transactionRequest);
+
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response != null) {
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth code : " + result.getAuthCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ } else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+ }
+}
diff --git a/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCapture.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCapture.java
new file mode 100644
index 00000000..3705af7f
--- /dev/null
+++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCapture.java
@@ -0,0 +1,94 @@
+package net.authorize.sample.PayPalExpressCheckout;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PayPalType;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class AuthorizationAndCapture {
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
+
+ System.out.println("PayPal Authorize Capture Transaction");
+
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ PayPalType payPalType = new PayPalType();
+ payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+ payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+
+ //standard api call to retrieve response
+ PaymentType paymentType = new PaymentType();
+ paymentType.setPayPal(payPalType);
+
+ // Create the payment transaction request
+ TransactionRequestType transactionRequest = new TransactionRequestType();
+
+ transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
+ transactionRequest.setPayment(paymentType);
+ transactionRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+
+ // Make the API Request
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(transactionRequest);
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Secure Acceptance URL : " + result.getSecureAcceptance().getSecureAcceptanceUrl());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+ }
+}
diff --git a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCaptureContinue.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCaptureContinued.java
similarity index 50%
rename from src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCaptureContinue.java
rename to src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCaptureContinued.java
index 03a88ec3..6b0844f8 100644
--- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCaptureContinue.java
+++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCaptureContinued.java
@@ -1,9 +1,10 @@
-package net.authorize.sample.PaypalExpressCheckout;
+package net.authorize.sample.PayPalExpressCheckout;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import net.authorize.Environment;
-import net.authorize.TransactionType;
+import net.authorize.api.contract.v1.ANetApiResponse;
import net.authorize.api.contract.v1.CreateTransactionRequest;
import net.authorize.api.contract.v1.CreateTransactionResponse;
import net.authorize.api.contract.v1.MerchantAuthenticationType;
@@ -11,16 +12,17 @@
import net.authorize.api.contract.v1.PayPalType;
import net.authorize.api.contract.v1.PaymentType;
import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
import net.authorize.api.contract.v1.TransactionTypeEnum;
import net.authorize.api.controller.CreateTransactionController;
import net.authorize.api.controller.base.ApiOperationBase;
-public class AuthorizationAndCaptureContinue
+public class AuthorizationAndCaptureContinued
{
- public static void run(String apiLoginId, String transactionKey, String TransactionID, String payerID){
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String TransactionID, String payerID , Double amount) {
- System.out.println("PayPal Authorize Capture-Continue Transaction");
+ System.out.println("PayPal Authorization and Capture, Continued Transaction");
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -47,7 +49,7 @@ public static void run(String apiLoginId, String transactionKey, String Transact
TransactionRequestType transactionRequest = new TransactionRequestType();
transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_CONTINUE_TRANSACTION.value().toString());
transactionRequest.setPayment(paymentType);
- transactionRequest.setAmount(new BigDecimal("19.45"));
+ transactionRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
transactionRequest.setRefTransId(TransactionID);
CreateTransactionRequest request = new CreateTransactionRequest();
@@ -60,18 +62,41 @@ public static void run(String apiLoginId, String transactionKey, String Transact
// get the response from the service (errors contained if any)
CreateTransactionResponse response = controller.getApiResponse();
- //validate
- if(response.getMessages().getResultCode() == MessageTypeEnum.OK){
- if(response.getTransactionResponse() != null){
- System.out.println("Success, \nMessage : "+response.getTransactionResponse().getMessages().getMessage().get(0).getDescription() );
- // Get Auth Code By : response.getTransactionResponse().getAuthCode()
+ //validate
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
}
}
else {
- System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode()+ " " + response.getMessages().getMessage().get(0).getText() );
- if(response.getTransactionResponse() != null){
- System.out.println("Transaction Error : "+ response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
- }
- }
+ System.out.println("Null Response.");
+ }
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnly.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnly.java
new file mode 100644
index 00000000..28fb438b
--- /dev/null
+++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnly.java
@@ -0,0 +1,98 @@
+package net.authorize.sample.PayPalExpressCheckout;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.MessagesType;
+import net.authorize.api.contract.v1.PayPalType;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class AuthorizationOnly {
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
+ System.out.println("PayPal Authorize Only Transaction");
+
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ PayPalType payPal = new PayPalType();
+ payPal.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+ payPal.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+
+ //standard api call to retrieve response
+ PaymentType paymentType = new PaymentType();
+ paymentType.setPayPal(payPal);
+
+ TransactionRequestType transactionRequest = new TransactionRequestType();
+ transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_TRANSACTION.value());
+ transactionRequest.setPayment(paymentType);
+ transactionRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+
+ CreateTransactionRequest request = new CreateTransactionRequest();
+ request.setTransactionRequest(transactionRequest);
+
+
+ CreateTransactionController controller = new CreateTransactionController(request);
+
+ // call the service
+ controller.execute();
+
+ // get the response from the service
+ CreateTransactionResponse response = controller.getApiResponse();
+ MessagesType responseMessage = response.getMessages();
+
+ //validate
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Secure Acceptance URL : " + result.getSecureAcceptance().getSecureAcceptanceUrl());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnlyContinued.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnlyContinued.java
new file mode 100644
index 00000000..1d665f42
--- /dev/null
+++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnlyContinued.java
@@ -0,0 +1,99 @@
+package net.authorize.sample.PayPalExpressCheckout;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PayPalType;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class AuthorizationOnlyContinued {
+
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionId, String payerId, Double amount) {
+
+ System.out.println("PayPal Authorization Only, Continued Transaction");
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ // Populate PayPal Transaction Data
+ PayPalType payPalType = new PayPalType();
+ payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+ payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+ payPalType.setPayerID(payerId);
+
+ // Populate the payment data
+ PaymentType paymentType = new PaymentType();
+ paymentType.setPayPal(payPalType);
+
+ // Create the payment transaction request
+ TransactionRequestType txnRequest = new TransactionRequestType();
+ txnRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_CONTINUE_TRANSACTION.value());
+ txnRequest.setPayment(paymentType);
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+ txnRequest.setRefTransId(transactionId);
+
+ // Make the API Request
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(txnRequest);
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+
+
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+
+ }
+
+
+
+}
diff --git a/src/main/java/net/authorize/sample/PayPalExpressCheckout/Credit.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/Credit.java
new file mode 100644
index 00000000..43ef3add
--- /dev/null
+++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/Credit.java
@@ -0,0 +1,87 @@
+package net.authorize.sample.PayPalExpressCheckout;
+
+import java.math.BigDecimal;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.controller.CreateTransactionController;
+
+public class Credit {
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionId) {
+
+ System.out.println("PayPal Credit Transaction");
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ // Populate PayPal Transaction Data
+ PayPalType payPalType = new PayPalType();
+ payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+ payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+
+ // Populate the payment data
+ PaymentType paymentType = new PaymentType();
+ paymentType.setPayPal(payPalType);
+
+ // Create the payment transaction request
+ TransactionRequestType txnRequest = new TransactionRequestType();
+ txnRequest.setTransactionType(TransactionTypeEnum.REFUND_TRANSACTION.value());
+ txnRequest.setPayment(paymentType);
+ txnRequest.setAmount(new BigDecimal(500.00));
+ txnRequest.setRefTransId(transactionId);
+
+ // Make the API Request
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(txnRequest);
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+
+
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+
+ }
+
+
+
+}
diff --git a/src/main/java/net/authorize/sample/PayPalExpressCheckout/GetDetails.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/GetDetails.java
new file mode 100644
index 00000000..2d6796d6
--- /dev/null
+++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/GetDetails.java
@@ -0,0 +1,87 @@
+package net.authorize.sample.PayPalExpressCheckout;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class GetDetails {
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionID) {
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ PayPalType payPalType = new PayPalType();
+ payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+ payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
+ // set payment type as PayPal
+ PaymentType paymentType = new PaymentType();
+ paymentType.setPayPal(payPalType);
+
+ //create GetDetailsTransaction for any valid PayPal transaction Id for the Merchant
+ TransactionRequestType transactionRequestType = new TransactionRequestType();
+ transactionRequestType.setTransactionType(TransactionTypeEnum.GET_DETAILS_TRANSACTION.value());
+ transactionRequestType.setPayment(paymentType);
+ transactionRequestType.setRefTransId(transactionID);
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(transactionRequestType);
+
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+
+
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+
+ if (result.getSecureAcceptance() != null)
+ System.out.println("PayPal PayerID : "+ result.getSecureAcceptance().getPayerID());
+
+ if (result.getShipTo() != null) {
+ System.out.println("Shipping Address : "+ result.getShipTo().getFirstName());
+ System.out.println(result.getShipTo().getAddress() +" " + result.getShipTo().getCity());
+ System.out.println(result.getShipTo().getState() +" "+ result.getShipTo().getZip());
+ System.out.println(result.getShipTo().getCountry());
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+
+ }
+
+}
diff --git a/src/main/java/net/authorize/sample/PaypalExpressCheckout/PriorAuthorizationCapture.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/PriorAuthorizationCapture.java
similarity index 52%
rename from src/main/java/net/authorize/sample/PaypalExpressCheckout/PriorAuthorizationCapture.java
rename to src/main/java/net/authorize/sample/PayPalExpressCheckout/PriorAuthorizationCapture.java
index b41e1378..b088f493 100644
--- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/PriorAuthorizationCapture.java
+++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/PriorAuthorizationCapture.java
@@ -4,7 +4,7 @@
* and open the template in the editor.
*/
-package net.authorize.sample.PaypalExpressCheckout;
+package net.authorize.sample.PayPalExpressCheckout;
import java.math.BigDecimal;
import net.authorize.api.controller.base.ApiOperationBase;
@@ -17,8 +17,8 @@
* @author gnongsie
*/
public class PriorAuthorizationCapture {
- public static void run(String apiLoginId, String apiTransactionKey, String transactionId){
- System.out.println("Paypal Prior Authorization Transaction");
+ public static ANetApiResponse run(String apiLoginId, String apiTransactionKey, String transactionId) {
+ System.out.println("PayPal Prior Authorization Transaction");
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -55,15 +55,40 @@ public static void run(String apiLoginId, String apiTransactionKey, String trans
CreateTransactionResponse response = controller.getApiResponse();
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK){
- if (response.getTransactionResponse() != null){
- System.out.println("Success, Auth Code: " + response.getTransactionResponse().getAuthCode());
- }
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
}
- else{
- System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() +
- " " + response.getMessages().getMessage().get(0).getText());
+ else {
+ System.out.println("Null Response.");
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/PayPalExpressCheckout/Void.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/Void.java
new file mode 100644
index 00000000..7a872e60
--- /dev/null
+++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/Void.java
@@ -0,0 +1,90 @@
+package net.authorize.sample.PayPalExpressCheckout;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PayPalType;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class Void {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionID) {
+
+ System.out.println("PayPal Void Transaction");
+
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ PayPalType payPalType = new PayPalType();
+ payPalType.setSuccessUrl("");
+ payPalType.setCancelUrl("");
+
+ //standard api call to retrieve response
+ PaymentType paymentType = new PaymentType();
+ paymentType.setPayPal(payPalType);
+
+ // Create the payment transaction request
+ TransactionRequestType transactionRequest = new TransactionRequestType();
+
+ transactionRequest.setTransactionType(TransactionTypeEnum.VOID_TRANSACTION.value());
+ transactionRequest.setPayment(paymentType);
+ transactionRequest.setRefTransId(transactionID);
+
+ // Make the API Request
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(transactionRequest);
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+ }
+
+}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/AuthorizeCreditCard.java b/src/main/java/net/authorize/sample/PaymentTransactions/AuthorizeCreditCard.java
index a20750f9..a3b56f06 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/AuthorizeCreditCard.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/AuthorizeCreditCard.java
@@ -1,76 +1,101 @@
package net.authorize.sample.PaymentTransactions;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.CreditCardType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
public class AuthorizeCreditCard {
//
// Run this sample from command line with:
- // java -jar target/ChargeCreditCard-jar-with-dependencies.jar
+ // java -jar target/AuthorizeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
-
- //Common code to set for all requests
+ // Set the request to operate in either the sandbox or production environment
ApiOperationBase.setEnvironment(Environment.SANDBOX);
-
+
+ // Create object with merchant authentication details
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
// Populate the payment data
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4242424242424242");
- creditCard.setExpirationDate("0822");
+ creditCard.setExpirationDate("0835");
paymentType.setCreditCard(creditCard);
- // Create the payment transaction request
+ // Create the payment transaction object
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_TRANSACTION.value());
txnRequest.setPayment(paymentType);
- txnRequest.setAmount(new BigDecimal(500.00));
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
- // Make the API Request
+ // Create the API request and set the parameters for this specific request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setMerchantAuthentication(merchantAuthenticationType);
apiRequest.setTransactionRequest(txnRequest);
+
+ // Call the controller
CreateTransactionController controller = new CreateTransactionController(apiRequest);
controller.execute();
-
- CreateTransactionResponse response = controller.getApiResponse();
-
+ // Get the response
+ CreateTransactionResponse response = new CreateTransactionResponse();
+ response = controller.getApiResponse();
+
+ // Parse the response to determine results
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
+ // If API Response is OK, go ahead and check the transaction response
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful Credit Card Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created auth-only transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
}
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
}
}
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
+ } else {
+ // Display the error code and message when response is null
+ ANetApiResponse errorResponse = controller.getErrorResponse();
+ System.out.println("Failed to get response");
+ if (!errorResponse.getMessages().getMessage().isEmpty()) {
+ System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
}
}
-
+
+ return response;
}
-
-
-
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.java b/src/main/java/net/authorize/sample/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.java
index dd43ba75..f8f049b5 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.java
@@ -1,11 +1,21 @@
package net.authorize.sample.PaymentTransactions;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.CreditCardType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
public class CaptureFundsAuthorizedThroughAnotherChannel {
@@ -13,7 +23,7 @@ public class CaptureFundsAuthorizedThroughAnotherChannel {
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -22,11 +32,20 @@ public static void run(String apiLoginId, String transactionKey) {
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ CreditCardType cc = new CreditCardType();
+ cc.setCardNumber("4111111111111111");
+ cc.setExpirationDate("2035-12");
+
+ PaymentType payment = new PaymentType();
+ payment.setCreditCard(cc);
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.CAPTURE_ONLY_TRANSACTION.value());
- txnRequest.setRefTransId("2238786428");
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+ txnRequest.setPayment(payment);
+ txnRequest.setAuthCode("ROHNFQ");
// Make the API Request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
@@ -36,29 +55,42 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
-
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successfully Captured Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- }
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
}
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/CapturePreviouslyAuthorizedAmount.java b/src/main/java/net/authorize/sample/PaymentTransactions/CapturePreviouslyAuthorizedAmount.java
index a222d4b4..9cecf8ea 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/CapturePreviouslyAuthorizedAmount.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/CapturePreviouslyAuthorizedAmount.java
@@ -13,7 +13,7 @@ public class CapturePreviouslyAuthorizedAmount {
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionID) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -26,7 +26,7 @@ public static void run(String apiLoginId, String transactionKey) {
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.PRIOR_AUTH_CAPTURE_TRANSACTION.value());
- txnRequest.setRefTransId("2238786428");
+ txnRequest.setRefTransId(transactionID);
// Make the API Request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
@@ -36,29 +36,42 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
-
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successfully Captured Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- }
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
}
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCreditCard.java b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCreditCard.java
index 3a9d1e4f..34e91905 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCreditCard.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCreditCard.java
@@ -1,76 +1,99 @@
package net.authorize.sample.PaymentTransactions;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import net.authorize.Environment;
import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
public class ChargeCreditCard {
-
+ public static void main(String[] args) {
+ run("5KP3u95bQpv", "346HZ32z3fP4hTG2", 25.00);
+ }
//
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
-
- //Common code to set for all requests
+ // Set the request to operate in either the sandbox or production environment
ApiOperationBase.setEnvironment(Environment.SANDBOX);
+ // Create object with merchant authentication details
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
// Populate the payment data
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4242424242424242");
- creditCard.setExpirationDate("0822");
+ creditCard.setExpirationDate("0835");
paymentType.setCreditCard(creditCard);
- // Create the payment transaction request
+ // Set email address (optional)
+ CustomerDataType customer = new CustomerDataType();
+ customer.setEmail("test@test.test");
+
+ // Create the payment transaction object
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
txnRequest.setPayment(paymentType);
- txnRequest.setAmount(new BigDecimal(500.00));
+ txnRequest.setCustomer(customer);
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
- // Make the API Request
+ // Create the API request and set the parameters for this specific request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setMerchantAuthentication(merchantAuthenticationType);
apiRequest.setTransactionRequest(txnRequest);
+
+ // Call the controller
CreateTransactionController controller = new CreateTransactionController(apiRequest);
controller.execute();
-
- CreateTransactionResponse response = controller.getApiResponse();
-
+ // Get the response
+ CreateTransactionResponse response = new CreateTransactionResponse();
+ response = controller.getApiResponse();
+
+ // Parse the response to determine results
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
+ // If API Response is OK, go ahead and check the transaction response
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful Credit Card Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
}
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
}
}
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
+ } else {
+ // Display the error code and message when response is null
+ ANetApiResponse errorResponse = controller.getErrorResponse();
+ System.out.println("Failed to get response");
+ if (!errorResponse.getMessages().getMessage().isEmpty()) {
+ System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
}
}
-
+
+ return response;
}
-
-
-
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfile.java b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfile.java
index a2bd6032..0d86c650 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfile.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfile.java
@@ -1,11 +1,21 @@
package net.authorize.sample.PaymentTransactions;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.CustomerProfilePaymentType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentProfile;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
public class ChargeCustomerProfile {
@@ -13,7 +23,8 @@ public class ChargeCustomerProfile {
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId,
+ String customerPaymentProfileId, Double amount) {
//Common code to set for all requests
@@ -27,16 +38,16 @@ public static void run(String apiLoginId, String transactionKey) {
// Set the profile ID to charge
CustomerProfilePaymentType profileToCharge = new CustomerProfilePaymentType();
- profileToCharge.setCustomerProfileId("36731856");
+ profileToCharge.setCustomerProfileId(customerProfileId);
PaymentProfile paymentProfile = new PaymentProfile();
- paymentProfile.setPaymentProfileId("33211899");
+ paymentProfile.setPaymentProfileId(customerPaymentProfileId);
profileToCharge.setPaymentProfile(paymentProfile);
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
txnRequest.setProfile(profileToCharge);
- txnRequest.setAmount(new BigDecimal(500.00));
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
@@ -48,26 +59,40 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- }
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
}
+
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfilesMT.java b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfilesMT.java
new file mode 100644
index 00000000..7b250046
--- /dev/null
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfilesMT.java
@@ -0,0 +1,111 @@
+package net.authorize.sample.PaymentTransactions;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.security.SecureRandom;
+import java.text.DecimalFormat;
+import java.util.Date;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.sample.CustomerProfiles.CreateCustomerPaymentProfile;
+import net.authorize.sample.CustomerProfiles.CreateCustomerProfile;
+
+public class ChargeCustomerProfilesMT {
+
+ private static final int MYTHREADS = 120;
+ private static String apiLoginId = "5KP3u95bQpv";
+ private static String transactionKey = "346HZ32z3fP4hTG2";
+
+ static SecureRandom rgenerator = new SecureRandom();
+
+ private static Double getAmount()
+ {
+ double d = (double)(1.05 + (450.0 * rgenerator.nextDouble()));
+ DecimalFormat df = new DecimalFormat("#.##");
+ d = Double.valueOf(df.format(d));
+ return d;
+ }
+
+ private static String getEmail()
+ {
+ return rgenerator.nextInt(10000000) + "@test.com";
+ }
+
+ //
+ // Run this sample from command line with:
+ // java -jar target/ChargeCreditCard-jar-with-dependencies.jar
+ //
+ public static Boolean run() {
+
+
+ ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);
+
+ Date dt1 = new Date();
+ for (int i = 0; i < MYTHREADS; i++) {
+ Runnable worker = new MyRunnable();
+ executor.execute(worker);
+ }
+ executor.shutdown();
+
+ // Wait until all threads are finish
+ while (!executor.isTerminated()) {
+
+ }
+ Date dt2 = new Date();
+ long difference = dt2.getTime() - dt1.getTime();
+
+ System.out.println("\nFinished all threads : " + difference/1000 + " sec");
+
+ return true;
+ }
+
+ public static class MyRunnable implements Runnable {
+
+ @Override
+ public void run() {
+ CreateCustomerProfileResponse response = null;
+ CreateCustomerPaymentProfileResponse paymentProfileResponse = null;
+
+ try{
+ response = (CreateCustomerProfileResponse) CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ paymentProfileResponse = (CreateCustomerPaymentProfileResponse) CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ }
+ catch (Exception e) {
+ System.out.println("Failure in CIM calls.");
+ System.out.println(e.getMessage());
+ return;
+ }
+
+ try {
+ Date dt1 = new Date();
+ System.out.println("============================================================================");
+ System.out.println("chargeResponse Dt1: + " + dt1.toString());
+
+ if ((response.getCustomerProfileId() != null) && (paymentProfileResponse.getCustomerPaymentProfileId() != null))
+ {
+ CreateTransactionResponse chargeResponse = (CreateTransactionResponse) ChargeCustomerProfile.run(apiLoginId, transactionKey,
+ response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), getAmount());
+ }
+ else
+ {
+ System.out.println("NULL PROFILE IDS.");
+ }
+
+ Date dt2 = new Date();
+ System.out.println("chargeResponse Dt2: + " + dt2.toString());
+
+ long difference = dt2.getTime() - dt1.getTime();
+ System.out.println("chargeResponse Diff: " + difference/1000);
+ System.out.println("============================================================================");
+ } catch (Exception e) {
+ System.out.println("Failure in charge customer profile call:");
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeTokenizedCreditCard.java b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeTokenizedCreditCard.java
index c24e4029..73909a75 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeTokenizedCreditCard.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeTokenizedCreditCard.java
@@ -1,11 +1,21 @@
package net.authorize.sample.PaymentTransactions;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.CreditCardType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
public class ChargeTokenizedCreditCard {
@@ -13,7 +23,7 @@ public class ChargeTokenizedCreditCard {
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
//Common code to set for all requests
@@ -28,7 +38,9 @@ public static void run(String apiLoginId, String transactionKey) {
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4242424242424242");
- creditCard.setExpirationDate("0822");
+ creditCard.setExpirationDate("0835");
+ // Set the token specific info
+ creditCard.setIsPaymentToken(true);
creditCard.setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA=");
paymentType.setCreditCard(creditCard);
@@ -36,7 +48,7 @@ public static void run(String apiLoginId, String transactionKey) {
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
txnRequest.setPayment(paymentType);
- txnRequest.setAmount(new BigDecimal(500.00));
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
// Make the API Request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
@@ -48,27 +60,41 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful Credit Card Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- }
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
}
+
+ return response;
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/CreateChasePayTransaction.java b/src/main/java/net/authorize/sample/PaymentTransactions/CreateChasePayTransaction.java
new file mode 100644
index 00000000..3627c2ee
--- /dev/null
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/CreateChasePayTransaction.java
@@ -0,0 +1,102 @@
+package net.authorize.sample.PaymentTransactions;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.CreditCardType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
+import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class CreateChasePayTransaction {
+
+ //
+ // Run this sample from command line with:
+ //
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
+
+ // Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ // Populate the payment data
+ PaymentType paymentType = new PaymentType();
+ CreditCardType creditCard = new CreditCardType();
+ creditCard.setCardNumber("4111111111111111");
+ creditCard.setExpirationDate("2035-12");
+ // Set the token specific info
+ creditCard.setIsPaymentToken(true);
+ creditCard.setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA=");
+ creditCard.setTokenRequestorName("CHASE_PAY");
+ creditCard.setTokenRequestorId("12345678901");
+ creditCard.setTokenRequestorEci("07");
+ creditCard.setCardCode("999");
+ paymentType.setCreditCard(creditCard);
+
+ // Create the payment transaction request
+ TransactionRequestType txnRequest = new TransactionRequestType();
+ txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
+ txnRequest.setPayment(paymentType);
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+ // Make the API Request
+ CreateTransactionRequest apiRequest = new CreateTransactionRequest();
+ apiRequest.setTransactionRequest(txnRequest);
+ CreateTransactionController controller = new CreateTransactionController(apiRequest);
+ controller.execute();
+
+ CreateTransactionResponse response = controller.getApiResponse();
+
+ if (response != null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ } else {
+ System.out.println("Failed get Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: "
+ + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: "
+ + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ } else {
+ System.out.println("Failed get Transaction.");
+ if (response.getTransactionResponse() != null
+ && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: "
+ + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: "
+ + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ } else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
+
+ }
+
+}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/CreditBankAccount.java b/src/main/java/net/authorize/sample/PaymentTransactions/CreditBankAccount.java
index a4331de5..06dd7733 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/CreditBankAccount.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/CreditBankAccount.java
@@ -1,11 +1,22 @@
package net.authorize.sample.PaymentTransactions;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.BankAccountType;
+import net.authorize.api.contract.v1.BankAccountTypeEnum;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
public class CreditBankAccount {
@@ -13,7 +24,7 @@ public class CreditBankAccount {
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionID, Double amount) {
//Common code to set for all requests
@@ -28,17 +39,17 @@ public static void run(String apiLoginId, String transactionKey) {
PaymentType paymentType = new PaymentType();
BankAccountType bankAccountType = new BankAccountType();
bankAccountType.setAccountType(BankAccountTypeEnum.CHECKING);
- bankAccountType.setRoutingNumber("125000024");
- bankAccountType.setAccountNumber("12345678");
+ bankAccountType.setRoutingNumber("121141754");
+ bankAccountType.setAccountNumber("7687245428");
bankAccountType.setNameOnAccount("John Doe");
paymentType.setBankAccount(bankAccountType);
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.REFUND_TRANSACTION.value());
- txnRequest.setRefTransId("2148889729");
+ txnRequest.setRefTransId(transactionID);
txnRequest.setPayment(paymentType);
- txnRequest.setAmount(new BigDecimal(500.00));
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
// Make the API Request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
@@ -50,26 +61,40 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful Credit Bank Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- }
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/DebitBankAccount.java b/src/main/java/net/authorize/sample/PaymentTransactions/DebitBankAccount.java
index 7d1b277e..23a57b8f 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/DebitBankAccount.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/DebitBankAccount.java
@@ -1,11 +1,22 @@
package net.authorize.sample.PaymentTransactions;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.BankAccountType;
+import net.authorize.api.contract.v1.BankAccountTypeEnum;
+import net.authorize.api.contract.v1.CreateTransactionRequest;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentType;
+import net.authorize.api.contract.v1.TransactionRequestType;
+import net.authorize.api.contract.v1.TransactionResponse;
+import net.authorize.api.contract.v1.TransactionTypeEnum;
import net.authorize.api.controller.CreateTransactionController;
+import net.authorize.api.controller.base.ApiOperationBase;
public class DebitBankAccount {
@@ -13,7 +24,7 @@ public class DebitBankAccount {
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
//Common code to set for all requests
@@ -28,8 +39,8 @@ public static void run(String apiLoginId, String transactionKey) {
PaymentType paymentType = new PaymentType();
BankAccountType bankAccountType = new BankAccountType();
bankAccountType.setAccountType(BankAccountTypeEnum.CHECKING);
- bankAccountType.setRoutingNumber("125000024");
- bankAccountType.setAccountNumber("12345678");
+ bankAccountType.setRoutingNumber("121141754");
+ bankAccountType.setAccountNumber("7687245428");
bankAccountType.setNameOnAccount("John Doe");
paymentType.setBankAccount(bankAccountType);
@@ -37,7 +48,7 @@ public static void run(String apiLoginId, String transactionKey) {
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
txnRequest.setPayment(paymentType);
- txnRequest.setAmount(new BigDecimal(500.00));
+ txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
// Make the API Request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
@@ -49,26 +60,40 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful Debit Bank Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction: "+result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- }
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/RefundTransaction.java b/src/main/java/net/authorize/sample/PaymentTransactions/RefundTransaction.java
index b7eea0aa..41913cc0 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/RefundTransaction.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/RefundTransaction.java
@@ -13,7 +13,7 @@ public class RefundTransaction {
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, Double transactionAmount, String transactionID) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -27,14 +27,14 @@ public static void run(String apiLoginId, String transactionKey) {
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("0015");
- creditCard.setExpirationDate("1220");
+ creditCard.setExpirationDate("XXXX");
paymentType.setCreditCard(creditCard);
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.REFUND_TRANSACTION.value());
- txnRequest.setRefTransId("2245803597");
- txnRequest.setAmount(new BigDecimal(1.00));
+ txnRequest.setRefTransId(transactionID);
+ txnRequest.setAmount(new BigDecimal(transactionAmount.toString()));
txnRequest.setPayment(paymentType);
// Make the API Request
@@ -45,35 +45,38 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
-
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successfully Refunded Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- if(!response.getMessages().getMessage().isEmpty())
- System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
-
- if (response.getTransactionResponse() != null)
- if(!response.getTransactionResponse().getErrors().getError().isEmpty())
- System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
- }
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ } else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ } else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ } else {
+ System.out.println("Null Response.");
}
+
+ return response;
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/UpdateSplitTenderGroup.java b/src/main/java/net/authorize/sample/PaymentTransactions/UpdateSplitTenderGroup.java
index e5468cff..456d3fdc 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/UpdateSplitTenderGroup.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/UpdateSplitTenderGroup.java
@@ -11,7 +11,7 @@
* @author gnongsie
*/
public class UpdateSplitTenderGroup {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
System.out.println("Update Split Tender Group Sample Code");
//Common code to set for all requests
@@ -24,7 +24,7 @@ public static void run(String apiLoginId, String transactionKey) {
// Provide a split tender Id
// To get a split Tender ID in sandbox, authorize any transaction with amount = 462.25 [if card present] and set allowPartialAuth = true
- String splitTenderId = "SPLIT_TENDER_ID";
+ String splitTenderId = "115901";
// Create a request
UpdateSplitTenderGroupRequest request = new UpdateSplitTenderGroupRequest();
@@ -39,7 +39,7 @@ public static void run(String apiLoginId, String transactionKey) {
UpdateSplitTenderGroupResponse response = controller.getApiResponse();
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK){
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
@@ -48,5 +48,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() +
" " + response.getMessages().getMessage().get(0).getText());
}
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/VoidTransaction.java b/src/main/java/net/authorize/sample/PaymentTransactions/VoidTransaction.java
index 10c3145d..781f4152 100644
--- a/src/main/java/net/authorize/sample/PaymentTransactions/VoidTransaction.java
+++ b/src/main/java/net/authorize/sample/PaymentTransactions/VoidTransaction.java
@@ -13,7 +13,7 @@ public class VoidTransaction {
// Run this sample from command line with:
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
//
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionID) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -26,7 +26,7 @@ public static void run(String apiLoginId, String transactionKey) {
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.VOID_TRANSACTION.value());
- txnRequest.setRefTransId("2238786428");
+ txnRequest.setRefTransId(transactionID);
// Make the API Request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
@@ -36,29 +36,42 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
-
if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successfully Voided Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- }
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
}
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
}
diff --git a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCapture.java b/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCapture.java
deleted file mode 100644
index bd541a2e..00000000
--- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCapture.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package net.authorize.sample.PaypalExpressCheckout;
-
-import java.math.BigDecimal;
-
-import net.authorize.Environment;
-import net.authorize.api.contract.v1.CreateTransactionRequest;
-import net.authorize.api.contract.v1.CreateTransactionResponse;
-import net.authorize.api.contract.v1.MerchantAuthenticationType;
-import net.authorize.api.contract.v1.MessageTypeEnum;
-import net.authorize.api.contract.v1.PayPalType;
-import net.authorize.api.contract.v1.PaymentType;
-import net.authorize.api.contract.v1.TransactionRequestType;
-import net.authorize.api.contract.v1.TransactionResponse;
-import net.authorize.api.contract.v1.TransactionTypeEnum;
-import net.authorize.api.controller.CreateTransactionController;
-import net.authorize.api.controller.base.ApiOperationBase;
-
-public class AuthorizationAndCapture {
-
- public static void run(String apiLoginId, String transactionKey) {
-
- System.out.println("PayPal Authorize Capture Transaction");
-
- //Common code to set for all requests
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
-
- MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
- merchantAuthenticationType.setName(apiLoginId);
- merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
-
- PayPalType payPalType = new PayPalType();
- payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
- payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
-
- //standard api call to retrieve response
- PaymentType paymentType = new PaymentType();
- paymentType.setPayPal(payPalType);
-
- // Create the payment transaction request
- TransactionRequestType transactionRequest = new TransactionRequestType();
-
- transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
- transactionRequest.setPayment(paymentType);
- transactionRequest.setAmount(new BigDecimal("123.89"));
-
- // Make the API Request
- CreateTransactionRequest apiRequest = new CreateTransactionRequest();
- apiRequest.setTransactionRequest(transactionRequest);
- CreateTransactionController controller = new CreateTransactionController(apiRequest);
- controller.execute();
-
- CreateTransactionResponse response = controller.getApiResponse();
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- if (response.getTransactionResponse() != null)
- {
- TransactionResponse result = response.getTransactionResponse();
- System.out.println("Successful Paypal Authorize Capture Transaction");
- System.out.println("Response Code : " + result.getResponseCode());
- System.out.println("Transaction ID : " + result.getTransId());
- System.out.println("Secure Acceptance URL : " + result.getSecureAcceptance().getSecureAcceptanceUrl());
- }
- }
- else
- {
- System.out.println("Failed Paypal Authorize Capture Transaction");
- if(!response.getMessages().getMessage().isEmpty())
- System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
-
- if (response.getTransactionResponse() != null)
- if(!response.getTransactionResponse().getErrors().getError().isEmpty())
- System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
- }
- }
-}
diff --git a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnly.java b/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnly.java
deleted file mode 100644
index a9018a90..00000000
--- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnly.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package net.authorize.sample.PaypalExpressCheckout;
-
-import java.math.BigDecimal;
-import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
-import net.authorize.api.controller.CreateTransactionController;
-
-public class AuthorizationOnly {
-
- public static void run(String apiLoginId, String transactionKey) {
- System.out.println("PayPal Authorize Only Transaction");
-
- //Common code to set for all requests
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
-
- MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
- merchantAuthenticationType.setName(apiLoginId);
- merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
-
- PayPalType payPal = new PayPalType();
- payPal.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
- payPal.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
-
- //standard api call to retrieve response
- PaymentType paymentType = new PaymentType();
- paymentType.setPayPal(payPal);
-
- TransactionRequestType transactionRequest = new TransactionRequestType();
- transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_TRANSACTION.value());
- transactionRequest.setPayment(paymentType);
- transactionRequest.setAmount(new BigDecimal("19.44"));
-
- CreateTransactionRequest request = new CreateTransactionRequest();
- request.setTransactionRequest(transactionRequest);
-
-
- CreateTransactionController controller = new CreateTransactionController(request);
-
- // call the service
- controller.execute();
-
- // get the response from the service
- CreateTransactionResponse response = controller.getApiResponse();
- MessagesType responseMessage = response.getMessages();
-
- //validate
- if (responseMessage.getResultCode().equals(MessageTypeEnum.OK)) {
- System.out.println("Message Code : " + responseMessage.getMessage().get(0).getCode() + " | Message Text : " + responseMessage.getMessage().get(0).getText());
- if (response.getTransactionResponse() != null) {
- System.out.println("Success, Response Code : " + response.getTransactionResponse().getResponseCode() + " | Transaction ID : " + response.getTransactionResponse().getTransId());
- }
- } else {
- System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
- if (response.getTransactionResponse() != null) {
- System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnlyContinued.java b/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnlyContinued.java
deleted file mode 100644
index 6bdcc52d..00000000
--- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnlyContinued.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package net.authorize.sample.PaypalExpressCheckout;
-
-import java.math.BigDecimal;
-
-import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
-import net.authorize.api.controller.CreateTransactionController;
-
-public class AuthorizationOnlyContinued {
-
-
- public static void run(String apiLoginId, String transactionKey, String transactionId, String payerId) {
-
- System.out.println("PayPal Authorize Only-Continue Transaction");
- //Common code to set for all requests
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
- MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
- merchantAuthenticationType.setName(apiLoginId);
- merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
-
- // Populate PayPal Transaction Data
- PayPalType payPalType = new PayPalType();
- payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
- payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
- payPalType.setPayerID(payerId);
-
- // Populate the payment data
- PaymentType paymentType = new PaymentType();
- paymentType.setPayPal(payPalType);
-
- // Create the payment transaction request
- TransactionRequestType txnRequest = new TransactionRequestType();
- txnRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_CONTINUE_TRANSACTION.value());
- txnRequest.setPayment(paymentType);
- txnRequest.setAmount(new BigDecimal(500.00));
- txnRequest.setRefTransId(transactionId);
-
- // Make the API Request
- CreateTransactionRequest apiRequest = new CreateTransactionRequest();
- apiRequest.setTransactionRequest(txnRequest);
- CreateTransactionController controller = new CreateTransactionController(apiRequest);
- controller.execute();
-
-
- CreateTransactionResponse response = controller.getApiResponse();
-
- if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful PayPal Transaction");
- //System.out.println("Reference Transaction ID: " + result.getRefTransID());
- System.out.println("Description: "+result.getMessages().getMessage().get(0).getDescription());
- }
- else
- {
- System.out.println(result.getResponseCode());
- System.out.println("Failed Transaction Description: "+result.getErrors().getError().get(0).getErrorText());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
- System.out.println("Error Code: "+response.getMessages().getMessage().get(0).getCode());
- }
- }
-
- }
-
-
-
-}
diff --git a/src/main/java/net/authorize/sample/PaypalExpressCheckout/Credit.java b/src/main/java/net/authorize/sample/PaypalExpressCheckout/Credit.java
deleted file mode 100644
index 9a17ccdc..00000000
--- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/Credit.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package net.authorize.sample.PaypalExpressCheckout;
-
-import java.math.BigDecimal;
-
-import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
-import net.authorize.api.controller.CreateTransactionController;
-
-public class Credit {
-
- public static void run(String apiLoginId, String transactionKey, String transactionId) {
-
- System.out.println("PayPal Credit Transaction");
- //Common code to set for all requests
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
- MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
- merchantAuthenticationType.setName(apiLoginId);
- merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
-
- // Populate PayPal Transaction Data
- PayPalType payPalType = new PayPalType();
- payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
- payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
-
- // Populate the payment data
- PaymentType paymentType = new PaymentType();
- paymentType.setPayPal(payPalType);
-
- // Create the payment transaction request
- TransactionRequestType txnRequest = new TransactionRequestType();
- txnRequest.setTransactionType(TransactionTypeEnum.REFUND_TRANSACTION.value());
- txnRequest.setPayment(paymentType);
- txnRequest.setAmount(new BigDecimal(500.00));
- txnRequest.setRefTransId(transactionId);
-
- // Make the API Request
- CreateTransactionRequest apiRequest = new CreateTransactionRequest();
- apiRequest.setTransactionRequest(txnRequest);
- CreateTransactionController controller = new CreateTransactionController(apiRequest);
- controller.execute();
-
-
- CreateTransactionResponse response = controller.getApiResponse();
-
- if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful PayPal Transaction");
- //System.out.println("Reference Transaction ID: " + result.getRefTransID());
- System.out.println(result.getMessages().getMessage().get(0).getDescription());
- }
- else
- {
- System.out.println("Transaction Error: "+result.getErrors().getError().get(0).getErrorCode()+" "+result.getErrors().getError().get(0).getErrorText());
-
- }
- }
- else
- {
- System.out.println("Error: "+response.getMessages().getMessage().get(0).getCode()+ " " + response.getMessages().getMessage().get(0).getText());
-
- }
- }
-
- }
-
-
-
-}
diff --git a/src/main/java/net/authorize/sample/PaypalExpressCheckout/GetDetails.java b/src/main/java/net/authorize/sample/PaypalExpressCheckout/GetDetails.java
deleted file mode 100644
index 76d46f41..00000000
--- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/GetDetails.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package net.authorize.sample.PaypalExpressCheckout;
-
-import net.authorize.Environment;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.CreateTransactionController;
-import net.authorize.api.controller.base.ApiOperationBase;
-
-public class GetDetails {
-
- public static void run(String apiLoginId, String transactionKey) {
- //Common code to set for all requests
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
- MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
- merchantAuthenticationType.setName(apiLoginId);
- merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
-
- PayPalType payPalType = new PayPalType();
- payPalType.setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
- payPalType.setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
- // set payment type as PayPal
- PaymentType paymentType = new PaymentType();
- paymentType.setPayPal(payPalType);
-
- //create GetDetailsTransaction for any valid PayPal transaction Id for the Merchant
- TransactionRequestType transactionRequestType = new TransactionRequestType();
- transactionRequestType.setTransactionType(TransactionTypeEnum.GET_DETAILS_TRANSACTION.value());
- transactionRequestType.setPayment(paymentType);
- transactionRequestType.setRefTransId("2241936095");
- CreateTransactionRequest apiRequest = new CreateTransactionRequest();
- apiRequest.setTransactionRequest(transactionRequestType);
-
- CreateTransactionController controller = new CreateTransactionController(apiRequest);
- controller.execute();
-
-
- CreateTransactionResponse response = controller.getApiResponse();
-
- if (response!=null && response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println("Successful PayPal Get Details Transaction");
- System.out.println("Account Type : "+ result.getAccountType());
- System.out.println("PayPal PayerID : "+ result.getSecureAcceptance().getPayerID());
- System.out.println("Shipping Address : "+ result.getShipTo().getFirstName());
- System.out.println(result.getShipTo().getAddress() +" " + result.getShipTo().getCity());
- System.out.println(result.getShipTo().getState() +" "+ result.getShipTo().getZip());
- System.out.println(result.getShipTo().getCountry());
- System.out.println("Transaction ID : " + result.getTransId());
- }
- }
- else
- {
- System.out.println("Failed Transaction: "+response.getMessages().getMessage().get(0).getCode()+ " " + response.getMessages().getMessage().get(0).getText());
- }
-
- }
-
-}
diff --git a/src/main/java/net/authorize/sample/PaypalExpressCheckout/Void.java b/src/main/java/net/authorize/sample/PaypalExpressCheckout/Void.java
deleted file mode 100644
index 01f200fc..00000000
--- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/Void.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package net.authorize.sample.PaypalExpressCheckout;
-
-import net.authorize.Environment;
-import net.authorize.api.contract.v1.CreateTransactionRequest;
-import net.authorize.api.contract.v1.CreateTransactionResponse;
-import net.authorize.api.contract.v1.MerchantAuthenticationType;
-import net.authorize.api.contract.v1.MessageTypeEnum;
-import net.authorize.api.contract.v1.PayPalType;
-import net.authorize.api.contract.v1.PaymentType;
-import net.authorize.api.contract.v1.TransactionRequestType;
-import net.authorize.api.contract.v1.TransactionResponse;
-import net.authorize.api.contract.v1.TransactionTypeEnum;
-import net.authorize.api.controller.CreateTransactionController;
-import net.authorize.api.controller.base.ApiOperationBase;
-
-public class Void {
- public static void run(String apiLoginId, String transactionKey) {
-
- System.out.println("PayPal Void Transaction");
-
- //Common code to set for all requests
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
-
- MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
- merchantAuthenticationType.setName(apiLoginId);
- merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
-
- PayPalType payPalType = new PayPalType();
- payPalType.setSuccessUrl("");
- payPalType.setCancelUrl("");
-
- //standard api call to retrieve response
- PaymentType paymentType = new PaymentType();
- paymentType.setPayPal(payPalType);
-
- // Create the payment transaction request
- TransactionRequestType transactionRequest = new TransactionRequestType();
-
- transactionRequest.setTransactionType(TransactionTypeEnum.VOID_TRANSACTION.value());
- transactionRequest.setPayment(paymentType);
- transactionRequest.setRefTransId("2241708879");
-
- // Make the API Request
- CreateTransactionRequest apiRequest = new CreateTransactionRequest();
- apiRequest.setTransactionRequest(transactionRequest);
- CreateTransactionController controller = new CreateTransactionController(apiRequest);
- controller.execute();
-
- CreateTransactionResponse response = controller.getApiResponse();
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- if (response.getTransactionResponse() != null)
- {
- TransactionResponse result = response.getTransactionResponse();
- System.out.println("Successful Paypal Void Transaction");
- System.out.println("Response Code : " + result.getResponseCode());
- }
- }
- else
- {
- System.out.println("Failed Paypal Void Transaction");
- if(!response.getMessages().getMessage().isEmpty())
- System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
-
- if (response.getTransactionResponse() != null)
- if(!response.getTransactionResponse().getErrors().getError().isEmpty())
- System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
- }
- }
-
-}
diff --git a/src/main/java/net/authorize/sample/RecurringBilling/CancelSubscription.java b/src/main/java/net/authorize/sample/RecurringBilling/CancelSubscription.java
index 75f692e1..5e55f8b0 100644
--- a/src/main/java/net/authorize/sample/RecurringBilling/CancelSubscription.java
+++ b/src/main/java/net/authorize/sample/RecurringBilling/CancelSubscription.java
@@ -1,17 +1,13 @@
package net.authorize.sample.RecurringBilling;
-import net.authorize.data.arb.*;
-import java.math.BigDecimal;
import net.authorize.Environment;
-import net.authorize.data.Customer;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.base.ApiOperationBase;
import net.authorize.api.controller.ARBCancelSubscriptionController;
-import javax.xml.datatype.XMLGregorianCalendar;
public class CancelSubscription {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String subscriptionId) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
@@ -21,7 +17,7 @@ public static void run(String apiLoginId, String transactionKey) {
// Make the API Request
ARBCancelSubscriptionRequest apiRequest = new ARBCancelSubscriptionRequest();
- apiRequest.setSubscriptionId("100748");
+ apiRequest.setSubscriptionId(subscriptionId);
ARBCancelSubscriptionController controller = new ARBCancelSubscriptionController(apiRequest);
controller.execute();
ARBCancelSubscriptionResponse response = controller.getApiResponse();
@@ -37,5 +33,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to cancel Subscription: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscription.java b/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscription.java
index 5eca930f..920e9e4d 100644
--- a/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscription.java
+++ b/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscription.java
@@ -1,18 +1,29 @@
package net.authorize.sample.RecurringBilling;
-import net.authorize.data.arb.*;
import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
import net.authorize.Environment;
-import net.authorize.data.Customer;
-import net.authorize.api.contract.v1.*;
-import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.ARBCreateSubscriptionRequest;
+import net.authorize.api.contract.v1.ARBCreateSubscriptionResponse;
+import net.authorize.api.contract.v1.ARBSubscriptionType;
+import net.authorize.api.contract.v1.ARBSubscriptionUnitEnum;
+import net.authorize.api.contract.v1.CreditCardType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.NameAndAddressType;
+import net.authorize.api.contract.v1.PaymentScheduleType;
+import net.authorize.api.contract.v1.PaymentType;
import net.authorize.api.controller.ARBCreateSubscriptionController;
-import javax.xml.datatype.*;
-import java.lang.Exception.*;
+import net.authorize.api.controller.base.ApiOperationBase;
public class CreateSubscription {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, short intervalLength, Double amount) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
@@ -23,16 +34,16 @@ public static void run(String apiLoginId, String transactionKey) {
// Set up payment schedule
PaymentScheduleType schedule = new PaymentScheduleType();
PaymentScheduleType.Interval interval = new PaymentScheduleType.Interval();
- interval.setLength( (short)1);
- interval.setUnit(ARBSubscriptionUnitEnum.MONTHS);
+ interval.setLength(intervalLength);
+ interval.setUnit(ARBSubscriptionUnitEnum.DAYS);
schedule.setInterval(interval);
try {
XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar();
startDate.setDay(30);
- startDate.setMonth(8);
- startDate.setYear(2020);
- schedule.setStartDate(startDate); //2020-08-30
+ startDate.setMonth(12);
+ startDate.setYear(2032);
+ schedule.setStartDate(startDate);
}
catch(Exception e) {
@@ -45,13 +56,13 @@ public static void run(String apiLoginId, String transactionKey) {
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4111111111111111");
- creditCard.setExpirationDate("1220");
+ creditCard.setExpirationDate("1235");
paymentType.setCreditCard(creditCard);
ARBSubscriptionType arbSubscriptionType = new ARBSubscriptionType();
arbSubscriptionType.setPaymentSchedule(schedule);
- arbSubscriptionType.setAmount(new BigDecimal("10.29"));
- arbSubscriptionType.setTrialAmount(new BigDecimal("0.00"));
+ arbSubscriptionType.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+ arbSubscriptionType.setTrialAmount(new BigDecimal(1.23).setScale(2, RoundingMode.CEILING));
arbSubscriptionType.setPayment(paymentType);
NameAndAddressType name = new NameAndAddressType();
@@ -77,7 +88,10 @@ public static void run(String apiLoginId, String transactionKey) {
else
{
System.out.println("Failed to create Subscription: " + response.getMessages().getResultCode());
+ System.out.println(response.getMessages().getMessage().get(0).getText());
}
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscriptionFromCustomerProfile.java b/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscriptionFromCustomerProfile.java
new file mode 100644
index 00000000..231b6de6
--- /dev/null
+++ b/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscriptionFromCustomerProfile.java
@@ -0,0 +1,86 @@
+package net.authorize.sample.RecurringBilling;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.ARBCreateSubscriptionRequest;
+import net.authorize.api.contract.v1.ARBCreateSubscriptionResponse;
+import net.authorize.api.contract.v1.ARBSubscriptionType;
+import net.authorize.api.contract.v1.ARBSubscriptionUnitEnum;
+import net.authorize.api.contract.v1.CustomerProfileIdType;
+import net.authorize.api.contract.v1.MerchantAuthenticationType;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.PaymentScheduleType;
+import net.authorize.api.controller.ARBCreateSubscriptionController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class CreateSubscriptionFromCustomerProfile {
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, short intervalLength, Double amount,
+ String profileId, String paymentProfileId, String customerAddressId) {
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ // Set up payment schedule
+ PaymentScheduleType schedule = new PaymentScheduleType();
+ PaymentScheduleType.Interval interval = new PaymentScheduleType.Interval();
+ interval.setLength(intervalLength);
+ interval.setUnit(ARBSubscriptionUnitEnum.DAYS);
+ schedule.setInterval(interval);
+
+ try {
+ XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar();
+ startDate.setDay(30);
+ startDate.setMonth(12);
+ startDate.setYear(2032);
+ schedule.setStartDate(startDate); //2020-08-30
+ }
+ catch(Exception e) { }
+
+ schedule.setTotalOccurrences((short)12);
+ schedule.setTrialOccurrences((short)1);
+
+ CustomerProfileIdType profile = new CustomerProfileIdType();
+ profile.setCustomerProfileId(profileId);
+ profile.setCustomerPaymentProfileId(paymentProfileId);
+ profile.setCustomerAddressId(customerAddressId);
+
+ ARBSubscriptionType arbSubscriptionType = new ARBSubscriptionType();
+ arbSubscriptionType.setPaymentSchedule(schedule);
+ arbSubscriptionType.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
+ arbSubscriptionType.setTrialAmount(new BigDecimal(0.0).setScale(2, RoundingMode.CEILING));
+ arbSubscriptionType.setProfile(profile);
+
+ // Make the API Request
+ ARBCreateSubscriptionRequest apiRequest = new ARBCreateSubscriptionRequest();
+ apiRequest.setSubscription(arbSubscriptionType);
+ ARBCreateSubscriptionController controller = new ARBCreateSubscriptionController(apiRequest);
+ controller.execute();
+ ARBCreateSubscriptionResponse response = controller.getApiResponse();
+ if (response!=null) {
+
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+
+ System.out.println(response.getSubscriptionId());
+ System.out.println(response.getMessages().getMessage().get(0).getCode());
+ System.out.println(response.getMessages().getMessage().get(0).getText());
+ }
+ else
+ {
+ System.out.println("Failed to create Subscription: " + response.getMessages().getResultCode());
+ System.out.println(response.getMessages().getMessage().get(0).getText());
+ }
+ }
+
+ return response;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/RecurringBilling/GetListOfSubscriptions.java b/src/main/java/net/authorize/sample/RecurringBilling/GetListOfSubscriptions.java
index 66d6669b..70c57e12 100644
--- a/src/main/java/net/authorize/sample/RecurringBilling/GetListOfSubscriptions.java
+++ b/src/main/java/net/authorize/sample/RecurringBilling/GetListOfSubscriptions.java
@@ -1,17 +1,13 @@
package net.authorize.sample.RecurringBilling;
-import net.authorize.data.arb.*;
-import java.math.BigDecimal;
import net.authorize.Environment;
-import net.authorize.data.Customer;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.base.ApiOperationBase;
import net.authorize.api.controller.ARBGetSubscriptionListController;
-import javax.xml.datatype.XMLGregorianCalendar;
public class GetListOfSubscriptions {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
@@ -41,14 +37,15 @@ public static void run(String apiLoginId, String transactionKey) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getTotalNumInResultSet());
- System.out.println(response.getSubscriptionDetails().getSubscriptionDetail());
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
else
{
- System.out.println("Failed to create Subscription: " + response.getMessages().getResultCode());
+ System.out.println("Failed to get Subscription list: " + response.getMessages().getResultCode());
}
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/RecurringBilling/GetSubscription.java b/src/main/java/net/authorize/sample/RecurringBilling/GetSubscription.java
index 9cac8b97..5377db4b 100644
--- a/src/main/java/net/authorize/sample/RecurringBilling/GetSubscription.java
+++ b/src/main/java/net/authorize/sample/RecurringBilling/GetSubscription.java
@@ -10,32 +10,36 @@
import net.authorize.api.controller.ARBGetSubscriptionController;
import net.authorize.api.controller.base.ApiOperationBase;
-public class GetSubscription
-{
- public static void run(String apiLoginId,String transactionKey)
- {
+public class GetSubscription {
+ public static ANetApiResponse run(String apiLoginId,String transactionKey, String subscriptionId) {
+
+ // Set the request to operate in either the sandbox or production environment
ApiOperationBase.setEnvironment(Environment.SANDBOX);
- // Giving the merchant authentication information
+
+ // Create object with merchant authentication details
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- // Making the API request
+
+ // Create the API request and set the parameters for this specific request
ARBGetSubscriptionRequest apiRequest = new ARBGetSubscriptionRequest();
+ apiRequest.setMerchantAuthentication(merchantAuthenticationType);
apiRequest.setRefId("Sample");
- apiRequest.setSubscriptionId("2930242");
- // Calling the controller
+ apiRequest.setSubscriptionId(subscriptionId);
+
+ // Call the controller
ARBGetSubscriptionController controller = new ARBGetSubscriptionController(apiRequest);
controller.execute();
- // Getting the response
- ARBGetSubscriptionResponse response = controller.getApiResponse();
+
+ // Get the response
+ ARBGetSubscriptionResponse response = new ARBGetSubscriptionResponse();
+ response = controller.getApiResponse();
- if(response!=null)
- {
- if(response.getMessages().getResultCode() == MessageTypeEnum.OK)
- {
- if(response.getSubscription() != null)
- {
+ // Parse the response to determine results
+ if (response!=null) {
+ // If API Response is OK, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ if (response.getSubscription() != null) {
// Displaying the subscription details
System.out.println("Successfully got ARB Subscription");
System.out.println("Subscription Details:");
@@ -46,23 +50,22 @@ public static void run(String apiLoginId,String transactionKey)
System.out.println("Subscription Description: "+response.getSubscription().getProfile().getDescription());
System.out.println("Customer Profile ID: "+ response.getSubscription().getProfile().getCustomerProfileId());
}
- }
- else
- {
+ } else {
// Displaying the error code and message when error occurs
System.out.println("Failed to get ARB Subscription");
- if(!response.getMessages().getMessage().isEmpty())
+ if (!response.getMessages().getMessage().isEmpty()) {
System.out.println("Error: "+response.getMessages().getMessage().get(0).getCode()+" "+ response.getMessages().getMessage().get(0).getText());
+ }
}
- }
- else
- {
- // Displaying the error code and message when response is null
+ } else {
+ // Display the error code and message when response is null
ANetApiResponse errorResponse = controller.getErrorResponse();
-
System.out.println("Failed to get response");
- if(!errorResponse.getMessages().getMessage().isEmpty())
+ if (!errorResponse.getMessages().getMessage().isEmpty()) {
System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
+ }
}
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/RecurringBilling/GetSubscriptionStatus.java b/src/main/java/net/authorize/sample/RecurringBilling/GetSubscriptionStatus.java
index 48001b23..8492c365 100644
--- a/src/main/java/net/authorize/sample/RecurringBilling/GetSubscriptionStatus.java
+++ b/src/main/java/net/authorize/sample/RecurringBilling/GetSubscriptionStatus.java
@@ -1,41 +1,38 @@
package net.authorize.sample.RecurringBilling;
-import net.authorize.data.arb.*;
-import java.math.BigDecimal;
import net.authorize.Environment;
-import net.authorize.data.Customer;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.base.ApiOperationBase;
import net.authorize.api.controller.ARBGetSubscriptionStatusController;
-import javax.xml.datatype.XMLGregorianCalendar;
public class GetSubscriptionStatus {
-
- public static void run(String apiLoginId, String transactionKey) {
- //Common code to set for all requests
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
- MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
- merchantAuthenticationType.setName(apiLoginId);
- merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- ARBGetSubscriptionStatusRequest apiRequest = new ARBGetSubscriptionStatusRequest();
- apiRequest.setSubscriptionId("100748");
- ARBGetSubscriptionStatusController controller = new ARBGetSubscriptionStatusController(apiRequest);
- controller.execute();
- ARBGetSubscriptionStatusResponse response = controller.getApiResponse();
- if (response!=null) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String subscriptionId) {
+ //Common code to set for all requests
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- System.out.println(response.getStatus());
- System.out.println(response.getMessages().getMessage().get(0).getCode());
- System.out.println(response.getMessages().getMessage().get(0).getText());
- }
- else
- {
- System.out.println("Failed to update Subscription: " + response.getMessages().getResultCode());
- }
- }
- }
+ ARBGetSubscriptionStatusRequest apiRequest = new ARBGetSubscriptionStatusRequest();
+ apiRequest.setSubscriptionId(subscriptionId);
+ ARBGetSubscriptionStatusController controller = new ARBGetSubscriptionStatusController(apiRequest);
+ controller.execute();
+ ARBGetSubscriptionStatusResponse response = controller.getApiResponse();
+ if (response!=null) {
+
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+
+ System.out.println(response.getStatus());
+ System.out.println(response.getMessages().getMessage().get(0).getCode());
+ System.out.println(response.getMessages().getMessage().get(0).getText());
+ }
+ else
+ {
+ System.out.println("Failed to update Subscription: " + response.getMessages().getResultCode());
+ }
+ }
+ return response;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/RecurringBilling/UpdateSubscription.java b/src/main/java/net/authorize/sample/RecurringBilling/UpdateSubscription.java
index d72fc1f0..62243ac7 100644
--- a/src/main/java/net/authorize/sample/RecurringBilling/UpdateSubscription.java
+++ b/src/main/java/net/authorize/sample/RecurringBilling/UpdateSubscription.java
@@ -1,17 +1,13 @@
package net.authorize.sample.RecurringBilling;
-import net.authorize.data.arb.*;
-import java.math.BigDecimal;
import net.authorize.Environment;
-import net.authorize.data.Customer;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.base.ApiOperationBase;
import net.authorize.api.controller.ARBUpdateSubscriptionController;
-import javax.xml.datatype.XMLGregorianCalendar;
public class UpdateSubscription {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String subscriptionId) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
@@ -23,15 +19,23 @@ public static void run(String apiLoginId, String transactionKey) {
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4111111111111111");
- creditCard.setExpirationDate("1220");
+ creditCard.setExpirationDate("1235");
paymentType.setCreditCard(creditCard);
+
+ //set profile information
+ CustomerProfileIdType profile = new CustomerProfileIdType();
+ profile.setCustomerProfileId("121212");
+ profile.setCustomerPaymentProfileId("131313");
+ profile.setCustomerAddressId("141414");
ARBSubscriptionType arbSubscriptionType = new ARBSubscriptionType();
arbSubscriptionType.setPayment(paymentType);
+ //to update profile
+ //arbSubscriptionType.setProfile(profile);
// Make the API Request
ARBUpdateSubscriptionRequest apiRequest = new ARBUpdateSubscriptionRequest();
- apiRequest.setSubscriptionId("100748");
+ apiRequest.setSubscriptionId(subscriptionId);
apiRequest.setSubscription(arbSubscriptionType);
ARBUpdateSubscriptionController controller = new ARBUpdateSubscriptionController(apiRequest);
controller.execute();
@@ -48,5 +52,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to update Subscription: " + response.getMessages().getResultCode());
}
}
+ return response;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/SampleCode.java b/src/main/java/net/authorize/sample/SampleCode.java
index 70a1d1f3..70dbfc52 100644
--- a/src/main/java/net/authorize/sample/SampleCode.java
+++ b/src/main/java/net/authorize/sample/SampleCode.java
@@ -3,290 +3,351 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import net.authorize.sample.ApplePayTransactions.CreateAnApplePayTransaction;
import net.authorize.sample.VisaCheckout.*;
+import net.authorize.util.Constants;
import net.authorize.sample.PaymentTransactions.*;
-import net.authorize.sample.PaypalExpressCheckout.*;
-import net.authorize.sample.PaypalExpressCheckout.Void;
+import net.authorize.sample.PayPalExpressCheckout.*;
+import net.authorize.sample.PayPalExpressCheckout.Void;
import net.authorize.sample.RecurringBilling.*;
import net.authorize.sample.TransactionReporting.*;
import net.authorize.sample.CustomerProfiles.*;
-import net.authorize.sample.ApplePayTransactions.*;
+import net.authorize.sample.MobileInAppTransactions.*;
+import net.authorize.sample.FraudManagement.*;
+import net.authorize.sample.AcceptSuite.GetAcceptCustomerProfilePage;
+import net.authorize.sample.AcceptSuite.GetAnAcceptPaymentPage;
+
/**
* Created by anetdeveloper on 8/5/15.
*/
public class SampleCode {
- public static void main( String[] args )
- {
+ public static void main(String[] args) {
+
+ if (args.length == 0) {
+ SelectMethod();
+ } else if (args.length == 1) {
+ RunMethod(args[0]);
+ return;
+ } else {
+ ShowUsage();
+ }
+
+ System.out.println("");
+ System.out.print("Press to finish ...");
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ try {
+ int i = Integer.parseInt(br.readLine());
+ } catch (Exception ex) {
+ }
+
+ }
+
+ private static void ShowUsage() {
+ System.out.println("Usage : java -jar SampleCode.jar [CodeSampleName]");
+ System.out.println("");
+ System.out.println("Run with no parameter to select a method. Otherwise pass a method name.");
+ System.out.println("");
+ System.out.println("Code Sample Names: ");
+ ShowMethods();
+
+ }
- if (args.length == 0)
- {
- SelectMethod();
- }
- else if (args.length == 1)
- {
- RunMethod(args[0]);
- return;
- }
- else
- {
- ShowUsage();
- }
+ private static void SelectMethod() {
+ System.out.println("Code Sample Names: ");
+ System.out.println("");
+ ShowMethods();
+ System.out.println("");
+ System.out.print("Type a sample name & then press : ");
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ try {
+ RunMethod(br.readLine());
+ } catch (Exception ex) {
+ System.out.println(ex.toString());
+ }
+ }
- System.out.println("");
- System.out.print("Press to finish ...");
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- try{
- int i = Integer.parseInt(br.readLine());
- }catch(Exception ex){
- }
+ private static void ShowMethods() {
+ System.out.println(" DecryptVisaSrcData");
+ System.out.println(" CreateVisaSrcTransaction");
+ System.out.println(" ChargeCreditCard");
+ System.out.println(" AuthorizeCreditCard");
+ System.out.println(" RefundTransaction");
+ System.out.println(" VoidTransaction");
+ System.out.println(" CreateCustomerProfileFromTransaction");
+ System.out.println(" CaptureFundsAuthorizedThroughAnotherChannel");
+ System.out.println(" CapturePreviouslyAuthorizedAmount");
+ System.out.println(" DebitBankAccount");
+ System.out.println(" CreditBankAccount");
+ System.out.println(" ChargeTokenizedCreditCard");
+ System.out.println(" CreateAnApplePayTransaction");
+ System.out.println(" CreateAnAndroidPayTransaction");
+ System.out.println(" CreateAnAcceptTransaction");
+ System.out.println(" CreateGooglePayTransaction");
+ System.out.println(" ChargeCustomerProfile");
+ System.out.println(" CreateSubscription");
+ System.out.println(" CreateSubscriptionFromCustomerProfile");
+ System.out.println(" GetSubscription");
+ System.out.println(" GetSubscriptionStatus");
+ System.out.println(" CancelSubscription");
+ System.out.println(" UpdateSubscription");
+ System.out.println(" GetListOfSubscriptions");
+ System.out.println(" GetBatchStatistics");
+ System.out.println(" GetSettledBatchList");
+ System.out.println(" GetTransactionList");
+ System.out.println(" GetUnsettledTransactionList");
+ System.out.println(" GetTransactionDetails");
+ System.out.println(" CreateCustomerProfile");
+ System.out.println(" CreateCustomerPaymentProfile");
+ System.out.println(" CreateCustomerShippingAddress");
+ System.out.println(" DeleteCustomerPaymentProfile");
+ System.out.println(" DeleteCustomerProfile");
+ System.out.println(" DeleteCustomerShippingAddress");
+ System.out.println(" GetCustomerPaymentProfile");
+ System.out.println(" GetCustomerPaymentProfileList");
+ System.out.println(" GetCustomerProfile");
+ System.out.println(" GetCustomerProfileIds");
+ System.out.println(" GetCustomerProfileTransactionList");
+ System.out.println(" GetCustomerShippingAddress");
+ System.out.println(" GetAcceptCustomerProfilePage");
+ System.out.println(" UpdateCustomerProfile");
+ System.out.println(" UpdateCustomerPaymentProfile");
+ System.out.println(" UpdateCustomerShippingAddress");
+ System.out.println(" ValidateCustomerPaymentProfile");
+ System.out.println(" PayPalAuthorizeCapture");
+ System.out.println(" PayPalVoid");
+ System.out.println(" PayPalAuthorizationOnly");
+ System.out.println(" PayPalAuthorizeCaptureContinued");
+ System.out.println(" PayPalGetDetails");
+ System.out.println(" PayPalPriorAuthorizationCapture");
+ System.out.println(" PayPalAuthorizeOnlyContinued");
+ System.out.println(" PayPalCredit");
+ System.out.println(" UpdateSplitTenderGroup");
+ System.out.println(" GetMerchantDetails");
+ System.out.println(" GetHeldTransactionList");
+ System.out.println(" ApproveOrDeclineHeldTransaction");
+ System.out.println(" GetAnAcceptPaymentPage");
+ System.out.println(" CreateChasePayTransaction");
+ }
- }
+ private static void RunMethod(String methodName) {
+ // These are default transaction keys.
+ // You can create your own keys in seconds by signing up for a sandbox account
+ // here: https://developer.authorize.net/sandbox/
+ String apiLoginId = "5KP3u95bQpv";
+ String transactionKey = "346HZ32z3fP4hTG2";
+ // Update the payedId with which you want to run the sample code
+ String payerId = "6ZSCSYG33VP8Q";
+ // Update the transactionId with which you want to run the sample code
+ String transactionId = "123456";
- private static void ShowUsage()
- {
- System.out.println("Usage : java -jar SampleCode.jar [CodeSampleName]");
- System.out.println("");
- System.out.println("Run with no parameter to select a method. Otherwise pass a method name.");
- System.out.println("");
- System.out.println("Code Sample Names: ");
- ShowMethods();
+ String customerProfileId = "918133235";
+ String customerPaymentProfileId = "917585361";
+ String customerAddressId = "918189891";
+ String emailId = "test@test2021.com";
- }
+ String subscriptionId = "326280";
- private static void SelectMethod()
- {
- System.out.println("Code Sample Names: ");
- System.out.println("");
- ShowMethods();
- System.out.println("");
- System.out.print("Type a sample name & then press : ");
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- try{
- RunMethod(br.readLine());
- }catch(Exception ex){
- System.out.print("Error no such method");
- }
- }
+ Double amount = 123.45;
- private static void ShowMethods()
- {
- System.out.println(" DecryptVisaCheckoutData");
- System.out.println(" CreateVisaCheckoutTransaction");
- System.out.println(" ChargeCreditCard");
- System.out.println(" AuthorizeCreditCard");
- System.out.println(" RefundTransaction");
- System.out.println(" VoidTransaction");
- System.out.println(" CreateCustomerProfileFromTransaction");
- System.out.println(" CaptureFundsAuthorizedThroughAnotherChannel");
- System.out.println(" CapturePreviouslyAuthorizedAmount");
- System.out.println(" DebitBankAccount");
- System.out.println(" CreditBankAccount");
- System.out.println(" ChargeTokenizedCreditCard");
- System.out.println(" CreateAnApplePayTransaction");
- System.out.println(" ChargeCustomerProfile");
- System.out.println(" CreateSubscription");
- System.out.println(" GetSubscription");
- System.out.println(" GetSubscriptionStatus");
- System.out.println(" CancelSubscription");
- System.out.println(" UpdateSubscription");
- System.out.println(" GetListOfSubscriptions");
- System.out.println(" GetBatchStatistics");
- System.out.println(" GetSettledBatchList");
- System.out.println(" GetTransactionList");
- System.out.println(" GetUnsettledTransactionList");
- System.out.println(" GetTransactionDetails");
- System.out.println(" CreateCustomerProfile");
- System.out.println(" CreateCustomerPaymentProfile");
- System.out.println(" CreateCustomerShippingAddress");
- System.out.println(" DeleteCustomerPaymentProfile");
- System.out.println(" DeleteCustomerProfile");
- System.out.println(" DeleteCustomerShippingAddress");
- System.out.println(" GetCustomerPaymentProfile");
- System.out.println(" GetCustomerPaymentProfileList");
- System.out.println(" GetCustomerProfile");
- System.out.println(" GetCustomerProfileIds");
- System.out.println(" GetCustomerShippingAddress");
- System.out.println(" GetHostedProfilePage");
- System.out.println(" UpdateCustomerPaymentProfile");
- System.out.println(" UpdateCustomerShippingAddress");
- System.out.println(" ValidateCustomerPaymentProfile");
- System.out.println(" PayPalAuthorizeCapture");
- System.out.println(" PayPalVoid");
- System.out.println(" PayPalAuthorizationOnly");
- System.out.println(" PayPalAuthorizeCaptureContinue");
- System.out.println(" PayPalGetDetails");
- System.out.println(" PayPalPriorAuthorizationCapture");
- System.out.println(" PayPalAuthorizeOnlyContinue");
- System.out.println(" PayPalCredit");
- System.out.println(" UpdateSplitTenderGroup");
- }
+ // Proxy server settings.
+ // Enable these lines for using Sample Codes behind a proxy server
- private static void RunMethod(String methodName)
- {
- // These are default transaction keys.
- // You can create your own keys in seconds by signing up for a sandbox account here: https://developer.authorize.net/sandbox/
- String apiLoginId = "5KP3u95bQpv";
- String transactionKey = "4Ktq966gC55GAX7S";
- //Update the payedId with which you want to run the sample code
- String payerId = "";
- //Update the transactionId with which you want to run the sample code
- String transactionId = "";
+// System.setProperty(Constants.HTTPS_USE_PROXY, "true");
+// System.setProperty(Constants.HTTPS_PROXY_HOST , "example.proxy.server");
+// System.setProperty(Constants.HTTPS_PROXY_PORT, "portNumber");
+// System.setProperty(Constants.HTTPS_PROXY_USERNAME, "exampleUsername");
+// System.setProperty(Constants.HTTPS_PROXY_PASSWORD, "examplePassword");
- switch (methodName) {
- case "DecryptVisaCheckoutData":
- DecryptVisaCheckoutData.run(apiLoginId, transactionKey);
- break;
- case "CreateVisaCheckoutTransaction":
- CreateVisaCheckoutTransaction.run(apiLoginId, transactionKey);
- break;
- case "ChargeCreditCard":
- ChargeCreditCard.run(apiLoginId, transactionKey);
- break;
- case "VoidTransaction":
- VoidTransaction.run(apiLoginId, transactionKey);
- break;
- case "AuthorizeCreditCard":
- AuthorizeCreditCard.run(apiLoginId, transactionKey);
- break;
- case "RefundTransaction":
- RefundTransaction.run(apiLoginId, transactionKey);
- break;
- case "CreateCustomerProfileFromTransaction":
- CreateCustomerProfileFromTransaction.run(apiLoginId, transactionKey);
- break;
- case "CaptureFundsAuthorizedThroughAnotherChannel":
- CaptureFundsAuthorizedThroughAnotherChannel.run(apiLoginId, transactionKey);
- break;
- case "CapturePreviouslyAuthorizedAmount":
- CapturePreviouslyAuthorizedAmount.run(apiLoginId, transactionKey);
- break;
- case "DebitBankAccount":
- DebitBankAccount.run(apiLoginId, transactionKey);
- break;
- case "CreditBankAccount":
- CreditBankAccount.run(apiLoginId, transactionKey);
- break;
- case "ChargeTokenizedCreditCard":
- ChargeTokenizedCreditCard.run(apiLoginId, transactionKey);
- break;
- case "CreateAnApplePayTransaction":
- CreateAnApplePayTransaction.run(apiLoginId, transactionKey);
- break;
- case "ChargeCustomerProfile":
- ChargeCustomerProfile.run(apiLoginId, transactionKey);
- break;
- case "CreateSubscription":
- CreateSubscription.run(apiLoginId, transactionKey);
- break;
- case "GetSubscription":
- GetSubscription.run(apiLoginId, transactionKey);
- break;
- case "GetSubscriptionStatus":
- GetSubscriptionStatus.run(apiLoginId, transactionKey);
- break;
- case "CancelSubscription":
- CancelSubscription.run(apiLoginId, transactionKey);
- break;
- case "UpdateSubscription":
- UpdateSubscription.run(apiLoginId, transactionKey);
- break;
- case "GetListOfSubscriptions":
- GetListOfSubscriptions.run(apiLoginId, transactionKey);
- break;
- case "GetBatchStatistics":
- GetBatchStatistics.run(apiLoginId, transactionKey);
- break;
- case "GetSettledBatchList":
- GetSettledBatchList.run(apiLoginId, transactionKey);
- break;
- case "GetTransactionList":
- GetTransactionList.run(apiLoginId, transactionKey);
- break;
- case "GetUnsettledTransactionList":
- GetUnsettledTransactionList.run(apiLoginId, transactionKey);
- break;
- case "GetTransactionDetails":
- GetTransactionDetails.run(apiLoginId, transactionKey);
- break;
- case "CreateCustomerProfile":
- CreateCustomerProfile.run(apiLoginId, transactionKey);
- break;
- case "CreateCustomerPaymentProfile":
- CreateCustomerPaymentProfile.run(apiLoginId, transactionKey);
- break;
- case "CreateCustomerShippingAddress":
- CreateCustomerShippingAddress.run(apiLoginId, transactionKey);
- break;
- case "DeleteCustomerPaymentProfile":
- DeleteCustomerPaymentProfile.run(apiLoginId, transactionKey);
- break;
- case "DeleteCustomerProfile":
- DeleteCustomerProfile.run(apiLoginId, transactionKey);
- break;
- case "DeleteCustomerShippingAddress":
- DeleteCustomerShippingAddress.run(apiLoginId, transactionKey);
- break;
- case "GetCustomerPaymentProfile":
- GetCustomerPaymentProfile.run(apiLoginId, transactionKey);
- break;
- case "GetCustomerPaymentProfileList":
- GetCustomerPaymentProfileList.run(apiLoginId, transactionKey);
- break;
- case "GetCustomerProfile":
- GetCustomerProfile.run(apiLoginId, transactionKey);
- break;
- case "GetCustomerProfileIds":
- GetCustomerProfileIds.run(apiLoginId, transactionKey);
- break;
- case "GetCustomerShippingAddress":
- GetCustomerShippingAddress.run(apiLoginId, transactionKey);
- break;
- case "GetHostedProfilePage":
- GetHostedProfilePage.run(apiLoginId, transactionKey);
- break;
- case "UpdateCustomerPaymentProfile":
- UpdateCustomerPaymentProfile.run(apiLoginId, transactionKey);
- break;
- case "UpdateCustomerShippingAddress":
- UpdateCustomerShippingAddress.run(apiLoginId, transactionKey);
- break;
- case "ValidateCustomerPaymentProfile":
- ValidateCustomerPaymentProfile.run(apiLoginId, transactionKey);
- break;
- case "PayPalAuthorizeCapture":
- AuthorizationAndCapture.run(apiLoginId, transactionKey);
- break;
- case "PayPalVoid":
- Void.run(apiLoginId, transactionKey);
- break;
- case "PayPalAuthorizationOnly":
- AuthorizationOnly.run(apiLoginId, transactionKey);
- break;
- case "PayPalAuthorizeCaptureContinue":
- AuthorizationAndCaptureContinue.run(apiLoginId, transactionKey, transactionId, payerId);
- break;
- case "PayPalAuthorizeOnlyContinue":
- AuthorizationOnlyContinued.run(apiLoginId, transactionKey, transactionId, payerId);
- break;
- case "PayPalCredit":
- Credit.run(apiLoginId, transactionKey, transactionId);
- break;
- case "PayPalGetDetails":
- GetDetails.run(apiLoginId, transactionKey);
- case "PaypalPriorAuthorizationCapture":
- transactionId = "2241801682"; // Use a valid transaction ID here
- PriorAuthorizationCapture.run(apiLoginId, transactionKey, transactionId);
- break;
- case "UpdateSplitTenderGroup":
- UpdateSplitTenderGroup.run(apiLoginId, transactionKey);
- break;
- default:
- ShowUsage();
- break;
- }
- }
+ switch (methodName) {
+ case "DecryptVisaSrcData":
+ DecryptVisaSrcData.run(apiLoginId, transactionKey);
+ break;
+ case "CreateVisaSrcTransaction":
+ CreateVisaSrcTransaction.run(apiLoginId, transactionKey);
+ break;
+ case "ChargeCreditCard":
+ ChargeCreditCard.run(apiLoginId, transactionKey, amount);
+ break;
+ case "VoidTransaction":
+ VoidTransaction.run(apiLoginId, transactionKey, transactionId);
+ break;
+ case "AuthorizeCreditCard":
+ AuthorizeCreditCard.run(apiLoginId, transactionKey, amount);
+ break;
+ case "RefundTransaction":
+ RefundTransaction.run(apiLoginId, transactionKey, amount, transactionId);
+ break;
+ case "CreateCustomerProfileFromTransaction":
+ CreateCustomerProfileFromTransaction.run(apiLoginId, transactionKey, amount, emailId);
+ break;
+ case "CaptureFundsAuthorizedThroughAnotherChannel":
+ CaptureFundsAuthorizedThroughAnotherChannel.run(apiLoginId, transactionKey, amount);
+ break;
+ case "CapturePreviouslyAuthorizedAmount":
+ CapturePreviouslyAuthorizedAmount.run(apiLoginId, transactionKey, transactionId);
+ break;
+ case "DebitBankAccount":
+ DebitBankAccount.run(apiLoginId, transactionKey, amount);
+ break;
+ case "CreditBankAccount":
+ CreditBankAccount.run(apiLoginId, transactionKey, transactionId, amount);
+ break;
+ case "ChargeTokenizedCreditCard":
+ ChargeTokenizedCreditCard.run(apiLoginId, transactionKey, amount);
+ break;
+ case "CreateAnApplePayTransaction":
+ CreateAnApplePayTransaction.run(apiLoginId, transactionKey);
+ break;
+ case "CreateAnAndroidPayTransaction":
+ CreateAnAndroidPayTransaction.run(apiLoginId, transactionKey);
+ break;
+ case "CreateAnAcceptTransaction":
+ CreateAnAcceptTransaction.run(apiLoginId, transactionKey);
+ break;
+ case "CreateGooglePayTransaction":
+ CreateGooglePayTransaction.run(apiLoginId, transactionKey, amount);
+ break;
+ case "ChargeCustomerProfile":
+ ChargeCustomerProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId, amount);
+ break;
+ case "ChargeCustomerProfilesMT":
+ ChargeCustomerProfilesMT.run();
+ break;
+ case "CreateSubscription":
+ CreateSubscription.run(apiLoginId, transactionKey, (short) 12, amount);
+ break;
+ case "CreateSubscriptionFromCustomerProfile":
+ CreateSubscriptionFromCustomerProfile.run(apiLoginId, transactionKey, (short) 12, amount, customerProfileId,
+ customerPaymentProfileId, customerAddressId);
+ break;
+ case "GetSubscription":
+ GetSubscription.run(apiLoginId, transactionKey, subscriptionId);
+ break;
+ case "GetSubscriptionStatus":
+ GetSubscriptionStatus.run(apiLoginId, transactionKey, subscriptionId);
+ break;
+ case "CancelSubscription":
+ CancelSubscription.run(apiLoginId, transactionKey, subscriptionId);
+ break;
+ case "UpdateSubscription":
+ UpdateSubscription.run(apiLoginId, transactionKey, subscriptionId);
+ break;
+ case "GetListOfSubscriptions":
+ GetListOfSubscriptions.run(apiLoginId, transactionKey);
+ break;
+ case "GetBatchStatistics":
+ GetBatchStatistics.run(apiLoginId, transactionKey);
+ break;
+ case "GetSettledBatchList":
+ GetSettledBatchList.run(apiLoginId, transactionKey);
+ break;
+ case "GetTransactionList":
+ GetTransactionList.run(apiLoginId, transactionKey);
+ break;
+ case "GetUnsettledTransactionList":
+ GetUnsettledTransactionList.run(apiLoginId, transactionKey);
+ break;
+ case "GetTransactionDetails":
+ GetTransactionDetails.run(apiLoginId, transactionKey, transactionId);
+ break;
+ case "CreateCustomerProfile":
+ CreateCustomerProfile.run(apiLoginId, transactionKey, emailId);
+ break;
+ case "CreateCustomerPaymentProfile":
+ CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, customerProfileId);
+ break;
+ case "CreateCustomerShippingAddress":
+ CreateCustomerShippingAddress.run(apiLoginId, transactionKey, customerProfileId);
+ break;
+ case "DeleteCustomerPaymentProfile":
+ DeleteCustomerPaymentProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId);
+ break;
+ case "DeleteCustomerProfile":
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, customerProfileId);
+ break;
+ case "DeleteCustomerShippingAddress":
+ DeleteCustomerShippingAddress.run(apiLoginId, transactionKey, customerProfileId, customerAddressId);
+ break;
+ case "GetCustomerPaymentProfile":
+ GetCustomerPaymentProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId);
+ break;
+ case "GetCustomerPaymentProfileList":
+ GetCustomerPaymentProfileList.run(apiLoginId, transactionKey);
+ break;
+ case "GetCustomerProfile":
+ GetCustomerProfile.run(apiLoginId, transactionKey, customerProfileId);
+ break;
+ case "GetCustomerProfileIds":
+ GetCustomerProfileIds.run(apiLoginId, transactionKey);
+ break;
+ case "GetCustomerProfileTransactionList":
+ customerProfileId = "1811474252";
+ GetCustomerProfileTransactionList.run(apiLoginId, transactionKey, customerProfileId);
+ break;
+ case "GetCustomerShippingAddress":
+ GetCustomerShippingAddress.run(apiLoginId, transactionKey, customerProfileId, customerAddressId);
+ break;
+ case "GetAcceptCustomerProfilePage":
+ GetAcceptCustomerProfilePage.run(apiLoginId, transactionKey, customerProfileId);
+ break;
+ case "UpdateCustomerProfile":
+ UpdateCustomerProfile.run(apiLoginId, transactionKey, customerProfileId);
+ break;
+ case "UpdateCustomerPaymentProfile":
+ UpdateCustomerPaymentProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId);
+ break;
+ case "UpdateCustomerShippingAddress":
+ UpdateCustomerShippingAddress.run(apiLoginId, transactionKey, customerProfileId, customerAddressId);
+ break;
+ case "ValidateCustomerPaymentProfile":
+ ValidateCustomerPaymentProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId);
+ break;
+ case "PayPalAuthorizeCapture":
+ AuthorizationAndCapture.run(apiLoginId, transactionKey, amount);
+ break;
+ case "PayPalVoid":
+ Void.run(apiLoginId, transactionKey, transactionId);
+ break;
+ case "PayPalAuthorizationOnly":
+ AuthorizationOnly.run(apiLoginId, transactionKey, amount);
+ break;
+ case "PayPalAuthorizeCaptureContinued":
+ AuthorizationAndCaptureContinued.run(apiLoginId, transactionKey, transactionId, payerId, amount);
+ break;
+ case "PayPalAuthorizeOnlyContinued":
+ AuthorizationOnlyContinued.run(apiLoginId, transactionKey, transactionId, payerId, amount);
+ break;
+ case "PayPalCredit":
+ Credit.run(apiLoginId, transactionKey, transactionId);
+ break;
+ case "PayPalGetDetails":
+ GetDetails.run(apiLoginId, transactionKey, transactionId);
+ case "PayPalPriorAuthorizationCapture":
+ PriorAuthorizationCapture.run(apiLoginId, transactionKey, transactionId);
+ break;
+ case "UpdateSplitTenderGroup":
+ UpdateSplitTenderGroup.run(apiLoginId, transactionKey);
+ break;
+ case "GetMerchantDetails":
+ GetMerchantDetails.run(apiLoginId, transactionKey);
+ break;
+ case "GetHeldTransactionList":
+ GetHeldTransactionList.run(apiLoginId, transactionKey);
+ break;
+ case "ApproveOrDeclineHeldTransaction":
+ ApproveOrDeclineHeldTransaction.run(apiLoginId, transactionKey, transactionId);
+ break;
+ case "GetAnAcceptPaymentPage":
+ GetAnAcceptPaymentPage.run(apiLoginId, transactionKey, amount);
+ break;
+ case "CreateChasePayTransaction":
+ CreateChasePayTransaction.run(apiLoginId, transactionKey, amount);
+ break;
+ default:
+ ShowUsage();
+ break;
+ }
+ }
}
diff --git a/src/main/java/net/authorize/sample/Sha512/ComputeTransHashSHA2.java b/src/main/java/net/authorize/sample/Sha512/ComputeTransHashSHA2.java
new file mode 100644
index 00000000..2a3a146e
--- /dev/null
+++ b/src/main/java/net/authorize/sample/Sha512/ComputeTransHashSHA2.java
@@ -0,0 +1,99 @@
+package net.authorize.sample.Sha512;
+
+import java.security.*;
+import java.util.Formatter;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+public class ComputeTransHashSHA2 {
+
+ public static void main(String[] args) throws Exception {
+ String signatureKey = "56E529FE6C63D60E545F84686096E6AA01D5E18A119F18A130F7CFB3983104216979E95D84C91BDD382AA0875264A63940A2D0AA5548F6023B4C78A9D52C18DA";
+ String transId = "60115868980";
+ String apiLogin = "5T9cRn9FK";
+ String amount = "15.00";
+ //transHashSHA2 represents the computed TransHash2 using SignatureKey for the given transaction
+ //textToHash is formed by concatenating apilogin id , transId for the given transaction and transaction amount.
+ // For more details please visit https://developer.authorize.net/support/hash_upgrade/?utm_campaign=19Q2%20MD5%20Hash%20EOL%20Partner&utm_medium=email&utm_source=Eloqua for implementation details.
+ String transHashSHA2=getHMACSHA512(signatureKey, "^"+ apiLogin+"^"+ transId +"^"+ amount+"^");
+ }
+
+ /**
+ * This is method to generate HMAC512 key for a given signature key and Text to Hash
+ * @param signatureKey
+ * @param textToHash
+ * @return
+ * @throws Exception
+ */
+ public static String getHMACSHA512(String signatureKey, String textToHash)throws Exception
+ {
+ // Check if Key is null or empty
+ if (signatureKey==null||signatureKey.isEmpty())
+ throw new IllegalArgumentException("HMACSHA512: key Parameter cannot be empty.");
+ //Check if texttoHash is null or empty
+ if (textToHash==null||textToHash.isEmpty())
+ throw new IllegalArgumentException("HMACSHA512: textToHash Parameter cannot be empty.");
+
+ // Signature Key size cannot be less than 2 or odd
+ if (signatureKey.length() % 2 != 0 || signatureKey.trim().length() < 2)
+ {
+ throw new IllegalArgumentException("HMACSHA512: key Parameter cannot be odd or less than 2 characters.");
+ }
+
+ // Convert Hex string to byte array
+ byte signatureKeyInByteArray[]=hexStringToByteArray(signatureKey);
+ // Calculate hmac 512 for the byte array contents and text to hash.
+ String hashedValue=calculateHMAC(signatureKeyInByteArray,textToHash);
+ if(hashedValue==null)
+ throw new NullPointerException("For Signature Key :["+signatureKey+"] And Text To Hash ["+textToHash+"] the generated HMAC512 Key is null .Please contact Authorize.net for more information");
+
+ return hashedValue.toUpperCase();
+ }
+
+ /**
+ * This is the method to Calculate Hmac sha512 for given signature signatureKey in byte array and text to hash in byte array
+ * @param signatureKey
+ * @param textToHash
+ * @return
+ * @throws SignatureException
+ * @throws NoSuchAlgorithmException
+ * @throws InvalidKeyException
+ */
+ public static String calculateHMAC(byte signatureKey[], String textToHash)
+ throws SignatureException, NoSuchAlgorithmException, InvalidKeyException
+ {
+ SecretKeySpec secretKeySpec = new SecretKeySpec(signatureKey, "HmacSHA512");
+ Mac mac = Mac.getInstance("HmacSHA512");
+ mac.init(secretKeySpec);
+ return toHexString(mac.doFinal(textToHash.getBytes()));
+ }
+
+ /**
+ * This is the method to convert byte array into hexadecimal string
+ * @param bytes
+ * @return hexadecimal string.
+ */
+ private static String toHexString(byte[] bytes) {
+ Formatter formatter = new Formatter();
+ for (byte b : bytes) {
+ formatter.format("%02x", b);
+ }
+ return formatter.toString();
+ }
+
+ /**
+ * This is the method convert hexadecimal string to byte array
+ * @param str
+ * @return byte array
+ */
+ public static byte[] hexStringToByteArray(String str) {
+ int len = str.length();
+ byte[] data = new byte[len / 2];
+ for (int i = 0; i < len; i += 2) {
+ data[i / 2] = (byte) ((Character.digit(str.charAt(i), 16) << 4)
+ + Character.digit(str.charAt(i+1), 16));
+ }
+ return data;
+ }
+}
diff --git a/src/main/java/net/authorize/sample/TransactionReporting/GetBatchStatistics.java b/src/main/java/net/authorize/sample/TransactionReporting/GetBatchStatistics.java
index 96968239..ce1408c5 100644
--- a/src/main/java/net/authorize/sample/TransactionReporting/GetBatchStatistics.java
+++ b/src/main/java/net/authorize/sample/TransactionReporting/GetBatchStatistics.java
@@ -8,7 +8,7 @@
//author @krgupta
public class GetBatchStatistics {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
@@ -37,5 +37,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to get batch statistics: " + getResponse.getMessages().getResultCode());
}
}
+ return getResponse;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/authorize/sample/TransactionReporting/GetCustomerProfileTransactionList.java b/src/main/java/net/authorize/sample/TransactionReporting/GetCustomerProfileTransactionList.java
new file mode 100644
index 00000000..680385e1
--- /dev/null
+++ b/src/main/java/net/authorize/sample/TransactionReporting/GetCustomerProfileTransactionList.java
@@ -0,0 +1,63 @@
+package net.authorize.sample.TransactionReporting;
+
+import java.util.List;
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.GetTransactionListForCustomerController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+//author @akashah
+public class GetCustomerProfileTransactionList{
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) {
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+
+ GetTransactionListForCustomerRequest getRequest = new GetTransactionListForCustomerRequest();
+ getRequest.setMerchantAuthentication(merchantAuthenticationType);
+ getRequest.setCustomerProfileId(customerProfileId);
+
+ Paging paging = new Paging();
+ paging.setLimit(100);
+ paging.setOffset(1);
+
+ getRequest.setPaging(paging);
+
+ TransactionListSorting sorting = new TransactionListSorting();
+ sorting.setOrderBy(TransactionListOrderFieldEnum.ID);
+ sorting.setOrderDescending(true);
+
+ getRequest.setSorting(sorting);
+
+ GetTransactionListForCustomerController controller = new GetTransactionListForCustomerController(getRequest);
+ controller.execute();
+
+ GetTransactionListResponse getResponse = controller.getApiResponse();
+ if (getResponse!=null) {
+ ArrayOfTransactionSummaryType transactions = getResponse.getTransactions();
+ List list = transactions.getTransaction();
+
+ for (TransactionSummaryType summary : list) {
+ System.out.println(summary.getFirstName());
+ System.out.println(summary.getTransId());
+ System.out.println(summary.getSettleAmount());
+ System.out.println(summary.getSubmitTimeLocal());
+ }
+
+ if (getResponse.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ System.out.println(getResponse.getMessages().getMessage().get(0).getCode());
+ System.out.println(getResponse.getMessages().getMessage().get(0).getText());
+ } else {
+ System.out.println("Failed to get transaction list: " + getResponse.getMessages().getResultCode());
+ }
+ }
+ return getResponse;
+
+ }
+}
diff --git a/src/main/java/net/authorize/sample/TransactionReporting/GetMerchantDetails.java b/src/main/java/net/authorize/sample/TransactionReporting/GetMerchantDetails.java
new file mode 100644
index 00000000..f4d3b6da
--- /dev/null
+++ b/src/main/java/net/authorize/sample/TransactionReporting/GetMerchantDetails.java
@@ -0,0 +1,48 @@
+package net.authorize.sample.TransactionReporting;
+
+
+import net.authorize.Environment;
+import net.authorize.api.contract.v1.*;
+import net.authorize.api.controller.GetMerchantDetailsController;
+import net.authorize.api.controller.base.ApiOperationBase;
+
+public class GetMerchantDetails {
+
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
+
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
+
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
+
+ GetMerchantDetailsRequest getRequest = new GetMerchantDetailsRequest();
+ getRequest.setMerchantAuthentication(merchantAuthenticationType);
+
+ GetMerchantDetailsController controller = new GetMerchantDetailsController(getRequest);
+ controller.execute();
+ GetMerchantDetailsResponse getResponse = controller.getApiResponse();
+
+ if (getResponse!=null) {
+
+ if (getResponse.getMessages().getResultCode() == MessageTypeEnum.OK) {
+
+ System.out.println("Merchant Name : " + getResponse.getMerchantName());
+ System.out.println("Gateway Id : " + getResponse.getGatewayId());
+
+ System.out.println(getResponse.getMessages().getMessage().get(0).getCode());
+ System.out.println(getResponse.getMessages().getMessage().get(0).getText());
+ }
+ else
+ {
+ System.out.println("Failed to get merchant details: " + getResponse.getMessages().getResultCode());
+ }
+ }
+ return getResponse;
+}
+}
+
+
+
+
diff --git a/src/main/java/net/authorize/sample/TransactionReporting/GetSettledBatchList.java b/src/main/java/net/authorize/sample/TransactionReporting/GetSettledBatchList.java
index 3a7fd72c..db690d65 100644
--- a/src/main/java/net/authorize/sample/TransactionReporting/GetSettledBatchList.java
+++ b/src/main/java/net/authorize/sample/TransactionReporting/GetSettledBatchList.java
@@ -11,7 +11,7 @@
//author @krgupta modified @kikmak42
public class GetSettledBatchList {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -60,5 +60,6 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println(getResponse.getMessages().getMessage().get(0).getText());
}
}
+ return getResponse;
}
}
diff --git a/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionDetails.java b/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionDetails.java
index 157638ec..a4fb6ca6 100644
--- a/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionDetails.java
+++ b/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionDetails.java
@@ -9,7 +9,7 @@
//author @krgupta
public class GetTransactionDetails {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionId) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -18,12 +18,9 @@ public static void run(String apiLoginId, String transactionKey) {
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- //need valid transacaction Id to run
- String transId = "2238248926";
-
GetTransactionDetailsRequest getRequest = new GetTransactionDetailsRequest();
getRequest.setMerchantAuthentication(merchantAuthenticationType);
- getRequest.setTransId(transId);
+ getRequest.setTransId(transactionId);
GetTransactionDetailsController controller = new GetTransactionDetailsController(getRequest);
controller.execute();
@@ -41,6 +38,7 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to get transaction details: " + getResponse.getMessages().getResultCode());
}
}
+ return getResponse;
}
}
diff --git a/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionList.java b/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionList.java
index 07334ecc..eb26d6e8 100644
--- a/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionList.java
+++ b/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionList.java
@@ -8,7 +8,7 @@
//author @krgupta
public class GetTransactionList{
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
@@ -21,6 +21,18 @@ public static void run(String apiLoginId, String transactionKey) {
GetTransactionListRequest getRequest = new GetTransactionListRequest();
getRequest.setMerchantAuthentication(merchantAuthenticationType);
getRequest.setBatchId(batchId);
+
+ Paging paging = new Paging();
+ paging.setLimit(100);
+ paging.setOffset(1);
+
+ getRequest.setPaging(paging);
+
+ TransactionListSorting sorting = new TransactionListSorting();
+ sorting.setOrderBy(TransactionListOrderFieldEnum.ID);
+ sorting.setOrderDescending(true);
+
+ getRequest.setSorting(sorting);
GetTransactionListController controller = new GetTransactionListController(getRequest);
controller.execute();
@@ -37,6 +49,7 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Failed to get transaction list: " + getResponse.getMessages().getResultCode());
}
}
+ return getResponse;
}
}
diff --git a/src/main/java/net/authorize/sample/TransactionReporting/GetUnsettledTransactionList.java b/src/main/java/net/authorize/sample/TransactionReporting/GetUnsettledTransactionList.java
index a88aa944..72b8b237 100644
--- a/src/main/java/net/authorize/sample/TransactionReporting/GetUnsettledTransactionList.java
+++ b/src/main/java/net/authorize/sample/TransactionReporting/GetUnsettledTransactionList.java
@@ -3,43 +3,51 @@
import net.authorize.Environment;
import net.authorize.api.contract.v1.*;
-
import net.authorize.api.controller.GetSettledBatchListController;
import net.authorize.api.controller.GetUnsettledTransactionListController;
import net.authorize.api.controller.base.ApiOperationBase;
//author @krgupta
public class GetUnsettledTransactionList{
-
- public static void run(String apiLoginId, String transactionKey) {
- ApiOperationBase.setEnvironment(Environment.SANDBOX);
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
+ ApiOperationBase.setEnvironment(Environment.SANDBOX);
- MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
- merchantAuthenticationType.setName(apiLoginId);
- merchantAuthenticationType.setTransactionKey(transactionKey);
- ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
-
+ MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
+ merchantAuthenticationType.setName(apiLoginId);
+ merchantAuthenticationType.setTransactionKey(transactionKey);
+ ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
- GetUnsettledTransactionListRequest getRequest = new GetUnsettledTransactionListRequest();
- getRequest.setMerchantAuthentication(merchantAuthenticationType);
-
-
- GetUnsettledTransactionListController controller = new GetUnsettledTransactionListController(getRequest);
- controller.execute();
- GetUnsettledTransactionListResponse getResponse = controller.getApiResponse();
-
- if (getResponse!=null) {
-
- if (getResponse.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- System.out.println(getResponse.getMessages().getMessage().get(0).getCode());
- System.out.println(getResponse.getMessages().getMessage().get(0).getText());
- }
- else
- {
- System.out.println("Failed to get unsettled transaction list: " + getResponse.getMessages().getResultCode());
- }
- }
-
- }
+ GetUnsettledTransactionListRequest getRequest = new GetUnsettledTransactionListRequest();
+ getRequest.setMerchantAuthentication(merchantAuthenticationType);
+ getRequest.setStatus(TransactionGroupStatusEnum.ANY);
+
+ Paging paging = new Paging();
+ paging.setLimit(100);
+ paging.setOffset(1);
+
+ getRequest.setPaging(paging);
+
+ TransactionListSorting sorting = new TransactionListSorting();
+ sorting.setOrderBy(TransactionListOrderFieldEnum.ID);
+ sorting.setOrderDescending(true);
+
+ getRequest.setSorting(sorting);
+
+ GetUnsettledTransactionListController controller = new GetUnsettledTransactionListController(getRequest);
+ controller.execute();
+ GetUnsettledTransactionListResponse getResponse = controller.getApiResponse();
+
+ if (getResponse!=null) {
+ if (getResponse.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ System.out.println(getResponse.getMessages().getMessage().get(0).getCode());
+ System.out.println(getResponse.getMessages().getMessage().get(0).getText());
+ }
+ else
+ {
+ System.out.println("Failed to get unsettled transaction list: " + getResponse.getMessages().getResultCode());
+ }
+ }
+ return getResponse;
+
+ }
}
diff --git a/src/main/java/net/authorize/sample/VisaCheckout/CreateVisaCheckoutTransaction.java b/src/main/java/net/authorize/sample/VisaCheckout/CreateVisaSrcTransaction.java
similarity index 67%
rename from src/main/java/net/authorize/sample/VisaCheckout/CreateVisaCheckoutTransaction.java
rename to src/main/java/net/authorize/sample/VisaCheckout/CreateVisaSrcTransaction.java
index 138ca2a8..c449e173 100644
--- a/src/main/java/net/authorize/sample/VisaCheckout/CreateVisaCheckoutTransaction.java
+++ b/src/main/java/net/authorize/sample/VisaCheckout/CreateVisaSrcTransaction.java
@@ -4,6 +4,7 @@
import net.authorize.Environment;
import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
import net.authorize.api.contract.v1.CreateTransactionRequest;
import net.authorize.api.contract.v1.CreateTransactionResponse;
import net.authorize.api.contract.v1.MerchantAuthenticationType;
@@ -19,11 +20,11 @@
//
// Run this sample by doing mvn package,
// then
-// java -jar target/VisaCheckoutTransaction-jar-with-dependencies.jar
+// java -jar target/CreateVisaSrcTransaction-jar-with-dependencies.jar
//
-public class CreateVisaCheckoutTransaction {
+public class CreateVisaSrcTransaction {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
//Common code to set for all requests
@@ -56,24 +57,42 @@ public static void run(String apiLoginId, String transactionKey) {
CreateTransactionResponse response = controller.getApiResponse();
- if (response!=null) {
-
- // If API Response is ok, go ahead and check the transaction response
- if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
-
- TransactionResponse result = response.getTransactionResponse();
- if (result.getResponseCode().equals("1")) {
- System.out.println(result.getResponseCode());
- System.out.println("Successful Visa Checkout Transaction");
- System.out.println(result.getAuthCode());
- System.out.println(result.getTransId());
- }
- else
- {
- System.out.println("Failed Transaction"+result.getResponseCode());
- }
- }
- }
+ if (response!=null) {
+ // If API Response is ok, go ahead and check the transaction response
+ if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
+ TransactionResponse result = response.getTransactionResponse();
+ if (result.getMessages() != null) {
+ System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
+ System.out.println("Response Code: " + result.getResponseCode());
+ System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
+ System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
+ System.out.println("Auth Code: " + result.getAuthCode());
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ }
+ }
+ else {
+ System.out.println("Failed Transaction.");
+ if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
+ System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
+ System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
+ }
+ else {
+ System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
+ System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
+ }
+ }
+ }
+ else {
+ System.out.println("Null Response.");
+ }
+
+ return response;
}
}
diff --git a/src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaCheckoutData.java b/src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaSrcData.java
similarity index 95%
rename from src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaCheckoutData.java
rename to src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaSrcData.java
index ae54145a..d470cb78 100644
--- a/src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaCheckoutData.java
+++ b/src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaSrcData.java
@@ -2,6 +2,7 @@
import net.authorize.Environment;
import net.authorize.api.controller.base.ApiOperationBase;
+import net.authorize.api.contract.v1.ANetApiResponse;
import net.authorize.api.contract.v1.DecryptPaymentDataRequest;
import net.authorize.api.contract.v1.DecryptPaymentDataResponse;
import net.authorize.api.contract.v1.MerchantAuthenticationType;
@@ -9,9 +10,9 @@
import net.authorize.api.contract.v1.MessageTypeEnum;
import net.authorize.api.controller.DecryptPaymentDataController;
-public class DecryptVisaCheckoutData {
+public class DecryptVisaSrcData {
- public static void run(String apiLoginId, String transactionKey) {
+ public static ANetApiResponse run(String apiLoginId, String transactionKey) {
//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);
@@ -38,7 +39,7 @@ public static void run(String apiLoginId, String transactionKey) {
DecryptPaymentDataResponse response = controller.getApiResponse();
- if (response != null){
+ if (response != null) {
System.out.println("Response Code : "+ response.getMessages().getResultCode());
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
@@ -52,6 +53,7 @@ public static void run(String apiLoginId, String transactionKey) {
System.out.println("Error : " + response.getMessages().getMessage().get(0).getText());
}
}
+ return response;
}
}
diff --git a/src/test/java/net/authorize/sample/SampleCodeTest/Constants.java b/src/test/java/net/authorize/sample/SampleCodeTest/Constants.java
new file mode 100644
index 00000000..730b8038
--- /dev/null
+++ b/src/test/java/net/authorize/sample/SampleCodeTest/Constants.java
@@ -0,0 +1,9 @@
+package net.authorize.sample.SampleCodeTest;
+
+public final class Constants {
+ public static final String API_LOGIN_ID = "5KP3u95bQpv";
+ public static final String TRANSACTION_KEY = "346HZ32z3fP4hTG2";
+ public static final String TRANSACTION_ID = "123456";
+ public static final String PAYER_ID = "6ZSCSYG33VP8Q";
+ public static final String CONFIG_FILE = "./src/test/java/net/authorize/sample/SampleCodeTest/SampleCodeList.txt";
+}
diff --git a/src/test/java/net/authorize/sample/SampleCodeTest/SampleCodeList.txt b/src/test/java/net/authorize/sample/SampleCodeTest/SampleCodeList.txt
new file mode 100644
index 00000000..83497fc2
--- /dev/null
+++ b/src/test/java/net/authorize/sample/SampleCodeTest/SampleCodeList.txt
@@ -0,0 +1,58 @@
+SampleCode IsDependent RunApi
+RecurringBilling.CreateSubscription 1 1
+RecurringBilling.CreateSubscriptionFromCustomerProfile 1 1
+RecurringBilling.GetListOfSubscriptions 0 1
+RecurringBilling.CancelSubscription 1 1
+RecurringBilling.GetSubscriptionStatus 1 1
+RecurringBilling.GetSubscription 1 1
+RecurringBilling.UpdateSubscription 1 1
+CustomerProfiles.ValidateCustomerPaymentProfile 1 0
+CustomerProfiles.UpdateCustomerShippingAddress 1 1
+CustomerProfiles.UpdateCustomerProfile 1 1
+CustomerProfiles.UpdateCustomerPaymentProfile 1 1
+CustomerProfiles.GetCustomerShippingAddress 1 1
+CustomerProfiles.GetCustomerProfileIds 0 0
+CustomerProfiles.GetCustomerProfile 1 1
+CustomerProfiles.GetAcceptCustomerProfilePage 1 1
+CustomerProfiles.GetCustomerPaymentProfile 1 1
+CustomerProfiles.DeleteCustomerShippingAddress 1 1
+CustomerProfiles.DeleteCustomerProfile 1 1
+CustomerProfiles.DeleteCustomerPaymentProfile 1 1
+CustomerProfiles.CreateCustomerShippingAddress 1 1
+CustomerProfiles.CreateCustomerProfileFromTransaction 1 1
+CustomerProfiles.GetCustomerPaymentProfileList 0 1
+CustomerProfiles.CreateCustomerProfile 1 1
+CustomerProfiles.CreateCustomerPaymentProfile 1 1
+PayPalExpressCheckout.PayPalAuthorizationOnly 1 1
+PayPalExpressCheckout.PayPalVoid 1 0
+PayPalExpressCheckout.PayPalAuthorizationAndCapture 1 1
+PayPalExpressCheckout.PayPalAuthorizationAndCaptureContinued 1 1
+PayPalExpressCheckout.PayPalAuthorizationOnlyContinued 1 0
+PayPalExpressCheckout.PayPalCredit 1 0
+PayPalExpressCheckout.PayPalGetDetails 1 1
+PayPalExpressCheckout.PayPalPriorAuthorizationCapture 1 0
+PaymentTransactions.ChargeCreditCard 1 1
+PaymentTransactions.CapturePreviouslyAuthorizedAmount 1 1
+PaymentTransactions.RefundTransaction 1 0
+PaymentTransactions.VoidTransaction 1 1
+PaymentTransactions.CreditBankAccount 1 0
+PaymentTransactions.ChargeCustomerProfile 1 1
+PaymentTransactions.CaptureFundsAuthorizedThroughAnotherChannel 1 1
+PaymentTransactions.AuthorizeCreditCard 1 1
+PaymentTransactions.DebitBankAccount 1 1
+PaymentTransactions.ChargeTokenizedCreditCard 1 1
+PaymentTransactions.UpdateSplitTenderGroup 0 1
+PaymentTransactions.UpdateHeldTransation 0 0
+PaymentTransactions.GetAnAcceptPaymentPage 1 1
+TransactionReporting.GetTransactionList 0 1
+TransactionReporting.GetTransactionListForCustomer 0 0
+TransactionReporting.GetUnsettledTransactionList 0 1
+TransactionReporting.GetBatchStatistics 0 1
+TransactionReporting.GetSettledBatchList 0 1
+TransactionReporting.GetTransactionDetails 1 1
+TransactionReporting.GetMerchantDetails 0 1
+MobileInAppTransactions.CreateAnApplePayTransaction 0 0
+MobileInAppTransactions.CreateAnAndroidPayTransaction 0 0
+MobileInAppTransactions.CreateAnAcceptTransaction 0 0
+VisaCheckout.DecryptVisaSrcData 0 0
+VisaCheckout.CreateVisaSrcTransaction 0 0
diff --git a/src/test/java/net/authorize/sample/SampleCodeTest/TestRunner.java b/src/test/java/net/authorize/sample/SampleCodeTest/TestRunner.java
new file mode 100644
index 00000000..b6551189
--- /dev/null
+++ b/src/test/java/net/authorize/sample/SampleCodeTest/TestRunner.java
@@ -0,0 +1,534 @@
+package net.authorize.sample.SampleCodeTest;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.SecureRandom;
+import java.text.DecimalFormat;
+
+import org.junit.Test;
+
+import junit.framework.Assert;
+import net.authorize.api.contract.v1.ANetApiResponse;
+import net.authorize.api.contract.v1.ARBCreateSubscriptionResponse;
+import net.authorize.api.contract.v1.ARBGetSubscriptionResponse;
+import net.authorize.api.contract.v1.ARBGetSubscriptionStatusResponse;
+import net.authorize.api.contract.v1.ARBUpdateSubscriptionResponse;
+import net.authorize.api.contract.v1.CreateCustomerPaymentProfileResponse;
+import net.authorize.api.contract.v1.CreateCustomerProfileResponse;
+import net.authorize.api.contract.v1.CreateCustomerShippingAddressResponse;
+import net.authorize.api.contract.v1.CreateTransactionResponse;
+import net.authorize.api.contract.v1.DeleteCustomerPaymentProfileResponse;
+import net.authorize.api.contract.v1.DeleteCustomerShippingAddressResponse;
+import net.authorize.api.contract.v1.GetCustomerPaymentProfileResponse;
+import net.authorize.api.contract.v1.GetCustomerProfileResponse;
+import net.authorize.api.contract.v1.GetCustomerShippingAddressResponse;
+import net.authorize.api.contract.v1.GetHostedProfilePageResponse;
+import net.authorize.api.contract.v1.MessageTypeEnum;
+import net.authorize.api.contract.v1.UpdateCustomerPaymentProfileResponse;
+import net.authorize.api.contract.v1.UpdateCustomerProfileResponse;
+import net.authorize.api.contract.v1.UpdateCustomerShippingAddressResponse;
+import net.authorize.api.contract.v1.ValidateCustomerPaymentProfileResponse;
+import net.authorize.sample.AcceptSuite.GetAcceptCustomerProfilePage;
+import net.authorize.sample.AcceptSuite.GetAnAcceptPaymentPage;
+import net.authorize.sample.CustomerProfiles.CreateCustomerPaymentProfile;
+import net.authorize.sample.CustomerProfiles.CreateCustomerProfile;
+import net.authorize.sample.CustomerProfiles.CreateCustomerProfileFromTransaction;
+import net.authorize.sample.CustomerProfiles.CreateCustomerShippingAddress;
+import net.authorize.sample.CustomerProfiles.DeleteCustomerPaymentProfile;
+import net.authorize.sample.CustomerProfiles.DeleteCustomerProfile;
+import net.authorize.sample.CustomerProfiles.DeleteCustomerShippingAddress;
+import net.authorize.sample.CustomerProfiles.GetCustomerPaymentProfile;
+import net.authorize.sample.CustomerProfiles.GetCustomerProfile;
+import net.authorize.sample.CustomerProfiles.GetCustomerShippingAddress;
+import net.authorize.sample.CustomerProfiles.UpdateCustomerPaymentProfile;
+import net.authorize.sample.CustomerProfiles.UpdateCustomerProfile;
+import net.authorize.sample.CustomerProfiles.UpdateCustomerShippingAddress;
+import net.authorize.sample.CustomerProfiles.ValidateCustomerPaymentProfile;
+import net.authorize.sample.PaymentTransactions.AuthorizeCreditCard;
+import net.authorize.sample.PaymentTransactions.CaptureFundsAuthorizedThroughAnotherChannel;
+import net.authorize.sample.PaymentTransactions.CapturePreviouslyAuthorizedAmount;
+import net.authorize.sample.PaymentTransactions.ChargeCreditCard;
+import net.authorize.sample.PaymentTransactions.ChargeCustomerProfile;
+import net.authorize.sample.PaymentTransactions.ChargeTokenizedCreditCard;
+import net.authorize.sample.PaymentTransactions.CreditBankAccount;
+import net.authorize.sample.PaymentTransactions.DebitBankAccount;
+import net.authorize.sample.PaymentTransactions.RefundTransaction;
+import net.authorize.sample.PaymentTransactions.VoidTransaction;
+import net.authorize.sample.PayPalExpressCheckout.AuthorizationAndCapture;
+import net.authorize.sample.PayPalExpressCheckout.AuthorizationAndCaptureContinued;
+import net.authorize.sample.PayPalExpressCheckout.AuthorizationOnly;
+import net.authorize.sample.PayPalExpressCheckout.AuthorizationOnlyContinued;
+import net.authorize.sample.PayPalExpressCheckout.Credit;
+import net.authorize.sample.PayPalExpressCheckout.GetDetails;
+import net.authorize.sample.PayPalExpressCheckout.PriorAuthorizationCapture;
+import net.authorize.sample.RecurringBilling.CancelSubscription;
+import net.authorize.sample.RecurringBilling.CreateSubscription;
+import net.authorize.sample.RecurringBilling.CreateSubscriptionFromCustomerProfile;
+import net.authorize.sample.RecurringBilling.GetSubscription;
+import net.authorize.sample.RecurringBilling.GetSubscriptionStatus;
+import net.authorize.sample.RecurringBilling.UpdateSubscription;
+import net.authorize.sample.TransactionReporting.GetTransactionDetails;
+
+public class TestRunner {
+
+ String apiLoginId = Constants.API_LOGIN_ID;
+ String transactionKey = Constants.TRANSACTION_KEY;
+ String TransactionID = Constants.TRANSACTION_ID;
+ String payerID = Constants.PAYER_ID;
+
+ static SecureRandom rgenerator = new SecureRandom();
+
+ private static String getEmail()
+ {
+ return rgenerator.nextInt(1000000) + "@test.com";
+ }
+
+ private static Double getAmount()
+ {
+ double d = (double)(1.05 + (450.0 * rgenerator.nextDouble()));
+ DecimalFormat df = new DecimalFormat("#.##");
+ d = Double.valueOf(df.format(d));
+ return d;
+ }
+
+ private static short getDays()
+ {
+ return (short) (rgenerator.nextInt(358) + 7);
+ }
+
+ @Test
+ public void TestAllSampleCodes()
+ {
+ String fileName = Constants.CONFIG_FILE;
+
+ int numRetries = 3;
+
+ BufferedReader reader = null;
+
+ try {
+ reader = new BufferedReader(new FileReader(fileName));
+ } catch (FileNotFoundException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ TestRunner tr = new TestRunner();
+ int cnt = 0;
+ String line;
+ try {
+
+ while ((line = reader.readLine()) != null)
+ {
+ String[] items = line.split("\t");
+
+ String apiName = items[0];
+ String isDependent = items[1];
+ String shouldApiRun = items[2];
+
+ System.out.println(apiName);
+
+ if (!shouldApiRun.equals("1"))
+ continue;
+
+
+ System.out.println("-------------------");
+ System.out.println("Running test case for :: " + apiName);
+ System.out.println("-------------------");
+
+ ANetApiResponse response = null;
+
+ cnt++;
+
+ for (int i = 0;i classType = null;
+ try {
+ classType = Class.forName(fqClassName);
+ } catch (ClassNotFoundException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ Method runMethod = null;
+ try {
+ runMethod = classType.getMethod("run", String.class, String.class);
+ } catch (NoSuchMethodException | SecurityException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ try {
+ return (ANetApiResponse)runMethod.invoke(null, Constants.API_LOGIN_ID, Constants.TRANSACTION_KEY);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public ANetApiResponse TestValidateCustomerPaymentProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse) CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerPaymentProfileResponse customerPaymentProfile = (CreateCustomerPaymentProfileResponse)CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ System.out.println(response.getCustomerProfileId());
+ System.out.println(customerPaymentProfile.getCustomerPaymentProfileId());
+ ValidateCustomerPaymentProfileResponse validateResponse = (ValidateCustomerPaymentProfileResponse) ValidateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId(), customerPaymentProfile.getCustomerPaymentProfileId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return validateResponse;
+ }
+
+
+ public ANetApiResponse TestUpdateCustomerShippingAddress()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerShippingAddressResponse shippingResponse = (CreateCustomerShippingAddressResponse)CreateCustomerShippingAddress.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ UpdateCustomerShippingAddressResponse updateResponse = (UpdateCustomerShippingAddressResponse) UpdateCustomerShippingAddress.run(apiLoginId, transactionKey, response.getCustomerProfileId(), shippingResponse.getCustomerAddressId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return updateResponse;
+ }
+
+ public ANetApiResponse TestUpdateCustomerProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ UpdateCustomerProfileResponse updateResponse = (UpdateCustomerProfileResponse) UpdateCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return updateResponse;
+ }
+
+ public ANetApiResponse TestUpdateCustomerPaymentProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerPaymentProfileResponse paymentProfileResponse = (CreateCustomerPaymentProfileResponse)CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ UpdateCustomerPaymentProfileResponse updateResponse = (UpdateCustomerPaymentProfileResponse) UpdateCustomerPaymentProfile.run(apiLoginId, transactionKey,
+ response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return updateResponse;
+ }
+
+ public ANetApiResponse TestGetCustomerShippingAddress()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerShippingAddressResponse shippingResponse = (CreateCustomerShippingAddressResponse)CreateCustomerShippingAddress.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ GetCustomerShippingAddressResponse getResponse = (GetCustomerShippingAddressResponse) GetCustomerShippingAddress.run(apiLoginId, transactionKey,
+ response.getCustomerProfileId(), shippingResponse.getCustomerAddressId());
+
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ return getResponse;
+ }
+
+ public ANetApiResponse TestGetCustomerProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ GetCustomerProfileResponse profileResponse = (GetCustomerProfileResponse) GetCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return profileResponse;
+ }
+
+ public ANetApiResponse TestGetAcceptCustomerProfilePage()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ GetHostedProfilePageResponse profileResponse = (GetHostedProfilePageResponse) GetAcceptCustomerProfilePage.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return profileResponse;
+ }
+
+ public ANetApiResponse TestGetCustomerPaymentProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerPaymentProfileResponse paymentProfileResponse = (CreateCustomerPaymentProfileResponse)CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ GetCustomerPaymentProfileResponse getResponse = (GetCustomerPaymentProfileResponse) GetCustomerPaymentProfile.run(apiLoginId, transactionKey,
+ response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId());
+
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ return getResponse;
+ }
+
+ public ANetApiResponse TestDeleteCustomerShippingAddress()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerShippingAddressResponse shippingResponse = (CreateCustomerShippingAddressResponse)CreateCustomerShippingAddress.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ DeleteCustomerShippingAddressResponse deleteResponse = (DeleteCustomerShippingAddressResponse) DeleteCustomerShippingAddress.run(apiLoginId, transactionKey,
+ response.getCustomerProfileId(), shippingResponse.getCustomerAddressId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return deleteResponse;
+ }
+
+ public ANetApiResponse TestDeleteCustomerProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ return DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ }
+
+ public ANetApiResponse TestDeleteCustomerPaymentProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerPaymentProfileResponse paymentProfileResponse = (CreateCustomerPaymentProfileResponse)CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ DeleteCustomerPaymentProfileResponse deleteResponse = (DeleteCustomerPaymentProfileResponse) DeleteCustomerPaymentProfile.run(apiLoginId, transactionKey,
+ response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return deleteResponse;
+ }
+
+ public ANetApiResponse TestCreateCustomerShippingAddress()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerShippingAddressResponse shippingResponse = (CreateCustomerShippingAddressResponse)CreateCustomerShippingAddress.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return shippingResponse;
+ }
+
+ public ANetApiResponse TestAuthorizeCreditCard()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizeCreditCard.run(apiLoginId, transactionKey, getAmount());
+ return response;
+ }
+
+ public ANetApiResponse TestDebitBankAccount()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)DebitBankAccount.run(apiLoginId, transactionKey, getAmount());
+ return response;
+ }
+
+ public ANetApiResponse TestChargeTokenizedCreditCard()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)ChargeTokenizedCreditCard.run(apiLoginId, transactionKey, getAmount());
+ return response;
+ }
+
+ public ANetApiResponse TestGetTransactionDetails()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizeCreditCard.run(apiLoginId, transactionKey, getAmount());
+ return GetTransactionDetails.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId());
+ }
+
+ public ANetApiResponse TestChargeCreditCard()
+ {
+ return ChargeCreditCard.run(apiLoginId, transactionKey, getAmount());
+ }
+
+ public ANetApiResponse TestCreateCustomerProfileFromTransaction()
+ {
+ return CreateCustomerProfileFromTransaction.run(apiLoginId, transactionKey, getAmount(), getEmail());
+ }
+
+ public ANetApiResponse TestCapturePreviouslyAuthorizedAmount()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizeCreditCard.run(apiLoginId, transactionKey, getAmount());
+ return CapturePreviouslyAuthorizedAmount.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId());
+ }
+
+ public ANetApiResponse TestRefundTransaction()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizeCreditCard.run(apiLoginId, transactionKey, getAmount());
+ response = (CreateTransactionResponse)CapturePreviouslyAuthorizedAmount.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId());
+ return RefundTransaction.run(apiLoginId, transactionKey, getAmount(), response.getTransactionResponse().getTransId());
+ }
+
+ public ANetApiResponse TestVoidTransaction()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizeCreditCard.run(apiLoginId, transactionKey, getAmount());
+ return VoidTransaction.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId());
+ }
+
+ public ANetApiResponse TestCreditBankAccount()
+ {
+ return CreditBankAccount.run(apiLoginId, transactionKey, TransactionID, getAmount());
+ }
+
+ public ANetApiResponse TestChargeCustomerProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerPaymentProfileResponse paymentProfileResponse = (CreateCustomerPaymentProfileResponse)CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ CreateTransactionResponse chargeResponse = (CreateTransactionResponse) ChargeCustomerProfile.run(apiLoginId, transactionKey,
+ response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), getAmount());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+
+ return chargeResponse;
+ }
+
+ public ANetApiResponse TestPayPalVoid()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount());
+ return net.authorize.sample.PayPalExpressCheckout.Void.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId());
+ }
+
+ public ANetApiResponse TestPayPalAuthorizationAndCapture()
+ {
+ return AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount());
+ }
+
+ public ANetApiResponse TestPayPalAuthorizationAndCaptureContinued()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount());
+ return AuthorizationAndCaptureContinued.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId(), payerID, getAmount());
+ }
+
+ public ANetApiResponse TestPayPalAuthorizationOnly()
+ {
+ return AuthorizationOnly.run(apiLoginId, transactionKey, getAmount());
+ }
+
+ public ANetApiResponse TestPayPalAuthorizationOnlyContinued()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount());
+ return AuthorizationOnlyContinued.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId(), payerID, getAmount());
+ }
+
+ public ANetApiResponse TestPayPalCredit()
+ {
+ return Credit.run(apiLoginId, transactionKey, TransactionID);
+ }
+
+ public ANetApiResponse TestPayPalGetDetails()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount());
+ return GetDetails.run(apiLoginId, transactionKey, response.getTransactionResponse()
+ .getTransId());
+ }
+
+ public ANetApiResponse TestPayPalPriorAuthorizationCapture()
+ {
+ CreateTransactionResponse response = (CreateTransactionResponse)AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount());
+ return PriorAuthorizationCapture.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId());
+ }
+
+ public ANetApiResponse TestCancelSubscription()
+ {
+ ARBCreateSubscriptionResponse response = (ARBCreateSubscriptionResponse)CreateSubscription.run(apiLoginId, transactionKey, getDays(), getAmount());
+ return CancelSubscription.run(apiLoginId, transactionKey, response.getSubscriptionId());
+ }
+
+ public ANetApiResponse TestCreateSubscription()
+ {
+ ARBCreateSubscriptionResponse response = (ARBCreateSubscriptionResponse)CreateSubscription.run(apiLoginId, transactionKey, getDays(), getAmount());
+ CancelSubscription.run(apiLoginId, transactionKey, response.getSubscriptionId());
+
+ return response;
+ }
+
+ public ANetApiResponse TestCreateSubscriptionFromCustomerProfile()
+ {
+ CreateCustomerProfileResponse profileResponse = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ CreateCustomerPaymentProfileResponse paymentResponse = (CreateCustomerPaymentProfileResponse) CreateCustomerPaymentProfile.
+ run(apiLoginId, transactionKey, profileResponse.getCustomerProfileId());
+
+ CreateCustomerShippingAddressResponse shippingResponse = (CreateCustomerShippingAddressResponse)CreateCustomerShippingAddress.
+ run(apiLoginId, transactionKey, profileResponse.getCustomerProfileId());
+
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+
+ ARBCreateSubscriptionResponse response = (ARBCreateSubscriptionResponse) CreateSubscriptionFromCustomerProfile.run(apiLoginId, transactionKey, getDays(), getAmount(), profileResponse.getCustomerProfileId(),
+ paymentResponse.getCustomerPaymentProfileId(), shippingResponse.getCustomerAddressId());
+
+ CancelSubscription.run(apiLoginId, transactionKey, response.getSubscriptionId());
+ DeleteCustomerProfile.run(apiLoginId, transactionKey, profileResponse.getCustomerProfileId());
+
+ return response;
+ }
+
+ public ANetApiResponse TestGetSubscriptionStatus()
+ {
+ ARBCreateSubscriptionResponse response = (ARBCreateSubscriptionResponse)CreateSubscription.run(apiLoginId, transactionKey, getDays(), getAmount());
+ ARBGetSubscriptionStatusResponse subscriptionResponse = (ARBGetSubscriptionStatusResponse) GetSubscriptionStatus.run(apiLoginId, transactionKey, response.getSubscriptionId());
+
+
+ return subscriptionResponse;
+ }
+
+ public ANetApiResponse TestGetSubscription()
+ {
+ ARBCreateSubscriptionResponse response = (ARBCreateSubscriptionResponse)CreateSubscription.run(apiLoginId, transactionKey, getDays(), getAmount());
+ ARBGetSubscriptionResponse getResponse = (ARBGetSubscriptionResponse) GetSubscription.run(apiLoginId, transactionKey, response.getSubscriptionId());
+ CancelSubscription.run(apiLoginId, transactionKey, response.getSubscriptionId());
+ return getResponse;
+ }
+
+ public ANetApiResponse TestUpdateSubscription()
+ {
+ ARBCreateSubscriptionResponse response = (ARBCreateSubscriptionResponse)CreateSubscription.run(apiLoginId, transactionKey, getDays(), getAmount());
+ ARBUpdateSubscriptionResponse updateResponse = (ARBUpdateSubscriptionResponse) UpdateSubscription.run(apiLoginId, transactionKey, response.getSubscriptionId());
+ CancelSubscription.run(apiLoginId, transactionKey, response.getSubscriptionId());
+
+ return updateResponse;
+ }
+
+ public ANetApiResponse TestCreateCustomerProfile()
+ {
+ return CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ }
+
+ public ANetApiResponse TestCaptureFundsAuthorizedThroughAnotherChannel()
+ {
+ return CaptureFundsAuthorizedThroughAnotherChannel.run(apiLoginId, transactionKey, getAmount());
+ }
+
+ public ANetApiResponse TestCreateCustomerPaymentProfile()
+ {
+ CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
+ return CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
+ }
+
+ public ANetApiResponse TestGetAnAcceptPaymentPage()
+ {
+ return GetAnAcceptPaymentPage.run(apiLoginId, transactionKey, getAmount());
+ }
+}