Sourcemap Explorer
Stack · npm package

stripe

Stripe API wrapper

latest 22.4.0· MIT· 789 versions publishedView on npm

About

Stripe API wrapper

stripepayment processingcredit cardsapi

What detecting stripe tells you about a site

stripe is the server-side Node.js SDK, which carries a secret API key and is meant to run only on a backend, so finding it in a client-shipped bundle is a serious red flag: it strongly suggests a leaked secret key or a server module that was misbundled into client code. In its proper place (server output, edge functions, API routes), its presence confirms real payment processing, subscriptions or billing logic and a product that handles money. The distinction from @stripe/stripe-js, the browser-safe publishable-key library, is what makes this such a meaningful signal.

Why the exact stripe version matters

The Stripe Node SDK pins a specific Stripe API version, and major SDK versions change pinned-API defaults, TypeScript typings and request behaviour, so the version tells you which era of Stripe's API the integration targets. Given it handles payments, staying current also matters for security and for access to newer payment methods and compliance features.

stripe in a real-world stack

When you find stripe in a bundle, it rarely travels alone. Server-side; on the client the legitimate counterpart is @stripe/stripe-js.

Quick facts

Latest version22.4.0
LicenseMIT
AuthorStripe
Installnpm install stripe
Direct dependencies0
Peer dependencies@types/node

Common pairings

Packages this one expects to find in the same project. Each is also a Sourcemap Explorer detection target.

@types/node

How Sourcemap Explorer detects stripe

stripe ships as v22.4.0, published 2026-07-29 and carries 0 direct dependencies, 1 peer dependency (@types/node), 789 versions on the registry. Those exact numbers are the footprint Sourcemap Explorer matches when stripe rides inside a deployed bundle — here is how the detection works.

We catch stripe from two complementary signals: bundled source paths and the embedded package.json. Modern bundlers (webpack, Vite, esbuild, Rollup, Turbopack) preserve the original node_modules/stripe/ paths inside the JavaScript sourcemap's sources[] array — that's the canonical signal. When the matching package.json is also captured in sourcesContent[], we read the exact version field — patch number included. No regex guessing, no version inference.

  1. 1

    Confirm the site exposes sourcemaps

    In DevTools Network, check the response headers of any application script for `SourceMap` or `X-SourceMap`. Failing that, fetch the script's last 4 KB and look for a `//# sourceMappingURL=` comment — that map is where the `stripe` paths live.

  2. 2

    Find the package in the bundle

    Open DevTools → Network → reload. Click any application script and look at its sourcemap. Inside, search `sources[]` for entries matching `node_modules/stripe/` — every match confirms the package is bundled. The matching `sourcesContent[i]` for `node_modules/stripe/package.json` gives you the exact installed version.

  3. 3

    Read the version directly from package.json

    Run `jq -r '. as $m | $m.sources | to_entries[] | select(.value | endswith("node_modules/stripe/package.json")) | $m.sourcesContent[.key] | fromjson | .version' bundle.js.map`. Sourcemap Explorer automates the same query in the popup.

Major releases of stripe

When each major version first landed. Major bumps are where breaking changes live, so this timeline is the fastest way to date the stripe version a site actually ships against the ecosystem.

Major
First release
Date
v22
22.0.0
2026-04-03
v21
21.0.0
2026-03-26
v20
20.0.0
2025-11-18
v19
19.0.0
2025-09-30
v18
18.0.0
2025-04-01
v17
17.0.0
2024-10-01

Recent versions

Version
Released
22.4.0
2026-07-29
22.3.2
2026-07-16
22.3.1
2026-07-09
22.3.0
2026-06-24
22.2.3
2026-06-22
22.2.2
2026-06-18
22.2.1
2026-06-12
22.2.0
2026-05-27

stripe README

Live mirror of the GitHub README, for reference. Updated whenever the repo's default branch changes.

Stripe Node.js Library

Version Build Status Downloads

[!TIP] Want to chat live with Stripe engineers? Join us on our Discord server.

The Stripe Node library provides convenient access to the Stripe API from applications written in server-side JavaScript.

For collecting customer and payment information in the browser, use Stripe.js.

Documentation

See the stripe-node API docs for Node.js.

Requirements

Per our Language Version Support Policy, we currently support all LTS versions of Node.js 18+.

Read more and see the full schedule in the docs: https://docs.stripe.com/sdks/versioning?lang=node#stripe-sdk-language-version-support-policy

Installation

Install the package with:

npm install stripe
# or
yarn add stripe

Usage

The package needs to be configured with your account's secret key, which is available in the Stripe Dashboard. Require it with the key's value:

import Stripe from 'stripe';
const stripeClient = new Stripe('sk_test_...');

const customer = await stripeClient.customers.create({
  email: 'customer@example.com',
});

console.log(customer.id);

Or using CJS:

const Stripe = require('stripe');
const stripeClient = Stripe('sk_test_...');

stripeClient.customers
  .create({
    email: 'customer@example.com',
  })
  .then((customer) => console.log(customer.id))
  .catch((error) => console.error(error));

[!WARNING] If you're using v17.x.x or later and getting an error about a missing API key despite being sure it's available, it's likely you're importing the file that instantiates Stripe while the key isn't present (for instance, during a build step). If that's the case, consider instantiating the client lazily:

import Stripe from 'stripe';

let _stripe: Stripe | null = null;
const getStripeClient = (): Stripe => {
  if (!_stripe) {
    _stripe = new Stripe(process.env.STRIPE_SECRET_KEY as string, {
      // ...
    });
  }
  return _stripe;
};

const getCustomers = () => getStripeClient().customers.list();

Alternatively, you can provide a placeholder for the real key (which will be enough to get the code through a build step):

import Stripe from 'stripe';

export const stripeClient = new Stripe(
  process.env.STRIPE_SECRET_KEY || 'api_key_placeholder',
  {
    // ...
  }
);

Usage with TypeScript

As of 8.0.1, Stripe maintains types for the latest API version.

Import Stripe as a default import (not * as Stripe, unlike the DefinitelyTyped version) and instantiate it as new Stripe() with the latest API version.

import Stripe from 'stripe';
const stripeClient = new Stripe('sk_test_...');

const createCustomer = async () => {
  const params: Stripe.CustomerCreateParams = {
    description: 'test customer',
  };

  const customer: Stripe.Customer = await stripeClient.customers.create(params);

  console.log(customer.id);
};
createCustomer();

You can find a full TS server example in stripe-samples.

Using old API versions with TypeScript

Types can change between API versions (e.g., Stripe may have changed a field from a string to a hash), so our types only reflect the latest API version.

We therefore encourage upgrading your API version if you would like to take advantage of Stripe's TypeScript definitions.

If you are on an older API version (e.g., 2019-10-17) and not able to upgrade, you may pass another version and use a comment like // @ts-ignore stripe-version-2019-10-17 to silence type errors here and anywhere the types differ between your API version and the latest. When you upgrade, you should remove these comments.

We also recommend using // @ts-ignore if you have access to a beta feature and need to send parameters beyond the type definitions.

Using expand with TypeScript

Expandable fields are typed as string | Foo, so you must cast them appropriately, e.g.,

const paymentIntent: Stripe.PaymentIntent = await stripeClient.paymentIntents.retrieve(
  'pi_123456789',
  {
    expand: ['customer'],
  }
);
const customerEmail: string = (paymentIntent.customer as Stripe.Customer).email;

// Define and use this helper method if you extract `id` often
function getId(stripeObject: {id: string} | string) {
  return typeof stripeObject === 'string' ? stripeObject : stripeObject.id;
}

const customerId: string = getId(paymentIntent.customer);
TypeScript and the stripe-node versioning policy

The TypeScript types in stripe-node always reflect the latest shape of the Stripe API. When the Stripe API changes in a backwards-incompatible way, there is a new Stripe API version, and we release a new major version of stripe-node. Sometimes, though, the Stripe API changes in a way that weakens the guarantees provided by the TypeScript types, but that cannot result in any backwards incompatibility at runtime. For example, we might add a new enum value on a response, along with a new parameter to a request. Adding a new value to a response enum weakens the TypeScript type. However, if the new enum value is only returned when the new parameter is provided, this cannot break any existing usages and so would not be considered a breaking API change. In stripe-node, we do NOT consider such changes to be breaking under our current versioning policy. This means that you might see new type errors from TypeScript as you upgrade minor versions of stripe-node, that you can resolve by adding additional type guards.

Please feel welcome to share your thoughts about the versioning policy in a Github issue. For now, we judge it to be better than the two alternatives: outdated, inaccurate types, or vastly more frequent major releases, which would distract from any future breaking changes with potentially more disruptive runtime implications.

Using Promises

Every method returns a chainable promise which can be used instead of a regular callback:

// Create a new customer and then create an invoice item then invoice it:
stripeClient.customers
  .create({
    email: 'customer@example.com',
  })
  .then((customer) => {
    // have access to the customer object
    return stripe.invoiceItems
      .create({
        customer: customer.id, // set the customer id
        amount: 2500, // 25
        currency: 'usd',
        description: 'One-time setup fee',
      })
      .then((invoiceItem) => {
        return stripe.invoices.create({
          collection_method: 'send_invoice',
          customer: invoiceItem.customer,
        });
      })
      .then((invoice) => {
        // New invoice created on a new customer
      })
      .catch((err) => {
        // Deal with an error
      });
  });

Usage with Deno

As of 11.16.0, stripe-node provides a deno export target. In your Deno project, import stripe-node using an npm specifier:

Import using npm specifiers:

import Stripe from 'npm:stripe';

Please see https://github.com/stripe-samples/stripe-node-deno-samples for more detailed examples and instructions on how to use stripe-node in Deno.

Configuration

Initialize with config object

The package can be initialized with several options:

import ProxyAgent from 'https-proxy-agent';

const stripe = Stripe('sk_test_...', {
  maxNetworkRetries: 1,
  httpAgent: new ProxyAgent(process.env.http_proxy),
  timeout: 1000,
  host: 'api.example.com',
  port: 123,
  telemetry: true,
});
OptionDefaultDescription
apiVersionnullStripe API version to be used. If not set, stripe-node will use the latest version at the time of release.
maxNetworkRetries1The amount of times a request should be retried.
httpAgentnullProxy agent to be used by the library.
timeout80000Maximum time each request can take in ms.
host'api.stripe.com'Host that requests are made to.
port443Port that requests are made to.
protocol'https''https' or 'http'. http is never appropriate for sending requests to Stripe servers, and we strongly discourage http, even in local testing scenarios, as this can result in your credentials being transmitted over an insecure channel.
telemetrytrueAllow Stripe to send telemetry.

Note Both maxNetworkRetries and timeout can be overridden on a per-request basis.

Configuring Timeout

Timeout can be set globally via the config object:

const stripeClient = Stripe('sk_test_...', {
  timeout: 20 * 1000, // 20 seconds
});

And overridden on a per-request basis:

stripeClient.customers.create(
  {
    email: 'customer@example.com',
  },
  {
    timeout: 1000, // 1 second
  }
);

Configuring For Connect

A per-request Stripe-Account header for use with Stripe Connect can be added to any method:

// List the balance transactions for a connected account:
stripeClient.balanceTransactions.list(
  {
    limit: 10,
  },
  {
    stripeAccount: 'acct_foo',
  }
);

Configuring a Proxy

To use stripe behind a proxy you can pass an https-proxy-agent on initialization:

if (process.env.http_proxy) {
  const ProxyAgent = require('https-proxy-agent');

  const stripe = Stripe('sk_test_...', {
    httpAgent: new ProxyAgent(process.env.http_proxy),
  });
}

Network retries

As of v13 stripe-node will automatically do one reattempt for failed requests that are safe to retry. Automatic network retries can be disabled by setting the maxNetworkRetries config option to 0. You can also set a higher number to reattempt multiple times, with exponential backoff. Idempotency keys are added where appropriate to prevent duplication.

const stripeClient = Stripe('sk_test_...', {
  maxNetworkRetries: 0, // Disable retries
});
const stripeClient = Stripe('sk_test_...', {
  maxNetworkRetries: 2, // Retry a request twice before giving up
});

Network retries can also be set on a per-request basis:

stripeClient.customers.create(
  {
    email: 'customer@example.com',
  },
  {
    maxNetworkRetries: 2, // Retry this specific request twice before giving up
  }
);

Examining Responses

Some information about the response which generated a resource is available with the lastResponse property:

customer.lastResponse.requestId; // see: https://stripe.com/docs/api/request_ids?lang=node
customer.lastResponse.statusCode;

request and response events

The Stripe object emits request and response events. You can use them like this:

const Stripe = require('stripe');
const stripeClient = Stripe('sk_test_...');

const onRequest = (request) => {
  // Do something.
};

// Add the event handler function:
stripeClient.on('request', onRequest);

// Remove the event handler function:
stripeClient.off('request', onRequest);
request object
{
  api_version: 'latest',
  account: 'acct_TEST',              // Only present if provided
  idempotency_key: 'abc123',         // Only present if provided
  method: 'POST',
  path: '/v1/customers',
  body: {name: 'test'},              // Only present if emitEventBodies is true
  request_start_time: 1565125303932  // Unix timestamp in milliseconds
}
response object
{
  api_version: 'latest',
  account: 'acct_TEST',                       // Only present if provided
  idempotency_key: 'abc123',                  // Only present if provided
  method: 'POST',
  path: '/v1/customers',
  status: 200,
  request_id: 'req_Ghc9r26ts73DRf',
  body: {id: 'cus_123', object: 'customer'},  // Only present if emitEventBodies is true
  elapsed: 445,                               // Elapsed time in milliseconds
  request_start_time: 1565125303932,          // Unix timestamp in milliseconds
  request_end_time: 1565125304377             // Unix timestamp in milliseconds
}

Webhook signing

Stripe can optionally sign the webhook events it sends to your endpoint, allowing you to validate that they were not sent by a third-party. You can read more about it here.

Please note that you must pass the raw request body, exactly as received from Stripe, to the constructEvent() function; this will not work with a parsed (i.e., JSON) request body.

You can find an example of how to use this with various JavaScript frameworks in examples/webhook-signing folder, but here's what it looks like:

const event = stripeClient.webhooks.constructEvent(
  webhookRawBody,
  webhookStripeSignatureHeader,
  webhookSecret
);
Testing Webhook signing

You can use stripeClient.webhooks.generateTestHeaderString to mock webhook events that come from Stripe:

const payload = {
  id: 'evt_test_webhook',
  object: 'event',
};

const payloadString = JSON.stringify(payload, null, 2);
const secret = 'whsec_test_secret';

const header = stripeClient.webhooks.generateTestHeaderString({
  payload: payloadString,
  secret,
});

const event = stripeClient.webhooks.constructEvent(
  payloadString,
  header,
  secret
);

// Do something with mocked signed event
expect(event.id).to.equal(payload.id);

How to use undocumented parameters and properties

In some cases, you might encounter parameters on an API request or fields on an API response that aren’t available in the SDKs. This might happen when they’re undocumented or when they’re in preview and you aren’t using a preview SDK. See undocumented params and properties to send those parameters or access those fields.

Writing a Plugin

If you're writing a plugin that uses the library, we'd appreciate it if you instantiated your stripe client with appInfo, eg;

With ES modules or TypeScript:

import Stripe from 'stripe';
const stripeClient = new Stripe(apiKey, {
  appInfo: {
    name: 'MyAwesomePlugin',
    version: '1.2.34', // Optional
    url: 'https://myawesomeplugin.info', // Optional
  },
});

Or using CJS:

const Stripe = require('stripe');
const stripeClient = Stripe('sk_test_...', {
  appInfo: {
    name: 'MyAwesomePlugin',
    version: '1.2.34', // Optional
    url: 'https://myawesomeplugin.info', // Optional
  },
});

This information is passed along when the library makes calls to the Stripe API.

Auto-pagination

We provide a few different APIs for this to aid with a variety of node versions and styles.

Async iterators (for-await-of)

If you are in a Node environment that has support for async iteration, such as Node 10+ or babel, the following will auto-paginate:

for await (const customer of stripeClient.customers.list()) {
  doSomething(customer);
  if (shouldStop()) {
    break;
  }
}
autoPagingEach

If you are in a Node environment that has support for await, such as Node 7.9 and greater, you may pass an async function to .autoPagingEach:

await stripeClient.customers.list().autoPagingEach(async (customer) => {
  await doSomething(customer);
  if (shouldBreak()) {
    return false;
  }
});
console.log('Done iterating.');

Equivalently, without await, you may return a Promise, which can resolve to false to break:

stripeClient.customers
  .list()
  .autoPagingEach((customer) => {
    return doSomething(customer).then(() => {
      if (shouldBreak()) {
        return false;
      }
    });
  })
  .then(() => {
    console.log('Done iterating.');
  })
  .catch(handleError);
autoPagingToArray

This is a convenience for cases where you expect the number of items to be relatively small; accordingly, you must pass a limit option to prevent runaway list growth from consuming too much memory. Once the limit number of items have been fetched, auto-pagination will stop.

Returns a promise of an array of all items across pages for a list request.

const allNewCustomers = await stripeClient.customers
  .list({created: {gt: lastMonth}, limit: 100}) // 100 items per page
  .autoPagingToArray({limit: 10000}); // Stop after 10000 items total

Telemetry

By default, the library sends request telemetry to Stripe regarding request latency and feature usage. These numbers help Stripe improve the overall latency of its API for all users, and improve popular features.

You can disable this behavior if you prefer:

const stripeClient = new Stripe('sk_test_...', {
  telemetry: false,
});

Public Preview SDKs

Stripe has features in the public preview phase that can be accessed via versions of this package that have the -beta.X suffix like 18.6.0-beta.1. We would love for you to try these as we incrementally release new features and improve them based on your feedback.

The easiest way to install a public-preview release is to use the dedicated npm tag:

npm install stripe@public-preview --save-exact

Or, to install a specific version from the releases page, you can specify that version explicitly:

npm install stripe@<some-version>
# for example:
# npm install stripe@18.6.0-beta.1

Note There can be breaking changes between two versions of the public preview SDKs without a bump in the major version. Therefore we recommend pinning the package version to a specific version (i.e. using --save-exact) in your package.json file. This way you can install the same version each time without breaking changes unless you are intentionally looking for the latest public preview SDK.

Some preview features require a name and version to be set in the Stripe-Version header like feature_beta=v3. If your preview feature has this requirement, use the apiVersion property of config object to set it:

const stripeClient = new Stripe('sk_test_...', {
  apiVersion: '2022-08-01; feature_beta=v3',
});

Private Preview SDKs

Stripe has features in the private preview phase that can be accessed via versions of this package that have the -alpha.X suffix like 18.6.0-alpha.1. You can install the private preview SDKs by following the same instructions as for the public preview SDKs above and replacing the term public-preview with private-preview. Note that access to specific private preview API features may require separate approval:

npm install stripe@private-preview --save-exact

Custom requests

This feature is only available from version 17 of this SDK.

If you would like to send a request to an undocumented API (for example you are in a private beta), or if you prefer to bypass the method definitions in the library and specify your request details directly, you can use the rawRequest method on the StripeClient object.

Using ES modules and async/await:

import Stripe from 'stripe';
const stripe = new Stripe('sk_test_...');

const response = await stripe.rawRequest(
  'POST',
  '/v1/beta_endpoint',
  {param: 123},
  {apiVersion: '2022-11-15; feature_beta=v3'}
);

// handle response

Or using CJS and promises:

const stripeClient = new Stripe('sk_test_...');

stripeClient.rawRequest(
    'POST',
    '/v1/beta_endpoint',
    { param: 123 },
    { apiVersion: '2022-11-15; feature_beta=v3' }
  )
  .then((response) => /* handle response */ )
  .catch((error) => console.error(error));

Support

New features and bug fixes are released on the latest major version of the stripe package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.

More Information

Development

[!WARNING] External contributions to this repo from first-time contributors are currently on hiatus. If you'd like to see a change made to the package, please open an issue.(

Contribution guidelines for this project

The tests depend on stripe-mock, so make sure to fetch and run it from a background terminal (stripe-mock's README also contains instructions for installing via Homebrew and other methods):

go get -u github.com/stripe/stripe-mock
stripe-mock

We use just for conveniently running development tasks. You can use them directly, or copy the commands out of the justfile. To our help docs, run just.

Run all tests (installing the dependencies first, if needed)

just test
# or: yarn && yarn test

If you do not have yarn installed, consult its installation instructions.

Run a single test suite:

just test test/Error.spec.ts
# or: yarn test test/Error.spec.ts

Run a single test (case sensitive) in watch mode:

just test test/Error.spec.ts --grep 'StripeError' --watch
# or: yarn test test/Error.spec.ts --grep 'StripeError' --watch

If you wish, you may run tests using your Stripe Test API key by setting the environment variable STRIPE_TEST_API_KEY before running the tests:

export STRIPE_TEST_API_KEY='sk_test....'
just test
# or: yarn test

Run prettier:

Add an editor integration or:

just format
# or: yarn prettier src/**/*.ts --write

FAQ

What is stripe used for?

Stripe API wrapper

How can I tell if a website is using stripe?

Open the page in Chrome with the Sourcemap Explorer extension installed and read the Stack tab. We catch `stripe` from two complementary signals: `node_modules/stripe/` paths inside the JavaScript sourcemap, and the embedded `package.json` we read for exact-version detection. Without the extension you can do the same lookup manually in DevTools — the steps are listed in the "How Sourcemap Explorer detects" section above.

How do I find out which version of stripe a website is running?

Read it straight from the site's JavaScript sourcemap. When a build ships source maps, the bundled `stripe/package.json` carries the exact `version` string — Sourcemap Explorer extracts it in one click on the Stack tab, and you can do it by hand in DevTools by opening the `.map` file and searching for `node_modules/stripe/package.json`. That is far more reliable than inferring the version from an asset-hash or a `?ver=` query string, which is all surface-level detectors have to go on. The current npm release is 22.4.0, but real deployments frequently run an older pinned version — which is exactly why reading the bundled number matters.

What is the latest version of stripe?

22.4.0, as published on the npm registry. The "Recent versions" table on this page lists the most recent 8 releases with their release dates. Sourcemap Explorer reports the version actually bundled into a site, which can lag the latest release by months on real-world deployments.

Is stripe actively maintained?

Very actively maintained — the last release shipped within the past three months. The last published release was 2026-07-29. Source code: https://github.com/stripe/stripe-node.

Where can I read more?

Project homepage: https://github.com/stripe/stripe-node. Source code: https://github.com/stripe/stripe-node. Published on npm: https://www.npmjs.com/package/stripe. Licensed as MIT.

Keep reading on Sourcemap Explorer

Detected by Sourcemap Explorer

When a bundle ships sourcemaps, we read the embedded package.json for stripe and report the precise version (the registry's latest is v22.4.0, published 2026-07-29; the bundled copy is often older). Without sourcemaps, an import / require in the page's scripts is enough to flag it.

Install free on Chrome