Show Primer's Drop-In Checkout.

The simplest way to integrate with Primer. With just a few lines of code, you can display a fully in-context checkout UI with all your payment methods.

Availing Drop-In Checkout is as easy as implementing one line of code.

12345678
import { Primer } from '@primer-io/checkout-web' const checkout = await Primer.showUniversalCheckout(clientToken, {    container: '#container',    onCheckoutComplete(...args) {        console.log('onCheckoutComplete', ...args)    },})
ts
copy

Note that there are more options which can be passed to Drop-In Checkout. Please refer to the section below for more information.

Parameters

clientTokenstringRequired

A string containing a client token as returned by the Primer API when you create a client session.

universalCheckoutOptionsobjectRequired

When calling showUniversalCheckout you can provide Drop-In Checkout with some configuration options. These options range from callbacks notifying you of the current payment's status, to styling options for certain UI elements.

containerstring | ElementRequired

The container element in which the checkout should be rendered.

localestring

This option forces the locale. By default, the locale will be set to the browser's locale.
Payment lifecycle callbacks

onPaymentCreationStart() => void

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

dataobject

Properties

paymentMethodTypestring

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

handlerobject

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

dataobject

Properties

paymentobject

Properties

idstring

Primer's unique identifier for the payment.

orderIdstring

Your order identifier as provided in the client session.

paymentMethodDataobject

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

errorPrimerClientError

Properties

codeErrorCode

messagestring

diagnosticsIdNullable<string>

dataobject

isFromDeveloperboolean

fromErrorCode(code: ErrorCode, options: ErrorOptions) => PrimerClientError

dataobject

Properties

paymentobject

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

idstring

Primer's unique identifier for the payment.

orderIdstring

Your order identifier as provided in the client session.

paymentMethodDataobject

Optional payment method data - for some payment methods this object will contain additional information on the payment.

handlerobject

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

customErrorMessage?: stringstring

An optional custom error message.
Client session lifecycle callbacks

onBeforeClientSessionUpdate() => void

Called when the client session is in the process of being updated. Use it to show a loading indicator on your UI.

onClientSessionUpdate(clientSession: ClientSession) => void

Called when the client session has been updated by the checkout. Returns the updated client session which can be used to inform your UI. For example updating tax, shipping or discount amounts displayed to your customers.
Payment method callbacks

onPaymentMethodAction(action: string, data: object) => void

Notifies you when a specific payment method has been selected or unselected.

Parameters

action"PAYMENT_METHOD_SELECTED" | "PAYMENT_METHOD_UNSELECTED"

The action being performed on the payment method.

dataobject

Properties

paymentMethodTypestring

The type of the payment method Primer will use for payment creation, one of paymentMethodTypes
Payment methods options

cardobject

Customize the appearance and behavior of the card fields in the checkout form.
Properties

cardholderNameobject

Options for the cardholder name input field.
Properties

requiredboolean

Whether the cardholder name is required. Only works if the cardholder name is visible.

visiblebooleanDeprecated

Whether the cardholder name input field should be visible. This property is **deprecated**, set it on your Dashboard instead.

placeholderstring | (options: { locale: string }) => string

The placeholder text to display in the cardholder name input field. It can be either a string or a function that returns a string. The function receives an options object as first argument.

cardNumberobject

Customize the placeholder of the card number field.
Properties

placeholderstring | (options: { locale: string }) => string

The placeholder text to display in the cardholder number input field. It can be either a string or a function that returns a string. The function receives an options object as first argument.

expiryDateobject

Customize the placeholder of the expiry date field.
Properties

placeholderstring | (options: { locale: string }) => string

The placeholder text to display in the expiry date input field. It can be either a string or a function that returns a string. The function receives an options object as first argument.

cvvobject

Customize the placeholder of the CVV field.
Properties

placeholderstring | (options: { locale: string }) => string

The placeholder text to display in the CVV input field. It can be either a string or a function that returns a string. The function receives an options object as first argument.

preferredFlow"DEDICATED_SCENE" | "EMBEDDED_IN_HOME"

Specify the preferred flow for entering card details.

redirectobject

Options for payment methods that rely on redirecting.
Properties

returnUrlstring

The URL to return to after the redirect process has completed.

forceRedirectboolean

Whether to always use a redirect flow, rather than a popup window, even if other options are available. Default value is `false`.

paypalobject

Options for using PayPal as a payment method.
Properties

buttonColor"gold" | "blue" | "silver" | "white" | "black"

The color of the PayPal button.

buttonShape"pill" | "rect"

The shape of the PayPal button.

buttonSize"small" | "medium" | "large" | "responsive"

The size of the PayPal button.

buttonHeightnumber

The height of the PayPal button, in pixels.

buttonLabel"checkout" | "credit" | "pay" | "buynow" | "paypal" | "installment"

The label displayed on the PayPal button.

buttonTaglineboolean

Whether to display the PayPal tagline beneath the button.

paymentFlow"DEFAULT" | "PREFER_VAULT"

The payment flow to use for the PayPal button.

onClick() => void

A function to be called when the PayPal button is clicked.

googlePayobject

Options for using Google Pay as a payment method.
Properties

buttonType"long" | "short" | "book" | "buy" | "checkout" | "donate" | "order" | "pay" | "plain" | "subscribe"

buttonColor"default" | "black" | "white"

The color of the Google Pay button.

buttonSizeMode"fill" | "static"

The size mode of the Google Pay button.

onClick() => void

A function to be called when the Google Pay button is clicked.

captureBillingAddressboolean

Whether to prompt the user to select a billing address.

applePayobject

Options for using Apple Pay as a payment method.
Properties

buttonType"plain" | "buy" | "set-up" | "donate" | "check-out" | "book" | "subscribe"

The type of the Apple Pay button to display.

buttonStyle"white" | "white-outline" | "black"

The style of the Apple Pay button.

captureBillingAddressboolean

Whether to display a prompt for the user to enter their billing address during the payment process.

klarnaobject

Options for using Klarna as a payment method.
Properties

paymentFlow"DEFAULT" | "PREFER_VAULT"

The payment flow of the Klarna payment method.

recurringPaymentDescriptionstring

The description of the recurring payment.

allowedPaymentCategories("pay_now" | "pay_later" | "pay_over_time")[]

An array of string values that specify the allowed payment categories.

directDebitobject

Options for using direct debit as a payment method.
Properties

customerCountryCodestringRequired

The customer's two-letter country code.

companyNamestringRequired

The name of the company or organization accepting payments.

companyAddressstringRequired

The address of the company or organization accepting payments.

customerNamestring

The name of the customer making the payment.

customerEmailstring

The email address of the customer making the payment.

customerAddressLine1string

The first line of the customer's address.

customerAddressLine2string

The second line of the customer's address.

customerCitystring

The city of the customer's address.

customerPostalCodestring

The postal code of the customer's address.

ibanstring

The International Bank Account Number (IBAN) of the customer's bank account.

submitButtonLabelsobject

An object containing the text to display on the submit button for the Direct Debit form and mandate.
Properties

formstring | (options: { locale: string }) => string

The label to display on the submit button for the Direct Debit form.

mandatestring | (options: { locale: string }) => stringRequired

The label to display on the submit button for the Direct Debit mandate.

giftCardobject

Options for using gift cards as a payment method.
Properties

logoSrcstringRequired

The source URL of the button logo.

backgroundstringRequired

The background color of the button.

logoAltstring

An alternative text for the button logo.

textstring

The text to display on the button.
Customization Options

styleCheckoutStyle

See the CheckoutStyle page.

formobject

Properties

inputLabelsVisibleboolean

Choose whether to show the label above inputs.

submitButtonobject

Drop-In Checkout allows you to use your own submit button for submitting forms. By default, the built-in submit button will be favored.

Note that when disabling the built-in submit button and using your own custom submit button, it is required to implement the submit function in order to notify Drop-In Checkout of form submissions.

When using your own custom submit button, it's important to use the following callbacks to ensure that your submit button is in the correct state and in sync with the checkout as your customers interact with it.

123456789101112131415161718192021222324252627
const options = {    /* Other options ... */     submitButton: {        useBuiltInButton: false, // Default to true         // Callback for receiving the submit button's visible state in the current scene        onVisible(isVisible, context: { currentSceneId }) {            // Show or hide your custom submit button        },         // Callback for receiving the submit button's disabled state in the current scene        onDisable(isDisabled, context: { currentSceneId }) {            // Disable or enable your custom submit button        },         // Callback for receiving the submit button's loading state in the current scene        onLoading(isLoading, context: { currentSceneId }) {            // Show your submit button in a loading state        },         // Callback for receiving the submit button's content in the current scene        onContentChange(content, context: { currentSceneId }) {            // Set your submit button's content with either the content provided or your own custom content        },    },}
ts
copy
Properties

useBuiltInButtonboolean

Set whether to use built-in submit button or to display your own custom button.

amountVisibleboolean

Set whether the total order amount should be displayed in the submit button content.
Callbacks

onVisible(isVisible: boolean, context: object) => void

Show or hide your custom submit button.
context

currentSceneIdstring

An identifier for the current scene.

onDisable(isDisabled: boolean, context: object) => void

Disable or enable your custom submit button.
context

currentSceneIdstring

An identifier for the current scene.

onLoading(isLoading: boolean, context: object) => void

Put your submit button in a loading state.
context

currentSceneIdstring

An identifier for the current scene.

onContentChange(content: string, context: object) => void

Set your submit button's content with either the content provided or your own custom content.
context

currentSceneIdstring

An identifier for the current scene.

processingIndicatorobject

Properties

visibleboolean

Choose whether a processing indicator overlay should be shown on form submission.

errorMessageobject

Properties

disabledboolean

Choose whether to allow Universal Checkout to show error messages.
Callbacks

onErrorMessageShow(message: string) => void

A callback for when the error message should be displayed, you can choose to use the provided message for your own purposes.

onErrorMessageHide() => void

A callback for when the error message should be hidden, update own UI accordingly.

successScreenfalse | object

When the checkout is succefully complete, Drop-In Checkout displays a success scene with a default success message "Your payment was successful!".

Set the option successScreen to modify the default behavior of the success scene.

Remove the success screen:

1234
const options = {    /* Other options ... */    successScreen: false,}
ts
copy

Change the message of the default success screen:

1234567
const options = {    /* Other options ... */    successScreen: {        type: 'CHECK',        title: 'This is a custom success message!',    },}
ts
copy
Properties

type"CHECK"

"CHECK" is the only type of success screen supported at the moment.

titlestring

Your custom success message.
Advanced Options

The payment methods featuring a dedicated screen allow you to directly display their flow. For that, make sure to:

Set uxFlow to SINGLE_PAYMENT_METHOD_CHECKOUT Set paymentMethod to the payment method you want to display

123456
const options = {  /* Other options ... */   uxFlow: 'SINGLE_PAYMENT_METHOD_CHECKOUT',  paymentMethod: 'PAYMENT_CARD',};
ts
copy

uxFlowstring

Set uxFlow to "SINGLE_PAYMENT_METHOD_CHECKOUT" to display a dedicated screen for the payment methods that support it.

paymentMethod"PAYMENT_CARD" | "KLARNA" | "GOCARDLESS"

The payment method you want to display.

logoSrcstring

Data URL representing the logo you want to display in the payment method button.

backgroundstring

Color of the background of the payment method button.

logoAltstring

Accessibility label for the payment method button.

textstring

Label to display to the right of the logo.

Returns

Promise<UniversalCheckout>

A promise that is resolved when Drop-In Checkout has been properly rendered on the page, or rejected if any error occurred during initialisation.

The promise is resolved with an instance of PrimerCheckout