cancel
Showing results for 
Search instead for 
Did you mean: 

Accept.js with ARB python

I'm trying to create a subscription.

 

There is this python gist

 

The problem is this does it with the credit card info.  I'm trying to use the authorize.net accept.js and pass that to make the subscription.

 

Is there a sample code of this?

nadermx
Contributor
1 REPLY 1

I've managed to get the subscription working with the accept.js, but the problem I'm having now is that it does not populate the description, the customer id, or the customer's email.  Is there something I'm missing?

 

# Create a merchantAuthenticationType object with authentication details
# retrieved from the constants file
merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = app_config.AUTHORIZE_KEYS['apiLoginId']
merchantAuth.transactionKey = app_config.AUTHORIZE_KEYS['transactionKey']
# Set the transaction's refId

# Create the payment object for a payment nonce
opaqueData = apicontractsv1.opaqueDataType()
opaqueData.dataDescriptor = request.form['dataDesc']
opaqueData.dataValue = request.form['dataValue']

# Add the payment data to a paymentType object
paymentOne = apicontractsv1.paymentType()
paymentOne.opaqueData = opaqueData

# Create order information
order = apicontractsv1.orderType()
order.invoiceNumber = "10101"
order.description = "Your Description"

# Set the customer's identifying information
customerData = apicontractsv1.customerDataType()
customerData.type = "individual"
customerData.id = 'cool_1231123"
customerData.email = email@email.com

paymentschedule = apicontractsv1.paymentScheduleType()
paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval() # apicontractsv1.CTD_ANON() #modified by krgupta
paymentschedule.interval.length = 1
paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.months
paymentschedule.startDate = datetime.now(pytz.timezone('US/Mountain'))
paymentschedule.totalOccurrences = 999
# Giving the credit card info
# Setting billing information
billto = apicontractsv1.nameAndAddressType()
billto.firstName = request.form['first']
billto.lastName = request.form['last']
billto.email = request.form['email']
# Setting subscription details
subscription = apicontractsv1.ARBSubscriptionType()
subscription.name = "Monthly Subscription"
subscription.description = "Monthly"
subscription.paymentSchedule = paymentschedule
subscription.amount = Decimal(request.form['amount'])
subscription.billTo = billto
subscription.payment = paymentOne
# Creating the request
arbrequest = apicontractsv1.ARBCreateSubscriptionRequest()
arbrequest.merchantAuthentication = merchantAuth
arbrequest.subscription = subscription
# Creating and executing the controller
controller = ARBCreateSubscriptionController(arbrequest)
controller.execute()
# Getting the response
response = controller.getresponse()

if response is not None:
# Check to see if the API request was successfully received and acted upon
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)

Any help would be greatful

nadermx
Contributor