Search code examples
recurly

Creating Recurly BillingInfo using only a token_id


I have a Recurly token and am trying to start a subscription using it. I am following the example code snippets, such as the one in the right panel here.

subscription = recurly.Subscription(
  plan_code = 'bazooka_monthly',
  account = recurly.Account(
    account_code = 'john_rambo',
    billing_info = recurly.BillingInfo(token_id = 'TOKEN_ID')
  )
)
subscription.save

However whenever I try to just pass a token_id to BillingInfo, it complains "subscription.account.billing_info.number is required".

How can I create the BillingInfo with only a token_id without getting this ValidationError?


Solution

  • To solve this problem, I upgraded to the latest version of Recurly client library for Python.

    My billing code ended up looking like this and this works as long as the card number really is valid:

    account_code = "%s_%s" % (int(time.time()), random.randint(0,10**9))
    
    account = recurly.Account(
        account_code = account_code, 
        first_name = form.first_name, 
        last_name = form.last_name,
        email = form.email,
        billing_info = recurly.BillingInfo(
            token_id = form.token
        )
    )
    account.save()
    
    subscription = recurly.Subscription()
    subscription.plan_code = 'bimonthly-candy'
    subscription.currency = 'USD'
    subscription.account = recurly.Account.get(account_code)
    subscription.save()