Sign in
An image of the Stripe logo
Create account
Sign in
Home
Payments
Business operations
Financial services
Developer tools
No-code
All products
Home
Payments
Business operations
Home
Payments
Business operations
Financial services
Developer tools
Support
Overview
Overview
What is Terminal
Design an integration
Example applications
Quickstart
Accept an in-person payment
Set up your reader
Set up your integration
Connect to a reader
Collect payments
Regional considerations
Supported card brands
Terminal payments features
Multiparty payments with Connect
Collect tips
Save cards for future use
Refund transactions
Provide receipts
Cart display
Incremental authorizations
Extended authorizations
Operate offline
Deploy at scale
Order hardware
Manage locations
Configure readers
References
API references
JavaScript API reference
iOS API reference
Android API reference
React Native API reference
Bluetooth readers
Smart readers
SDK migration guide
Testing
Deployment checklist
Stripe Terminal reader product sheets
Testing
Terminal
·
HomePaymentsIn-person paymentsAPI references

JavaScript API reference

Use our API reference to navigate the Stripe Terminal JavaScript SDK.

API methods

  • StripeTerminal.create()
  • discoverReaders()
  • connectReader()
  • disconnectReader()
  • getConnectionStatus()
  • getPaymentStatus()
  • clearCachedCredentials()
  • collectPaymentMethod()
  • cancelCollectPaymentMethod()
  • processPayment()
  • readReusableCard()
  • cancelReadReusableCard()
  • setReaderDisplay()
  • clearReaderDisplay()
  • setSimulatorConfiguration()
  • getSimulatorConfiguration()
  • collectRefundPaymentMethod()
  • processRefund()
  • cancelCollectRefundPaymentMethod()

StripeTerminal.create([options])

Creates an instance of StripeTerminal with the given options:

Option Description
onFetchConnectionTokenAn event handler that fetches a connection token from your backend.
onUnexpectedReaderDisconnectAn event handler called when a reader disconnects from your app.
onConnectionStatusChange optionalAn event handler called when the SDK’s ConnectionStatus changes.
onPaymentStatusChange optionalAn event handler called when the SDK’s PaymentStatus changes.
readerBehavior optionalAn object that sets the behavior on the reader throughout the lifecycle of the SDK. See below for readerBehavior configuration options.

Reader Behavior Configuration

Today, there is only one behavior configuration option:

Behavior Description

allowCustomerCancel

A boolean that determines whether the customer can cancel collectPaymentMethod from the reader’s interface. Defaults to false.

Note: This property isn’t broadly available, and we’re not accepting users at this time.

discoverReaders([options])

Begins discovering readers with the given options:

Option Description
simulated optionalA boolean value indicating whether to discover a simulated reader. If left empty, this value defaults to false.

location optional

Return only readers assigned to the given location. This parameter is ignored when discovering a simulated reader.

For more information on using locations to filter discovered readers, see Manage locations.

Returns a Promise that resolves to an object with the following fields:

  • discoveredReaders: A list of discovered Reader objects, if the command succeeded.
  • error: An error, if the command failed.

Before you can discover the Verifone P400 in your application, you must register the reader to your account.

connectReader(reader, connectOptions)

Attempts to connect to the given reader with the given options:

Option Description
fail_if_in_use optionalA boolean value indicating whether the connection should fail if the reader is currently connected to a Terminal SDK. If left empty, this value defaults to false.

Returns a Promise that resolves to an object with the following fields:

  • reader: The connected Reader, if the command succeeded.
  • error: An error, if the command failed.

Don’t cache the Reader object in your application. Connecting to a stale Reader can fail if the reader’s IP address has changed.

disconnectReader()

Disconnects from the connected reader.

getConnectionStatus()

Returns the current connection status.

ConnectionStatus can be one of connecting, connected, or not_connected.

getPaymentStatus()

Returns the reader’s payment status.

PaymentStatus can be one of not_ready, ready, waiting_for_input, or processing.

clearCachedCredentials()

Clears the current ConnectionToken, and any other cached credentials.

Use this method to switch accounts in your application (for example, to switch between live and test Stripe API keys on your backend). To switch accounts, follow these steps:

  1. If a reader is connected, call disconnectReader.
  2. Configure your onFetchConnectionToken handler to return connection tokens for the new account.
  3. Call clearCachedCredentials.
  4. Reconnect to a reader. The SDK requests a new connection token from your onFetchConnectionToken handler.

collectPaymentMethod(request, options)

Begins collecting a payment method for a PaymentIntent. This method takes one required parameter, request:

  • request: The clientSecret field from a PaymentIntent object created on your backend. Learn how to create a PaymentIntent and pass its client secret.
  • options: An object containing additional payment parameters.
Option Description

config_override optional

An object that allows you to specify configuration overrides per transaction. This object defaults to null and takes effect only if tipping is enabled.

skip_tipping: a boolean that allows you to specify whether or not to skip the tipping screen on the reader

tipping: an object that allows you to specify tipping-related options per transaction

update_payment_intent: a boolean, when paired with payment_intent_id, instructs the call to update the PaymentIntent and return the attached PaymentMethod with card details.

payment_intent_id: the id from the PaymentIntent object created on your backend.

{ skip_tipping: boolean, tipping: object, update_payment_intent: boolean, payment_intent_id: string }

The following option is available for the tipping object:

Option Description

eligible_amount optional

A number that allows you to specify the amount of a transaction that percentage-based tips are calculated against. Set this value to 0 or higher.

If it’s equal to 0, tipping is skipped regardless of the value of skip_tipping.

If it’s equal to the payment intent amount, the parameter is ignored and the tip is calculated based on the specified amount.

{ eligible_amount: number, }

Returns a Promise that resolves to an object with the following fields:

  • paymentIntent: The updated PaymentIntent object, if the command succeeded.
  • error: An error, if the command failed.

For more information on collecting payments, see our Collecting Payments guide.

cancelCollectPaymentMethod()

Cancels an outstanding collectPaymentMethod command.

Returns a Promise that resolves to an empty object once the command has been successfully canceled. If cancelation fails, the Promise resolves to an object with an error

processPayment(paymentIntent)

Processes a payment after a payment method has been collected.

This method takes a single parameter, a PaymentIntent object obtained from a successful call to collectPaymentMethod.

Returns a Promise that resolves to an object with the following fields:

  • paymentIntent: The confirmed PaymentIntent object, if the command succeeded.
  • error: An error, if the command failed. For more information, see Handling processing failures.

readReusableCard()

Reads a card for online reuse.

Online payments initiated from Terminal do not benefit from the lower pricing and liability shift given to standard Terminal payments. Most integrations do not need to use readReusableCard. To simply collect an in-person payment from a customer, use the standard flow.

Returns a Promise that resolves to an object with the following fields:

  • payment_method: The PaymentMethod object, if the command succeeded.
  • error: An error, if the command failed.

Currently, you can’t use Stripe Terminal to save contactless cards and mobile wallets (for example, Apple Pay, Google Pay) for later reuse.

cancelReadReusableCard()

Cancels an outstanding readReusableCard command.

Returns a Promise that resolves to an empty object once the command has been successfully canceled. If cancellation fails, the Promise resolves to an object with an error.

setReaderDisplay(displayInfo)

Updates the reader display with cart details.

This method takes a DisplayInfo object as input.

{ type: 'cart', cart: { line_items: [ { description: string, amount: number, quantity: number, }, ], tax: number, total: number, currency: string, } }

Returns a Promise that resolves to an empty object if the command succeeds. If the command fails, the Promise resolves to an object with an error.

clearReaderDisplay()

If the reader is displaying cart details set with setReaderDisplay, this method clears the screen and resets it to the splash screen.

Returns a Promise that resolves to an empty object if the command succeeds. If the command fails, the Promise resolves to an object with an error.

setSimulatorConfiguration(configuration)

Sets the configuration object for the simulated card reader.

This method only takes effect when connected to the simulated reader; it performs no action otherwise.

The simulated reader will follow the specified configuration only until processPayment is complete. At that point, the simulated reader will revert to its default behavior.

Note that this method overwrites any currently active configuration object; to add specific key-value pairs to the object, make sure to use a combination of this method and getSimulatorConfiguration.

The configuration options available are:

FieldValuesDescription
testCardNumberRefer to the Simulated test cards list.Configures the simulated reader to use a test card number as the payment method presented by the user. This can be used to test different scenarios in your integration, such as payments with different card brands or processing errors like a declined charge.
testPaymentMethodRefer to the Simulated test cards list.Serves the same purpose as testCardNumber, but relies on test payment methods instead.
paymentMethodType deprecated
  • card_present (default)
  • interac_present
Determine the type of payment method created by the simulated reader when collectPaymentMethod is called.

getSimulatorConfiguration()

Returns the currently active configuration object.

The Stripe Terminal JavaScript SDK may overwrite this value as necessary, including (but not limited to) resetting the value after processPayment is complete, and removing unknown key-value pairs.

collectRefundPaymentMethod(charge_id, amount, currency, options)

Begins collecting a payment method to be refunded. The method takes two required parameters:

  • charge_id, the ID of the charge that will be refunded.
  • amount: a number that represents the amount, in cents, that will be refunded from the charge. This number must be less than or equal to the amount that was charged in the original payment.
  • currency: Three-letter ISO code for the currency, in lowercase. Must be a supported currency.
  • options: an optional object containing additional refund parameters.
Option Description

refund_application_fee

Optional, defaults to false. Connect only.

Boolean indicating whether the application fee should be refunded when refunding this charge. If a full charge refund is given, the full application fee will be refunded. Otherwise, the application fee will be refunded in an amount proportional to the amount of the charge refunded.

An application fee can be refunded only by the application that created the charge.

reverse_transfer

Optional, defaults to false. Connect only.

Boolean indicating whether the transfer should be reversed when refunding this charge. The transfer will be reversed proportionally to the amount being refunded (either the entire or partial amount).

A transfer can be reversed only by the application that created the charge.

Returns a Promise that resolves to either:

  • an empty object if the payment method collection was successful, or
  • an object with an error field if there was an error while collecting the refund payment method.

processRefund()

Processes an in-progress refund. This method can only be successfully called after collectRefundPaymentMethod has returned successfully.

Returns a Promise that resolves to either:

  • a refund object if the refund was successful, or
  • an object with an error field if there was an error while processing the refund.

cancelCollectRefundPaymentMethod()

Cancels an outstanding collectRefundPaymentMethod command.

Returns a Promise that resolves to an empty object if the cancellation was successful. If the cancellation fails, the Promise resolves to an object with an error field.

Errors

Errors returned by the JavaScript SDK include an error code, as well as a human-readable message.

For methods involving a PaymentIntent like processPayment, the error may also include a payment_intent object.

Error codes

CodeDescription
no_established_connectionThe command failed because no reader is connected.
no_active_collect_payment_method_attemptcancelCollectPaymentMethod can only be called when collectPaymentMethod is in progress.
no_active_read_reusable_card_attemptcancelCollectReusableCard can only be called when readReusableCard is in progress.
canceledThe command was canceled.
cancelable_already_completedCancelation failed because the operation has already completed.
cancelable_already_canceledCancelation failed because the operation has already been canceled.
network_errorAn unknown error occurred when communicating with the server or reader over the network. Refer to the error message for more information.
network_timeoutThe request timed out when communicating with the server or reader over the network. Make sure both your device and the reader are connected to the network with stable connections.
already_connectedconnectReader failed because a reader is already connected.
failed_fetch_connection_tokenFailed to fetch a connection token. Make sure your connection token handler returns a promise that resolves to the connection token.
discovery_too_many_readersdiscoverReaders returned too many readers. Use Locations to filter discovered readers by location.
invalid_reader_versionThe reader is running an unsupported software version. Please allow the reader to update and try again.
reader_errorThe reader returned an error while processing the request. Refer to the error message for more information.
command_already_in_progressThe action cannot be performed, because there is an in-progress action preventing it.

Changelog

If you are using an earlier version of the JavaScript SDK (before June 7, 2019), update to the latest release by changing the URL of the script your integration includes.

<script src="https://js.stripe.com/terminal/v1/"></script>

For more information on migrating from the Stripe Terminal beta, see the Terminal Beta Migration Guide.

v1

  • Renamed confirmPaymentIntent to processPayment.
  • Renamed the values for PaymentStatus. PaymentStatus can be one of not_ready, ready, waiting_for_input, or processing.
  • Removed card details from the response to collectPaymentMethod, previously available in response.paymentIntent.payment_method.card_payment.
  • Receipt information is now located in the payment_intent.charges[0].payment_method_details.card_present hash.
  • Changed the API for discovering a simulated reader to discoverReaders({ simulated: true }).
  • Renamed readSource to readReusableCard. A successful call to readReusableCard returns a PaymentMethod instead of a Source. Payment Methods must be used with Payment Intents. For more information, see the Payment Methods API overview.
  • Changed the response of connectReader to { reader: Reader }, removing the wrapper Connection object.
  • Removed the startReaderDiscovery and stopReaderDiscovery methods. To repeatedly discover readers, you can use the JavaScript setInterval method.
  • Renamed clearConnectionToken to clearCachedCredentials.
Was this page helpful?
Questions? Contact us.
Watch our developer tutorials.
Check out our product changelog.
Powered by Markdoc
You can unsubscribe at any time. Read our privacy policy.
On this page
API methods
Errors
Changelog
Stripe Shell
Test mode
▗▄ ▄▟█ █▀▀ ▗▟████▙▖ ██████ ███▗▟█ ███ ███▗▟██▙▖ ▗▟█████▙▖ ███▖ ▀▀ ███ ███▀▀▀ ███ ███▀ ███ ███ ███ ▝▜████▙▖ ███ ███ ███ ███ ███ █████████ ▄▄ ▝███ ███ ▄ ███ ███ ███▄ ███ ███ ▄▄ ▝▜████▛▘ ▝▜███▛ ███ ███ ███▝▜██▛▘ ▝▜█████▛▘ ███ ▀▘
Welcome to the Stripe Shell! Stripe Shell is a browser-based shell with the Stripe CLI pre-installed. Login to Stripe docs and press Control + Backtick on your keyboard to start managing your Stripe resources in test mode. - View supported commands: - Find webhook events: - Listen for webhook events: - Call Stripe APIs: stripe [api resource] [operation] (e.g. )
The Stripe Shell is best experienced on desktop.
$