Features
Payments
Handling payments with Stripe
By default SvelteLaunch is setup using checkout sessions with stripe checkout. It's the easiest and
fastest way to get your app up and running with. It supports Stripe Link
right out of the box.
You can also build your own checkout flow. We provide you with access to svelte-stripe
and all of its components to build any checkout flow you like. This is the official Stripe library
for building checkout flows in svelte.
When building your own checkout flow with the new Stripe API you will need to create a payment intent
.
We have provided an API endpoint at /api/payments/payment-intent/create
to generate one should you go that route.
Creating your own checkout flow is beyond the scope of this documentation and we recommend checking out the provided resources for more information.
Resources: svelte-stripe, Stripe Payments
Introduction
In SvelteLaunch payments are 1st priorty when building apps. Your payments should never be behind an authentication, but it's difficult when you start involving OAuth and all the other ways you can login to an account before you've paid even when you don't want them to. There's no way around it.
SvelteLaunch has separated concerns between payments(subscriptions) and accounts. When a user creates an account via magiclink or OAuth they might not necessarily have access to your application until they've created a subscription. Subscriptions are provisioned after payment and can be found in your stripe webhooks.
It's quite flexible and easy to account for free options or just change it to suite your specific needs for each application you build.
For an interesting read on why we do it this way learn about the $300,000,000 button.Helper Functions
Access helper functions by importing from $lib/payments
When creating a new checkout session you need to have unique priceId
for each subscription/price/length.
You can get a priceId by creating a product in your
Stripe dashboard.
createCheckoutSession()
createPaymentIntent()
openBillingPortal()
Subscriptions
To set your checkout session to subscriptions when calling createCheckoutSession
pass the mode
as 'subscription'
Payments
To set your checkout session to subscriptions when calling createCheckoutSession
pass the mode
as 'payment'
Billing Portal
To create a portal session pass the customer-portal
type to /api/payments/session/create
Webhooks
When a user completes a checkout session they will be redirected to /checkout/success
. However,
there is no gaurentee they will make it to our thank you page. There are many reasons why such as
losing power, closing their browser, etc.
Therefor, once a user completes purchase we want to handle account provisioning and maintenance via webhooks.
You can find your webhook endpoint at routes/api/payments/webhooks
API Endpoint
Your session endpoint is located at /api/payments/session/create
Testing
When testing payments locally you will need to forward webhooks to your dev machine with stripe cli