def get_settled_batch_list(): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() settledBatchListRequest.merchantAuthentication = merchantAuth settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta( days=31) settledBatchListRequest.lastSettlementDate = datetime.now() settledBatchListController = getSettledBatchListController( settledBatchListRequest) settledBatchListController.execute() settledBatchListResponse = settledBatchListController.getresponse() if settledBatchListResponse is not None: if settledBatchListResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: print('Successfully got settled batch list!') #if hasattr(response, 'batch') == True: #mylist = settledBatchListResponse.batchList.batch for batchItem in settledBatchListResponse.batchList.batch: #print ("LOOK batchItem = %s" %batchItem) print('Batch Id : %s' % batchItem.batchId) print('Settlement State : %s' % batchItem.settlementState) print('Payment Method : %s' % batchItem.paymentMethod) print('Product : %s' % batchItem.product) if hasattr(settledBatchListResponse.batchList.batch, 'statistics') == True: if hasattr( settledBatchListResponse.batchList.batch. statistics, 'statistic') == True: # if batchItem.statistics: for statistic in batchItem.statistics.statistic: print('Account Type : %s' % statistic.accountType) print('Charge Amount : %s' % statistic.chargeAmount) print('Refund Amount : %s' % statistic.refundAmount) print('Decline Count : %s' % statistic.declineCount) if settledBatchListResponse.messages: print('Message Code : %s' % settledBatchListResponse.messages.message[0].code) print('Message Text : %s' % settledBatchListResponse.messages.message[0].text) else: if settledBatchListResponse.messages: print('Failed to get settled batch list.\nCode:%s \nText:%s' % (settledBatchListResponse.messages.message[0].code, settledBatchListResponse.messages.message[0].text)) return settledBatchListResponse
def get_settled_batch_list(): utility.helper.setpropertyfile('anet_python_sdk_properties.ini') merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() settledBatchListRequest.merchantAuthentication = merchantAuth settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta(days=31) settledBatchListRequest.lastSettlementDate = datetime.now() settledBatchListController = getSettledBatchListController(settledBatchListRequest) settledBatchListController.execute() settledBatchListResponse = settledBatchListController.getresponse() if settledBatchListResponse is not None: if settledBatchListResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: print('Successfully got settled batch list!') #if hasattr(response, 'batch') == True: #mylist = settledBatchListResponse.batchList.batch for batchItem in settledBatchListResponse.batchList.batch: #print ("LOOK batchItem = %s" %batchItem) print('Batch Id : %s' % batchItem.batchId) print('Settlement State : %s' % batchItem.settlementState) print('Payment Method : %s' % batchItem.paymentMethod) if hasattr(batchItem, 'product') == True: print('Product : %s' % batchItem.product) if hasattr(settledBatchListResponse.batchList.batch, 'statistics') == True: if hasattr(settledBatchListResponse.batchList.batch.statistics, 'statistic') == True: # if batchItem.statistics: for statistic in batchItem.statistics.statistic: print('Account Type : %s' % statistic.accountType) print('Charge Amount : %s' % statistic.chargeAmount) print('Refund Amount : %s' % statistic.refundAmount) print('Decline Count : %s' % statistic.declineCount) if len(settledBatchListResponse.messages) != 0: print('Message Code : %s' % settledBatchListResponse.messages.message[0]['code'].text) print('Message Text : %s' % settledBatchListResponse.messages.message[0]['text'].text) else: if len(settledBatchListResponse.messages) != 0: print('Failed to get settled batch list.\nCode:%s \nText:%s' % (settledBatchListResponse.messages.message[0]['code'].text,settledBatchListResponse.messages.message[0]['text'].text)) return settledBatchListResponse
def get_settled_batch_list(self, start_date, end_date): """ Gets a list of batches for settled transaction between the start and end date. """ self.transaction = apicontractsv1.getSettledBatchListRequest() self.transaction.merchantAuthentication = self.merchant_auth self.transaction.firstSettlementDate = start_date self.transaction.lastSettlementDate = end_date self.controller = getSettledBatchListController(self.transaction) self.controller.execute() response = self.controller.getresponse() if response.messages.resultCode == apicontractsv1.messageTypeEnum.Ok and hasattr(response, 'batchList'): return [batch for batch in response.batchList.batch]
from authorizenet import apicontractsv1 from authorizenet.apicontrollers import * from decimal import * from datetime import datetime, timedelta merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = '5KP3u95bQpv' merchantAuth.transactionKey = '4Ktq966gC55GAX7S' settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() settledBatchListRequest.merchantAuthentication = merchantAuth settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta(days=31) settledBatchListRequest.lastSettlementDate = datetime.now() settledBatchListController = getSettledBatchListController(settledBatchListRequest) settledBatchListController.execute() settledBatchListResponse = settledBatchListController.getresponse() if settledBatchListResponse is not None: if settledBatchListResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: print('Successfully got settled batch list!') for batchItem in settledBatchListResponse.batchList.batch: print('Batch Id : %s' % batchItem.batchId) print('Settlement State : %s' % batchItem.settlementState) print('Payment Method : %s' % batchItem.paymentMethod) print('Product : %s' % batchItem.product) if batchItem.statistics:
def get_batch_ids(ds, **kwargs): rd = redis.Redis(host='redis', port=6379, db=9) if rd.exists(dag_name) == 1: batch_ids = [] tttt = rd.hget(dag_name, "last_date") ddd = dateparser.parse(tttt.decode("utf-8")) eee = datetime.now() print("Starting Date >>>>>> ", ddd) print("Ending Date >>>>>> ", eee) settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() settledBatchListRequest.merchantAuthentication = merchantAuth # settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta(days=31) # settledBatchListRequest.firstSettlementDate = dateparser.parse('2020-02-10') # settledBatchListRequest.firstSettlementDate = ddd # settledBatchListRequest.lastSettlementDate = eee # settledBatchListRequest.lastSettlementDate = datetime.now() settledBatchListController = getSettledBatchListController(settledBatchListRequest) settledBatchListController.setenvironment(ENV) settledBatchListController.execute() settledBatchListResponse = settledBatchListController.getresponse() if settledBatchListResponse is not None: if settledBatchListResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: print('Successfully got settled batch list!') try: for batchItem in settledBatchListResponse.batchList.batch: batch_ids.append(batchItem.batchId) if settledBatchListResponse.messages is not None: print('Message Code : %s' % settledBatchListResponse.messages.message[0].code) print('Message Text : %s' % settledBatchListResponse.messages.message[0].text) except: print('No records >>>>>> count >>>>>>> ') else: if settledBatchListResponse.messages is not None: print('Failed to get settled batch list.\nCode:%s \nText:%s' % ( settledBatchListResponse.messages.message[0].code, settledBatchListResponse.messages.message[0].text)) rd.hset(dag_name, "last_date", str(eee)) print("Last saved date for rerun >>>>>>>>>>>> ", str(rd.hget(dag_name, "last_date"))) return batch_ids else: batch_ids = [] back = kwargs['ti'].xcom_pull(task_ids='back_log_days') for d in back: ddd = dateparser.parse(d['start']) eee = dateparser.parse(d['end']) settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() settledBatchListRequest.merchantAuthentication = merchantAuth # settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta(days=31) # settledBatchListRequest.firstSettlementDate = dateparser.parse('2020-02-10') settledBatchListRequest.firstSettlementDate = ddd settledBatchListRequest.lastSettlementDate = eee # settledBatchListRequest.lastSettlementDate = datetime.now() settledBatchListController = getSettledBatchListController(settledBatchListRequest) settledBatchListController.setenvironment(ENV) settledBatchListController.execute() settledBatchListResponse = settledBatchListController.getresponse() if settledBatchListResponse is not None: if settledBatchListResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: print('Successfully got settled batch list!') try: for batchItem in settledBatchListResponse.batchList.batch: batch_ids.append(batchItem.batchId) if settledBatchListResponse.messages is not None: print('Message Code : %s' % settledBatchListResponse.messages.message[0].code) print('Message Text : %s' % settledBatchListResponse.messages.message[0].text) except: print('No records >>>>>> count >>>>>>> ') else: if settledBatchListResponse.messages is not None: print('Failed to get settled batch list.\nCode:%s \nText:%s' % ( settledBatchListResponse.messages.message[0].code, settledBatchListResponse.messages.message[0].text)) rd.hset(dag_name, "last_date", str(eee)) print("Last saved date >>>>>>>>>>>> ", str(rd.hget(dag_name, "last_date"))) return batch_ids
def get_settled_batch_list(): """get settled batch list""" merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = CONSTANTS.apiLoginId merchantAuth.transactionKey = CONSTANTS.transactionKey settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() settledBatchListRequest.merchantAuthentication = merchantAuth settledBatchListRequest.refId = "Sample" settledBatchListRequest.includeStatistics = True settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta( days=31) settledBatchListRequest.lastSettlementDate = datetime.now() settledBatchListController = getSettledBatchListController( settledBatchListRequest) settledBatchListController.execute() response = settledBatchListController.getresponse() # Work on the response if response is not None: if response.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: if hasattr(response, 'batchList'): print('Successfully retrieved batch list.') if response.messages is not None: print('Message Code: %s' % response.messages.message[0]['code'].text) print('Message Text: %s' % response.messages.message[0]['text'].text) print() for batchEntry in response.batchList.batch: print('Batch Id: %s' % batchEntry.batchId) print('Settlement Time UTC: %s' % batchEntry.settlementTimeUTC) print('Payment Method: %s' % batchEntry.paymentMethod) if hasattr(batchEntry, 'marketType'): print('Market Type: %s' % batchEntry.marketType) if hasattr(batchEntry, 'product'): print('Product: %s' % batchEntry.product) if hasattr(batchEntry, 'statistics'): if hasattr(batchEntry.statistics, 'statistic'): for statistic in batchEntry.statistics.statistic: if hasattr(statistic, 'accountType'): print('Account Type: %s' % statistic.accountType) if hasattr(statistic, 'chargeAmount'): print(' Charge Amount: %.2f' % statistic.chargeAmount) if hasattr(statistic, 'chargeCount'): print(' Charge Count: %s' % statistic.chargeCount) if hasattr(statistic, 'refundAmount'): print(' Refund Amount: %.2f' % statistic.refundAmount) if hasattr(statistic, 'refundCount'): print(' Refund Count: %s' % statistic.refundCount) if hasattr(statistic, 'voidCount'): print(' Void Count: %s' % statistic.voidCount) if hasattr(statistic, 'declineCount'): print(' Decline Count: %s' % statistic.declineCount) if hasattr(statistic, 'errorCount'): print(' Error Count: %s' % statistic.errorCount) if hasattr(statistic, 'returnedItemAmount'): print(' Returned Item Amount: %.2f' % statistic.returnedItemAmount) if hasattr(statistic, 'returnedItemCount'): print(' Returned Item Count: %s' % statistic.returnedItemCount) if hasattr(statistic, 'chargebackAmount'): print(' Chargeback Amount: %.2f' % statistic.chargebackAmount) if hasattr(statistic, 'chargebackCount'): print(' Chargeback Count: %s' % statistic.chargebackCount) if hasattr(statistic, 'correctionNoticeCount'): print(' Correction Notice Count: %s' % statistic.correctionNoticeCount) if hasattr(statistic, 'chargeChargeBackAmount'): print(' Charge Chargeback Amount: %.2f' % statistic.chargeChargeBackAmount) if hasattr(statistic, 'chargeChargeBackCount'): print(' Charge Chargeback Count: %s' % statistic.chargeChargeBackCount) if hasattr(statistic, 'refundChargeBackAmount'): print(' Refund Chargeback Amount: %.2f' % statistic.refundChargeBackAmount) if hasattr(statistic, 'refundChargeBackCount'): print(' Refund Chargeback Count: %s' % statistic.refundChargeBackCount) if hasattr(statistic, 'chargeReturnedItemsAmount'): print( ' Charge Returned Items Amount: %.2f' % statistic.chargeReturnedItemsAmount) if hasattr(statistic, 'chargeReturnedItemsCount'): print(' Charge Returned Items Count: %s' % statistic.chargeReturnedItemsCount) if hasattr(statistic, 'refundReturnedItemsAmount'): print( ' Refund Returned Items Amount: %.2f' % statistic.refundReturnedItemsAmount) if hasattr(statistic, 'refundReturnedItemsCount'): print(' Refund Returned Items Count: %s' % statistic.refundReturnedItemsCount) print() else: if response.messages is not None: print('Failed to get transaction list.') print('Code: %s' % (response.messages.message[0]['code'].text)) print('Text: %s' % (response.messages.message[0]['text'].text)) else: if response.messages is not None: print('Failed to get transaction list.') print('Code: %s' % (response.messages.message[0]['code'].text)) print('Text: %s' % (response.messages.message[0]['text'].text)) else: print('Error. No response received.') return response
def get_settled_batch_list(): """get settled batch list""" merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() settledBatchListRequest.merchantAuthentication = merchantAuth settledBatchListRequest.refId = "Sample" settledBatchListRequest.includeStatistics = True settledBatchListRequest.firstSettlementDate = datetime.now() - timedelta(days=7) settledBatchListRequest.lastSettlementDate = datetime.now() settledBatchListController = getSettledBatchListController(settledBatchListRequest) settledBatchListController.execute() response = settledBatchListController.getresponse() # Work on the response if response is not None: if response.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: if hasattr(response, 'batchList'): print('Successfully retrieved batch list.') if response.messages is not None: print('Message Code: %s' % response.messages.message[0]['code'].text) print('Message Text: %s' % response.messages.message[0]['text'].text) print() for batchEntry in response.batchList.batch: print('Batch Id: %s' % batchEntry.batchId) print('Settlement Time UTC: %s' % batchEntry.settlementTimeUTC) print('Payment Method: %s' % batchEntry.paymentMethod) if hasattr(batchEntry, 'marketType'): print('Market Type: %s' % batchEntry.marketType) if hasattr(batchEntry, 'product'): print('Product: %s' % batchEntry.product) if hasattr(batchEntry, 'statistics'): if hasattr(batchEntry.statistics, 'statistic'): for statistic in batchEntry.statistics.statistic: if hasattr(statistic, 'accountType'): print('Account Type: %s' % statistic.accountType) if hasattr(statistic, 'chargeAmount'): print(' Charge Amount: %.2f' % statistic.chargeAmount) if hasattr(statistic, 'chargeCount'): print(' Charge Count: %s' % statistic.chargeCount) if hasattr(statistic, 'refundAmount'): print(' Refund Amount: %.2f' % statistic.refundAmount) if hasattr(statistic, 'refundCount'): print(' Refund Count: %s' % statistic.refundCount) if hasattr(statistic, 'voidCount'): print(' Void Count: %s' % statistic.voidCount) if hasattr(statistic, 'declineCount'): print(' Decline Count: %s' % statistic.declineCount) if hasattr(statistic, 'errorCount'): print(' Error Count: %s' % statistic.errorCount) if hasattr(statistic, 'returnedItemAmount'): print(' Returned Item Amount: %.2f' % statistic.returnedItemAmount) if hasattr(statistic, 'returnedItemCount'): print(' Returned Item Count: %s' % statistic.returnedItemCount) if hasattr(statistic, 'chargebackAmount'): print(' Chargeback Amount: %.2f' % statistic.chargebackAmount) if hasattr(statistic, 'chargebackCount'): print(' Chargeback Count: %s' % statistic.chargebackCount) if hasattr(statistic, 'correctionNoticeCount'): print(' Correction Notice Count: %s' % statistic.correctionNoticeCount) if hasattr(statistic, 'chargeChargeBackAmount'): print(' Charge Chargeback Amount: %.2f' % statistic.chargeChargeBackAmount) if hasattr(statistic, 'chargeChargeBackCount'): print(' Charge Chargeback Count: %s' % statistic.chargeChargeBackCount) if hasattr(statistic, 'refundChargeBackAmount'): print(' Refund Chargeback Amount: %.2f' % statistic.refundChargeBackAmount) if hasattr(statistic, 'refundChargeBackCount'): print(' Refund Chargeback Count: %s' % statistic.refundChargeBackCount) if hasattr(statistic, 'chargeReturnedItemsAmount'): print(' Charge Returned Items Amount: %.2f' % statistic.chargeReturnedItemsAmount) if hasattr(statistic, 'chargeReturnedItemsCount'): print(' Charge Returned Items Count: %s' % statistic.chargeReturnedItemsCount) if hasattr(statistic, 'refundReturnedItemsAmount'): print(' Refund Returned Items Amount: %.2f' % statistic.refundReturnedItemsAmount) if hasattr(statistic, 'refundReturnedItemsCount'): print(' Refund Returned Items Count: %s' % statistic.refundReturnedItemsCount) print() else: if response.messages is not None: print('Failed to get transaction list.') print('Code: %s' % (response.messages.message[0]['code'].text)) print('Text: %s' % (response.messages.message[0]['text'].text)) else: if response.messages is not None: print('Failed to get transaction list.') print('Code: %s' % (response.messages.message[0]['code'].text)) print('Text: %s' % (response.messages.message[0]['text'].text)) else: print('Error. No response received.') return response