1
createHeadless(clientToken: string): Promise<PrimerHeadlessCheckout>
ts
copy
Create an instance of PrimerHeadlessCheckout, which is used to interact with the Primer API in a headless environment.
- The
configure
method allows you to set the options for the checkout such as its style, payment method options, and callbacks. - The
start
method must be called to begin the checkout process after theconfigure
method is called.
Parameters
clientTokenstring
A string containing a client token as returned by the Primer API when you create a client session.
Returns
Promise<PrimerHeadlessCheckout>
A promise that resolves with an instance of PrimerHeadlessCheckout, which can be used to create and manage payments with your own UI components.
Example
See guide on initializing Headless Checkout for more details.
12345678910111213141516
import { Primer } from '@primer-io/checkout-web' const clientToken = 'YOUR_CLIENT_TOKEN'const paymentMethodType = 'PAYMENT_CARD' async function createHeadlessCheckout() { const primerHeadlessCheckout = await Primer.createHeadless(clientToken) // Use the instance to create a payment method manager const paymentMethodManager = await primerHeadlessCheckout.createPaymentMethodManager(paymentMethodType) // Configure the checkout with the desired options primerHeadlessCheckout.configure({ // Options... }) // Start the checkout process primerHeadlessCheckout.start()}
ts
copy