|
12 | 12 | import net.authorize.api.contract.v1.CreditCardType; |
13 | 13 | import net.authorize.api.contract.v1.CustomerDataType; |
14 | 14 | import net.authorize.api.contract.v1.CustomerProfileBaseType; |
15 | | -import net.authorize.api.contract.v1.ErrorResponse; |
16 | 15 | import net.authorize.api.contract.v1.MerchantAuthenticationType; |
17 | | -import net.authorize.api.contract.v1.MessageTypeEnum; |
18 | 16 | import net.authorize.api.contract.v1.PaymentType; |
19 | 17 | import net.authorize.api.contract.v1.TransactionRequestType; |
20 | 18 | import net.authorize.api.controller.CreateCustomerProfileFromTransactionController; |
@@ -48,72 +46,34 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Doub |
48 | 46 | customer.setEmail(email); |
49 | 47 | requestInternal.setCustomer(customer); |
50 | 48 |
|
51 | | - CreateTransactionRequest transactionRequest = new CreateTransactionRequest(); |
52 | | - transactionRequest.setTransactionRequest(requestInternal); |
| 49 | + CreateTransactionRequest request = new CreateTransactionRequest(); |
| 50 | + request.setTransactionRequest(requestInternal); |
53 | 51 |
|
54 | | - CreateTransactionController controller = new CreateTransactionController(transactionRequest); |
| 52 | + CreateTransactionController controller = new CreateTransactionController(request); |
55 | 53 | controller.execute(); |
56 | 54 |
|
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(); |
70 | 56 |
|
71 | 57 | CustomerProfileBaseType customerProfile = new CustomerProfileBaseType(); |
72 | 58 | customerProfile.setMerchantCustomerId("123213"); |
73 | 59 | customerProfile.setEmail("johnsnow@castleblack.com"); |
74 | 60 | customerProfile.setDescription("This is a sample customer profile"); |
75 | 61 |
|
76 | | - CreateCustomerProfileFromTransactionRequest request = new CreateCustomerProfileFromTransactionRequest(); |
77 | | - request.setTransId(transactionResponse.getTransactionResponse().getTransId()); |
| 62 | + CreateCustomerProfileFromTransactionRequest transaction_request = new CreateCustomerProfileFromTransactionRequest(); |
| 63 | + transaction_request.setTransId(response.getTransactionResponse().getTransId()); |
78 | 64 | // You can either specify the customer information in form of customerProfileBaseType object |
79 | | - request.setCustomer(customerProfile); |
| 65 | + transaction_request.setCustomer(customerProfile); |
80 | 66 | // OR |
81 | 67 | // You can just provide the customer Profile ID |
82 | 68 | // transaction_request.setCustomerProfileId("1232132"); |
83 | 69 |
|
84 | | - CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(request); |
| 70 | + CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(transaction_request); |
85 | 71 | createProfileController.execute(); |
86 | | - ANetApiResponse apiResponse = createProfileController.getApiResponse(); |
| 72 | + CreateCustomerProfileResponse customer_response = createProfileController.getApiResponse(); |
87 | 73 |
|
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; |
118 | 78 | } |
119 | 79 | } |
0 commit comments