diff --git a/.gitignore b/.gitignore index 68546a7a..f067f9e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +# Compiled class file *.class # Mobile Tools for Java (J2ME) @@ -11,6 +12,9 @@ # 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/ 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 -[![Build Status](https://travis-ci.org/AuthorizeNet/sample-code-java.png?branch=master)] -(https://travis-ci.org/AuthorizeNet/sample-code-java) +# Java Sample Code for the Authorize.Net SDK +[![Travis CI Status](https://travis-ci.org/AuthorizeNet/sample-code-java.svg?branch=master)](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 ca578120..f456c3e3 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ - 1.8.8 + 2.0.5 4.0.0 net.authorize.sample @@ -14,27 +14,39 @@ net.authorize anet-java-sdk - ${sdkVersion} + 3.0.0 junit junit - 4.8.1 + 4.13.1 maven-compiler-plugin + 3.7.0 - 1.7 - 1.7 + 9 + 9 org.apache.maven.plugins maven-shade-plugin 2.4.1 + + false + + + *:* + + **/Log4j2Plugins.dat + + + + package 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 95% rename from src/main/java/net/authorize/sample/CustomerProfiles/GetHostedProfilePage.java rename to src/main/java/net/authorize/sample/AcceptSuite/GetAcceptCustomerProfilePage.java index 5e1b7fd6..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,7 +8,7 @@ import net.authorize.api.controller.GetHostedProfilePageController; import net.authorize.api.controller.base.ApiOperationBase; -public class GetHostedProfilePage { +public class GetAcceptCustomerProfilePage { public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) { @@ -52,4 +52,4 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri } 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 d3169b35..94edc17d 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerPaymentProfile.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerPaymentProfile.java @@ -4,16 +4,8 @@ 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 { @@ -46,7 +38,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri //credit card details CreditCardType creditCard = new CreditCardType(); creditCard.setCardNumber("4111111111111111"); - creditCard.setExpirationDate("2023-12"); + creditCard.setExpirationDate("2035-12"); creditCard.setCardCode("122"); CustomerPaymentProfileType profile = new CustomerPaymentProfileType(); @@ -69,7 +61,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri System.out.println(response.getCustomerPaymentProfileId()); System.out.println(response.getMessages().getMessage().get(0).getCode()); System.out.println(response.getMessages().getMessage().get(0).getText()); - if(response.getValidationDirectResponse() != null) + if (response.getValidationDirectResponse() != null) System.out.println(response.getValidationDirectResponse()); } else diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java index 52aae7b6..8880e1b6 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java @@ -7,57 +7,77 @@ import net.authorize.api.controller.base.ApiOperationBase; public class CreateCustomerProfile { + public static ANetApiResponse run(String apiLoginId, String transactionKey, String eMail) { - public static ANetApiResponse run(String apiLoginId, String transactionKey, String eMail) { - - 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("M_" + eMail); - customerProfileType.setDescription("Profile description here"); + 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()); - 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)); + 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; + 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 97fc3f22..3e3ae284 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfileFromTransaction.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfileFromTransaction.java @@ -32,7 +32,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub CreditCardType creditCard = new CreditCardType(); creditCard.setCardNumber("4111111111111111"); - creditCard.setExpirationDate("0616"); + creditCard.setExpirationDate("0635"); PaymentType paymentType = new PaymentType(); paymentType.setCreditCard(creditCard); @@ -71,7 +71,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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/GetCustomerPaymentProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfile.java index b8627b2e..022f5d38 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfile.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfile.java @@ -53,15 +53,13 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri System.out.println(response.getPaymentProfile().getPayment().getCreditCard().getCardNumber()); System.out.println(response.getPaymentProfile().getPayment().getCreditCard().getExpirationDate()); - if((response.getPaymentProfile().getSubscriptionIds() != null) && (response.getPaymentProfile().getSubscriptionIds().getSubscriptionId() != null) && - (!response.getPaymentProfile().getSubscriptionIds().getSubscriptionId().isEmpty())){ + 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()) + for (String subscriptionid : response.getPaymentProfile().getSubscriptionIds().getSubscriptionId()) System.out.println(subscriptionid); } - } - else - { + } else { System.out.println("Failed to get customer payment profile: " + response.getMessages().getResultCode()); } } diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfileList.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerPaymentProfileList.java index 1633abc8..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 ANetApiResponse 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,56 +32,57 @@ public static ANetApiResponse 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; + + 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 033e3865..0169c33d 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfile.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfile.java @@ -20,7 +20,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType); GetCustomerProfileRequest apiRequest = new GetCustomerProfileRequest(); - apiRequest.setCustomerProfileId(customerProfileId); + apiRequest.setCustomerProfileId("1929820324"); //customerProfileId); GetCustomerProfileController controller = new GetCustomerProfileController(apiRequest); controller.execute(); @@ -30,7 +30,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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,8 +40,8 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri System.out.println(response.getProfile().getEmail()); System.out.println(response.getProfile().getCustomerProfileId()); - if((!response.getProfile().getPaymentProfiles().isEmpty()) && - (response.getProfile().getPaymentProfiles().get(0).getBillTo() != null)){ + 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()); @@ -59,7 +59,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri System.out.println(response.getProfile().getPaymentProfiles().get(0).getPayment().getCreditCard().getExpirationDate()); } - if(!response.getProfile().getShipToList().isEmpty()){ + 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()); @@ -72,16 +72,14 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri System.out.println(response.getProfile().getShipToList().get(0).getFaxNumber()); } - if((response.getSubscriptionIds() != null) && (response.getSubscriptionIds().getSubscriptionId() != null) && - (!response.getSubscriptionIds().getSubscriptionId().isEmpty())){ + if ((response.getSubscriptionIds() != null) && (response.getSubscriptionIds().getSubscriptionId() != null) && + (!response.getSubscriptionIds().getSubscriptionId().isEmpty())) { System.out.println("List of subscriptions:"); - for(String subscriptionid : response.getSubscriptionIds().getSubscriptionId()) + for (String subscriptionid : response.getSubscriptionIds().getSubscriptionId()) System.out.println(subscriptionid); } - } - else - { + } else { System.out.println("Failed to get customer profile: " + response.getMessages().getResultCode()); } } diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfileIds.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfileIds.java index e2666fee..6e25d51c 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfileIds.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerProfileIds.java @@ -34,7 +34,7 @@ public static ANetApiResponse 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)); } diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerShippingAddress.java b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerShippingAddress.java index 8b245436..e5f63005 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerShippingAddress.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/GetCustomerShippingAddress.java @@ -50,15 +50,13 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri System.out.println(response.getAddress().getCustomerAddressId()); - if((response.getSubscriptionIds() != null) && (response.getSubscriptionIds().getSubscriptionId() != null) && - (!response.getSubscriptionIds().getSubscriptionId().isEmpty())){ + if ((response.getSubscriptionIds() != null) && (response.getSubscriptionIds().getSubscriptionId() != null) && + (!response.getSubscriptionIds().getSubscriptionId().isEmpty())) { System.out.println("List of subscriptions:"); - for(String subscriptionid : response.getSubscriptionIds().getSubscriptionId()) + for (String subscriptionid : response.getSubscriptionIds().getSubscriptionId()) System.out.println(subscriptionid); } - } - else - { + } else { System.out.println("Failed to get customer shipping address: " + response.getMessages().getResultCode()); } } diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerPaymentProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerPaymentProfile.java index d4ea1554..de859f97 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerPaymentProfile.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerPaymentProfile.java @@ -30,7 +30,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri //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); diff --git a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerProfile.java b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerProfile.java index e03bbf79..ef888414 100644 --- a/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerProfile.java +++ b/src/main/java/net/authorize/sample/CustomerProfiles/UpdateCustomerProfile.java @@ -16,11 +16,12 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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(customerProfileId); + customer.setProfileType(CustomerProfileTypeEnum.REGULAR); UpdateCustomerProfileRequest apiRequest = new UpdateCustomerProfileRequest(); apiRequest.setProfile(customer); 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 71% rename from src/main/java/net/authorize/sample/ApplePayTransactions/CreateAnApplePayTransaction.java rename to src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnApplePayTransaction.java index d3b797ec..f75feae4 100644 --- a/src/main/java/net/authorize/sample/ApplePayTransactions/CreateAnApplePayTransaction.java +++ b/src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnApplePayTransaction.java @@ -1,8 +1,7 @@ -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; @@ -37,30 +36,38 @@ public static ANetApiResponse 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 similarity index 53% rename from src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCapture.java rename to src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCapture.java index 12176f7e..3705af7f 100644 --- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCapture.java +++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCapture.java @@ -1,4 +1,4 @@ -package net.authorize.sample.PaypalExpressCheckout; +package net.authorize.sample.PayPalExpressCheckout; import java.math.BigDecimal; import java.math.RoundingMode; @@ -54,28 +54,41 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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()); - } + 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 56% rename from src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCaptureContinue.java rename to src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCaptureContinued.java index b0d067ad..6b0844f8 100644 --- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationAndCaptureContinue.java +++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationAndCaptureContinued.java @@ -1,4 +1,4 @@ -package net.authorize.sample.PaypalExpressCheckout; +package net.authorize.sample.PayPalExpressCheckout; import java.math.BigDecimal; import java.math.RoundingMode; @@ -12,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 ANetApiResponse run(String apiLoginId, String transactionKey, String TransactionID, String payerID , Double amount){ + 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); @@ -62,22 +63,38 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri CreateTransactionResponse response = controller.getApiResponse(); //validate - if(response != null){ - if(response.getMessages().getResultCode() == MessageTypeEnum.OK){ - if(response.getTransactionResponse() != null){ - if((response.getTransactionResponse().getMessages() != null) && - (!response.getTransactionResponse().getMessages().getMessage().isEmpty())) { - System.out.println("Success, \nMessage : "+response.getTransactionResponse().getMessages().getMessage().get(0).getDescription() ); - // Get Auth Code By : response.getTransactionResponse().getAuthCode() - } - } - } - 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()); - } - } + 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/AuthorizationOnly.java b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnly.java similarity index 55% rename from src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnly.java rename to src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnly.java index e97841e8..28fb438b 100644 --- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnly.java +++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnly.java @@ -1,4 +1,4 @@ -package net.authorize.sample.PaypalExpressCheckout; +package net.authorize.sample.PayPalExpressCheckout; import java.math.BigDecimal; import java.math.RoundingMode; @@ -13,6 +13,7 @@ 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; @@ -57,17 +58,41 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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()); - } + 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 similarity index 56% rename from src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnlyContinued.java rename to src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnlyContinued.java index 9c9ba464..1d665f42 100644 --- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/AuthorizationOnlyContinued.java +++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/AuthorizationOnlyContinued.java @@ -1,4 +1,4 @@ -package net.authorize.sample.PaypalExpressCheckout; +package net.authorize.sample.PayPalExpressCheckout; import java.math.BigDecimal; import java.math.RoundingMode; @@ -22,7 +22,7 @@ public class AuthorizationOnlyContinued { public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionId, String payerId, Double amount) { - System.out.println("PayPal Authorize Only-Continue Transaction"); + System.out.println("PayPal Authorization Only, Continued Transaction"); //Common code to set for all requests ApiOperationBase.setEnvironment(Environment.SANDBOX); MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ; @@ -57,29 +57,39 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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()); - } + // 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 54% rename from src/main/java/net/authorize/sample/PaypalExpressCheckout/PriorAuthorizationCapture.java rename to src/main/java/net/authorize/sample/PayPalExpressCheckout/PriorAuthorizationCapture.java index 9e86cb22..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 ANetApiResponse 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,16 +55,40 @@ public static ANetApiResponse run(String apiLoginId, String apiTransactionKey, S 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 similarity index 52% rename from src/main/java/net/authorize/sample/PaypalExpressCheckout/Void.java rename to src/main/java/net/authorize/sample/PayPalExpressCheckout/Void.java index f4fdbfad..7a872e60 100644 --- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/Void.java +++ b/src/main/java/net/authorize/sample/PayPalExpressCheckout/Void.java @@ -1,4 +1,4 @@ -package net.authorize.sample.PaypalExpressCheckout; +package net.authorize.sample.PayPalExpressCheckout; import net.authorize.Environment; import net.authorize.api.contract.v1.ANetApiResponse; @@ -50,26 +50,40 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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()); - } + 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 b8ce7371..a3b56f06 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/AuthorizeCreditCard.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/AuthorizeCreditCard.java @@ -4,75 +4,98 @@ 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 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(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; - + + 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 580164fd..f8f049b5 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.java @@ -35,7 +35,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub CreditCardType cc = new CreditCardType(); cc.setCardNumber("4111111111111111"); - cc.setExpirationDate("2020-12"); + cc.setExpirationDate("2035-12"); PaymentType payment = new PaymentType(); payment.setCreditCard(cc); @@ -55,29 +55,41 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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 e923fd39..9cecf8ea 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/CapturePreviouslyAuthorizedAmount.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/CapturePreviouslyAuthorizedAmount.java @@ -36,29 +36,41 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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 31367402..34e91905 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCreditCard.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCreditCard.java @@ -4,84 +4,96 @@ 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.contract.v1.*; 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 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.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; - + + 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 60c20827..0d86c650 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfile.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfile.java @@ -59,27 +59,40 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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 4d9556c5..73909a75 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/ChargeTokenizedCreditCard.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/ChargeTokenizedCreditCard.java @@ -38,7 +38,9 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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); @@ -58,27 +60,40 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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 a253cbcb..06dd7733 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/CreditBankAccount.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/CreditBankAccount.java @@ -39,8 +39,8 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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); @@ -61,27 +61,40 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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 06756f3b..23a57b8f 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/DebitBankAccount.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/DebitBankAccount.java @@ -39,8 +39,8 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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); @@ -60,27 +60,40 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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 49017959..41913cc0 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/RefundTransaction.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/RefundTransaction.java @@ -45,35 +45,37 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub 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 a6bccc94..456d3fdc 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/UpdateSplitTenderGroup.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/UpdateSplitTenderGroup.java @@ -39,7 +39,7 @@ public static ANetApiResponse 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()); } diff --git a/src/main/java/net/authorize/sample/PaymentTransactions/VoidTransaction.java b/src/main/java/net/authorize/sample/PaymentTransactions/VoidTransaction.java index b870f845..781f4152 100644 --- a/src/main/java/net/authorize/sample/PaymentTransactions/VoidTransaction.java +++ b/src/main/java/net/authorize/sample/PaymentTransactions/VoidTransaction.java @@ -36,29 +36,41 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri 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/Credit.java b/src/main/java/net/authorize/sample/PaypalExpressCheckout/Credit.java deleted file mode 100644 index 4b84d8a6..00000000 --- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/Credit.java +++ /dev/null @@ -1,77 +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 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.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()); - - } - } - return response; - - } - - - -} 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 3db99653..00000000 --- a/src/main/java/net/authorize/sample/PaypalExpressCheckout/GetDetails.java +++ /dev/null @@ -1,66 +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 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 && 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()); - 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()); - } - - 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()); - } - return response; - - } - -} diff --git a/src/main/java/net/authorize/sample/RecurringBilling/CancelSubscription.java b/src/main/java/net/authorize/sample/RecurringBilling/CancelSubscription.java index 95746019..5e55f8b0 100644 --- a/src/main/java/net/authorize/sample/RecurringBilling/CancelSubscription.java +++ b/src/main/java/net/authorize/sample/RecurringBilling/CancelSubscription.java @@ -1,13 +1,9 @@ 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 { diff --git a/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscription.java b/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscription.java index 19d58ade..920e9e4d 100644 --- a/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscription.java +++ b/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscription.java @@ -41,9 +41,9 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, shor 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) { @@ -56,7 +56,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, shor PaymentType paymentType = new PaymentType(); CreditCardType creditCard = new CreditCardType(); creditCard.setCardNumber("4111111111111111"); - creditCard.setExpirationDate("1220"); + creditCard.setExpirationDate("1235"); paymentType.setCreditCard(creditCard); ARBSubscriptionType arbSubscriptionType = new ARBSubscriptionType(); diff --git a/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscriptionFromCustomerProfile.java b/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscriptionFromCustomerProfile.java index 023724a5..231b6de6 100644 --- a/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscriptionFromCustomerProfile.java +++ b/src/main/java/net/authorize/sample/RecurringBilling/CreateSubscriptionFromCustomerProfile.java @@ -40,8 +40,8 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, shor try { XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(); startDate.setDay(30); - startDate.setMonth(8); - startDate.setYear(2020); + startDate.setMonth(12); + startDate.setYear(2032); schedule.setStartDate(startDate); //2020-08-30 } catch(Exception e) { } diff --git a/src/main/java/net/authorize/sample/RecurringBilling/GetSubscription.java b/src/main/java/net/authorize/sample/RecurringBilling/GetSubscription.java index 6b1ebc41..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 ANetApiResponse run(String apiLoginId,String transactionKey, String subscriptionId) - { +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(subscriptionId); - // Calling the controller + + // 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,24 +50,22 @@ public static ANetApiResponse run(String apiLoginId,String transactionKey, Strin 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; + + 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 14c89f8b..8492c365 100644 --- a/src/main/java/net/authorize/sample/RecurringBilling/GetSubscriptionStatus.java +++ b/src/main/java/net/authorize/sample/RecurringBilling/GetSubscriptionStatus.java @@ -1,13 +1,9 @@ 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 { diff --git a/src/main/java/net/authorize/sample/RecurringBilling/UpdateSubscription.java b/src/main/java/net/authorize/sample/RecurringBilling/UpdateSubscription.java index 04e0c127..62243ac7 100644 --- a/src/main/java/net/authorize/sample/RecurringBilling/UpdateSubscription.java +++ b/src/main/java/net/authorize/sample/RecurringBilling/UpdateSubscription.java @@ -1,13 +1,9 @@ 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 { @@ -23,7 +19,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri PaymentType paymentType = new PaymentType(); CreditCardType creditCard = new CreditCardType(); creditCard.setCardNumber("4111111111111111"); - creditCard.setExpirationDate("1220"); + creditCard.setExpirationDate("1235"); paymentType.setCreditCard(creditCard); //set profile information diff --git a/src/main/java/net/authorize/sample/SampleCode.java b/src/main/java/net/authorize/sample/SampleCode.java index c9a5a058..70dbfc52 100644 --- a/src/main/java/net/authorize/sample/SampleCode.java +++ b/src/main/java/net/authorize/sample/SampleCode.java @@ -3,303 +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.println(ex.toString()); - } - } + 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(" 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(" 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 = "6ZSCSYG33VP8Q"; - //Update the transactionId with which you want to run the sample code - String transactionId = "123456"; - - String customerProfileId = "36731856"; - String customerPaymentProfileId = "33211899"; - String customerAddressId = "123"; - - String emailId = "test@test.com"; - - String subscriptionId = "2930242"; - - Double amount = 123.45; +// 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, 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 "ChargeCustomerProfile": - ChargeCustomerProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId, amount); - break; - case "CreateSubscription": - CreateSubscription.run(apiLoginId, transactionKey, (short)12, amount); - break; - case "CreateSubscriptionFromCustomerProfile": - CreateSubscriptionFromCustomerProfile.run(apiLoginId, transactionKey, (short)12, amount, "123212", "123213", "123213"); - 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 "GetCustomerShippingAddress": - GetCustomerShippingAddress.run(apiLoginId, transactionKey, customerProfileId, customerAddressId); - break; - case "GetHostedProfilePage": - GetHostedProfilePage.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 "PayPalAuthorizeCaptureContinue": - AuthorizationAndCaptureContinue.run(apiLoginId, transactionKey, transactionId, payerId, amount); - break; - case "PayPalAuthorizeOnlyContinue": - 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; - 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/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/GetTransactionList.java b/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionList.java index 7de38531..eb26d6e8 100644 --- a/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionList.java +++ b/src/main/java/net/authorize/sample/TransactionReporting/GetTransactionList.java @@ -21,6 +21,18 @@ public static ANetApiResponse 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(); diff --git a/src/main/java/net/authorize/sample/TransactionReporting/GetUnsettledTransactionList.java b/src/main/java/net/authorize/sample/TransactionReporting/GetUnsettledTransactionList.java index ea42f806..72b8b237 100644 --- a/src/main/java/net/authorize/sample/TransactionReporting/GetUnsettledTransactionList.java +++ b/src/main/java/net/authorize/sample/TransactionReporting/GetUnsettledTransactionList.java @@ -3,44 +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 ANetApiResponse 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()); - } - } - return getResponse; - - } + 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 70% rename from src/main/java/net/authorize/sample/VisaCheckout/CreateVisaCheckoutTransaction.java rename to src/main/java/net/authorize/sample/VisaCheckout/CreateVisaSrcTransaction.java index c6b40700..c449e173 100644 --- a/src/main/java/net/authorize/sample/VisaCheckout/CreateVisaCheckoutTransaction.java +++ b/src/main/java/net/authorize/sample/VisaCheckout/CreateVisaSrcTransaction.java @@ -20,9 +20,9 @@ // // 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 ANetApiResponse run(String apiLoginId, String transactionKey) { @@ -57,24 +57,41 @@ public static ANetApiResponse 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 98% rename from src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaCheckoutData.java rename to src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaSrcData.java index c9a09763..d470cb78 100644 --- a/src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaCheckoutData.java +++ b/src/main/java/net/authorize/sample/VisaCheckout/DecryptVisaSrcData.java @@ -10,7 +10,7 @@ import net.authorize.api.contract.v1.MessageTypeEnum; import net.authorize.api.controller.DecryptPaymentDataController; -public class DecryptVisaCheckoutData { +public class DecryptVisaSrcData { public static ANetApiResponse run(String apiLoginId, String transactionKey) { @@ -39,7 +39,7 @@ public static ANetApiResponse 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) { diff --git a/src/test/java/net/authorize/sample/SampleCodeTest/Constants.java b/src/test/java/net/authorize/sample/SampleCodeTest/Constants.java index 672c6b1e..730b8038 100644 --- a/src/test/java/net/authorize/sample/SampleCodeTest/Constants.java +++ b/src/test/java/net/authorize/sample/SampleCodeTest/Constants.java @@ -2,7 +2,7 @@ public final class Constants { public static final String API_LOGIN_ID = "5KP3u95bQpv"; - public static final String TRANSACTION_KEY = "4Ktq966gC55GAX7S"; + 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 index 3ff1927c..83497fc2 100644 --- a/src/test/java/net/authorize/sample/SampleCodeTest/SampleCodeList.txt +++ b/src/test/java/net/authorize/sample/SampleCodeTest/SampleCodeList.txt @@ -11,9 +11,9 @@ CustomerProfiles.UpdateCustomerShippingAddress 1 1 CustomerProfiles.UpdateCustomerProfile 1 1 CustomerProfiles.UpdateCustomerPaymentProfile 1 1 CustomerProfiles.GetCustomerShippingAddress 1 1 -CustomerProfiles.GetCustomerProfileIds 0 1 +CustomerProfiles.GetCustomerProfileIds 0 0 CustomerProfiles.GetCustomerProfile 1 1 -CustomerProfiles.GetHostedProfilePage 1 1 +CustomerProfiles.GetAcceptCustomerProfilePage 1 1 CustomerProfiles.GetCustomerPaymentProfile 1 1 CustomerProfiles.DeleteCustomerShippingAddress 1 1 CustomerProfiles.DeleteCustomerProfile 1 1 @@ -23,14 +23,14 @@ 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.PayPalAuthorizationAndCaptureContinue 1 1 -PaypalExpressCheckout.PayPalAuthorizationOnlyContinued 1 0 -PaypalExpressCheckout.PayPalCredit 1 0 -PaypalExpressCheckout.PayPalGetDetails 1 1 -PaypalExpressCheckout.PayPalPriorAuthorizationCapture 1 0 +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 @@ -42,11 +42,17 @@ 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 -ApplePayTransactions.CreateAnApplePayTransaction 0 0 -VisaCheckout.DecryptVisaCheckoutData 0 1 -VisaCheckout.CreateVisaCheckoutTransaction 0 0 \ No newline at end of file +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 index 8c424bcd..b6551189 100644 --- a/src/test/java/net/authorize/sample/SampleCodeTest/TestRunner.java +++ b/src/test/java/net/authorize/sample/SampleCodeTest/TestRunner.java @@ -6,8 +6,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.math.RoundingMode; import java.security.SecureRandom; import java.text.DecimalFormat; @@ -34,6 +32,8 @@ 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; @@ -44,7 +44,6 @@ import net.authorize.sample.CustomerProfiles.GetCustomerPaymentProfile; import net.authorize.sample.CustomerProfiles.GetCustomerProfile; import net.authorize.sample.CustomerProfiles.GetCustomerShippingAddress; -import net.authorize.sample.CustomerProfiles.GetHostedProfilePage; import net.authorize.sample.CustomerProfiles.UpdateCustomerPaymentProfile; import net.authorize.sample.CustomerProfiles.UpdateCustomerProfile; import net.authorize.sample.CustomerProfiles.UpdateCustomerShippingAddress; @@ -59,13 +58,13 @@ 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.AuthorizationAndCaptureContinue; -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.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; @@ -85,7 +84,7 @@ public class TestRunner { private static String getEmail() { - return rgenerator.nextInt(10000) + "@test.com"; + return rgenerator.nextInt(1000000) + "@test.com"; } private static Double getAmount() @@ -106,6 +105,8 @@ public void TestAllSampleCodes() { String fileName = Constants.CONFIG_FILE; + int numRetries = 3; + BufferedReader reader = null; try { @@ -132,36 +133,44 @@ public void TestAllSampleCodes() if (!shouldApiRun.equals("1")) continue; - + + + System.out.println("-------------------"); + System.out.println("Running test case for :: " + apiName); + System.out.println("-------------------"); + ANetApiResponse response = null; + + cnt++; - try + for (int i = 0;i classType = null; try { classType = Class.forName(fqClassName); } catch (ClassNotFoundException e1) { @@ -184,28 +193,19 @@ public ANetApiResponse InvokeRunMethod(String className) Method runMethod = null; try { - runMethod = classType.getMethod("run",String.class, String.class); - } catch (NoSuchMethodException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } catch (SecurityException e1) { + runMethod = classType.getMethod("run", String.class, String.class); + } catch (NoSuchMethodException | SecurityException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } - try { + try { return (ANetApiResponse)runMethod.invoke(null, Constants.API_LOGIN_ID, Constants.TRANSACTION_KEY); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } - return null; + return null; } public ANetApiResponse TestValidateCustomerPaymentProfile() @@ -272,10 +272,10 @@ public ANetApiResponse TestGetCustomerProfile() return profileResponse; } - public ANetApiResponse TestGetHostedProfilePage() + public ANetApiResponse TestGetAcceptCustomerProfilePage() { CreateCustomerProfileResponse response = (CreateCustomerProfileResponse)CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail()); - GetHostedProfilePageResponse profileResponse = (GetHostedProfilePageResponse) GetHostedProfilePage.run(apiLoginId, transactionKey, response.getCustomerProfileId()); + GetHostedProfilePageResponse profileResponse = (GetHostedProfilePageResponse) GetAcceptCustomerProfilePage.run(apiLoginId, transactionKey, response.getCustomerProfileId()); DeleteCustomerProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId()); return profileResponse; @@ -401,7 +401,7 @@ public ANetApiResponse TestChargeCustomerProfile() public ANetApiResponse TestPayPalVoid() { CreateTransactionResponse response = (CreateTransactionResponse)AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount()); - return net.authorize.sample.PaypalExpressCheckout.Void.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId()); + return net.authorize.sample.PayPalExpressCheckout.Void.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId()); } public ANetApiResponse TestPayPalAuthorizationAndCapture() @@ -409,10 +409,10 @@ public ANetApiResponse TestPayPalAuthorizationAndCapture() return AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount()); } - public ANetApiResponse TestPayPalAuthorizationAndCaptureContinue() + public ANetApiResponse TestPayPalAuthorizationAndCaptureContinued() { CreateTransactionResponse response = (CreateTransactionResponse)AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount()); - return AuthorizationAndCaptureContinue.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId(), payerID, getAmount()); + return AuthorizationAndCaptureContinued.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId(), payerID, getAmount()); } public ANetApiResponse TestPayPalAuthorizationOnly() @@ -434,7 +434,8 @@ public ANetApiResponse TestPayPalCredit() public ANetApiResponse TestPayPalGetDetails() { CreateTransactionResponse response = (CreateTransactionResponse)AuthorizationAndCapture.run(apiLoginId, transactionKey, getAmount()); - return GetDetails.run(apiLoginId, transactionKey, response.getTransactionResponse().getTransId()); + return GetDetails.run(apiLoginId, transactionKey, response.getTransactionResponse() + .getTransId()); } public ANetApiResponse TestPayPalPriorAuthorizationCapture() @@ -466,6 +467,15 @@ public ANetApiResponse TestCreateSubscriptionFromCustomerProfile() 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()); @@ -516,4 +526,9 @@ 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()); + } }