Skip to content

Commit d3eea7e

Browse files
authored
Merge pull request AuthorizeNet#76 from gnongsie/master
Adding files to Accept Suite
2 parents 7257173 + b4da3d2 commit d3eea7e

9 files changed

+147
-203
lines changed

src/main/java/net/authorize/sample/AcceptSuite/GetAcceptCustomerProfilePage.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import net.authorize.Environment;
44
import net.authorize.api.contract.v1.*;
5+
6+
import net.authorize.api.contract.v1.MerchantAuthenticationType;
57
import net.authorize.api.controller.base.ApiOperationBase;
68
import net.authorize.api.controller.GetHostedProfilePageController;
9+
import net.authorize.api.controller.base.ApiOperationBase;
710

811
public class GetAcceptCustomerProfilePage {
912

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

3033
GetHostedProfilePageController controller = new GetHostedProfilePageController(apiRequest);
3134
controller.execute();
32-
33-
ANetApiResponse apiResponse = controller.getApiResponse();
34-
if (apiResponse != null) {
35-
if (apiResponse instanceof GetHostedProfilePageResponse) {
36-
GetHostedProfilePageResponse response = (GetHostedProfilePageResponse) apiResponse;
37-
38-
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
39-
System.out.println(response.getToken());
40-
System.out.println(response.getMessages().getMessage().get(0).getCode());
41-
System.out.println(response.getMessages().getMessage().get(0).getText());
42-
}
43-
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
44-
System.out.println(response.getMessages().getMessage().get(0).getCode());
45-
System.out.println(response.getMessages().getMessage().get(0).getText());
46-
}
35+
36+
GetHostedProfilePageResponse response = new GetHostedProfilePageResponse();
37+
response = controller.getApiResponse();
38+
39+
if (response!=null) {
40+
41+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
42+
43+
System.out.println(response.getMessages().getMessage().get(0).getCode());
44+
System.out.println(response.getMessages().getMessage().get(0).getText());
45+
46+
System.out.println(response.getToken());
4747
}
48-
else if (apiResponse instanceof ErrorResponse) {
49-
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
50-
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
51-
System.out.println("Failed to get hosted profile page: " + apiResponse.getMessages().getResultCode());
48+
else
49+
{
50+
System.out.println("Failed to get hosted profile page: " + response.getMessages().getResultCode());
5251
}
5352
}
54-
55-
return apiResponse;
53+
return response;
5654
}
5755
}

src/main/java/net/authorize/sample/PaymentTransactions/GetAnAcceptPaymentPage.java renamed to src/main/java/net/authorize/sample/AcceptSuite/GetAnAcceptPaymentPage.java

File renamed without changes.

src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerPaymentProfile.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
import net.authorize.api.contract.v1.MerchantAuthenticationType;
77
import net.authorize.api.controller.base.ApiOperationBase;
88

9+
import net.authorize.Transaction;
10+
import net.authorize.api.controller.CreateCustomerProfileController;
11+
import net.authorize.api.controller.CreateCustomerProfileFromTransactionController;
912
import net.authorize.api.controller.CreateCustomerPaymentProfileController;
13+
import net.authorize.api.controller.base.ApiOperationBase;
14+
import net.authorize.cim.Result;
15+
import net.authorize.cim.TransactionType;
16+
import net.authorize.cim.ValidationModeType;
1017

1118
//author @krgupta
1219
public class CreateCustomerPaymentProfile {
@@ -54,30 +61,23 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri
5461
CreateCustomerPaymentProfileController controller = new CreateCustomerPaymentProfileController(apiRequest);
5562
controller.execute();
5663

57-
ANetApiResponse apiResponse = controller.getApiResponse();
58-
if (apiResponse != null) {
59-
if (apiResponse instanceof CreateCustomerPaymentProfileResponse) {
60-
CreateCustomerPaymentProfileResponse response = (CreateCustomerPaymentProfileResponse) apiResponse;
61-
62-
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
63-
System.out.println(response.getCustomerPaymentProfileId());
64-
System.out.println(response.getMessages().getMessage().get(0).getCode());
65-
System.out.println(response.getMessages().getMessage().get(0).getText());
66-
if (response.getValidationDirectResponse() != null)
67-
System.out.println(response.getValidationDirectResponse());
68-
}
69-
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
70-
System.out.println(response.getMessages().getMessage().get(0).getCode());
71-
System.out.println(response.getMessages().getMessage().get(0).getText());
72-
}
64+
CreateCustomerPaymentProfileResponse response = new CreateCustomerPaymentProfileResponse();
65+
response = controller.getApiResponse();
66+
if (response!=null) {
67+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
68+
69+
System.out.println(response.getCustomerPaymentProfileId());
70+
System.out.println(response.getMessages().getMessage().get(0).getCode());
71+
System.out.println(response.getMessages().getMessage().get(0).getText());
72+
if (response.getValidationDirectResponse() != null)
73+
System.out.println(response.getValidationDirectResponse());
7374
}
74-
else if (apiResponse instanceof ErrorResponse) {
75-
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
76-
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
77-
System.out.println("Failed to create customer payment profile: " + apiResponse.getMessages().getResultCode());
75+
else
76+
{
77+
System.out.println("Failed to create customer payment profile: " + response.getMessages().getResultCode());
7878
}
7979
}
8080

81-
return apiResponse;
81+
return response;
8282
}
8383
}

src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfile.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.authorize.Environment;
44
import net.authorize.api.contract.v1.*;
5+
import java.math.BigDecimal;
56
import net.authorize.api.controller.CreateCustomerProfileController;
67
import net.authorize.api.controller.base.ApiOperationBase;
78

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

4849
// Get the response
49-
ANetApiResponse apiResponse = controller.getApiResponse();
50+
CreateCustomerProfileResponse response = new CreateCustomerProfileResponse();
51+
response = controller.getApiResponse();
5052

5153
// Parse the response to determine results
52-
if (apiResponse != null) {
53-
if (apiResponse instanceof CreateCustomerProfileResponse) {
54+
if (response!=null) {
5455
// If API Response is OK, go ahead and check the transaction response
55-
CreateCustomerProfileResponse response = (CreateCustomerProfileResponse) apiResponse;
56-
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
57-
System.out.println(response.getCustomerProfileId());
58-
if (!response.getCustomerPaymentProfileIdList().getNumericString().isEmpty()) {
59-
System.out.println(response.getCustomerPaymentProfileIdList().getNumericString().get(0));
60-
}
61-
if (!response.getCustomerShippingAddressIdList().getNumericString().isEmpty()) {
62-
System.out.println(response.getCustomerShippingAddressIdList().getNumericString().get(0));
63-
}
64-
if (!response.getValidationDirectResponseList().getString().isEmpty()) {
65-
System.out.println(response.getValidationDirectResponseList().getString().get(0));
66-
}
67-
}
68-
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
69-
System.out.println(response.getMessages().getMessage().get(0).getCode());
70-
System.out.println(response.getMessages().getMessage().get(0).getText());
71-
}
72-
}
73-
else if (apiResponse instanceof ErrorResponse) {
74-
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
75-
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
76-
System.out.println("Failed to create customer profile: " + apiResponse.getMessages().getResultCode());
56+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
57+
System.out.println(response.getCustomerProfileId());
58+
if (!response.getCustomerPaymentProfileIdList().getNumericString().isEmpty()) {
59+
System.out.println(response.getCustomerPaymentProfileIdList().getNumericString().get(0));
60+
}
61+
if (!response.getCustomerShippingAddressIdList().getNumericString().isEmpty()) {
62+
System.out.println(response.getCustomerShippingAddressIdList().getNumericString().get(0));
63+
}
64+
if (!response.getValidationDirectResponseList().getString().isEmpty()) {
65+
System.out.println(response.getValidationDirectResponseList().getString().get(0));
66+
}
7767
}
78-
}
79-
return apiResponse;
68+
else
69+
{
70+
System.out.println("Failed to create customer profile: " + response.getMessages().getResultCode());
71+
}
72+
} else {
73+
// Display the error code and message when response is null
74+
ANetApiResponse errorResponse = controller.getErrorResponse();
75+
System.out.println("Failed to get response");
76+
if (!errorResponse.getMessages().getMessage().isEmpty()) {
77+
System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
78+
}
79+
}
80+
return response;
8081

8182
}
8283
}

src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerProfileFromTransaction.java

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import net.authorize.api.contract.v1.CreditCardType;
1313
import net.authorize.api.contract.v1.CustomerDataType;
1414
import net.authorize.api.contract.v1.CustomerProfileBaseType;
15-
import net.authorize.api.contract.v1.ErrorResponse;
1615
import net.authorize.api.contract.v1.MerchantAuthenticationType;
17-
import net.authorize.api.contract.v1.MessageTypeEnum;
1816
import net.authorize.api.contract.v1.PaymentType;
1917
import net.authorize.api.contract.v1.TransactionRequestType;
2018
import net.authorize.api.controller.CreateCustomerProfileFromTransactionController;
@@ -48,72 +46,34 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub
4846
customer.setEmail(email);
4947
requestInternal.setCustomer(customer);
5048

51-
CreateTransactionRequest transactionRequest = new CreateTransactionRequest();
52-
transactionRequest.setTransactionRequest(requestInternal);
49+
CreateTransactionRequest request = new CreateTransactionRequest();
50+
request.setTransactionRequest(requestInternal);
5351

54-
CreateTransactionController controller = new CreateTransactionController(transactionRequest);
52+
CreateTransactionController controller = new CreateTransactionController(request);
5553
controller.execute();
5654

57-
ANetApiResponse apiResponseForTransaction = controller.getApiResponse();
58-
59-
if (apiResponseForTransaction != null) {
60-
if (!(apiResponseForTransaction instanceof CreateTransactionResponse) && !(apiResponseForTransaction instanceof ErrorResponse)) {
61-
System.out.println(apiResponseForTransaction.getMessages().getMessage().get(0).getCode());
62-
System.out.println(apiResponseForTransaction.getMessages().getMessage().get(0).getText());
63-
System.out.println("Failed to create transaction: " + apiResponseForTransaction.getMessages().getResultCode());
64-
65-
return apiResponseForTransaction;
66-
}
67-
}
68-
69-
CreateTransactionResponse transactionResponse = (CreateTransactionResponse) apiResponseForTransaction;
55+
CreateTransactionResponse response = controller.getApiResponse();
7056

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

76-
CreateCustomerProfileFromTransactionRequest request = new CreateCustomerProfileFromTransactionRequest();
77-
request.setTransId(transactionResponse.getTransactionResponse().getTransId());
62+
CreateCustomerProfileFromTransactionRequest transaction_request = new CreateCustomerProfileFromTransactionRequest();
63+
transaction_request.setTransId(response.getTransactionResponse().getTransId());
7864
// You can either specify the customer information in form of customerProfileBaseType object
79-
request.setCustomer(customerProfile);
65+
transaction_request.setCustomer(customerProfile);
8066
// OR
8167
// You can just provide the customer Profile ID
8268
// transaction_request.setCustomerProfileId("1232132");
8369

84-
CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(request);
70+
CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(transaction_request);
8571
createProfileController.execute();
86-
ANetApiResponse apiResponse = createProfileController.getApiResponse();
72+
CreateCustomerProfileResponse customer_response = createProfileController.getApiResponse();
8773

88-
if (apiResponse != null) {
89-
if (apiResponse instanceof CreateCustomerProfileResponse) {
90-
CreateCustomerProfileResponse response = (CreateCustomerProfileResponse) apiResponse;
91-
92-
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
93-
System.out.println("Transaction ID : " + transactionResponse.getTransactionResponse().getTransId());
94-
System.out.println("Customer Profile Created : " + response.getCustomerProfileId());
95-
if (!response.getCustomerPaymentProfileIdList().getNumericString().isEmpty()) {
96-
System.out.println(response.getCustomerPaymentProfileIdList().getNumericString().get(0));
97-
}
98-
if (!response.getCustomerShippingAddressIdList().getNumericString().isEmpty()) {
99-
System.out.println(response.getCustomerShippingAddressIdList().getNumericString().get(0));
100-
}
101-
if (!response.getValidationDirectResponseList().getString().isEmpty()) {
102-
System.out.println(response.getValidationDirectResponseList().getString().get(0));
103-
}
104-
}
105-
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
106-
System.out.println(response.getMessages().getMessage().get(0).getCode());
107-
System.out.println(response.getMessages().getMessage().get(0).getText());
108-
}
109-
}
110-
else if (apiResponse instanceof ErrorResponse) {
111-
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
112-
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
113-
System.out.println("Failed to create customer payment profile: " + apiResponse.getMessages().getResultCode());
114-
}
115-
}
116-
117-
return apiResponse;
74+
if (customer_response != null) {
75+
System.out.println(transaction_request.getTransId());
76+
}
77+
return customer_response;
11878
}
11979
}

src/main/java/net/authorize/sample/CustomerProfiles/CreateCustomerShippingAddress.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.authorize.Environment;
44
import net.authorize.api.contract.v1.*;
5+
import java.math.BigDecimal;
56
import net.authorize.api.controller.CreateCustomerShippingAddressController;
67
import net.authorize.api.controller.base.ApiOperationBase;
78

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

36-
ANetApiResponse apiResponse = controller.getApiResponse();
37-
if (apiResponse != null) {
38-
if (apiResponse instanceof CreateCustomerShippingAddressResponse) {
39-
CreateCustomerShippingAddressResponse response = (CreateCustomerShippingAddressResponse) apiResponse;
40-
41-
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
42-
System.out.println(response.getCustomerAddressId());
43-
System.out.println(response.getMessages().getMessage().get(0).getCode());
44-
System.out.println(response.getMessages().getMessage().get(0).getText());
45-
}
46-
else if (response.getMessages().getResultCode() == MessageTypeEnum.ERROR) {
47-
System.out.println(response.getMessages().getMessage().get(0).getCode());
48-
System.out.println(response.getMessages().getMessage().get(0).getText());
49-
}
50-
}
51-
else if (apiResponse instanceof ErrorResponse) {
52-
System.out.println(apiResponse.getMessages().getMessage().get(0).getCode());
53-
System.out.println(apiResponse.getMessages().getMessage().get(0).getText());
54-
System.out.println("Failed to create customer shipping address: " + apiResponse.getMessages().getResultCode());
37+
CreateCustomerShippingAddressResponse response = controller.getApiResponse();
38+
if (response!=null) {
39+
40+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
41+
42+
System.out.println(response.getCustomerAddressId());
43+
System.out.println(response.getMessages().getMessage().get(0).getCode());
44+
System.out.println(response.getMessages().getMessage().get(0).getText());
45+
}
46+
else
47+
{
48+
System.out.println("Failed to create customer shipping address: " + response.getMessages().getResultCode());
5549
}
5650
}
57-
return apiResponse;
51+
return response;
5852

5953
}
6054
}

0 commit comments

Comments
 (0)