| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,29 +1,66 @@ | |||
| 1 | - import os, sys | ||
| 1 | + """http://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile-ids""" | ||
| 2 | + import os | ||
| 3 | + import sys | ||
| 2 | 4 | import imp | |
| 3 | 5 | ||
| 4 | 6 | from authorizenet import apicontractsv1 | |
| 5 | - from authorizenet.apicontrollers import * | ||
| 7 | + from authorizenet.apicontrollers import getCustomerProfileIdsController | ||
| 6 | 8 | constants = imp.load_source('modulename', 'constants.py') | |
| 7 | 9 | ||
| 8 | 10 | def get_customer_profile_ids(): | |
| 11 | + """get customer profile IDs""" | ||
| 9 | 12 | merchantAuth = apicontractsv1.merchantAuthenticationType() | |
| 10 | 13 | merchantAuth.name = constants.apiLoginId | |
| 11 | 14 | merchantAuth.transactionKey = constants.transactionKey | |
| 12 | 15 | ||
| 13 | - getCustomerProfileIds = apicontractsv1.getCustomerProfileIdsRequest() | ||
| 14 | - getCustomerProfileIds.merchantAuthentication = merchantAuth | ||
| 16 | + CustomerProfileIdsRequest = apicontractsv1.getCustomerProfileIdsRequest() | ||
| 17 | + CustomerProfileIdsRequest.merchantAuthentication = merchantAuth | ||
| 18 | + CustomerProfileIdsRequest.refId = "Sample" | ||
| 15 | 19 | ||
| 16 | - controller = getCustomerProfileIdsController(getCustomerProfileIds) | ||
| 20 | + controller = getCustomerProfileIdsController(CustomerProfileIdsRequest) | ||
| 17 | 21 | controller.execute() | |
| 18 | 22 | ||
| 23 | + # Work on the response | ||
| 19 | 24 | response = controller.getresponse() | |
| 20 | 25 | ||
| 21 | - if (response.messages.resultCode=="Ok"): | ||
| 22 | - print("Successfully retrieved customer ids:") | ||
| 23 | - for identity in response.ids.numericString: | ||
| 24 | - print(identity) | ||
| 26 | + # if (response.messages.resultCode == "Ok"): | ||
| 27 | + # print("Successfully retrieved customer ids:") | ||
| 28 | + # for identity in response.ids.numericString: | ||
| 29 | + # print(identity) | ||
| 30 | + # else: | ||
| 31 | + # print("response code: %s" % response.messages.resultCode) | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + if response is not None: | ||
| 36 | + if response.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: | ||
| 37 | + if hasattr(response, 'ids'): | ||
| 38 | + if hasattr(response.ids, 'numericString'): | ||
| 39 | + print('Successfully retrieved customer IDs.') | ||
| 40 | + if response.messages is not None: | ||
| 41 | + print('Message Code: %s' % response.messages.message[0]['code'].text) | ||
| 42 | + print('Message Text: %s' % response.messages.message[0]['text'].text) | ||
| 43 | + print('Total Number of IDs Returned in Results: %s' | ||
| 44 | + % len(response.ids.numericString)) | ||
| 45 | + print() | ||
| 46 | + # There's no paging options in this API request; the full list is returned every call. | ||
| 47 | + # If the result set is going to be large, for this sample we'll break it down into smaller | ||
| 48 | + # chunks so that we don't put 72,000 lines into a log file | ||
| 49 | + print('First 20 results:') | ||
| 50 | + for profileId in range(0,19): | ||
| 51 | + print(response.ids.numericString[profileId]) | ||
| 52 | + else: | ||
| 53 | + if response.messages is not None: | ||
| 54 | + print('Failed to get list.') | ||
| 55 | + print('Code: %s' % (response.messages.message[0]['code'].text)) | ||
| 56 | + print('Text: %s' % (response.messages.message[0]['text'].text)) | ||
| 57 | + else: | ||
| 58 | + if response.messages is not None: | ||
| 59 | + print('Failed to get list.') | ||
| 60 | + print('Code: %s' % (response.messages.message[0]['code'].text)) | ||
| 61 | + print('Text: %s' % (response.messages.message[0]['text'].text)) | ||
| 25 | 62 | else: | |
| 26 | - print("response code: %s" % response.messages.resultCode) | ||
| 63 | + print('Error. No response received.') | ||
| 27 | 64 | ||
| 28 | 65 | return response | |
| 29 | 66 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,12 +13,15 @@ def get_list_of_subscriptions(): | |||
| 13 | 13 | merchantAuth.name = constants.apiLoginId | |
| 14 | 14 | merchantAuth.transactionKey = constants.transactionKey | |
| 15 | 15 | ||
| 16 | + # set sorting parameters | ||
| 16 | 17 | sorting = apicontractsv1.ARBGetSubscriptionListSorting() | |
| 17 | 18 | sorting.orderBy = apicontractsv1.ARBGetSubscriptionListOrderFieldEnum.id | |
| 18 | - sorting.orderDescending = "false" | ||
| 19 | + sorting.orderDescending = True | ||
| 19 | 20 | ||
| 21 | + # set paging and offset parameters | ||
| 20 | 22 | paging = apicontractsv1.Paging() | |
| 21 | - paging.limit = 100 | ||
| 23 | + # Paging limit can be up to 1000 for this request | ||
| 24 | + paging.limit = 20 | ||
| 22 | 25 | paging.offset = 1 | |
| 23 | 26 | ||
| 24 | 27 | request = apicontractsv1.ARBGetSubscriptionListRequest() | |
@@ -31,17 +34,36 @@ def get_list_of_subscriptions(): | |||
| 31 | 34 | controller = ARBGetSubscriptionListController(request) | |
| 32 | 35 | controller.execute() | |
| 33 | 36 | ||
| 37 | + # Work on the response | ||
| 34 | 38 | response = controller.getresponse() | |
| 35 | 39 | ||
| 36 | - if response.messages.resultCode == "Ok": | ||
| 37 | - print "SUCCESS" | ||
| 38 | - print "Message Code : %s" % response.messages.message[0]['code'].text | ||
| 39 | - print "Message text : %s" % response.messages.message[0]['text'].text | ||
| 40 | - print "Total Number In Results : %s" % response.totalNumInResultSet | ||
| 40 | + if response is not None: | ||
| 41 | + if response.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: | ||
| 42 | + if hasattr(response, 'subscriptionDetails'): | ||
| 43 | + print('Successfully retrieved subscription list.') | ||
| 44 | + if response.messages is not None: | ||
| 45 | + print('Message Code: %s' % response.messages.message[0]['code'].text) | ||
| 46 | + print('Message Text: %s' % response.messages.message[0]['text'].text) | ||
| 47 | + print('Total Number In Results: %s' % response.totalNumInResultSet) | ||
| 48 | + print() | ||
| 49 | + for subscription in response.subscriptionDetails.subscriptionDetail: | ||
| 50 | + print('Subscription Id: %s' % subscription.id) | ||
| 51 | + print('Subscription Name: %s' % subscription.name) | ||
| 52 | + print('Subscription Status: %s' % subscription.status) | ||
| 53 | + print('Customer Profile Id: %s' % subscription.customerProfileId) | ||
| 54 | + print() | ||
| 55 | + else: | ||
| 56 | + if response.messages is not None: | ||
| 57 | + print('Failed to get subscription list.') | ||
| 58 | + print('Code: %s' % (response.messages.message[0]['code'].text)) | ||
| 59 | + print('Text: %s' % (response.messages.message[0]['text'].text)) | ||
| 60 | + else: | ||
| 61 | + if response.messages is not None: | ||
| 62 | + print('Failed to get transaction list.') | ||
| 63 | + print('Code: %s' % (response.messages.message[0]['code'].text)) | ||
| 64 | + print('Text: %s' % (response.messages.message[0]['text'].text)) | ||
| 41 | 65 | else: | |
| 42 | - print "ERROR" | ||
| 43 | - print "Message Code : %s" % response.messages.message[0]['code'].text | ||
| 44 | - print "Message text : %s" % response.messages.message[0]['text'].text | ||
| 66 | + print('Error. No response received.') | ||
| 45 | 67 | ||
| 46 | 68 | return response | |
| 47 | 69 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,63 +1,108 @@ | |||
| 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() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments