Callbacks instead of events
If you prefer not to use event emitters, you can supply callback functions directly in thecreateCheckout
options for success, error, and status changes. This provides a quick way to handle outcomes without separately registering event listeners:
'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).
Custom Primer options
Primer’s Universal Checkout supports various configuration options (payment methods, button styles, etc.). You can pass these through the Billing SDK via theuniversalCheckoutOptions
field when creating a checkout. These options will be forwarded to Primer’s SDK.
For example, to customize the PayPal button color and payment flow, and apply custom style overrides:
gold
and use a specific payment flow. You can similarly configure other payment methods and UI aspects.
Learn more about all available universalCheckoutOptions
in Primer’s documentation.
Manual session creation
For full control over the checkout flow, you can manually create a client session and then launch the Primer 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).1. Create client session
Create a client session to get aclientToken
(and orderId
):
2. Show Primer checkout
Use the obtainedclientToken
to show the Primer checkout UI:
createClientSession
, you might send the clientToken
to your frontend (or generate it on the frontend as shown above). Then, showUniversalCheckout
renders the payment form.
The onTokenizeSuccess
callback gives you the opportunity to handle the payment token (data
) as needed.
Once your server confirms the payment or subscription creation, you call handler.handleSuccess()
to let the Primer UI know it can show a success state (or call handler.handleFailure()
to show an error state).
This advanced approach is useful for integrating additional custom business logic into the payment flow.