簡體   English   中英

Stripe-Api:如何從客戶對象中獲取“ PaymentMethod”(ID)?

[英]Stripe-Api: How to get the “PaymentMethod” (ID) from the Customer Object?

在進行強客戶身份驗證(SCA)之前,我可以使用$customer->sources['data']從Customer對象中獲取source集合。

現在,我正在嘗試遷移到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不能與客戶對象一起公開訪問。

有可能以某種方式獲得它嗎?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM