Skip to main content
Creates and opens a new checkout session for a given price and customer, and renders the payment UI on the page. This is the primary method to initiate a subscription checkout.

Parameters

orgId
string
required
Your organization ID, if not already configured globally. Useful if you did not call configure() or need to override it for this checkout.
priceId
string
required
The price identifier for the subscription or product.
customer
object
required
Customer information.
container
string
required
A CSS selector for the DOM element where the checkout form will be mounted.
orgId
string
Organization ID, if not already configured globally. Useful if you did not call configure() or need to override it for this checkout.
clientMetadata
object
Additional metadata to associate with this checkout or customer. This data will be passed through to your backend.
cardSelectors
object
Custom CSS selectors for card input fields. If not provided, FunnelFox will auto-generate the payment form.
paypalButtonContainer
string
CSS selector for the element where the PayPal button will be rendered.
googlePayButtonContainer
string
CSS selector for the element where the Google Pay button will be rendered.
applePayButtonContainer
string
CSS selector for the element where the Apple Pay button will be rendered.
paymentMethodOrder
array
Array of payment method identifiers to control the display order. Available values: 'PAYMENT_CARD', 'PAYPAL', 'GOOGLE_PAY', 'APPLE_PAY'. Defaults to ['PAYMENT_CARD', 'PAYPAL', 'GOOGLE_PAY', 'APPLE_PAY'].
onInitialized
function
Callback invoked when the checkout has been initialized and is ready.
onSuccess
function
Callback to execute when the payment is successful. An alternative to listening for the 'success' event.
onError
function
Callback for handling errors. Alternative to the 'error' event.
onStatusChange
function
Callback invoked on every status change. Alternative to the 'status-change' event.

Returns

A Promise<CheckoutInstance> that resolves to a CheckoutInstance object representing the checkout session. You can use this object to monitor events or perform actions on the active checkout.

Example

import { createCheckout } from '@funnelfox/billing';

const checkout = await createCheckout({
  // Required
  priceId: 'price_123',
  customer: {
    externalId: 'user_456',
    email: '[email protected]',
    countryCode: 'US', // Optional
  },
  container: '#checkout-container',

  // Optional
  orgId: 'your-org-id', // If not configured globally
  clientMetadata: { source: 'web' },
  cardSelectors: {
    // Custom card input selectors (optional, defaults to auto-generated)
    cardNumber: '#cardNumberInput',
    expiryDate: '#expiryInput',
    cvv: '#cvvInput',
    cardholderName: '#cardHolderInput',
    button: '#submitButton',
  },
  paypalButtonContainer: '#paypalButton', // Optional
  googlePayButtonContainer: '#googlePayButton', // Optional
  applePayButtonContainer: '#applePayButton', // Optional
  paymentMethodOrder: ['PAYMENT_CARD', 'PAYPAL', 'GOOGLE_PAY', 'APPLE_PAY'], // Optional

  // Callbacks (alternative to events)
  onInitialized: () => {
    /* ... */
  },
  onSuccess: result => {
    /* ... */
  },
  onError: error => {
    /* ... */
  },
  onStatusChange: (state, oldState) => {
    /* ... */
  },
});