【问题标题】:How to get default payment method from Stripe invoice?如何从 Stripe 发票中获取默认付款方式?
【发布时间】:2022-01-21 12:46:13
【问题描述】:

我正在使用我的网络应用收听 Stripe 的 invoice.payment_failed webhook,我想从每张发票中获取 default_payment_method,但由于某种原因,它总是只返回一个空数组!

当我在命令行上查询 Stripe invoice 并像这样展开 default_payment_method...

Stripe::Invoice.retrieve('in_3K6dIY2KgYRkshw2LAzya63P', :expand => "default_payment_method")

...我也得到空数组。这让我很吃惊,因为所有我的 Stripe 客户都有与之关联的默认付款方式。

我在这里错过了什么?

感谢您的帮助。

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    可以在三个独立的地方设置默认付款方式。他们从更具体到不太具体:

    • invoice.default_payment_method(您正在查看)
    • subscription.default_payment_method
    • customer.invoice_settings.default_payment_method

    如果已设置,Stripe 会收取最具体的费用。从 API 读取时,这些值不会从上面的级别继承,它们都可以单独设置,如果没有明确设置,则它们是 null。这就是为什么您在发票级别将其视为null

    相反,您可能希望查看 Subscription 对象或 Customer 对象(并且可以为此利用扩展功能),具体取决于您构建集成的方式以及它设置的对象。

    不过,总体而言,您可能实际上希望在发票付款中使用 PaymentMethod?那将来自last_payment_error

    inv = Stripe::Invoice.retrieve({
       id: 'in_1K8iiKJoUivz182DMzSkuBgp',
       expand: ["customer.invoice_settings.default_payment_method",
           "subscription.default_payment_method",
           "payment_intent"]
      }
    )
    
    print("invoice : #{inv.default_payment_method} \n")
    print("subscription : #{inv.subscription.default_payment_method} \n")
    print("customer : #{inv.customer.invoice_settings.default_payment_method} \n")
    print("failed charge : #{inv.payment_intent.last_payment_error.payment_method} \n") 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-11
      • 2021-02-14
      • 1970-01-01
      • 2019-03-13
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 2021-03-24
      相关资源
      最近更新 更多