1
configure(options: HeadlessUniversalCheckoutOptions): void
ts
copy

Configure the Headless Checkout instance with the provided options.

Parameters

options
object
Options for a Headless Universal Checkout, its properties can be defined to configure the checkout experience.
onAvailablePaymentMethodsLoad
(paymentMethods: PaymentMethodInfo[]) => voidRequired
Called when the available payment methods have been loaded. Takes an array of objects as its argument.
Parameters
paymentMethods
PaymentMethodInfo[]
Properties
type
PaymentMethodTypeRequired

The type of payment method, one of PaymentMethodType.

managerType
"CARD" | "NATIVE" | "REDIRECT"Required
The type of payment manager to use.
locale
string
This option forces the locale for certain UI elements. By default, the locale will be set to the browser's locale.
Payment lifecycle callbacks
Notifies you before the checkout tokenizes a payment method and creates a payment.
onBeforePaymentCreate
(data: object, handler: object) => void

Called when a payment will be created. Use as an opportunity to update UI accordingly - for example, to display a "loading" component. The handler must be used to then abort or continue with payment creation. Primer will continue with payment creation if onBeforePaymentCreate is not implemented.

Parameters
data
object
Properties

The type of the payment method Primer will use for payment creation, one of PaymentMethodType

handler
object

Provides two methods to continue or abort the payment.

You MUST call one of the methods of the handler if onBeforePaymentCreate is implemented.

Choose to abort a payment.

1
return handler.abortPaymentCreation()
ts
copy

Choose to continue with payment creation

1
return handler.continuePaymentCreation()
ts
copy
onCheckoutComplete
(data: object) => void

Called when a payment has been created. Move on to next step in your checkout flow, such as showing a success message, giving access to the service, fulfilling the order, etc.

Parameters
data
object
Properties
payment
object
Properties
id
string
Primer's unique identifier for the payment.
orderId
string
Your order identifier as provided in the client session.
Optional payment method data - for some payment methods this object will contain additional information on the payment.
onCheckoutFail
(error: PrimerClientError, data: object, handler: object) => void

Called when the checkout flow has failed. This callback can also be used to display an error state within your own UI.

Parameters
error
PrimerClientError
Properties
code
ErrorCode
message
string
diagnosticsId
Nullable<string>
data
object
fromErrorCode
(code: ErrorCode, options: ErrorOptions) => PrimerClientError
data
object
Properties
payment
object
When checkout fails, the payment might or might not have been created. If it was created, the payment object contains some information regarding it.
Properties
id
string
Primer's unique identifier for the payment.
orderId
string
Your order identifier as provided in the client session.
Optional payment method data - for some payment methods this object will contain additional information on the payment.
handler
object

Show an error message.

If handler is undefined, the SDK does not expect anything from you.

If handler exists, you MUST call one of the functions of the handler.

12345678910111213141516171819
import { Primer } from '@primer-io/checkout-web'
const checkout = await Primer.showUniversalCheckout(clientToken, {    container: '#container',    onCheckoutComplete(...args) {        console.log('onCheckoutComplete', ...args)    },    onCheckoutFail(error, data, handler) {        if (!handler) {            return        }
        // Show a default error message        return handler.showErrorMessage()
        // Or show a custom error message        // return handler.showErrorMessage('This is my custom message');    },})
ts
copy
Properties
showErrorMessage
(customErrorMessage?: string) => void
Parameters
An optional custom error message.
Payment methods options
allowedCardNetworks
CardNetwork[]Deprecated

Allowed card networks for credit card payments, one of CardNetwork.

Manual payment handling
paymentHandling
"AUTO" | "MANUAL"

The paymentHandling option defines how the SDK should handle payment creation and resume.

The default is AUTO, set paymentHandling to MANUAL to turn off automatic payment handling. This disables the callbacks onBeforePayment and onCheckoutComplete.

Two callbacks must be implemented:

  • onTokenizeSuccess() to create payments with the paymentMethodToken.
  • onResumeSuccess() to resume payments with resumeToken.

See the Manual Payment Creation guide for examples.

ℹ️

The guide's examples are written for PrimerCheckout, but the same concepts apply to PrimerHeadlessCheckout.

onTokenizeSuccess
(data: PaymentMethodTokenData, handler: OnTokenizeSuccessHandler) => void
ℹ️

If you set paymentHandling to MANUAL, implementing this is mandatory.

Parameters
data
PaymentMethodTokenData
Properties
token
stringRequired

The payment instrument token you can use to create a payment request from your backend.

An unique identifier for the payment instrument token.

paymentInstrumentData
PaymentInstrumentData

Additional information about the payment instrument. Depending on the payment method type, only some of the following properties are present on the object.

Properties
The identifier for the payment method configuration.

The type of the payment method used for the transaction, one of PaymentMethodType.

sessionInfo
SessionInfo
Information about the session associated with the transaction.
The first six digits of the payment card.
The last four digits of the payment card.
The expiration month of the payment card.
The expiration year of the payment card.
The name of the cardholder as it appears on the payment card.
network
string
The network associated with the payment card (e.g., Visa, Mastercard).
Indicates whether the payment card's network is tokenized.
binData
BinData
Information about the Bank Identification Number (BIN) of the payment card.
threeDSecureAuthentication
ThreeDSAuthenticationData

Data related to 3D Secure authentication for the transaction.

Properties
responseCode
ThreeDSecureStatus

Indicates the outcome of the 3D Secure authentication process.
Possible values:

  • AUTH_SUCCESS: The authentication was successful.
  • AUTH_FAILED: The authentication process failed.
  • SKIPPED: The authentication was skipped.
  • CHALLENGE: A challenge was issued during the authentication process.
An optional code indicating the reason for the outcome of the 3D Secure authentication.
An optional text description providing further details about the reason for the authentication outcome.
Specifies the version of the 3D Secure protocol that was used.

Indicates whether a challenge was issued as part of the authentication process.

  • true: A challenge was issued.
  • false: No challenge was issued.
The identifier for a PayPal billing agreement, if applicable.
externalPayerInfo
ExternalPayerInfo
External information about the payer associated with the transaction.
shippingAddress
ShippingAddress
The shipping address for the transaction, if applicable.
The customer token associated with Klarna payment, if applicable.
sessionData
SessionData
Additional data related to the session.
paymentInstrumentType
PaymentInstrumentType

The type of the payment instrument.

Example of possible values (new values could be added as we add new payment methods):

  • APPLE_PAY
  • CARD_OFF_SESSION_PAYMENT
  • GOOGLE_PAY
  • KLARNA_CUSTOMER_TOKEN
  • OFF_SESSION_PAYMENT
  • PAYMENT_CARD
  • PAYPAL_BILLING_AGREEMENT
  • PAYPAL_ORDER
threeDSecureAuthentication
ThreeDSAuthenticationData

Data related to 3D Secure authentication for the transaction.

Properties
responseCode
ThreeDSecureStatus

Indicates the outcome of the 3D Secure authentication process.
Possible values:

  • AUTH_SUCCESS: The authentication was successful.
  • AUTH_FAILED: The authentication process failed.
  • SKIPPED: The authentication was skipped.
  • CHALLENGE: A challenge was issued during the authentication process.
An optional code indicating the reason for the outcome of the 3D Secure authentication.
An optional text description providing further details about the reason for the authentication outcome.
Specifies the version of the 3D Secure protocol that was used.

Indicates whether a challenge was issued as part of the authentication process.

  • true: A challenge was issued.
  • false: No challenge was issued.
tokenType
"SINGLE_USE" | "MULTI_USE"
Whether this payment method token can be used only once or multiple times.
vaultData
VaultData
Properties

The customerId associated to the payment method, if vaulted.

handler
OnTokenizeSuccessHandler
Properties
handleSuccess
() => void
Display a success screen.
handleFailure
(errorMessage: string) => void

Display errorMessage as an error or failure message.

continueWithNewClientToken
(clientToken: string) => void

Continue the payment flow using the given clientToken.

Called after a customer submitted their payment data and the payment details have been tokenized. You'll receive a paymentMethodToken in onTokenizeSuccess().

  • Create a payment request passing the paymentMethodToken to your backend

  • If the payment is successful, call handler.handleSuccess() in order to display a success screen

  • If the payment is unsuccessful, call handler.handleFailure(errorMessage) to display an error or failure message

  • Payments API may return a new clientToken for additional steps (in the requiredActions on the response). In this case, call handler.continueWithNewClientToken(clientToken) to continue with the payment flow

onTokenizeError
(error: PrimerClientError) => void

Called after a customer submitted their payment data and the payment details could not be tokenized. Use the PrimerClientError data to display an error message.

Parameters
error
PrimerError
Properties
code
ErrorCode
message
string
diagnosticsId
Nullable<string>
data
object
fromErrorCode
(code: ErrorCode, options: ErrorOptions) => PrimerClientError
onResumeSuccess
(data: ResumeToken, handler: OnResumeSuccessHandler) => void

Called when the resume token must be sent to your server to resume the payment flow, typically after the customer has completed some authorization step outside of the Primer SDK.

ℹ️

If you set paymentHandling to MANUAL, handling onResumeSuccess() is required to fully support 3DS and the majority of payment methods.

Parameters
data
ResumeToken
Properties

The resume token you can use to resume the payment flow on your backend.

paymentId
string
An unique identifier of the payment on Primer.
handler
OnResumeSuccessHandler
Properties
handleSuccess
() => void
Display a success screen.
handleFailure
(errorMessage: string) => void

Display errorMessage as an error or failure message.

continueWithNewClientToken
(clientToken: string) => void

Continue the payment flow using the given clientToken.

  • You will receive a resumeToken via the onResumeSuccess() callback if applicable

  • Send a resume payment request with the resumeToken

  • If the payment is successful, call handler.handleSuccess() in order to display a success screen

  • If the payment is unsuccessful, call handler.handleFailure(errorMessage) to display an error or failure message

  • The Payments API may again return a new clientToken for additional steps. In this case, call handler.continueWithNewClientToken(clientToken) again

onResumeError
(error: PrimerClientError) => void

Called when the payment cannot be resumed. Use the PrimerClientError data to display an error message.

Parameters
error
PrimerError
Properties
code
ErrorCode
message
string
diagnosticsId
Nullable<string>
data
object
fromErrorCode
(code: ErrorCode, options: ErrorOptions) => PrimerClientError
onTokenizeShouldStart
(data: { paymentMethodType: PaymentMethodType }) => boolean

Called to determine if the payment method tokenization should start.

Parameters
data
{ paymentMethodType: PaymentMethodType }

An object containing a paymentMethodType property, one of PaymentMethodType.

Implement this if you need to abort the payment method tokenization according to your own logic. You should return true to continue or false to abort.

onTokenizeStart
() => void

Called just before the payment method tokenization starts. Implement this to perform any custom action, for example, displaying a custom loading indicator.

onTokenizeDidNotStart
(reason: "TOKENIZATION_DISABLED" | "TOKENIZATION_SHOULD_NOT_START") => void

Called if the payment method tokenization did not start. Receives a reason as a string.

Parameters
reason
"TOKENIZATION_SHOULD_NOT_START" | "TOKENIZATION_DISABLED"
  • TOKENIZATION_SHOULD_NOT_START: tokenization was interrupted returning false from onTokenizeShouldStart.

  • TOKENIZATION_DISABLED: tokenization was disabled using setIsTokenizationEnabled or setPaymentCreationEnabled.