If you’re looking for a more customizable way of integrating Universal Checkout, consider integrating Headless Checkout.
Not all payment methods are currently compatible with Drop-in Checkout.Please refer to this table to learn more about the payment methods available for Drop-in Checkout.
Before you start
Before you start, make sure:- you are ready to process a payment
- Universal Checkout is properly configured in the dashboard
Create a client session
A client session is the starting point for integrating payments at Primer. You can attach any data associated with theorder
to your client session.
Creating a client session provides you with a client token, a temporary key used to initialize the Universal Checkout.
The information you include in the client session is used in the Dashboard:
- to conditionally route payments with Workflows
- to activate payment methods and other features in Universal Checkout
Generate an API key
Requests to our API are authenticated using an API key in theX-Api-Key
header. Create an API key by visiting the developer page of the Primer Dashboard.
Make sure to set the following scopes for your API Key:
client_tokens:write
transactions:authorize
Make a client session request
On your server, create a client session with . Make sure to pass at least the following data:Field | Description |
---|---|
orderId | Your reference for the payment. Make sure to keep track of orderId - you will later receive updates to the payment via Webhooks. The payment will contain the orderId specified in the client session. |
currencyCode | The three-letter currency code in ISO 4217 format. e.g. use USD for US dollars. |
order.lineItems | The details of the line items of the order. |
The body of a successful response contains a clientToken that you will use to initialize the Universal Checkout.
BASH
Install the SDK
Please review the Content Security Policy (CSP) recommendations before installing!
With npm
Our Web SDK is available on npm under the name@primer-io/checkout-web
.This package includes TypeScript definitions.BASH
Typescript
- The npm package only works if used alongside a bundler such as Webpack or Parcel. If you’re directly writing JavaScript using
script
tag, please use our CDN instead. - As of today, the npm package does not work in a server environment. If you are using Next.js, Gatsby, or a similar framework, make sure the
Primer
functions are called on the client side, or use our CDN instead.
With our CDN
Include thePrimer.min.js
script and the Checkout.css
stylesheet on the page where you want to render the Checkout.
Make sure to pass the proper version in the URL.HTML
Primer.min.js
will add the Primer
object to the global scope:Typescript
Initialize and Show Universal Checkout
Use the generated client token on the client-side to show Universal Checkout by callingPrimer.showUniversalCheckout(clientToken, options)
. Make sure to pass a selector to your container in the options.Javascript
- Update the client session
- Create a payment (by default)
Handle successful payments
Listen to callback
On the client-side, listen to theonCheckoutComplete
callback to be notified when the payment has been successfully completed. Use it to show an order confirmation screen.Handle webhooks
To receive updates about the status of your payments you’ll need to listen to webhooks. This is particularly useful for updating an order or any other data stored server-side.Head to the Developers section of the Primer Dashboard to setup and test a webhook forPAYMENT.STATUS
event.If you are not yet ready to receive webhooks, you can use https://webhook.site to test your implementation.Handle redirects
Some payment methods require redirecting to another web page in order to capture payment details.Drop-in checkout automatically renders that web page in a popup window in order to maintain the current context.If the browser cannot open popup windows, the current window will be redirected instead.To ensure maximum compatibility, read the guide on how to handle redirects.
Handle failed payments
Any errors, cancelled payment interactions or failed payments will trigger theonCheckoutFail
callbackJavascript