|
1 | 1 | package net.authorize.sample.TransactionReporting; |
2 | 2 |
|
| 3 | +import java.util.Calendar; |
| 4 | +import java.util.GregorianCalendar; |
3 | 5 | import net.authorize.Environment; |
4 | 6 | import net.authorize.api.contract.v1.*; |
5 | 7 | import net.authorize.api.controller.GetSettledBatchListController; |
6 | 8 | import net.authorize.api.controller.base.ApiOperationBase; |
| 9 | +import javax.xml.datatype.DatatypeFactory; |
7 | 10 |
|
8 | | -//author @krgupta |
| 11 | +//author @krgupta modified @kikmak42 |
9 | 12 | public class GetSettledBatchList { |
10 | 13 |
|
11 | | - public static void run(String apiLoginId, String transactionKey) { |
| 14 | + public static void run(String apiLoginId, String transactionKey) { |
12 | 15 |
|
13 | 16 | ApiOperationBase.setEnvironment(Environment.SANDBOX); |
14 | 17 |
|
15 | | - MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ; |
| 18 | + MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType(); |
16 | 19 | merchantAuthenticationType.setName(apiLoginId); |
17 | 20 | merchantAuthenticationType.setTransactionKey(transactionKey); |
18 | 21 | ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType); |
19 | | - |
| 22 | + |
20 | 23 | GetSettledBatchListRequest getRequest = new GetSettledBatchListRequest(); |
21 | 24 | getRequest.setMerchantAuthentication(merchantAuthenticationType); |
| 25 | + |
| 26 | + try { |
| 27 | + // Set first settlement date in format (year, month, day)(should not be less that 31 days since last settlement date) |
| 28 | + GregorianCalendar pastDate = new GregorianCalendar(); |
| 29 | + pastDate.add(Calendar.DAY_OF_YEAR, -7); |
| 30 | + getRequest.setFirstSettlementDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(pastDate)); |
| 31 | + |
| 32 | + // Set last settlement date in format (year, month, day) (should not be greater that 31 days since first settlement date) |
| 33 | + GregorianCalendar currentDate = new GregorianCalendar(); |
| 34 | + getRequest.setLastSettlementDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(currentDate)); |
| 35 | + |
| 36 | + } catch (Exception ex) { |
| 37 | + System.out.println("Error : while setting dates"); |
| 38 | + ex.printStackTrace(); |
| 39 | + } |
| 40 | + |
22 | 41 | GetSettledBatchListController controller = new GetSettledBatchListController(getRequest); |
23 | 42 | controller.execute(); |
24 | | - GetSettledBatchListResponse getResponse = new GetSettledBatchListResponse(); |
25 | | - if (getResponse!=null) { |
| 43 | + GetSettledBatchListResponse getResponse = controller.getApiResponse(); |
| 44 | + if (getResponse != null) { |
26 | 45 |
|
27 | | - if (getResponse.getMessages().getResultCode() == MessageTypeEnum.OK) { |
| 46 | + if (getResponse.getMessages().getResultCode() == MessageTypeEnum.OK) { |
28 | 47 |
|
29 | 48 | System.out.println(getResponse.getMessages().getMessage().get(0).getCode()); |
30 | 49 | System.out.println(getResponse.getMessages().getMessage().get(0).getText()); |
31 | | - } |
32 | | - else |
33 | | - { |
| 50 | + |
| 51 | + ArrayOfBatchDetailsType batchList = getResponse.getBatchList(); |
| 52 | + if (batchList != null) { |
| 53 | + System.out.println("List of Settled Transaction :"); |
| 54 | + for (BatchDetailsType batch : batchList.getBatch()) { |
| 55 | + System.out.println(batch.getBatchId() + " - " + batch.getMarketType() + " - " + batch.getPaymentMethod() + " - " + batch.getProduct() + " - " + batch.getSettlementState()); |
| 56 | + } |
| 57 | + } |
| 58 | + } else { |
34 | 59 | System.out.println("Failed to get settled batch list: " + getResponse.getMessages().getResultCode()); |
| 60 | + System.out.println(getResponse.getMessages().getMessage().get(0).getText()); |
35 | 61 | } |
36 | 62 | } |
| 63 | + } |
37 | 64 | } |
38 | | -} |
39 | | - |
40 | | - |
|
0 commit comments