Stripe
Subscriptions and One-time with Stripe
For Initial Setup check out the Stripe docs from Larafast on how to setup One-time payments and Subscriptions.
Subscriptions and One-time Payments
Unlike for TALL or VILT stack, in the API we cannot redirect users directly to the payment page. Instead, we need to create a checkout session and return the checkout url to the Frontend or Mobile App. The client then uses the url to redirect the user to the payment page.
Subscriptions
To create a subscription, you can use subscriptionCheckout
method.
It requires price` is the price id from Stripe Store.
$checkoutData
will contain the checkout session id and the url to redirect the user to the payment page.
success_url
and cancel_url
are the urls that the user will be redirected to after the payment is successful or canceled.
Make sure to add FRONTEND_URL
in your .env
file.
One-time Payments
To create a one-time payment, you can use the productCheckout
method.
It requires $price
parameter. The $price
is the price id in Stripe.
$checkoutData
will contain the checkout session id and the url to redirect the user to the payment page.
success_url
and cancel_url
are the urls that the user will be redirected to after the payment is successful or canceled.
After successful payment, the user will be redirected to the success_url
with the session_id
in the query string.
Use the session id to retrieve the payment details and update the user’s subscription or product.
Send the session_id
to the backend to verify the payment.
Webhook
Check out the Webhook docs from Larafast on how to setup the webhook for Stripe.
Billing Portal
If you want to allow users to manage their subscriptions, you can use the billing portal. Redirect the user to the billing portal url to allow them to manage their subscriptions.
User should be a Stripe customer (means purchased a product or have a subscription) to access the billing portal.