Php 创建paymentIntent后,如何更新Stripe中的客户默认付款方式?

Php 创建paymentIntent后,如何更新Stripe中的客户默认付款方式?,php,stripe-payments,Php,Stripe Payments,我正在尝试为connect帐户设置订阅。我的流程是创建客户: $customer = \Stripe\Customer::create([ 'description' => "Product", ], ['stripe_account' => $configuration['StripeKey']]); 然后我创建PaymentIntent: $intent = \Stripe\PaymentIntent::create(

我正在尝试为connect帐户设置订阅。我的流程是创建客户:

    $customer = \Stripe\Customer::create([
        'description' => "Product",
    ], ['stripe_account' => $configuration['StripeKey']]);
然后我创建PaymentIntent:

    $intent = \Stripe\PaymentIntent::create([
      'amount' => $price,
      'currency' => $configuration['Currency'],
      'customer' => $customer->id,
    ], ['stripe_account' => $configuration['StripeKey']]);
客户输入其卡的详细信息,并将该卡成功应用于客户。 但是,我需要将卡设置为默认卡,以便为客户创建订阅,但在检索paymentIntent时,需要:

 $pm = \Stripe\PaymentIntent::retrieve($_POST['payment_intent'], ['stripe_account' =>  $configuration['StripeKey']]);
尽管仪表板中有付款方法,付款方法仍显示为null


我哪里出错了?

首先,在检索支付意图时,您可能无法看到
支付方法,因为该字段是可扩展的(请参阅)。您需要将检索代码更新为以下内容:

$pm = \Stripe\PaymentIntent::retrieve([
  'id'=>$_POST['payment_intent'],
  'stripe_account' =>  $configuration['StripeKey'],
  'expand' => ['payment_method']
]);
此外,在创建支付意图时,应设置
setup\u future\u用法:off\u session
。这将在确认付款意图后自动将PaymentMethod附加到您的客户

附加付款方式后,您可以更新客户()上的
发票设置。默认付款方式
为条带订阅使用的默认付款方式

话虽如此,我还是有点困惑,为什么你要创建一个PaymentIntent,却要谈论订阅。您是否自己管理订阅(不使用Stripe的订阅API)?如果您正在使用Stripe的订阅,并且只想设置付款方式,则可以使用SetupIntent