2.0.9 • Published 3 years ago

stripe-terminal v2.0.9

Weekly downloads
54
License
MIT
Repository
github
Last release
3 years ago

Deprecated

Use the Stripe maintained @stripe/terminal-js version instead. I will stop working on this in favor of using the new Stripe integration.

Stripe Terminal

npm version

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.

Documentation

Installation

npm i stripe-terminal --save
or
yarn add stripe-terminal

Usage

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

Discover readers connected to your stripe account.

let {discoveredReaders} = await StripeTerminal.discoverReaders({simulated: false});
OptionDefaultDescription
simulatedfalseA boolean value indicating whether to discover a simulated reader.
locationundefinedReturn only readers assigned to the given location

Connect Reader

Discover readers connected to your stripe account.

let device = await StripeTerminal.connectReader(discoveredReaders[0]);
OptionDefaultDescription
readerundefinedThe target reader you got from the discover call

Create Payment Intent

The first thing needed is create a payment intent. The only way you can do this is by creating it on the server.

Collect Payment

Collect the payment intent using the secret from creating the payment intent

let {paymentIntent} = await StripeTerminal.collectPaymentMethod(clientSecret);
OptionDefaultDescription
client_secretundefinedThe client_secret field from a PaymentIntent object created on your backend

Process Payment

Process a payment after collecting the payment method.

let paymentResponse = await StripeTerminal.processPayment(paymentIntent);
OptionDefaultDescription
paymentIntentundefinedA PaymentIntent object obtained from a successful call to collectPaymentMethod.

Other Methods

Here are the other methods that you can call.

Get Connection Status

Payment status options for the payment workflow.

let status = StripeTerminal.getConnectionStatus();
if (status === StripeTerminal.CONNECTION_STATUS.PROCESSING) {
    // do something
} 

Get Payment Status

Connection status options for the terminal.

let status = StripeTerminal.getPaymentStatus();
if (status === StripeTerminal.PAYMENT_STATUS.PROCESSING) {
    // do something
} 

Cancel Collect Payment

Cancels an outstanding collectPaymentMethod command.

StripeTerminal.cancelCollectPaymentMethod();

Disconnect Reader

Disconnects from the connected reader.

StripeTerminal.disconnectReader();

Clear Cashed Credentials

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();

Clear Reader Display

Clears the reader display and resets it to the splash screen.

StripeTerminal.clearReaderDisplay();

Clear Reader Display

Updates the reader display with cart details.

StripeTerminal.setReaderDisplay(displayInfo);

Creating Refunds

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 reusable card

Reads a card for online reuse.

StripeTerminal.readReusableCard();

Cancels reusable card

Reads a card for online reuse.

StripeTerminal.cancelReadReusableCard();

Set Simulator Configuration

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"});

Todo

  • Think about switching to exports instead of class based
  • Maybe reject promise instead of returning error
  • Add in some better examples
  • Add in tests
2.0.9

3 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

1.2.4

4 years ago

2.0.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago