|
1 |
| -import os, sys |
| 1 | +"""http://developer.authorize.net/api/reference/index.html#transaction-reporting-get-settled-batch-list""" |
| 2 | +import os |
| 3 | +import sys |
2 | 4 | import imp
|
3 | 5 |
|
| 6 | +from datetime import datetime, timedelta |
4 | 7 | from authorizenet import apicontractsv1
|
5 |
| -from authorizenet.apicontrollers import * |
| 8 | +from authorizenet.apicontrollers import getSettledBatchListController |
6 | 9 | constants = imp.load_source('modulename', 'constants.py')
|
7 |
| -from decimal import * |
8 |
| -from datetime import datetime, timedelta |
9 |
| -from authorizenet.utility import * |
10 |
| -#from authorizenet.apicontractsv1 import CTD_ANON |
11 |
| -from authorizenet import utility |
12 | 10 |
|
13 | 11 | def get_settled_batch_list():
|
14 |
| - utility.helper.setpropertyfile('anet_python_sdk_properties.ini') |
| 12 | + """get settled batch list""" |
15 | 13 | merchantAuth = apicontractsv1.merchantAuthenticationType()
|
16 | 14 | merchantAuth.name = constants.apiLoginId
|
17 | 15 | merchantAuth.transactionKey = constants.transactionKey
|
18 | 16 |
|
19 | 17 | settledBatchListRequest = apicontractsv1.getSettledBatchListRequest()
|
20 | 18 | settledBatchListRequest.merchantAuthentication = merchantAuth
|
21 |
| - settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta(days=31) |
| 19 | + settledBatchListRequest.refId = "Sample" |
| 20 | + settledBatchListRequest.includeStatistics = True |
| 21 | + settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta(days=7) |
22 | 22 | settledBatchListRequest.lastSettlementDate = datetime.now()
|
23 | 23 |
|
24 | 24 | settledBatchListController = getSettledBatchListController(settledBatchListRequest)
|
25 |
| - |
26 | 25 | settledBatchListController.execute()
|
27 | 26 |
|
28 |
| - settledBatchListResponse = settledBatchListController.getresponse() |
29 |
| - |
30 |
| - if settledBatchListResponse is not None: |
31 |
| - if settledBatchListResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: |
32 |
| - print('Successfully got settled batch list!') |
33 |
| - |
34 |
| - #if hasattr(response, 'batch') == True: |
35 |
| - #mylist = settledBatchListResponse.batchList.batch |
36 |
| - |
37 |
| - for batchItem in settledBatchListResponse.batchList.batch: |
38 |
| - #print ("LOOK batchItem = %s" %batchItem) |
39 |
| - print('Batch Id : %s' % batchItem.batchId) |
40 |
| - print('Settlement State : %s' % batchItem.settlementState) |
41 |
| - print('Payment Method : %s' % batchItem.paymentMethod) |
42 |
| - if hasattr(batchItem, 'product') == True: |
43 |
| - print('Product : %s' % batchItem.product) |
44 |
| - |
45 |
| - if hasattr(settledBatchListResponse.batchList.batch, 'statistics') == True: |
46 |
| - if hasattr(settledBatchListResponse.batchList.batch.statistics, 'statistic') == True: |
47 |
| -# if batchItem.statistics: |
48 |
| - for statistic in batchItem.statistics.statistic: |
49 |
| - print('Account Type : %s' % statistic.accountType) |
50 |
| - print('Charge Amount : %s' % statistic.chargeAmount) |
51 |
| - print('Refund Amount : %s' % statistic.refundAmount) |
52 |
| - print('Decline Count : %s' % statistic.declineCount) |
53 |
| - if len(settledBatchListResponse.messages) != 0: |
54 |
| - print('Message Code : %s' % settledBatchListResponse.messages.message[0]['code'].text) |
55 |
| - print('Message Text : %s' % settledBatchListResponse.messages.message[0]['text'].text) |
| 27 | + response = settledBatchListController.getresponse() |
| 28 | + |
| 29 | + # Work on the response |
| 30 | + if response is not None: |
| 31 | + if response.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: |
| 32 | + if hasattr(response, 'batchList'): |
| 33 | + print('Successfully retrieved batch list.') |
| 34 | + if response.messages is not None: |
| 35 | + print('Message Code: %s' % response.messages.message[0]['code'].text) |
| 36 | + print('Message Text: %s' % response.messages.message[0]['text'].text) |
| 37 | + print() |
| 38 | + for batchEntry in response.batchList.batch: |
| 39 | + print('Batch Id: %s' % batchEntry.batchId) |
| 40 | + print('Settlement Time UTC: %s' % batchEntry.settlementTimeUTC) |
| 41 | + print('Payment Method: %s' % batchEntry.paymentMethod) |
| 42 | + if hasattr(batchEntry, 'marketType'): |
| 43 | + print('Market Type: %s' % batchEntry.marketType) |
| 44 | + if hasattr(batchEntry, 'product'): |
| 45 | + print('Product: %s' % batchEntry.product) |
| 46 | + if hasattr(batchEntry, 'statistics'): |
| 47 | + if hasattr(batchEntry.statistics, 'statistic'): |
| 48 | + for statistic in batchEntry.statistics.statistic: |
| 49 | + if hasattr(statistic, 'accountType'): |
| 50 | + print('Account Type: %s' % statistic.accountType) |
| 51 | + if hasattr(statistic, 'chargeAmount'): |
| 52 | + print(' Charge Amount: %.2f' % statistic.chargeAmount) |
| 53 | + if hasattr(statistic, 'chargeCount'): |
| 54 | + print(' Charge Count: %s' % statistic.chargeCount) |
| 55 | + if hasattr(statistic, 'refundAmount'): |
| 56 | + print(' Refund Amount: %.2f' % statistic.refundAmount) |
| 57 | + if hasattr(statistic, 'refundCount'): |
| 58 | + print(' Refund Count: %s' % statistic.refundCount) |
| 59 | + if hasattr(statistic, 'voidCount'): |
| 60 | + print(' Void Count: %s' % statistic.voidCount) |
| 61 | + if hasattr(statistic, 'declineCount'): |
| 62 | + print(' Decline Count: %s' % statistic.declineCount) |
| 63 | + if hasattr(statistic, 'errorCount'): |
| 64 | + print(' Error Count: %s' % statistic.errorCount) |
| 65 | + if hasattr(statistic, 'returnedItemAmount'): |
| 66 | + print(' Returned Item Amount: %.2f' % statistic.returnedItemAmount) |
| 67 | + if hasattr(statistic, 'returnedItemCount'): |
| 68 | + print(' Returned Item Count: %s' % statistic.returnedItemCount) |
| 69 | + if hasattr(statistic, 'chargebackAmount'): |
| 70 | + print(' Chargeback Amount: %.2f' % statistic.chargebackAmount) |
| 71 | + if hasattr(statistic, 'chargebackCount'): |
| 72 | + print(' Chargeback Count: %s' % statistic.chargebackCount) |
| 73 | + if hasattr(statistic, 'correctionNoticeCount'): |
| 74 | + print(' Correction Notice Count: %s' % statistic.correctionNoticeCount) |
| 75 | + if hasattr(statistic, 'chargeChargeBackAmount'): |
| 76 | + print(' Charge Chargeback Amount: %.2f' % statistic.chargeChargeBackAmount) |
| 77 | + if hasattr(statistic, 'chargeChargeBackCount'): |
| 78 | + print(' Charge Chargeback Count: %s' % statistic.chargeChargeBackCount) |
| 79 | + if hasattr(statistic, 'refundChargeBackAmount'): |
| 80 | + print(' Refund Chargeback Amount: %.2f' % statistic.refundChargeBackAmount) |
| 81 | + if hasattr(statistic, 'refundChargeBackCount'): |
| 82 | + print(' Refund Chargeback Count: %s' % statistic.refundChargeBackCount) |
| 83 | + if hasattr(statistic, 'chargeReturnedItemsAmount'): |
| 84 | + print(' Charge Returned Items Amount: %.2f' % statistic.chargeReturnedItemsAmount) |
| 85 | + if hasattr(statistic, 'chargeReturnedItemsCount'): |
| 86 | + print(' Charge Returned Items Count: %s' % statistic.chargeReturnedItemsCount) |
| 87 | + if hasattr(statistic, 'refundReturnedItemsAmount'): |
| 88 | + print(' Refund Returned Items Amount: %.2f' % statistic.refundReturnedItemsAmount) |
| 89 | + if hasattr(statistic, 'refundReturnedItemsCount'): |
| 90 | + print(' Refund Returned Items Count: %s' % statistic.refundReturnedItemsCount) |
| 91 | + print() |
| 92 | + else: |
| 93 | + if response.messages is not None: |
| 94 | + print('Failed to get transaction list.') |
| 95 | + print('Code: %s' % (response.messages.message[0]['code'].text)) |
| 96 | + print('Text: %s' % (response.messages.message[0]['text'].text)) |
56 | 97 | else:
|
57 |
| - if len(settledBatchListResponse.messages) != 0: |
58 |
| - print('Failed to get settled batch list.\nCode:%s \nText:%s' % (settledBatchListResponse.messages.message[0]['code'].text,settledBatchListResponse.messages.message[0]['text'].text)) |
| 98 | + if response.messages is not None: |
| 99 | + print('Failed to get transaction list.') |
| 100 | + print('Code: %s' % (response.messages.message[0]['code'].text)) |
| 101 | + print('Text: %s' % (response.messages.message[0]['text'].text)) |
| 102 | + else: |
| 103 | + print('Error. No response received.') |
59 | 104 |
|
60 |
| - return settledBatchListResponse |
| 105 | + return response |
61 | 106 |
|
62 | 107 | if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
|
63 | 108 | get_settled_batch_list()
|
0 commit comments