我有一个Recurly令牌,我正在尝试使用它开始订阅。我正在关注示例代码段,例如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
然而,每当我尝试将token_id传递给BillingInfo时,它都会抱怨“subscri.account.billing_info.number是必需的”。
如何在不获取此ValidationError的情况下仅使用token_id创建BillingInfo?
答案 0 :(得分:3)
为了解决这个问题,我升级到了Python的Recurly客户端库的最新版本。
我的结算代码最终看起来像这样,只要卡号确实有效,这就有效:
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()