svelte-stripe
svelte-stripe copied to clipboard
Add example of subscriptions
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.
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
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:
- On the server side, create the customer object.
- On the server side, create the subscription object, attaching the customer and price_id.
- If you set expand: ["latest_invoice.payment_intent"], it'll return the payment intent.
- 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
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:
- On the server side, create the customer object.
- On the server side, create the subscription object, attaching the customer and price_id.
- If you set expand: ["latest_invoice.payment_intent"], it'll return the payment intent.
- 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.
Thanks @coin-au-carre, glad you figured it out, and thanks for sharing the link.
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:
- On the server side, create the customer object.
- On the server side, create the subscription object, attaching the customer and price_id.
- If you set expand: ["latest_invoice.payment_intent"], it'll return the payment intent.
- 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."
@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?
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.
Perfect, thank you!