我正在尝试创建一个条带订阅,然后向客户收取该订阅的费用。我的条带交易在仪表板上显示为“未完成”,因为它们没有付款。在
前端端正在使用条纹.js成功地使用了预先制作的stripe信用卡表单,但我不确定用于创建订阅和收费的后端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")
...
听起来你的客户没有附加卡,所以在创建订阅时不会支付订阅费!在
如果您已经创建了客户,您应该执行以下操作:
相关问题 更多 >
编程相关推荐