Skip to content

Commit 5d6a1f8

Browse files
author
krgupta
committed
sample code using lxmls objectify
1 parent a62e257 commit 5d6a1f8

File tree

9 files changed

+114
-95
lines changed

9 files changed

+114
-95
lines changed

CustomerProfiles/create-customer-payment-profile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def create_customer_payment_profile(customerProfileId):
2828
createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest()
2929
createCustomerPaymentProfile.merchantAuthentication = merchantAuth
3030
createCustomerPaymentProfile.paymentProfile = profile
31-
createCustomerPaymentProfile.customerProfileId = customerProfileId
31+
print("customerProfileId in create_customer_payment_profile. customerProfileId = %s" %customerProfileId)
32+
createCustomerPaymentProfile.customerProfileId = str(customerProfileId)
3233

3334
controller = createCustomerPaymentProfileController(createCustomerPaymentProfile)
3435
controller.execute()

CustomerProfiles/get-customer-payment-profile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ def get_customer_payment_profile(customerProfileId, customerPaymentProfileId):
2323

2424
if (response.messages.resultCode=="Ok"):
2525
print "Successfully retrieved a payment profile with profile id %s and customer id %s" % (getCustomerPaymentProfile.customerProfileId, getCustomerPaymentProfile.customerProfileId)
26-
26+
'''
2727
if response.paymentProfile.subscriptionIds:
2828
print "list of subscriptionid:"
2929
for subscriptionid in response.paymentProfile.subscriptionIds.subscriptionId:
3030
print subscriptionid
31+
else: #added by krgupta
32+
print "no subscription" #added by krgupta
33+
'''
3134
else:
3235
print "response code: %s" % response.messages.resultCode
3336
print "Failed to get payment profile information with id %s" % getCustomerPaymentProfile.customerPaymentProfileId
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
import os, sys
22
import imp
3-
3+
44
from authorizenet import apicontractsv1
55
from authorizenet.apicontrollers import *
66
constants = imp.load_source('modulename', 'constants.py')
7-
7+
88
def get_customer_profile(customerProfileId):
99
merchantAuth = apicontractsv1.merchantAuthenticationType()
1010
merchantAuth.name = constants.apiLoginId
1111
merchantAuth.transactionKey = constants.transactionKey
12-
12+
1313
getCustomerProfile = apicontractsv1.getCustomerProfileRequest()
1414
getCustomerProfile.merchantAuthentication = merchantAuth
1515
getCustomerProfile.customerProfileId = customerProfileId
1616
controller = getCustomerProfileController(getCustomerProfile)
1717
controller.execute()
18-
18+
1919
response = controller.getresponse()
20-
20+
2121
if (response.messages.resultCode=="Ok"):
2222
print "Successfully retrieved a customer with profile id %s and customer id %s" % (getCustomerProfile.customerProfileId, response.profile.merchantCustomerId)
23-
for paymentProfile in response.profile.paymentProfiles:
24-
print "Payment Profile ID %s" % paymentProfile.customerPaymentProfileId
25-
for ship in response.profile.shipToList:
26-
print "Shipping Details:"
27-
print "First Name %s" % ship.firstName
28-
print "Last Name %s" % ship.lastName
29-
print "Address %s" % ship.address
30-
print "Customer Address ID %s" % ship.customerAddressId
31-
32-
if response.subscriptionIds:
33-
print "list of subscriptionid:"
34-
for subscriptionid in response.subscriptionIds.subscriptionId:
35-
print subscriptionid
23+
if hasattr(response, 'profile') == True:
24+
if hasattr(response.profile, 'paymentProfiles') == True:
25+
for paymentProfile in response.profile.paymentProfiles:
26+
print ("paymentProfile in get_customerprofile is:" %paymentProfile)
27+
print "Payment Profile ID %s" % str(paymentProfile.customerPaymentProfileId)
28+
if hasattr(response.profile, 'shipToList') == True:
29+
for ship in response.profile.shipToList:
30+
print "Shipping Details:"
31+
print "First Name %s" % ship.firstName
32+
print "Last Name %s" % ship.lastName
33+
print "Address %s" % ship.address
34+
print "Customer Address ID %s" % ship.customerAddressId
35+
if hasattr(response, 'subscriptionIds') == True:
36+
if hasattr(response.subscriptionIds, 'subscriptionId') == True:
37+
print "list of subscriptionid:"
38+
for subscriptionid in (response.subscriptionIds.subscriptionId):
39+
print subscriptionid
3640
else:
3741
print "response code: %s" % response.messages.resultCode
3842
print "Failed to get customer profile information with id %s" % getCustomerProfile.customerProfileId
39-
43+
4044
return response
41-
45+
4246
if(os.path.basename(__file__) == sys.argv[0].split('/')[-1]):
4347
get_customer_profile(constants.customerProfileId)

CustomerProfiles/get-customer-shipping-address.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ def get_customer_shipping_address(customerProfileId, customerAddressId):
2424

2525
if response.messages.resultCode == "Ok":
2626
print "SUCCESS"
27-
print "The address is"
28-
print response.address.firstName +" " + response.address.lastName
29-
print response.address.address
30-
print response.address.city
31-
print response.address.state
32-
print response.address.zip
33-
print response.address.country
34-
35-
if response.subscriptionIds:
36-
print "list of subscriptionid:"
37-
for subscriptionid in response.subscriptionIds.subscriptionId:
38-
print subscriptionid
27+
if hasattr(response, 'address') == True:
28+
print "The address is"
29+
print response.address.firstName +" " + response.address.lastName
30+
print response.address.address
31+
print response.address.city
32+
print response.address.state
33+
print response.address.zip
34+
print response.address.country
35+
if not hasattr(response, 'subscriptionIds'):
36+
print ("no subscriptionIds attr in response")
37+
else:
38+
if hasattr(response, 'subscriptionIds') == True:
39+
if hasattr(response.subscriptionIds, 'subscriptionId') == True:
40+
print "list of subscriptionid:"
41+
for subscriptionid in (response.subscriptionIds.subscriptionId):
42+
print subscriptionid
3943
else:
4044
print "ERROR"
4145
print "Message code : %s " % response.messages.message[0].code

RecurringBilling/create-subscription-from-customer-profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def create_subscription_from_customer_profile(amount, days, profileId, paymentPr
1515
merchantAuth.transactionKey = constants.transactionKey
1616
# Setting payment schedule
1717
paymentschedule = apicontractsv1.paymentScheduleType()
18-
paymentschedule.interval = apicontractsv1.CTD_ANON()
18+
paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval() #apicontractsv1.CTD_ANON() #modified by krgupta
1919
paymentschedule.interval.length = days
2020
paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days
2121
paymentschedule.startDate = datetime(2020, 8, 30)

RecurringBilling/create-subscription.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def create_subscription(amount, days):
1515
merchantAuth.transactionKey = constants.transactionKey
1616
# Setting payment schedule
1717
paymentschedule = apicontractsv1.paymentScheduleType()
18-
paymentschedule.interval = apicontractsv1.CTD_ANON()
18+
paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval() #apicontractsv1.CTD_ANON() #modified by krgupta
1919
paymentschedule.interval.length = days
2020
paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days
2121
paymentschedule.startDate = datetime(2020, 8, 30)
@@ -52,7 +52,7 @@ def create_subscription(amount, days):
5252
if (response.messages.resultCode=="Ok"):
5353
print "SUCCESS:"
5454
print "Message Code : %s" % response.messages.message[0].code
55-
print "Message text : %s" % response.messages.message[0].text
55+
print "Message text : %s" % str(response.messages.message[0].text)
5656
print "Subscription ID : %s" % response.subscriptionId
5757
else:
5858
print "ERROR:"

TransactionReporting/get-settled-batch-list.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,25 @@ def get_settled_batch_list():
2626
if settledBatchListResponse is not None:
2727
if settledBatchListResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok:
2828
print('Successfully got settled batch list!')
29+
30+
#if hasattr(response, 'batch') == True:
31+
#mylist = settledBatchListResponse.batchList.batch
2932

3033
for batchItem in settledBatchListResponse.batchList.batch:
34+
#print ("LOOK batchItem = %s" %batchItem)
3135
print('Batch Id : %s' % batchItem.batchId)
3236
print('Settlement State : %s' % batchItem.settlementState)
3337
print('Payment Method : %s' % batchItem.paymentMethod)
3438
print('Product : %s' % batchItem.product)
3539

36-
if batchItem.statistics:
37-
for statistic in batchItem.statistics.statistic:
38-
print('Account Type : %s' % statistic.accountType)
39-
print('Charge Amount : %s' % statistic.chargeAmount)
40-
print('Refund Amount : %s' % statistic.refundAmount)
41-
print('Decline Count : %s' % statistic.declineCount)
42-
40+
if hasattr(settledBatchListResponse.batchList.batch, 'statistics') == True:
41+
if hasattr(settledBatchListResponse.batchList.batch.statistics, 'statistic') == True:
42+
# if batchItem.statistics:
43+
for statistic in batchItem.statistics.statistic:
44+
print('Account Type : %s' % statistic.accountType)
45+
print('Charge Amount : %s' % statistic.chargeAmount)
46+
print('Refund Amount : %s' % statistic.refundAmount)
47+
print('Decline Count : %s' % statistic.declineCount)
4348
if settledBatchListResponse.messages:
4449
print('Message Code : %s' % settledBatchListResponse.messages.message[0].code)
4550
print('Message Text : %s' % settledBatchListResponse.messages.message[0].text)

list_of_sample_codes.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ delete_customer_payment_profile 1 1
88
delete_customer_profile 1 1
99
delete_customer_shipping_address 1 1
1010
get_customer_payment_profile 1 1
11-
get_customer_profile_ids 1 1
12-
get_customer_profile 1 1
13-
get_customer_shipping_address 1 1
14-
get_hosted_profile_page 1 1
1511
update_customer_payment_profile 1 1
1612
update_customer_profile 1 1
1713
update_customer_shipping_address 1 1
@@ -34,6 +30,9 @@ authorization_only 1 0
3430
credit 1 0
3531
get_details 1 0
3632
prior_authorization_capture 1 0
33+
get_customer_shipping_address 1 0
34+
get_customer_profile 1 0
35+
get_hosted_profile_page 1 0
3736
void 1 0
3837
cancel_subscription 1 0
3938
create_subscription 1 1
@@ -49,3 +48,4 @@ get_transaction_list 1 1
4948
get_unsettled_transaction_list 1 0
5049
create_visa_checkout_transaction 1 0
5150
decrypt_visa_checkout_data 1 0
51+
get_customer_profile_ids 1 1

0 commit comments

Comments
 (0)