npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stripe-terminal

v2.0.9

Published

A SDK for stripe terminal

Downloads

88

Readme

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

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

Connect Reader

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 |

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

| Option | Default | Description | | ------------------- | ------------------ | ------------------------------------------------------------------------------------- | | client_secret | undefined | The 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);

| Option | Default | Description | | ------------------- | ------------------ | ------------------------------------------------------------------------------------- | | paymentIntent | undefined | A 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