Skip to content

Commit 1e17660

Browse files
committed
shorten responses to some lengthy requests; general cleanup and commenting
1 parent 6c369c2 commit 1e17660

5 files changed

Lines changed: 270 additions & 110 deletions

File tree

CustomerProfiles/get-customer-profile-ids.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff 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
24
import imp
35

46
from authorizenet import apicontractsv1
5-
from authorizenet.apicontrollers import *
7+
from authorizenet.apicontrollers import getCustomerProfileIdsController
68
constants = imp.load_source('modulename', 'constants.py')
79

810
def get_customer_profile_ids():
11+
"""get customer profile IDs"""
912
merchantAuth = apicontractsv1.merchantAuthenticationType()
1013
merchantAuth.name = constants.apiLoginId
1114
merchantAuth.transactionKey = constants.transactionKey
1215

13-
getCustomerProfileIds = apicontractsv1.getCustomerProfileIdsRequest()
14-
getCustomerProfileIds.merchantAuthentication = merchantAuth
16+
CustomerProfileIdsRequest = apicontractsv1.getCustomerProfileIdsRequest()
17+
CustomerProfileIdsRequest.merchantAuthentication = merchantAuth
18+
CustomerProfileIdsRequest.refId = "Sample"
1519

16-
controller = getCustomerProfileIdsController(getCustomerProfileIds)
20+
controller = getCustomerProfileIdsController(CustomerProfileIdsRequest)
1721
controller.execute()
1822

23+
# Work on the response
1924
response = controller.getresponse()
2025

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))
2562
else:
26-
print("response code: %s" % response.messages.resultCode)
63+
print('Error. No response received.')
2764

2865
return response
2966

RecurringBilling/get-list-of-subscriptions.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ def get_list_of_subscriptions():
1313
merchantAuth.name = constants.apiLoginId
1414
merchantAuth.transactionKey = constants.transactionKey
1515

16+
# set sorting parameters
1617
sorting = apicontractsv1.ARBGetSubscriptionListSorting()
1718
sorting.orderBy = apicontractsv1.ARBGetSubscriptionListOrderFieldEnum.id
18-
sorting.orderDescending = "false"
19+
sorting.orderDescending = True
1920

21+
# set paging and offset parameters
2022
paging = apicontractsv1.Paging()
21-
paging.limit = 100
23+
# Paging limit can be up to 1000 for this request
24+
paging.limit = 20
2225
paging.offset = 1
2326

2427
request = apicontractsv1.ARBGetSubscriptionListRequest()
@@ -31,17 +34,36 @@ def get_list_of_subscriptions():
3134
controller = ARBGetSubscriptionListController(request)
3235
controller.execute()
3336

37+
# Work on the response
3438
response = controller.getresponse()
3539

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))
4165
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.')
4567

4668
return response
4769

Lines changed: 86 additions & 41 deletions
Original file line numberDiff line numberDiff 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
24
import imp
35

6+
from datetime import datetime, timedelta
47
from authorizenet import apicontractsv1
5-
from authorizenet.apicontrollers import *
8+
from authorizenet.apicontrollers import getSettledBatchListController
69
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
1210

1311
def get_settled_batch_list():
14-
utility.helper.setpropertyfile('anet_python_sdk_properties.ini')
12+
"""get settled batch list"""
1513
merchantAuth = apicontractsv1.merchantAuthenticationType()
1614
merchantAuth.name = constants.apiLoginId
1715
merchantAuth.transactionKey = constants.transactionKey
1816

1917
settledBatchListRequest = apicontractsv1.getSettledBatchListRequest()
2018
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)
2222
settledBatchListRequest.lastSettlementDate = datetime.now()
2323

2424
settledBatchListController = getSettledBatchListController(settledBatchListRequest)
25-
2625
settledBatchListController.execute()
2726

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))
5697
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.')
59104

60-
return settledBatchListResponse
105+
return response
61106

62107
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
63108
get_settled_batch_list()

0 commit comments

Comments
 (0)