【发布时间】:2019-05-21 16:06:23
【问题描述】:
我正在尝试创建条带订阅,然后向客户收取该订阅的费用。我的条带交易在仪表板中显示为“不完整”,因为它们没有被支付。
前端正在使用 stripe.js 使用预制的条纹信用卡表格成功创建令牌,但我不确定用于创建订阅和收费的后端 python 代码是否正确..
订阅费用应立即收取:
"collection_method": "charge_automatically",
...
if request.method == "POST":
try:
token = request.POST['stripeToken']
#Create Stripe Subscription Charge
subscription = stripe.Subscription.create(
customer=user_membership.stripe_customer_id,
items=[
{
"plan": selected_membership.stripe_plan_id,
},
],
)
#Charge Stripe Subscription
charge = stripe.Charge.create(
amount=selected_membership.stripe_price,
currency="usd",
source=token, # obtained with Stripe.js
description=selected_membership.description,
receipt_email=email,
)
return redirect(reverse('memberships:update_transactions',
kwargs={
'subscription_id': subscription.id
}))
except stripe.error.CardError as e:
messages.info(request, "Oops, your card has been declined")
...
【问题讨论】:
-
你用的是哪张测试卡?似乎给定的卡片被划定了。试试
4242424242424242卡
标签: python django stripe-payments