Get started
The simplest way to integrate Universal Checkout is with our drop-in UI. With just a few lines of code, you can display a fully in-context checkout UI with all your payment methods.
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 the order
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
So pass as much information as you can!
Generate an API key
Requests to our API are authenticated using an API key in the X-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.
Here is how the client session request to the Primer API should look like:
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.
- 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 the Primer.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.
The Primer.min.js
will add the Primer
object to the global scope:
Initialize and Show Universal Checkout
Use the generated client token on the client-side to show Universal Checkout by calling Primer.showUniversalCheckout(clientToken, options)
. Make sure to pass a selector to your container in the options.
When the user interacts with the checkout:
- Update the client session
- Create a payment (by default)
Handle successful payments
Listen to callback
On the client-side, listen to the onCheckoutComplete
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 for PAYMENT.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 the onCheckoutFail
callback
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.
- 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 the Primer.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.
The Primer.min.js
will add the Primer
object to the global scope:
Initialize and Show Universal Checkout
Use the generated client token on the client-side to show Universal Checkout by calling Primer.showUniversalCheckout(clientToken, options)
. Make sure to pass a selector to your container in the options.
When the user interacts with the checkout:
- Update the client session
- Create a payment (by default)
Handle successful payments
Listen to callback
On the client-side, listen to the onCheckoutComplete
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 for PAYMENT.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 the onCheckoutFail
callback
Backend API V2.4 enhances reliability and minimizes synchronization issues with external processors by significantly extending payment timeouts. This longer timeout accommodates external processor limits and internal operations, ensuring more reliable transaction handling. These improvements are fully supported starting with Primer iOS SDK 2.34.0, so upgrading your app to use the newest SDK version is highly recommended when creating client sessions with API V2.4.
Install the SDK
With CocoaPods
Add the following in your Podfile
:
Then run pod install
to install PrimerSDK
on your workspace.
In case you encounter an error that the bundle needs signing on Xcode 14, add the following post-install script in your podfile.
With Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into Xcode. In order to add PrimerSDK with Swift Package Manager:
- Select your project, and then navigate to
Package Dependencies
- Click on the + button at the bottom-left of the
Packages
section - Paste https://github.com/primer-io/primer-sdk-ios.git into the Search Bar, or search for
primer-sdk-ios
in the Search Bar. - Press Add Package
- Let Xcode download the package and set everything up
For more details about SDK versions, please see our changelog.
Initialize Universal Checkout
Import the PrimerSDK
and set its delegate as shown in the following example:
See all the configurations in the SDK Reference.
Show Universal Checkout
At this step you should have a client token available - see Manage Client Sessions for more.
Call the showUniversalCheckout(clientToken:)
function (as shown below) to present Universal Checkout.
You should now be able to see Universal Checkout! The user can now interact with Universal Checkout, and the SDK will create the payment. The payment’s data will be returned on primerDidCompleteCheckoutWithData(_:)
configured in the previous step.
When the user interacts with the checkout and clicks to pay, the Universal Checkout:
- Shows the payment method screen if applicable
- Tokenizes the payment method for payment
- Creates the payment
- Handles any other interactions (e.g. 3DS)
Handle successful payments
Listen to delegate function
Listen to the primerDidCompleteCheckoutWithData(_:)
delegate function
This function will notify you of a successful payment.
Handle webhooks in your dashboard
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 for PAYMENT.STATUS
event.
If you are not yet ready to receive webhooks, you can use https://webhook.site to test your implementation.
Handle failed payments
Any errors, cancelled payment interactions or failed payments will trigger the primerDidFailWithError(_:data:decisionHandler:)
delegate function.
Backend API V2.4 enhances reliability and minimizes synchronization issues with external processors by significantly extending payment timeouts. This longer timeout accommodates external processor limits and internal operations, ensuring more reliable transaction handling. These improvements are fully supported starting with Primer Android SDK 2.35.0, so upgrading your app to use the newest SDK version is highly recommended when creating client sessions with API V2.4.
Install the SDK
Add the following to your app/build.gradle
file:
For more details about SDK versions, please see our changelog.
It is highly recommended adding the following settings to your app/build.gradle
file:
Initialize Universal Checkout
Prepare the PrimerCheckoutListener
that will handle the callbacks that happen during the lifecycle. Import the Primer SDK and set its listener as shown in the following example:
See all the configurations in the SDK Reference.
Show Universal Checkout
At this step you should have a client token available - see Manage Client Sessions for more.
When the client token is retrieved, show Universal Checkout by calling showUniversalCheckout
method:
You should now be able to see Universal Checkout! The user can now interact with Universal Checkout, and the SDK will create the payment. The payment’s data will be returned on onCheckoutCompleted()
configured in the previous step.
When the user interacts with the checkout and clicks to pay, the Universal Checkout:
- Shows the payment method screen if applicable
- Tokenizes the payment method for payment
- Creates the payment
- Handles any other interactions (e.g. 3DS)
Handle successful payments
Listen to callback
Listen to onCheckoutCompleted
callback
This function will notify you of a successful payment
Handle webhooks in your dashboard
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 for PAYMENT.STATUS
event.
If you are not yet ready to receive webhooks, you can use https://webhook.site to test your implementation.
Handle failed payments
Any errors, cancelled payment interactions or failed payments will trigger the onFailed
callback
This SDK requires React Native v0.63 or higher.
Backend API V2.4 enhances reliability and minimizes synchronization issues with external processors by significantly extending payment timeouts. This longer timeout accommodates external processor limits and internal operations, ensuring more reliable transaction handling. These improvements are fully supported starting with Primer React Native SDK 2.35.0, so upgrading your app to use the newest SDK version is highly recommended when creating client sessions with API V2.4.
Install the SDK
Add the SDK package
Requirement for iOS
Once you are done, navigate to the /ios
folder and run pod install
.
For more details about SDK versions, please see our changelog.
Initialize Universal Checkout
Import the Primer SDK, construct your settings and call the SDK’s configure
function.
See all the configurations in the SDK Reference.
Show Universal Checkout
First, make an API call to your backend to fetch a client token. Here is a simple example of how it can be done from your component. Once successful store your client token for future use.
See Manage Client Sessions for more.
Now, call the showUniversalCheckout(clientToken)
function, with the client token to present Universal Checkout.
You should now be able to see Universal Checkout! The user can now interact with Universal Checkout, and the SDK will create the payment. The payment’s data will be returned on primerDidCompleteCheckoutWithData(_:)
configured in the previous step.
When the user interacts with the checkout and clicks to pay, the Universal Checkout:
- Shows the payment method screen if applicable
- Tokenizes the payment method for payment
- Creates the payment
- Handles any other interactions (e.g. 3DS)
Handle successful payments
Listen to callback
This function will notify you of a successful payment
Handle webhooks in your dashboard
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 for PAYMENT.STATUS
event.
If you are not yet ready to receive webhooks, you can use https://webhook.site to test your implementation.
Handle failed payments
Any errors, cancelled payment interactions or failed payments will trigger the onError
callback