2
votes

I am trying to setup a subscription for a connect account. My flow is create the customer:

    $customer = \Stripe\Customer::create([
        'description' => "Product",
    ], ['stripe_account' => $configuration['StripeKey']]);

Then I create the PaymentIntent:

    $intent = \Stripe\PaymentIntent::create([
      'amount' => $price,
      'currency' => $configuration['Currency'],
      'customer' => $customer->id,
    ], ['stripe_account' => $configuration['StripeKey']]);

The customer enters their card details and the card is successfully applied to the customer. However I need to set the card as default in order to create a subscription for the customer but when retrieving the paymentIntent with:

 $pm = \Stripe\PaymentIntent::retrieve($_POST['payment_intent'], ['stripe_account' =>  $configuration['StripeKey']]);

The payment_method shows as null despite there being a payment method in the dashboard.

Where am I going wrong here?

1

1 Answers

2
votes

To start off, you're probably not able to see the payment_method when you retrieve the Payment Intent because that field is expandable (see https://stripe.com/docs/expand). You need to update your retrieval code to the following:

$pm = \Stripe\PaymentIntent::retrieve([
  'id'=>$_POST['payment_intent'],
  'stripe_account' =>  $configuration['StripeKey'],
  'expand' => ['payment_method']
]);

In addition, you should set setup_future_usage:off_session when creating the Payment Intent. This will automatically attach the PaymentMethod to your Customer after the Payment Intent is confirmed.

Once the Payment Method has been attached, you can update invoice_settings.default_payment_method on the Customer (https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method) to be the default Payment Method used for Stripe Subscriptions.

That being said, I'm a bit confused why you're creating a PaymentIntent but talking about Subscriptions. Are you managing the Subscription yourself (not using Stripe's Subscription API)? If you are using Stripe's Subscriptions and just want to set up the Payment Method, you could do so with a SetupIntent instead.