Web SDK
- Getting started
- Primer
- PrimerCheckout
- PrimerHeadlessCheckout
- CheckoutStyle
- Common objects
- Constants
showUniversalCheckout(
clientToken: string,
options: UniversalCheckoutOptions
): Promise<PrimerCheckout>
Showing Drop-in Checkout is 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.
import { Primer } from "@primer-io/checkout-web";
const checkout = await Primer.showUniversalCheckout(clientToken, {
container: "#container",
onCheckoutComplete(...args) {
console.log("onCheckoutComplete", ...args);
},
});
Note that there are more options which can be passed to Drop-In Checkout. Please refer to the section below for more information.
Parameters
Hide child attributes
Hide child attributes
A string containing a client token as returned by the Primer API when you create a client session.
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.
Hide child attributes
Hide child attributes
The container element in which the checkout should be rendered.
This option forces the locale. By default, the locale will be set to the browser’s locale.
Specifies the API version to use when interacting with the Primer backend.
- If not explicitly set, defaults to version
'2.4'
. - Set this to
'legacy'
if you encounter compatibility issues with the latest API version and wish to revert to the previous stable behavior.
Hide Payment lifecycle callbacks
Hide Payment lifecycle callbacks
Notifies you before the checkout tokenizes a payment method and creates a payment.
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.
Hide Parameters
Hide Parameters
Hide Properties
Hide Properties
The type of the payment method Primer will use for payment creation, one of PaymentMethodType
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.
return handler.abortPaymentCreation();
Choose to continue with payment creation
return handler.continuePaymentCreation();
Called when a payment has been created. Move on to next step in your checkout flow, such as showing a success message, etc.
Hide Parameters
Hide Parameters
Hide Properties
Hide Properties
Called when the checkout flow has failed. This callback can also be used to display an error state within your own UI.
Hide Parameters
Hide Parameters
Hide Properties
Hide Properties
When checkout fails, the payment might or might not have been created. If it was created, the payment object contains some information regarding it.
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.
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');
},
});
Hide Client session lifecycle callbacks
Hide Client session lifecycle callbacks
Called when the client session is in the process of being updated. Use it to show a loading indicator on your UI.
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.
Hide Event callbacks
Hide Event callbacks
Notifies you when a specific payment method has been selected or unselected.
Hide Parameters
Hide Parameters
The action being performed on the payment method. Payment will be unselected when a popup is closed.
Hide Properties
Hide Properties
The type of the payment method Primer will use for payment creation, one of PaymentMethodType
Hide Payment methods options
Hide Payment methods options
Customize the appearance and behavior of the card fields in the checkout form.
Hide Properties
Hide Properties
Options for the cardholder name input field.
Hide Properties
Hide Properties
Whether the cardholder name is required. Only works if the cardholder name is visible.
Whether the cardholder name input field should be visible. This property is deprecated, set it on your Dashboard instead.
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.
Customize the placeholder of the card number field.
Hide Properties
Hide Properties
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.
Customize the placeholder of the expiry date field.
Hide Properties
Hide Properties
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.
Customize the placeholder of the CVV field.
Hide Properties
Hide Properties
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.
Specify the preferred flow for entering card details.
Options for using PayPal as a payment method.
Hide Properties
Hide Properties
The color of the PayPal button.
The shape of the PayPal button.
The size of the PayPal button.
The height of the PayPal button, in pixels.
The label displayed on the PayPal button.
Whether to display the PayPal tagline beneath the button.
The payment flow to use for the PayPal button.
A function to be called when the PayPal button is clicked.
Options for using Google Pay as a payment method.
Hide Properties
Hide Properties
The color of the Google Pay button.
The size mode of the Google Pay button.
A function to be called when the Google Pay button is clicked.
Whether to prompt the user to select a billing address.
Options for using Apple Pay as a payment method.
Hide Properties
Hide Properties
The type of the Apple Pay button to display.
The style of the Apple Pay button.
Whether to display a prompt for the user to enter their billing address during the payment process.
Billing contact configuration options for Apple Pay.
Hide Properties
Hide Properties
An array of string values that specify which required contact information fields should be collected during the checkout process.
Shipping contact configuration options for Apple Pay.
Hide Properties
Hide Properties
An array of string values that specify which required contact information fields should be collected during the checkout process.
Options for using Klarna as a payment method.
Hide Properties
Hide Properties
The payment flow of the Klarna payment method.
The description of the recurring payment.
An array of string values that specify the allowed payment categories.
Options for using direct debit as a payment method.
Hide Properties
Hide Properties
The customer’s two-letter country code.
The name of the company or organization accepting payments.
The address of the company or organization accepting payments.
The name of the customer making the payment.
The email address of the customer making the payment.
The first line of the customer’s address.
The second line of the customer’s address.
The city of the customer’s address.
The postal code of the customer’s address.
The International Bank Account Number (IBAN) of the customer’s bank account.
An object containing the text to display on the submit button for the Direct Debit form and mandate.
Hide Vault options
Hide Vault options
An interface for configuring the display of vaulted payment methods.
Hide Properties
Hide Properties
Whether the vaulted payment methods are visible or not.
If this is not necessary for your use case, we recommend setting this to false
to skip the retrieval of the vault and speed up the loading of the checkout.
Default value is true
.
Whether deleting a vaulted payment method is disabled or enabled.
Hide Customization options
Hide Customization options
See the CheckoutStyle page.
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.
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
},
},
};
Hide Properties
Hide Properties
Hide Callbacks
Hide Callbacks
Show or hide your custom submit button.
Hide context
Hide context
An identifier for the current scene.
Disable or enable your custom submit button.
Hide context
Hide context
An identifier for the current scene.
Put your submit button in a loading state.
Hide context
Hide context
An identifier for the current scene.
Hide Properties
Hide Properties
Choose whether a processing indicator overlay should be shown on form submission.
Hide Properties
Hide Properties
Choose whether to allow Universal Checkout to show error messages.
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:
const options = {
/* Other options ... */
successScreen: false,
};
Change the message of the default success screen:
const options = {
/* Other options ... */
successScreen: {
type: "CHECK",
title: "This is a custom success message!",
},
};
Hide Manual payment handling
Hide Manual payment handling
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 thepaymentMethodToken
.onResumeSuccess()
to resume payments withresumeToken
.
See the Manual Payment Creation guide for examples.
The guide’s examples are written for PrimerCheckout
, but the same concepts apply to PrimerHeadlessCheckout
.
If you set paymentHandling
to MANUAL
, implementing this is mandatory.
Hide Parameters
Hide Parameters
Hide Properties
Hide Properties
The payment instrument token you can use to create a payment request from your backend.
An unique identifier for the payment instrument token.
Additional information about the payment instrument. Depending on the payment method type, only some of the following properties are present on the object.
Hide Properties
Hide Properties
The identifier for the payment method configuration.
The type of the payment method used for the transaction, one of PaymentMethodType.
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.
The network associated with the payment card (e.g., Visa, Mastercard).
Indicates whether the payment card’s network is tokenized.
Information about the Bank Identification Number (BIN) of the payment card.
Data related to 3D Secure authentication for the transaction.
Hide Properties
Hide Properties
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.
External information about the payer associated with the transaction.
The shipping address for the transaction, if applicable.
The customer token associated with Klarna payment, if applicable.
Additional data related to the session.
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
Data related to 3D Secure authentication for the transaction.
Hide Properties
Hide Properties
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.
Whether this payment method token can be used only once or multiple times.
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 therequiredActions
on the response). In this case, callhandler.continueWithNewClientToken(clientToken)
to continue with the payment flow
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.
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.
Hide Parameters
Hide Parameters
Hide Properties
Hide Properties
The resume token you can use to resume the payment flow on your backend.
An unique identifier of the payment on Primer.
-
You will receive a
resumeToken
via theonResumeSuccess()
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, callhandler.continueWithNewClientToken(clientToken)
again
Called when the payment cannot be resumed.
Use the PrimerClientError
data to display an error message.
Called to determine if the payment method tokenization should start.
Hide Parameters
Hide Parameters
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.
Called just before the payment method tokenization starts. Implement this to perform any custom action, for example, displaying a custom loading indicator.
Called if the payment method tokenization did not start. Receives a reason
as a string.
Hide Parameters
Hide Parameters
-
TOKENIZATION_SHOULD_NOT_START
: tokenization was interrupted returningfalse
fromonTokenizeShouldStart
. -
TOKENIZATION_DISABLED
: tokenization was disabled usingsetIsTokenizationEnabled
orsetPaymentCreationEnabled
.
Hide Client session caching
Hide Client session caching
Before enabling the flag to true
it’s recommended to reach out to Primer support for additional verification since there are edge cases where it’s not advised.
Indicates whether client session caching is enabled.
When set to true
, responses from the server will be cached on the client side, allowing for faster subsequent
access to the same data within the cache duration. When set to false
, every request to the server will be
processed without utilizing any client-side cache, ensuring that the client always receives the most up-to-date data.
Returns
Hide child attributes
Hide child attributes
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