1

On my server I create a payment intent based on Stripes docs with:

const subscription = await stripe.subscriptions.create({
    customer: customer.id,
    items: [{ price: getPricePlan(plan) }],
    payment_behavior: "default_incomplete",
    payment_settings: { save_default_payment_method: "on_subscription" },
    expand: ["latest_invoice.payment_intent"],
  });

Then I pass the client_secret to my front end and I render the Stripe Payment Component (React)

<Elements options={{ clientSecret }} stripe={stripePromise}>
  <PaymentElement
    onChange={(e) => {
      setIsPaymentFormCompleted(e.complete);
    }}
  />
  <Button
    onClick={async () => {
      const response = await stripe.confirmPayment({
        type: "card",
        elements,
        redirect: "if_required",
      });
    }}
  >
    Pay Now
  </Button>
</Elements>;

After I enter the card details and pay, the subscription is created, the first payment works but the card used does not become the default. This means that for the subsequent payment (like month 2 of the subscription for example) the payment will fail, since there is no default payment method.

This is super strange. Any idea why the card does not get set as a default given the save_default_payment_method: "on_subscription" is passed?

johnnyshrewd
  • 1,038
  • 2
  • 12
  • 29

1 Answers1

1

Setting payment_settings.save_default_payment_method to on_subscription when creating the Subscription should save the Payment Method as the default on the Subscription.

If you retrieve the Subscription using the Subscription ID you should see the Payment Method ID in the default_payment_method property. You can also confirm the value of payment_settings.save_default_payment_method is set to on_subscription as expected.

Justin Michael
  • 5,634
  • 1
  • 29
  • 32
  • 1
    Well, it's not setting it. If I open the Dashboard it gives me the option to manually set it as default so I assume it's not working. Do you think this is a problem with the "confirmPayment" I see in the stripe example that they use confirmParams: {return_url: "https://example.com/order/123/complete",} instead of what I use – johnnyshrewd Apr 19 '23 at 23:21
  • Is there a "default card for the subscription" vs "default card for the customer" differentiation? When I open the customer tab I see the option to Set As Default in the customers Payment Methods – johnnyshrewd Apr 19 '23 at 23:25
  • Maybe. If you [look at the Subscription creation request and the confirmation request in your Dashboard](https://dashboard.stripe.com/test/logs) what does it show for the parameters being passed in? – Justin Michael Apr 19 '23 at 23:25
  • Yeah, there are different defaults for [Customers](https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method) and [Subscriptions](https://stripe.com/docs/api/subscriptions/object#subscription_object-default_payment_method). – Justin Michael Apr 19 '23 at 23:26
  • 1
    Looking at the call to /v1/subscription I see that I am passing "save_default_payment_method": "on_subscription"; and I see the default_payment_method as null then in the / /v1/payment_intents/pi_XXX/confirm I see "payment_method": "pm_XXX". I think It works. If I open the subscription I see a payment method associated to it. With the ones where I had issues it shows no payment method. It only shows Billign: "Charge default payment method" – johnnyshrewd Apr 19 '23 at 23:42