svelte-stripe icon indicating copy to clipboard operation
svelte-stripe copied to clipboard

Add example of subscriptions

Open lgs opened this issue 2 years ago • 2 comments

Hey @joshnuss great work so far :+1:

It should be great having Subscriptions API implemented, and showed as Exampes.

Here it is another Stripe Subscriptions on Svelte implementation to compare to.

lgs avatar Mar 27 '22 08:03 lgs

Hi @lgs

This is on the roadmap, we will eventually have a starter kit for SvelteKit with Subscriptions.

In the meantime if you have any questions, feel free to drop them there

joshnuss avatar Mar 28 '22 14:03 joshnuss

I plan to create a demo after SvelteKit reaches 1.0.

In the meantime, if anyone is curious how to do it, here is the rough idea:

  1. On the server side, create the customer object.
  2. On the server side, create the subscription object, attaching the customer and price_id.
  3. If you set expand: ["latest_invoice.payment_intent"], it'll return the payment intent.
  4. Then you can use the payment intent with any components in this library.

You can see an example using node/express here: https://github.com/stripe-samples/subscriptions-with-card-and-direct-debit/blob/main/server/node/server.js

joshnuss avatar Oct 02 '22 20:10 joshnuss

I plan to create a demo after SvelteKit reaches 1.0.

In the meantime, if anyone is curious how to do it, here is the rough idea:

  1. On the server side, create the customer object.
  2. On the server side, create the subscription object, attaching the customer and price_id.
  3. If you set expand: ["latest_invoice.payment_intent"], it'll return the payment intent.
  4. Then you can use the payment intent with any components in this library.

You can see an example using node/express here: https://github.com/stripe-samples/subscriptions-with-card-and-direct-debit/blob/main/server/node/server.js

The proposed steps do not seem to work for me. When creating the subscription, Stripe sends a 400 saying:

"This customer has no attached payment source or default payment method. Please consider adding a default payment method. For more information, visit https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority."

It seems that a payment must be proceed already in order to create the subscription.

Edit: I have succeeded implemented Subscription with paymentIntent by following these steps https://stackoverflow.com/a/62456011. Note that it is possible to use paymentIntent instead of setupIntent to confirm a default payment method.

coin-au-carre avatar Nov 28 '22 15:11 coin-au-carre

Thanks @coin-au-carre, glad you figured it out, and thanks for sharing the link.

joshnuss avatar Nov 30 '22 19:11 joshnuss

I plan to create a demo after SvelteKit reaches 1.0. In the meantime, if anyone is curious how to do it, here is the rough idea:

  1. On the server side, create the customer object.
  2. On the server side, create the subscription object, attaching the customer and price_id.
  3. If you set expand: ["latest_invoice.payment_intent"], it'll return the payment intent.
  4. Then you can use the payment intent with any components in this library.

You can see an example using node/express here: https://github.com/stripe-samples/subscriptions-with-card-and-direct-debit/blob/main/server/node/server.js

The proposed steps do not seem to work for me. When creating the subscription, Stripe sends a 400 saying:

"This customer has no attached payment source or default payment method. Please consider adding a default payment method. For more information, visit https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority."

It seems that a payment must be proceed already in order to create the subscription.

Edit: I have succeeded implemented Subscription with paymentIntent by following these steps https://stackoverflow.com/a/62456011. Note that it is possible to use paymentIntent instead of setupIntent to confirm a default payment method.

I'm currently also struggling a bit with this, do you mind elaborating on how you solved the "This customer has no attached payment source or default payment method. Please consider adding a default payment method. For more information, visit https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority."

Chrisphy avatar Dec 17 '22 00:12 Chrisphy

@joshnuss, we are currently looking for a sveltekit/stripe integration, but in our case we want to use subscriptions as well, do you have an ETA when examples for this might show up in the docs?

perostlin avatar May 31 '23 14:05 perostlin

Hi,

I've created an example of using Stripe Subscriptions & Payment Element with SvelteKit: https://github.com/joshnuss/sveltekit-stripe-subscriptions

Please give it a try and let me know if you have any further questions! Happy to look into them.

joshnuss avatar Jun 01 '23 23:06 joshnuss

Perfect, thank you!

perostlin avatar Jun 07 '23 08:06 perostlin