Set up your integration
Getting started with the JavaScript SDK requires three steps:
- Install the SDK and client library on your checkout page
- Set up the connection token endpoint on your backend and web application
- Initialize the SDK in your web application
If you integrate your web application with the JavaScript SDK, you can run it in a mobile browser as long as the mobile device is connected to the same local network as the reader and devices on that network can communicate directly with one another.
Install the SDK and client libraryClient-sideServer-side
Client-side
To get started, include this script on your checkout page. This script must always load directly from https://js.stripe.com for compatibility with the latest reader software. Do not include the script in a bundle or host a copy yourself; this could break your integration without warning.
<script src="https://js.stripe.com/terminal/v1/"></script>
Use the Terminal JS SDK as a module
We also provide an npm package that makes it easier to load and use the Terminal JS SDK as a module. For more information, check out the project on GitHub.
For information on migrating from beta versions of the JavaScript SDK, see the Stripe Terminal Beta Migration Guide.
Server-side
Use our official libraries for access to the Stripe API from your application:
Set up the ConnectionToken endpointServer-sideClient-side
Server-side
To connect to a reader, your backend needs to give the SDK permission to use the reader with your Stripe account, by providing it with the secret from a ConnectionToken. Your backend should only create connection tokens for clients that it trusts.
Obtain the secret from the ConnectionToken on your server and pass it to the client side.
The ConnectionToken’s secret lets you connect to any Stripe Terminal reader and take payments with your Stripe account. Be sure to authenticate the endpoint for creating connection tokens and protect it from cross-site request forgery (CSRF).
Client-side
To give the SDK access to this endpoint, create a function in your web application that requests a ConnectionToken from your backend and returns the secret
from the ConnectionToken object.
This function is called whenever the SDK needs to authenticate with Stripe or the Reader. It’s also called when a new connection token is needed to connect to a reader (for example, when your app disconnects from a reader). If the SDK is unable to retrieve a new connection token from your backend, connecting to a reader fails with the error from your server.
Do not cache or hardcode the connection token. The SDK manages the connection token’s lifecycle.
Initialize the SDKClient-side
The StripeTerminal
object made available by the SDK exposes a generic interface for discovering readers, connecting to a reader, and creating payments. To initialize a StripeTerminal
instance in your JavaScript application, provide the ConnectionToken function implemented in Step 2.
You must also provide a function to handle unexpected disconnects from the reader, onUnexpectedReaderDisconnect
. In this function, your app should notify the user that the reader disconnected. You can also include a way to attempt to reconnect to a reader. For more information, see Handling disconnects.
SDK updates
Stripe periodically releases updates to the Stripe Terminal React Native SDK, Stripe Terminal JavaScript SDK, the Stripe Terminal iOS SDK, and the Stripe Terminal Android SDK, which can include new functionality, bug fixes, and security updates. Update your integrated version of the Stripe Terminal React Native, JavaScript, iOS, or Android SDK as soon as a new version is available.
Next steps
Congratulations! You’ve setup the Stripe Terminal SDK. Next, connect your application to the reader.
Supported browsers
The Stripe Terminal JavaScript SDK strives to support all recent versions of major browsers. We support:
- Internet Explorer 11 and Edge on Windows.
- Firefox on desktop platforms.
- Chrome and Safari on all platforms.
- The Android native browser on Android 4.4 and later.
If you have issues with the Stripe Terminal JavaScript SDK on a specific browser, please email support-terminal@stripe.com.