繁体   English   中英

Stripe - 检索客户 PaymentIntent 历史记录

[英]Stripe - Retrieve Customer PaymentIntent history

我正在构建一个平台,我正在使用 Stripe 的父“平台”帐户和属于该平台的 Connected Stripe 帐户的概念。 (例如 Lyft 模型) 按照 Stripe 的文档,当我在 Stripe 中创建一个新客户时,我会在主平台帐户下创建它,并将所有付款方式存储在该客户下。 当客户从 Connected 帐户购买东西时,我会按照 文档进行操作,在其中克隆付款方式并创建附加到特定 Connected 帐户的 PaymentIntent。 这一切都有效。 但是,当我尝试获取客户交易的历史记录(PaymentIntents 列表)时,它返回一个空列表,因为它针对主平台帐户运行它:

stripe.PaymentIntent.list(customer='cus_FJDHFGSJHDF')

当我指定一个客户和关联账户 ID 时,它返回一个空列表,因为该客户在该关联账户中不存在,但是,paymentIntents 存在于该关联账户中。

那么,为 Connected 帐户的客户创建 PaymentIntent 然后获取该客户 PER Connected Stripe 帐户的付款历史记录的正确方法是什么?

以下是我克隆 PaymentMethod 并创建 PaymentIntent 的方法:

payment_method = stripe.PaymentMethod.create(
        customer=customer,
        payment_method=customer.invoice_settings.default_payment_method,
        stripe_account=stripe_connect_id,
    )


    intent = stripe.PaymentIntent.create(
        payment_method=payment_method,
        amount=amount,
        currency='usd',
        confirm=True,
        application_fee_amount=fee_in_cents if fee_in_cents >= 1 else None,
        stripe_account=stripe_connect_id,
    )

据我所知,您有两个选择:

  1. 在连接的帐户上创建客户并在那里创建费用,然后您就拥有了关系 [0]。
  2. 将客户 ID 保存在 PaymentIntent 的元数据中,然后在您的代码 [1] 中协调它们。

希望有帮助!

[0] https://stripe.com/docs/connect/cloning-saved-payment-methods#making-a-charge

[1] https://stripe.com/docs/api/metadata

这是我决定采取的方法。 由于我对提取特定客户在特定 Connected 帐户中的费用特别感兴趣,因此我阅读了有关费用的更多信息,并注意到您可以根据transfer_group='{ORDER10}'获得费用清单。 所以,这是我的流程:

  • 客户和客户的付款方式存储在主平台帐户下(以便我可以在一个地方跟踪当前的默认付款方式)
  • 当客户向特定的关联账户付款时,我克隆了他们的默认付款方式
  • 创建一个 PaymentIntent 并将transfer_group设置为客户的电话号码,因为它是整个平台的唯一标识符。

现在,当我需要提取特定客户的所有费用时,我会遍历与客户关联的每个 Connected 帐户(此关系存储在我的平台上),并使用transfer_groupstripe_account_id简单地提取所有费用:

def get_all_charges(user, stripe_account_id):
     return stripe.Charge.list(transfer_group=user.phone_number, stripe_account=stripe_account_id, limit=100).data

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM