Skip to content

Commit 95414ac

Browse files
committed
add sample for getCustomerPaymentProfileList
1 parent bdac275 commit 95414ac

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""http://developer.authorize.net/api/reference/#customer-profiles-get-customer-payment-profile-list"""
2+
import os
3+
import sys
4+
import imp
5+
import time
6+
7+
from authorizenet import apicontractsv1
8+
from authorizenet.apicontrollers import getCustomerPaymentProfileListController
9+
constants = imp.load_source('modulename', 'constants.py')
10+
11+
12+
def get_customer_payment_profile_list():
13+
"""Retrieve a list of customer payment profiles matching the specific search parameters"""
14+
15+
# Create a merchantAuthenticationType object with authentication details
16+
# retrieved from the constants file
17+
merchant_auth = apicontractsv1.merchantAuthenticationType()
18+
merchant_auth.name = constants.apiLoginId
19+
merchant_auth.transactionKey = constants.transactionKey
20+
21+
# Set the transaction's refId
22+
ref_id = "ref{}".format(int(time.time())*1000)
23+
24+
# Set the paging (this particular API call will only return up to 10 results at a time)
25+
paging = apicontractsv1.Paging()
26+
paging.limit = 10
27+
paging.offset = 1
28+
29+
# Set the sorting
30+
sorting = apicontractsv1.CustomerPaymentProfileSorting()
31+
sorting.orderBy = apicontractsv1.CustomerPaymentProfileOrderFieldEnum.id
32+
sorting.orderDescending = "false"
33+
34+
# Set search parameters
35+
search = apicontractsv1.CustomerPaymentProfileSearchTypeEnum.cardsExpiringInMonth
36+
month = "2020-12"
37+
38+
# Creating the request with the required parameters
39+
request = apicontractsv1.getCustomerPaymentProfileListRequest()
40+
request.merchantAuthentication = merchant_auth
41+
request.refId = ref_id
42+
request.paging = paging
43+
request.sorting = sorting
44+
request.searchType = search
45+
request.month = month
46+
47+
controller = getCustomerPaymentProfileListController(request)
48+
controller.execute()
49+
50+
response = controller.getresponse()
51+
52+
if response is not None:
53+
if response.messages.resultCode == apicontractsv1.messageTypeEnum.Ok:
54+
print ("SUCCESS")
55+
print ("Total Num in Result Set: %s" % response.totalNumInResultSet)
56+
for profile in response.paymentProfiles.paymentProfile:
57+
print("Profile ID: %s" % profile.customerProfileId)
58+
print("Payment Profile ID: %s" % profile.customerPaymentProfileId)
59+
try:
60+
print("Card: %s" % profile.payment.creditCard.cardNumber)
61+
except AttributeError:
62+
print("Bank account: %s" % profile.payment.bankAccount.accountNumber)
63+
print()
64+
65+
else:
66+
print ("ERROR")
67+
if response.messages is not None:
68+
print ("Result code: %s" % response.messages.resultCode)
69+
print ("Message code: %s" % response.messages.message[0]['code'].text)
70+
print ("Message text: %s" % response.messages.message[0]['text'].text)
71+
return response
72+
73+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
74+
get_customer_payment_profile_list()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy