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