Use the Stripe maintained @stripe/terminal-js version instead. I will stop working on this in favor of using the new Stripe integration.
A project that will allow you to use the Stripe JS Terminal integration using javascript's importing/requiring instead of using a script in your header. This was specifically created for use in code bases that don't allow static script importing (ex. React, React Native).
This package gets the Stripe Terminal code from the static hosting at https://js.stripe.com/terminal/v1 and converts it to local code (like using a script tag on the web does). We rebuild the module the first time we access it each run ( when a website is loaded or app is opened) to comply with Stripe's guidelines.
- Stripe Api Reference
- Stripe Setup Guide
- Stripe Payment Guide
- Avery's Simple How-To's
- Avery's Troubleshooting
npm i stripe-terminal --save
or
yarn add stripe-terminal
The package needs to be configured to your stripe account using. Use the setup function to setup your token integration and other available callbacks.
import StripeTerminal from "stripe-terminal"
await StripeTerminal.setup({
onFetchConnectionToken: this.fetchToken.bind(this), // Required
onUnexpectedReaderDisconnect: this.readerDisconnect.bind(this),
});
Discover readers connected to your stripe account.
let {discoveredReaders} = await StripeTerminal.discoverReaders({simulated: false});
Option | Default | Description |
---|---|---|
simulated |
false | A boolean value indicating whether to discover a simulated reader. |
location |
undefined | Return only readers assigned to the given location |
Discover readers connected to your stripe account.
let device = await StripeTerminal.connectReader(discoveredReaders[0]);
Option | Default | Description |
---|---|---|
reader |
undefined | The target reader you got from the discover call |
The first thing needed is create a payment intent. The only way you can do this is by creating it on the server.
Collect the payment intent using the secret from creating the payment intent
let {paymentIntent} = await StripeTerminal.collectPaymentMethod(clientSecret);
Option | Default | Description |
---|---|---|
client_secret |
undefined | The client_secret field from a PaymentIntent object created on your backend |
Process a payment after collecting the payment method.
let paymentResponse = await StripeTerminal.processPayment(paymentIntent);
Option | Default | Description |
---|---|---|
paymentIntent |
undefined | A PaymentIntent object obtained from a successful call to collectPaymentMethod. |
Here are the other methods that you can call.
Payment status options for the payment workflow.
let status = StripeTerminal.getConnectionStatus();
if (status === StripeTerminal.CONNECTION_STATUS.PROCESSING) {
// do something
}
Connection status options for the terminal.
let status = StripeTerminal.getPaymentStatus();
if (status === StripeTerminal.PAYMENT_STATUS.PROCESSING) {
// do something
}
Cancels an outstanding collectPaymentMethod command.
StripeTerminal.cancelCollectPaymentMethod();
Disconnects from the connected reader.
StripeTerminal.disconnectReader();
Clears the current ConnectionToken, and any other cached credentials.
Use this method to switch accounts in your application (e.g., to switch between live and test Stripe API keys on your backend). To switch accounts, follow these steps:
StripeTerminal.clearCachedCredentials();
Clears the reader display and resets it to the splash screen.
StripeTerminal.clearReaderDisplay();
Updates the reader display with cart details.
StripeTerminal.setReaderDisplay(displayInfo);
Begins collecting a payment method to be refunded.
Check about how to use this method here https://stripe.com/docs/terminal/js-api-reference#stripeterminal-collectrefundpaymentmethod
StripeTerminal.collectRefundPaymentMethod(charge_id, amount, currency, options);
To process the refund:
StripeTerminal.processRefund();
If you need to cancel the refund:
StripeTerminal.cancelCollectRefundPaymentMethod();
Reads a card for online reuse.
StripeTerminal.readReusableCard();
Reads a card for online reuse.
StripeTerminal.cancelReadReusableCard();
Sets the configuration object for the simulated card reader.
Check the reference for each parameter at Stripe https://stripe.com/docs/terminal/js-api-reference#stripeterminal-setsimulatorconfig
StripeTerminal.setSimulatorConfiguration({testCardNumber: "4242424242424242", testPaymentMethod: "visa"});
- Think about switching to exports instead of class based
- Maybe reject promise instead of returning error
- Add in some better examples
- Add in tests