【问题标题】:Stripe-Api: How to get the "PaymentMethod" (ID) from the Customer Object?Stripe-Api:如何从客户对象中获取“PaymentMethod”(ID)?
【发布时间】:2019-12-25 18:05:27
【问题描述】:

在强客户身份验证 (SCA) 之前,我可以使用 $customer->sources['data'] 从客户对象中获取源集合

现在我正在尝试迁移到 SCA,但无法弄清楚如何在不将其保存到数据库的情况下通过客户对象获取“paymentMethod”。

这里又是文档:https://stripe.com/docs/payments/cards/saving-cards#save-payment-method-without-payment

但为了简短起见,我这样保存“paymentMethod”:

// This creates a new Customer and attaches the PaymentMethod in one API call.
\Stripe\Customer::create([
  'payment_method' => $intent->payment_method,
]);

但是,客户对象无法公开访问 Payment-Method-ID。

有没有可能得到它?

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

    PaymentMethods 没有嵌入到 Customer 对象本身,也不会出现在 $customer->sources 中。相反,您可以例如使用 API [0] 列出它们或直接检索给定的 ID(您也可以将其保存在与客户 ID 关联的数据库中以及您的用户信息中)。

    $customer = \Stripe\Customer::create([
      'payment_method' => $intent->payment_method,
    ]);
    
    $cards = \Stripe\PaymentMethod::all([
      "customer" => $customer->id, "type" => "card"
    ]);
    
    /*
    OR
    */
    
    $card = \Stripe\PaymentMethod::retrieve($intent->payment_method);
    

    [0] - https://stripe.com/docs/api/payment_methods/list

    【讨论】:

      猜你喜欢
      • 2019-10-28
      • 2017-11-30
      • 2018-09-28
      • 2019-01-11
      • 2021-11-13
      • 2020-07-30
      • 1970-01-01
      • 2011-03-16
      • 1970-01-01
      相关资源
      最近更新 更多