【问题标题】:Retrieve Stripe customer by E-mail | Django通过电子邮件检索 Stripe 客户 |姜戈
【发布时间】:2020-11-15 06:55:31
【问题描述】:

我正在尝试一种方法来弄清楚如何通过电子邮件检索 Stripe 客户:

在我看来,我写了以下代码:

    if stripe.Customer.retrieve(email=request.POST['email']):
        customer = stripe.Customer.retrieve(id)
    else:
        customer = stripe.Customer.create(
            email=request.POST['email'],
            name=request.POST['nickname'],
        )

    charge = stripe.Charge.create(
        customer=customer,
        amount=500,
        currency='brl',
        description='First Test Ever!',
        source=request.POST['stripeToken'],
    )

基本上,如果客户是通过他们的电子邮件找到的,那么我不需要创建新帐户。否则,将创建帐户。最后一步是向新客户或现有客户收费。

代码无法正常工作。我认为这是搜索现有客户的错误方法。

有什么帮助吗?

谢谢!

【问题讨论】:

标签: django stripe-payments


【解决方案1】:

您无法通过电子邮件检索单个客户,因为您可以有多个客户使用相同的电子邮件地址 - 这不是唯一值。

相反,您可以列出与该电子邮件匹配的 [0] 个客户,然后自行决定是否有任何结果是您想要的。

[0]https://stripe.com/docs/api/customers/list#list_customers-email

【讨论】:

  • 谢谢!由于我阻止用户使用同一电子邮件创建多个帐户,因此该列表仅返回 1 条记录。
猜你喜欢
  • 2015-01-02
  • 2010-11-11
  • 1970-01-01
  • 2022-11-25
  • 2014-08-05
  • 2021-12-12
  • 1970-01-01
  • 2022-01-13
  • 2014-12-01
相关资源
最近更新 更多