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

v0.12.0

Published

Stripe Terminal loading utility

Downloads

76,994

Readme

Terminal JS ES Module

Use the Terminal JS SDK as an ES module.

Note: This package dynamically loads the Stripe Terminal SDK from https://js.stripe.com and wraps the SDK's globalStripeTerminal function. To be PCI compliant, you must load the SDK directly from https://js.stripe.com by using this library. You cannot include the dynamically loaded code in a bundle or host it yourself.

npm version

Installation

Use npm or yarn to install the Terminal JS module:

> npm install @stripe/terminal-js

> yarn add @stripe/terminal-js

Usage

loadStripeTerminal

This function returns a Promise that resolves with a newly created StripeTerminal object once the Terminal JS SDK has loaded. If necessary, it will load the SDK for you by inserting the Terminal JS script tag. If you call loadStripeTerminal in a server environment it will resolve to null.

import {loadStripeTerminal} from '@stripe/terminal-js';

const StripeTerminal = await loadStripeTerminal();

const terminal = StripeTerminal.create({
  onFetchConnectionToken: async () => {
    …
  }
})

For more information on how to use the Terminal JS SDK once it loads, please refer to the Terminal JS SDK API reference or follow our getting started guide.

TypeScript support

This package includes TypeScript declarations for the Terminal JS SDK. We support projects using TypeScript versions >= 3.1.

Some methods in Terminal JS SDK accept and return objects from the Stripe API. The type declarations in @stripe/terminal-js for these objects in currently track to version 2018-08-23 of the Stripe API. If you have code using other versions of the Stripe API you may have to override type definitions as necessary.

Note that we may release new minor and patch versions of @stripe/terminal-js with small but backwards-incompatible fixes to the type declarations. These changes will not affect the Terminal JS SDK itself.

Ensuring the Terminal JS SDK is available everywhere

By default, this module will insert a <script> tag that loads the Terminal JS SDK from https://js.stripe.com. This happens as a side effect immediately upon importing this module.

Import as a side effect

Import @stripe/terminal-js as a side effect in code that will be included throughout your site (e.g. your root module). This will make sure the Terminal JS SDk script tag is inserted immediately upon page load.

import '@stripe/terminal-js';

Manually include the script tag

Manually add the Stripe.js script tag to the <head> of each page on your site. If an existing script tag is already present, this module will not insert a new one. When you call loadStripeTerminal, it will use the existing script tag.

<!-- Somewhere in your site's <head> -->
<script src="https://js.stripe.com/terminal/v1/" async></script>

Importing loadStripeTerminal without side effects

If you would like to use loadStripeTerminal in your application, but defer loading the Terminal JS SDK script until loadStripeTerminal is first called, use the alternative @stripe/terminal-js/pure import path:

import {loadStripeTerminal} from '@stripe/terminal-js/pure';

// Terminal SDK will not be loaded until `loadStripeTerminal` is called

Terminal JS SDK Documentation