|
| 1 | +from authorizenet import apicontractsv1 |
| 2 | +from authorizenet.apicontrollers import * |
| 3 | +from decimal import * |
| 4 | +from datetime import * |
| 5 | +# Setting the merchant details |
| 6 | +merchantAuth = apicontractsv1.merchantAuthenticationType() |
| 7 | +merchantAuth.name = '5KP3u95bQpv' |
| 8 | +merchantAuth.transactionKey = '4Ktq966gC55GAX7S' |
| 9 | +# Setting payment schedule |
| 10 | +paymentschedule = apicontractsv1.paymentScheduleType() |
| 11 | +paymentschedule.interval = apicontractsv1.CTD_ANON() |
| 12 | +paymentschedule.interval.length = 1 |
| 13 | +paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.months |
| 14 | +paymentschedule.startDate = datetime(2020, 8, 30) |
| 15 | +paymentschedule.totalOccurrences = 12 |
| 16 | +paymentschedule.trialOccurrences = 1 |
| 17 | +# Giving the credit card info |
| 18 | +creditcard = apicontractsv1.creditCardType() |
| 19 | +creditcard.cardNumber = "4111111111111111" |
| 20 | +creditcard.expirationDate = "2020-12" |
| 21 | +payment = apicontractsv1.paymentType() |
| 22 | +payment.creditCard = creditcard |
| 23 | +# Setting billing information |
| 24 | +billto = apicontractsv1.nameAndAddressType() |
| 25 | +billto.firstName = "John" |
| 26 | +billto.lastName = "Smith" |
| 27 | +# Setting subscription details |
| 28 | +subscription = apicontractsv1.ARBSubscriptionType() |
| 29 | +subscription.name = "Sample Subscription" |
| 30 | +subscription.paymentSchedule = paymentschedule |
| 31 | +subscription.amount = Decimal('22.29') |
| 32 | +subscription.trialAmount = Decimal('0.00') |
| 33 | +subscription.billTo = billto |
| 34 | +subscription.payment = payment |
| 35 | +# Creating the request |
| 36 | +request = apicontractsv1.ARBCreateSubscriptionRequest() |
| 37 | +request.merchantAuthentication = merchantAuth |
| 38 | +request.subscription = subscription |
| 39 | +# Creating and executing the controller |
| 40 | +controller = ARBCreateSubscriptionController(request) |
| 41 | +controller.execute() |
| 42 | +# Getting the response |
| 43 | +response = controller.getresponse() |
| 44 | + |
| 45 | +if (response.messages.resultCode=="Ok"): |
| 46 | + print "SUCCESS:" |
| 47 | + print "Message Code : %s" % response.messages.message[0].code |
| 48 | + print "Message text : %s" % response.messages.message[0].text |
| 49 | + print "Subscription ID : %s" % response.subscriptionId |
| 50 | +else: |
| 51 | + print "ERROR:" |
| 52 | + print "Message Code : %s" % response.messages.message[0].code |
| 53 | + print "Message text : %s" % response.messages.message[0].text |
| 54 | + |
| 55 | + |
| 56 | + |
0 commit comments