Staq.js

getStripeCheckoutSession

getStripeCheckoutSession

This function is a helper for creating a Stripe Checkout Session. It pings a corresponding backend function to create a short-term session that can be used to allow a customer to pay for one-time purchases or subscriptions through Stripe Checkout.

Import

import { getStripeCheckoutSession } from '@staqjs/client'

API

type: function

signature:

(uid: string, customerId: string, priceId: string) => Promise<Session>

This function takes a user ID, a Stripe Customer ID, and a Stripe Price ID.

When successful, the function returns a Promise which resolves to the Session object. Use the session object to call redirectToCheckout.

When unsuccessful, the Promise resolves to an error.

Example Usage

import { getStripeCheckoutSession, withAuth, withStripe } from '@staqjs/client'
function Dashboard(props) {
import { auth, stripe } = props
const onClickCheckoutBtn = () => {
setLoadingCheckoutSession(true)
getStripeCheckoutSession(
auth.currentUser.uid,
auth.currentUser.stripeCustomerId,
'price_1I2n7cAVNzJkebq9qZajEq0E'
)
.then((result) => {
setLoadingCheckoutSession(false)
return stripe.redirectToCheckout({ sessionId: result.data.id })
})
.catch((error) => {
console.error(error)
// error handling
})
}
// ... code ...
}
export default withAuth(withStripe(Dashboard))
Edit this page on GitHub

On this page