|
| 1 | +package net.authorize.sample.TransactionReporting; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import net.authorize.Environment; |
| 5 | +import net.authorize.api.contract.v1.ANetApiResponse; |
| 6 | +import net.authorize.api.contract.v1.AUJobTypeEnum; |
| 7 | +import net.authorize.api.contract.v1.AuDeleteType; |
| 8 | +import net.authorize.api.contract.v1.AuDetailsType; |
| 9 | +import net.authorize.api.contract.v1.AuUpdateType; |
| 10 | +import net.authorize.api.contract.v1.CreditCardMaskedType; |
| 11 | +import net.authorize.api.contract.v1.GetAUJobDetailsRequest; |
| 12 | +import net.authorize.api.contract.v1.GetAUJobDetailsResponse; |
| 13 | +import net.authorize.api.contract.v1.MerchantAuthenticationType; |
| 14 | +import net.authorize.api.contract.v1.MessageTypeEnum; |
| 15 | +import net.authorize.api.contract.v1.Paging; |
| 16 | +import net.authorize.api.controller.GetAUJobDetailsController; |
| 17 | +import net.authorize.api.controller.base.ApiOperationBase; |
| 18 | + |
| 19 | +public class GetAccountUpdaterJobDetails { |
| 20 | + |
| 21 | + public static ANetApiResponse run(String apiLoginId, String transactionKey) { |
| 22 | + |
| 23 | + // Set the request to operate in either the sandbox or production environment |
| 24 | + ApiOperationBase.setEnvironment(Environment.SANDBOX); |
| 25 | + |
| 26 | + // Create object with merchant authentication details |
| 27 | + MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType(); |
| 28 | + merchantAuthenticationType.setName(apiLoginId); |
| 29 | + merchantAuthenticationType.setTransactionKey(transactionKey); |
| 30 | + |
| 31 | + String month = "2018-08"; |
| 32 | + String reFid = "123456"; |
| 33 | + Paging paging = new Paging(); |
| 34 | + paging.setLimit(100); |
| 35 | + paging.setOffset(2); |
| 36 | + |
| 37 | + // Create the API request and set the parameters for this specific request |
| 38 | + GetAUJobDetailsRequest apiRequest = new GetAUJobDetailsRequest(); |
| 39 | + apiRequest.setMerchantAuthentication(merchantAuthenticationType); |
| 40 | + apiRequest.setPaging(paging); |
| 41 | + apiRequest.setRefId(reFid); |
| 42 | + apiRequest.setMonth(month); |
| 43 | + apiRequest.setModifiedTypeFilter(AUJobTypeEnum.ALL); |
| 44 | + |
| 45 | + // Call the controller |
| 46 | + GetAUJobDetailsController controller = new GetAUJobDetailsController(apiRequest); |
| 47 | + controller.execute(); |
| 48 | + |
| 49 | + GetAUJobDetailsResponse response = new GetAUJobDetailsResponse(); |
| 50 | + response = controller.getApiResponse(); |
| 51 | + |
| 52 | + // If API Response is OK, go ahead and check the transaction response |
| 53 | + if (response != null && response.getMessages().getResultCode() == MessageTypeEnum.OK) { |
| 54 | + |
| 55 | + System.out.println("SUCCESS: Get Account Updater job details for Month: " + month); |
| 56 | + |
| 57 | + if (response.getAuDetails() == null) { |
| 58 | + System.out.println("No GetAccountUpdaterjobdetails for Month."); |
| 59 | + return response; |
| 60 | + } |
| 61 | + |
| 62 | + ArrayList<AuUpdateType> updateTypeList = new ArrayList<AuUpdateType>(); |
| 63 | + ArrayList<AuDeleteType> deleteTypeList = new ArrayList<AuDeleteType>(); |
| 64 | + |
| 65 | + for (AuDetailsType details : response.getAuDetails().getAuUpdateOrAuDelete()) { |
| 66 | + |
| 67 | + System.out.println("---Customer Profile Details Start---"); |
| 68 | + System.out.println("Profile ID:" + details.getCustomerProfileID()); |
| 69 | + System.out.println("Payment Profile ID:" + details.getCustomerPaymentProfileID()); |
| 70 | + System.out.println("First Name:" + details.getFirstName()); |
| 71 | + System.out.println("Last Name:" + details.getLastName()); |
| 72 | + System.out.println("Update Time UTC:" + details.getUpdateTimeUTC()); |
| 73 | + System.out.println("Reason Code:" + details.getAuReasonCode()); |
| 74 | + System.out.println("Reason Description:" + details.getReasonDescription()); |
| 75 | + |
| 76 | + if (details.getClass().getTypeName().toString().contains("AuUpdateType")) { |
| 77 | + |
| 78 | + updateTypeList.add((AuUpdateType) details); |
| 79 | + |
| 80 | + } else if (details.getClass().getTypeName().toString().contains("AuDeleteType")) { |
| 81 | + |
| 82 | + deleteTypeList.add((AuDeleteType) details); |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + if (!(updateTypeList.isEmpty())) { |
| 87 | + for (int i = 0; i < updateTypeList.size(); i++) { |
| 88 | + |
| 89 | + System.out.println("---AU Update Start---"); |
| 90 | + System.out.println("Profile ID:" + details.getCustomerProfileID()); |
| 91 | + System.out.println("Payment Profile ID:" + details.getCustomerPaymentProfileID()); |
| 92 | + System.out.println("First Name:" + details.getFirstName()); |
| 93 | + System.out.println("Last Name:" + details.getLastName()); |
| 94 | + System.out.println("Update Time UTC:" + details.getUpdateTimeUTC()); |
| 95 | + System.out.println("Reason Code:" + details.getAuReasonCode()); |
| 96 | + System.out.println("Reason Description:" + details.getReasonDescription()); |
| 97 | + |
| 98 | + if (updateTypeList.get(i).getNewCreditCard() != null) { |
| 99 | + CreditCardMaskedType newCreditCard = updateTypeList.get(i).getNewCreditCard(); |
| 100 | + System.out.println("---Fetching New Card Details---"); |
| 101 | + System.out.println("Card Number:" + newCreditCard.getCardNumber()); |
| 102 | + System.out.println("Expiration Date:" + newCreditCard.getExpirationDate()); |
| 103 | + System.out.println("Card Type:" + newCreditCard.getCardType()); |
| 104 | + } |
| 105 | + |
| 106 | + if (updateTypeList.get(i).getOldCreditCard() != null) { |
| 107 | + CreditCardMaskedType oldCreditCard = updateTypeList.get(i).getOldCreditCard(); |
| 108 | + System.out.println("---Fetching Old Card Details---"); |
| 109 | + System.out.println("Card Number:" + oldCreditCard.getCardNumber()); |
| 110 | + System.out.println("Expiration Date:" + oldCreditCard.getExpirationDate()); |
| 111 | + System.out.println("Card Type:" + oldCreditCard.getCardType()); |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + if (!(deleteTypeList.isEmpty())) { |
| 117 | + for (int i = 0; i < deleteTypeList.size(); i++) { |
| 118 | + |
| 119 | + System.out.println("---AU Delete Start---"); |
| 120 | + System.out.println("Profile ID:" + details.getCustomerProfileID()); |
| 121 | + System.out.println("Payment Profile ID:" + details.getCustomerPaymentProfileID()); |
| 122 | + System.out.println("First Name:" + details.getFirstName()); |
| 123 | + System.out.println("Last Name:" + details.getLastName()); |
| 124 | + System.out.println("Update Time UTC:" + details.getUpdateTimeUTC()); |
| 125 | + System.out.println("Reason Code:" + details.getAuReasonCode()); |
| 126 | + System.out.println("Reason Description:" + details.getReasonDescription()); |
| 127 | + |
| 128 | + if (deleteTypeList.get(i).getCreditCard() != null) { |
| 129 | + |
| 130 | + CreditCardMaskedType creditCard = deleteTypeList.get(i).getCreditCard(); |
| 131 | + System.out.println("Card Number:" + creditCard.getCardNumber()); |
| 132 | + System.out.println("Expiration Date:" + creditCard.getExpirationDate()); |
| 133 | + System.out.println("Card Type:" + creditCard.getCardType()); |
| 134 | + } |
| 135 | + |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + else { |
| 142 | + // Display the error code and message when response is null |
| 143 | + ANetApiResponse errorResponse = controller.getErrorResponse(); |
| 144 | + System.out.println("Failed to get response"); |
| 145 | + if (!errorResponse.getMessages().getMessage().isEmpty()) { |
| 146 | + System.out.println("Error: " + errorResponse.getMessages().getMessage().get(0).getCode() + " \n" |
| 147 | + + errorResponse.getMessages().getMessage().get(0).getText()); |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + return response; |
| 152 | + } |
| 153 | +} |
0 commit comments