Using "Subscriptions with Checkout" and setting a default payment source

1,734 views
Skip to first unread message

Alex Wait

unread,
Apr 8, 2021, 6:54:13 PM4/8/21
to api-d...@lists.stripe.com
Here's what I got going on.

1) New user signs up
2) I create a stripe customer object for them
3) I create a subscription checkout session (https://stripe.com/docs/billing/subscriptions/checkout) and they complete the process
4) Everything works great, I can query the customer object and see the card_ object there

However if I attempt to create subscription object direclty using the API and the customer ID created in step 1 it says  

Error: This customer has no attached payment source or default payment method..

I've looked through the docs and I can't seem to figure out if there is a way to get the payment method they set during the checkout process and set that as the default source.

Is this possible?

Thanks so much for your help!

Alex Wait

Remi J.

unread,
Apr 8, 2021, 7:02:56 PM4/8/21
to Stripe API Discussion
Hey Alex,

When you create a Subscription we usually try to charge the customer's card synchronously for the first invoice. For this to work, we need to know which payment method you want us to charge and by default, without this information, the payment will fail.

What you should do here is explicitly indicate which PaymentMethod (pm_123) should be used for that Subscription. This is done by passing the `default_payment_method` parameter on Subscription creation for example. Alternatively, you can also set the default payment method on the Customer itself via the `invoice_settings[default_payment_method]` [2] so that it applies to future invoices and subscriptions.

During Checkout, we will automatically use the former and set it on the Subscription as we create it. If you want to create a separate Subscription later you will need to track that PaymentMethod id (pm_123) back from the completed Session itself by looking at the associated subscription's default payment method for example.

I hope this helps!
Remi


--
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.

Alex Wait

unread,
Apr 12, 2021, 3:34:50 PM4/12/21
to api-d...@lists.stripe.com
Thanks so much! Totally cleared up our issue we were having!

Alex
--
Buoyancy and displacement float my boat.
Reply all
Reply to author
Forward
0 new messages