Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import net.authorize.Environment;
import net.authorize.api.contract.v1.*;

import net.authorize.api.contract.v1.MerchantAuthenticationType;
import net.authorize.api.controller.base.ApiOperationBase;
import net.authorize.api.controller.GetHostedProfilePageController;
import net.authorize.api.controller.base.ApiOperationBase;

public class GetAcceptCustomerProfilePage {

Expand All @@ -29,29 +32,24 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri

GetHostedProfilePageController controller = new GetHostedProfilePageController(apiRequest);
controller.execute();

ANetApiResponse apiResponse = controller.getApiResponse();
if (apiResponse != null) {
if (apiResponse instanceof GetHostedProfilePageResponse) {
GetHostedProfilePageResponse response = (GetHostedProfilePageResponse) apiResponse;

if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getToken());
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}

GetHostedProfilePageResponse response = new GetHostedProfilePageResponse();
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 if (apiResponse instanceof ErrorResponse) {
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
System.out.println("Failed to get hosted profile page: " + apiResponse.getMessages().getResultCode());
else
{
System.out.println("Failed to get hosted profile page: " + response.getMessages().getResultCode());
}
}

return apiResponse;
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
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 {
Expand Down Expand Up @@ -54,30 +61,23 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri
CreateCustomerPaymentProfileController controller = new CreateCustomerPaymentProfileController(apiRequest);
controller.execute();

ANetApiResponse apiResponse = controller.getApiResponse();
if (apiResponse != null) {
if (apiResponse instanceof CreateCustomerPaymentProfileResponse) {
CreateCustomerPaymentProfileResponse response = (CreateCustomerPaymentProfileResponse) apiResponse;

if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getCustomerPaymentProfileId());
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
if (response.getValidationDirectResponse() != null)
System.out.println(response.getValidationDirectResponse());
}
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
CreateCustomerPaymentProfileResponse response = new CreateCustomerPaymentProfileResponse();
response = controller.getApiResponse();
if (response!=null) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {

System.out.println(response.getCustomerPaymentProfileId());
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
if (response.getValidationDirectResponse() != null)
System.out.println(response.getValidationDirectResponse());
}
else if (apiResponse instanceof ErrorResponse) {
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
System.out.println("Failed to create customer payment profile: " + apiResponse.getMessages().getResultCode());
else
{
System.out.println("Failed to create customer payment profile: " + response.getMessages().getResultCode());
}
}

return apiResponse;
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.authorize.Environment;
import net.authorize.api.contract.v1.*;
import java.math.BigDecimal;
import net.authorize.api.controller.CreateCustomerProfileController;
import net.authorize.api.controller.base.ApiOperationBase;

Expand Down Expand Up @@ -46,37 +47,37 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri
controller.execute();

// Get the response
ANetApiResponse apiResponse = controller.getApiResponse();
CreateCustomerProfileResponse response = new CreateCustomerProfileResponse();
response = controller.getApiResponse();

// Parse the response to determine results
if (apiResponse != null) {
if (apiResponse instanceof CreateCustomerProfileResponse) {
if (response!=null) {
// If API Response is OK, go ahead and check the transaction response
CreateCustomerProfileResponse response = (CreateCustomerProfileResponse) apiResponse;
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));
}
}
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
}
else if (apiResponse instanceof ErrorResponse) {
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
System.out.println("Failed to create customer profile: " + apiResponse.getMessages().getResultCode());
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));
}
}
}
return apiResponse;
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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import net.authorize.api.contract.v1.CreditCardType;
import net.authorize.api.contract.v1.CustomerDataType;
import net.authorize.api.contract.v1.CustomerProfileBaseType;
import net.authorize.api.contract.v1.ErrorResponse;
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.controller.CreateCustomerProfileFromTransactionController;
Expand Down Expand Up @@ -48,72 +46,34 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub
customer.setEmail(email);
requestInternal.setCustomer(customer);

CreateTransactionRequest transactionRequest = new CreateTransactionRequest();
transactionRequest.setTransactionRequest(requestInternal);
CreateTransactionRequest request = new CreateTransactionRequest();
request.setTransactionRequest(requestInternal);

CreateTransactionController controller = new CreateTransactionController(transactionRequest);
CreateTransactionController controller = new CreateTransactionController(request);
controller.execute();

ANetApiResponse apiResponseForTransaction = controller.getApiResponse();

if (apiResponseForTransaction != null) {
if (!(apiResponseForTransaction instanceof CreateTransactionResponse) && !(apiResponseForTransaction instanceof ErrorResponse)) {
System.out.println(apiResponseForTransaction.getMessages().getMessage().get(0).getCode());
System.out.println(apiResponseForTransaction.getMessages().getMessage().get(0).getText());
System.out.println("Failed to create transaction: " + apiResponseForTransaction.getMessages().getResultCode());

return apiResponseForTransaction;
}
}

CreateTransactionResponse transactionResponse = (CreateTransactionResponse) apiResponseForTransaction;
CreateTransactionResponse response = controller.getApiResponse();

CustomerProfileBaseType customerProfile = new CustomerProfileBaseType();
customerProfile.setMerchantCustomerId("123213");
customerProfile.setEmail("johnsnow@castleblack.com");
customerProfile.setDescription("This is a sample customer profile");

CreateCustomerProfileFromTransactionRequest request = new CreateCustomerProfileFromTransactionRequest();
request.setTransId(transactionResponse.getTransactionResponse().getTransId());
CreateCustomerProfileFromTransactionRequest transaction_request = new CreateCustomerProfileFromTransactionRequest();
transaction_request.setTransId(response.getTransactionResponse().getTransId());
// You can either specify the customer information in form of customerProfileBaseType object
request.setCustomer(customerProfile);
transaction_request.setCustomer(customerProfile);
// OR
// You can just provide the customer Profile ID
// transaction_request.setCustomerProfileId("1232132");

CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(request);
CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(transaction_request);
createProfileController.execute();
ANetApiResponse apiResponse = createProfileController.getApiResponse();
CreateCustomerProfileResponse customer_response = createProfileController.getApiResponse();

if (apiResponse != null) {
if (apiResponse instanceof CreateCustomerProfileResponse) {
CreateCustomerProfileResponse response = (CreateCustomerProfileResponse) apiResponse;

if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println("Transaction ID : " + transactionResponse.getTransactionResponse().getTransId());
System.out.println("Customer Profile Created : " + 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));
}
}
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
}
else if (apiResponse instanceof ErrorResponse) {
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
System.out.println("Failed to create customer payment profile: " + apiResponse.getMessages().getResultCode());
}
}

return apiResponse;
if (customer_response != null) {
System.out.println(transaction_request.getTransId());
}
return customer_response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.authorize.Environment;
import net.authorize.api.contract.v1.*;
import java.math.BigDecimal;
import net.authorize.api.controller.CreateCustomerShippingAddressController;
import net.authorize.api.controller.base.ApiOperationBase;

Expand Down Expand Up @@ -33,28 +34,21 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri
CreateCustomerShippingAddressController controller = new CreateCustomerShippingAddressController(apiRequest);
controller.execute();

ANetApiResponse apiResponse = controller.getApiResponse();
if (apiResponse != null) {
if (apiResponse instanceof CreateCustomerShippingAddressResponse) {
CreateCustomerShippingAddressResponse response = (CreateCustomerShippingAddressResponse) apiResponse;

if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getCustomerAddressId());
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
}
else if (apiResponse instanceof ErrorResponse) {
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
System.out.println("Failed to create customer shipping address: " + apiResponse.getMessages().getResultCode());
CreateCustomerShippingAddressResponse response = controller.getApiResponse();
if (response!=null) {

if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {

System.out.println(response.getCustomerAddressId());
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
}
else
{
System.out.println("Failed to create customer shipping address: " + response.getMessages().getResultCode());
}
}
return apiResponse;
return response;

}
}
Loading