If you prefer not to use event emitters, you can supply callback functions directly in the createCheckout options for success, error, and status changes. This provides a quick way to handle outcomes without separately registering event listeners:
Using callbacks is equivalent to listening for the 'success', 'error', and 'status-change' events on the CheckoutInstance.Internally, the SDK will trigger these callbacks at the same time as the events. Choose the approach (callbacks vs. event listeners) that fits your application style; you can even mix them (for example, provide an onSuccess callback but also listen for 'status-change' events).
In the above snippet, we provide custom CSS selectors for card input fields and payment method button containers. If you don’t specify cardSelectors, FunnelFox will automatically generate the payment form for you.
For full control over the checkout flow, you can manually create a client session and then use it with Primer’s Headless Checkout.This is useful if you need to perform custom steps between tokenization and finalizing payment (for example, if you want to process the payment on your backend before confirming the UI).
Use the obtained clientToken with Primer’s Headless Checkout:
Report incorrect code
Copy
Ask AI
const headlessCheckout = await Primer.createHeadless(session.clientToken, { paymentHandling: 'MANUAL', apiVersion: '2.4', onTokenizeSuccess: async (paymentMethodTokenData, handler) => { // Your custom payment logic... // Call your payment API with paymentMethodTokenData.token handler.handleSuccess(); },});await headlessCheckout.start();
In this flow, you manually control when to display the checkout and what happens with the payment data. After calling createClientSession, you initialize Primer’s Headless Checkout with the clientToken.The onTokenizeSuccess callback gives you the opportunity to handle the payment token (paymentMethodTokenData.token) as needed.Once your server confirms the payment or subscription creation, you call handler.handleSuccess() to complete the flow (or call handler.handleFailure() if an error occurred).This advanced approach is useful for integrating additional custom business logic into the payment flow.
By default, payment methods are shown in the order: Card, PayPal, Google Pay, Apple Pay. You can reorder them to match your business priorities or regional preferences.