forked from AuthorizeNet/sample-code-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-customer-profile.py
More file actions
47 lines (40 loc) · 2.31 KB
/
get-customer-profile.py
File metadata and controls
47 lines (40 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os, sys
import imp
from authorizenet import apicontractsv1
from authorizenet.apicontrollers import *
constants = imp.load_source('modulename', 'constants.py')
def get_customer_profile(customerProfileId):
merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = constants.apiLoginId
merchantAuth.transactionKey = constants.transactionKey
getCustomerProfile = apicontractsv1.getCustomerProfileRequest()
getCustomerProfile.merchantAuthentication = merchantAuth
getCustomerProfile.customerProfileId = customerProfileId
controller = getCustomerProfileController(getCustomerProfile)
controller.execute()
response = controller.getresponse()
if (response.messages.resultCode=="Ok"):
print "Successfully retrieved a customer with profile id %s and customer id %s" % (getCustomerProfile.customerProfileId, response.profile.merchantCustomerId)
if hasattr(response, 'profile') == True:
if hasattr(response.profile, 'paymentProfiles') == True:
for paymentProfile in response.profile.paymentProfiles:
print ("paymentProfile in get_customerprofile is:" %paymentProfile)
print ("Payment Profile ID %s" % str(paymentProfile.customerPaymentProfileId))
if hasattr(response.profile, 'shipToList') == True:
for ship in response.profile.shipToList:
print ("Shipping Details:")
print ("First Name %s" % ship.firstName)
print ("Last Name %s" % ship.lastName)
print ("Address %s" % ship.address
print ("Customer Address ID %s" % ship.customerAddressId)
if hasattr(response, 'subscriptionIds') == True:
if hasattr(response.subscriptionIds, 'subscriptionId') == True:
print ("list of subscriptionid:")
for subscriptionid in (response.subscriptionIds.subscriptionId):
print (subscriptionid)
else:
print ("response code: %s" % response.messages.resultCode)
print ("Failed to get customer profile information with id %s" % getCustomerProfile.customerProfileId)
return response
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
get_customer_profile(constants.customerProfileId)