【发布时间】:2020-08-02 19:41:40
【问题描述】:
我在下面使用的这段代码运行良好,除了结帐完成时,我注意到每次有人在我的网站上结帐时都会输入两个客户条目。
一个有默认源集,一个没有。我附上了截图。
https://i.ibb.co/8dd0Cxz/Screenshot-from-2020-04-20-11-15-25.png
@login_required
def checkout(request):
if request.method == 'POST':
plan = Plan.objects.get(nickname=request.POST['plan'])
stripe_customer = stripe.Customer.create(
email=request.user.email, source=request.POST['stripeToken'])
stripe_subscription = stripe.Subscription.create(customer=stripe_customer.id,
items=[
{'plan': plan.id}],
trial_from_plan=True)
# Tried removing but no the reason for the issue.
Subscription.sync_from_stripe_data(
stripe_subscription
)
return redirect('settings')
else:
if request.method == 'GET':
plan = Plan.objects.get(nickname=request.GET['plan'])
return render(request, 'plans/checkout.html',
{'plan': plan, 'price': '0'})
我尝试将 {'plan':plan.id} 更改为 {'plan':plan} 并出现错误:
请求 req_0WL0lW2orGwLMV:没有这样的计划:家庭;存在一个名称为 Family,但其 ID 为 plan_H5fvA8jJ0qX9qF。
edit: dj-stripe+webhooks 正在使用,但我需要使用官方 API 创建客户。似乎在(出于某种原因)创建订阅后最后创建了重复的客户(没有付款来源)
【问题讨论】:
-
如果您查看 Stripe 仪表板中的 Customer 对象,则会有一个 Logs 部分说明您是哪个 API 请求创建它的。这是一个很好的起点,可以查看创建它的请求并通过您的代码进行跟踪。
-
我在挖。似乎是在(出于某种原因)创建订阅之后最后创建了重复的客户(没有付款来源)。
-
可能是用户双击了前端,或者前端发送了两次请求,你最终调用了
stripe.Customer.create,但是POST 正文为零或没有令牌。 -
不,是我在测试。我不排除 HTML/JS 做错了什么。
标签: python django python-3.x stripe-payments