Hubungkan ke reader
Hubungkan aplikasi Anda ke reader Stripe Terminal.
Catatan
If you haven’t chosen a reader yet, compare the available Terminal readers and choose one that best suits your needs.
Recommendation for smart readers
For smart readers, such as the BBPOS WisePOS E reader, Stripe Reader S700, and Verifone readers, we recommend using the server-driven integration instead of the JavaScript SDK.
The JavaScript SDK requires your POS and reader on the same local network with working local DNS. The server-driven integration uses the Stripe API instead, which can be simpler in complex network environments. See our platform comparison to help you choose the best platform for your needs.
Smart readers run Stripe reader software to communicate directly with Stripe over the internet. Connecting your app to a smart reader requires three steps:
- Register a reader to your Stripe account.
- Discover readers with the SDK.
- Connect to a reader with the SDK.
Register a readerSisi server
Before you can connect your application to a smart reader, you must register the reader to your account.
Menemukan readerSisi client
After registering the reader to your account, search for previously registered readers to connect to your point-of-sale application with discoverReaders, setting discoveryMethod to internet.
You can scope your discovery using the location you registered the reader to in the previous step.
async function discoverReaders() { const config = {simulated: false, location:} const discoverResult = await terminal.discoverReaders(config); if (discoverResult.error) { console.log('Failed to discover: ', discoverResult.error); } else if (discoverResult.discoveredReaders.length === 0) { console.log('No available readers.'); } else { // You should show the list of discoveredReaders to the // cashier here and let them select which to connect to (see below). connectReader(discoverResult); } }"{{LOCATION_ID}}"
Hubungkan ke readerSisi client
Peringatan
Chrome 142 (released October 28, 2025) and later versions require explicit permission before websites can access local network devices (like Terminal readers) when using the Stripe Terminal JavaScript SDK. For setup steps and troubleshooting, see Chrome 142+ instructions.
To connect your point-of-sale application to a reader, call connectReader with the selected reader.
async function connectReader(discoverResult) { // Just select the first reader here. const selectedReader = discoverResult.discoveredReaders[0]; const connectResult = await terminal.connectReader(selectedReader); if (connectResult.error) { console.log('Failed to connect:', connectResult.error); } else { console.log('Connected to reader:', connectResult.reader.label); } }
Multiple connections
Only one instance of the Stripe Terminal SDK can connect to a reader at a given time. By default, when you call connectReader from another application, the incoming connection replaces the existing SDK-to-reader connection, and the previously connected SDK disconnects from the reader. The connectReader method takes a configuration object with a fail_ property, whose default value is false. When your application sets fail_ to true, the connectReader call has an alternate behavior where the incoming connection fails when the reader is in the middle of a collectPaymentMethod or processPayment call initiated by another SDK. If the reader is connected to another SDK but is idle (displaying the splash screen before collectPaymentMethod is called), setting fail_ has no change to the connection behavior, and the incoming connection request can always break the existing SDK-to-reader connection.
const connectResult = await terminal.connectReader(reader, {fail_if_in_use: true});
| fail_if_in_use is false (default) | fail_if_in_use is true | |
|---|---|---|
connectReader called from a new SDK when the reader is idle. | The existing SDK-to-reader connection breaks, and the new SDK connects to the reader. The next command from the previously-connected SDK fails with a reader error, and that app’s onDisconnect method is called. | The existing SDK-to-reader connection breaks, and the new SDK connects to the reader. The next command from the previously-connected SDK fails with a reader error, and that app’s onDisconnect method is called. |
connectReader called from a new SDK when the reader is mid-transaction. | The existing SDK-to-reader connection breaks, and the new SDK connects to the reader. The next command from the previously-connected SDK fails with a reader error, and that app’s onDisconnect method is called. | The incoming connection fails with a reader error. The existing SDK-to-reader connection doesn’t break and the command in progress continues. |
For the least-disruptive connection experience in multi-reader environments, we recommend setting fail_ to true on your application’s initial connection attempt. Then, allow your users to retry the connection with fail_ set to false if the connection fails the first time.
With this setup, one of your users can’t accidentally interrupt a transaction by inadvertently connecting to an in-use reader, but can still connect if needed.
Handle disconnects
Your app must implement the onUnexpectedReaderDisconnect callback to handle when a reader disconnects. When you implement this callback, display a UI that notifies your user of the disconnected reader. You can call discoverReaders to scan for readers and initiate reconnection.
Your app can attempt to automatically reconnect to the disconnected reader or display a UI that prompts your user to reconnect to a different reader.
The reader can disconnect from your app if it loses connection to the network. To simulate an unexpected disconnect, power off the reader.
const terminal = StripeTerminal.create({ onFetchConnectionToken: fetchConnectionToken, onUnexpectedReaderDisconnect: unexpectedDisconnect, }); function unexpectedDisconnect() { // Consider displaying a UI to notify the user and start rediscovering readers }
Automatic reconnection
Stripe Terminal doesn’t automatically reconnect to a reader when your application starts. Instead, you can build a reconnection flow by storing reader IDs and attempting to connect to a known reader on startup.
- When you successfully connect to a reader, save its serial number in a persistent data storage location, such as the localStorage API.
- When your app launches, check that persistent store for a saved serial number. If one is found, call the
discoverReadersmethod so your application can try to find that reader again. - If the saved serial number matches any of the discovered readers, try connecting to that reader with the matching reader object returned from the call to
discoverReaders. If the previously connected reader isn’t found, stop the discovery process.
Display some UI during the discovery and connection process to indicate that an automatic reconnection is taking place.
Langkah berikutnya
You’ve connected your application to the reader. Next, collect your first Stripe Terminal payment.
The BBPOS and Chipper™ name and logo are trademarks or registered trademarks of BBPOS Limited in the United States or other countries. The Verifone® name and logo are either trademarks or registered trademarks of Verifone in the United States and/or other countries. Use of the trademarks doesn’t imply any endorsement by BBPOS or Verifone.