Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathcreate-subscription.py
More file actions
Latest commit
65 lines (59 loc) · 2.66 KB
/
Copy pathcreate-subscription.py
File metadata and controls
65 lines (59 loc) · 2.66 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
importos, sys
fromimportlib.machineryimportSourceFileLoader
fromauthorizenetimportapicontractsv1
fromauthorizenet.apicontrollersimport*
constants=SourceFileLoader('modulename', 'constants.py').load_module()
fromdecimalimport*
fromdatetimeimport*
defcreate_subscription(amount, days):
# Setting the merchant details
merchantAuth=apicontractsv1.merchantAuthenticationType()
merchantAuth.name=constants.apiLoginId
merchantAuth.transactionKey=constants.transactionKey
# Setting payment schedule
paymentschedule=apicontractsv1.paymentScheduleType()
paymentschedule.interval=apicontractsv1.paymentScheduleTypeInterval() #apicontractsv1.CTD_ANON() #modified by krgupta
paymentschedule.interval.length=days
paymentschedule.interval.unit=apicontractsv1.ARBSubscriptionUnitEnum.days
paymentschedule.startDate=datetime(2030, 12, 30)
paymentschedule.totalOccurrences=12
paymentschedule.trialOccurrences=1
# Giving the credit card info
creditcard=apicontractsv1.creditCardType()
creditcard.cardNumber="4111111111111111"
creditcard.expirationDate="2035-12"
payment=apicontractsv1.paymentType()
payment.creditCard=creditcard
# Setting billing information
billto=apicontractsv1.nameAndAddressType()
billto.firstName="John"
billto.lastName="Smith"
# Setting subscription details
subscription=apicontractsv1.ARBSubscriptionType()
subscription.name="Sample Subscription"
subscription.paymentSchedule=paymentschedule
subscription.amount=amount
subscription.trialAmount=Decimal('0.00')
subscription.billTo=billto
subscription.payment=payment
# Creating the request
request=apicontractsv1.ARBCreateSubscriptionRequest()
request.merchantAuthentication=merchantAuth
request.subscription=subscription
# Creating and executing the controller
controller=ARBCreateSubscriptionController(request)
controller.execute()
# Getting the response
response=controller.getresponse()
if (response.messages.resultCode=="Ok"):
print ("SUCCESS:")
print ("Message Code : %s"%response.messages.message[0]['code'].text)
print ("Message text : %s"%str(response.messages.message[0]['text'].text))
print ("Subscription ID : %s"%response.subscriptionId)
else:
print ("ERROR:")
print ("Message Code : %s"%response.messages.message[0]['code'].text)
print ("Message text : %s"%response.messages.message[0]['text'].text)
returnresponse
if(os.path.basename(__file__) ==os.path.basename(sys.argv[0])):
create_subscription(constants.amount, constants.days)