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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spring-payments/payments-react

v0.1.0

Published

Unstyled Spring Payments components for React 19 and Next.js

Readme

Spring Payments for React

Unstyled, typed card-entry components for React 19, including Next.js App Router and Pages Router. They use Spring's shared web SDK for card entry, bank verification and checking the result. Your backend still checks the customer's access and starts payments. Saving a card does not charge it.

Install

npm install @spring-payments/payments-react

The shared @spring-payments/payments-js SDK is installed automatically. Do not install React Native's package in a browser app, initialize Stripe separately or load a Gateway-hosted module.

React and Next.js example

Put your integration in a Client Component. This package preserves its own 'use client' boundary, but your createSession and event handlers also belong in client code—not function props passed from a Next.js Server Component.

'use client';

import { SpringAddCardButton } from '@spring-payments/payments-react';
import type { ComponentSession, CardResult } from '@spring-payments/payments-react';

async function createCardSession(request: { origin: string; returnUrl: string }): Promise<ComponentSession> {
  const response = await fetch('/api/payment/card-session', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(request),
    cache: 'no-store',
  });
  if (!response.ok) throw new Error('Unable to start card entry');
  return response.json();
}

export function AddCard({ onResult }: { onResult: (result: CardResult) => void }) {
  return <SpringAddCardButton
    createSession={createCardSession}
    className="add-card"
    labels={{ button: 'Add a card', confirm: 'Save card' }}
    appearance={{ theme: 'stripe', variables: { colorPrimary: '#234db5' } }}
    onResult={onResult}
  />;
}

/api/payment/card-session is a route you implement, not a Spring SDK endpoint. It authenticates your customer, checks their access, and calls POST /api/external/spg/v1/clients/{key}/card-sessions with your server-side Spring access token, {origin, returnUrl} and a stable Idempotency-Key. Return Spring's {sessionId, sessionToken, expiresAt, componentUrl} response. Reuse the key after a lost response; never expose your permanent API credentials. Keep session credentials in memory, not logs, URLs or storage, and return Cache-Control: no-store from your route. Apply your app's CSRF protection.

The customer must first be registered and have accepted all required onboarding documents. Spring must enable card funding and allow your web origin. A configured returnUrl must use the same origin as the app.

Result handling

  • COMPLETED: Spring confirmed the saved card; refresh your saved-card list. The result includes paymentAccountId.
  • PENDING: ask your backend to check before trying again.
  • CANCELLED: nothing was submitted.
  • FAILED: the operation could not continue.

Closing a form after pressing Save does not undo the request. Do not assume that dismissing the form means nothing was saved.

Styling and custom buttons

No Spring styles are injected. className, style, disabled, aria-* and other native button attributes apply to the launch button. Supply children for your own button content. The component keeps type="button", aria-haspopup="dialog", and disables repeated clicks while its dialog is open. Your onClick can prevent opening with event.preventDefault().

Use global CSS for .spring-card-dialog, ::backdrop, .spring-card-close, .spring-card-title, .spring-card-description, .spring-card-content and .spring-payment-component. The dialog normally mounts under document.body, outside the React component. CSS Modules need a global selector, or pass a connected element as dialogContainer to scope your theme. Keep visible focus indicators and readable contrast.

Pass appearance to style Stripe's secure fields, not the launch button or dialog. Stripe's iframe cannot be styled with ordinary page CSS. The bank controls its 3DS verification screen. See the shared web SDK's README for supported classes, labels and recovery requirements.

Inline card entry

import { SpringAddCard } from '@spring-payments/payments-react';

// Inside a Client Component; signedInCustomerId and handlers come from your app.
<SpringAddCard
  key={signedInCustomerId}
  createSession={createCardSession}
  className="inline-card"
  onSuccess={() => refreshSavedCards()}
  onError={() => showError()}
/>;

The SDK owns the host element's children; do not add children or HTML to this component. If you put inline entry in your own modal, you own that modal's focus and keyboard accessibility.

Renders, configuration changes and cleanup

  • The button captures session and appearance options when opened. Prop changes do not restart an active payment; the next opening uses the new options.
  • Inline entry captures session and appearance options on mount. Use a new React key to apply a different customer's configuration or deliberately restart it. Do not mutate option objects or change the identity behind createSession while an operation is active.
  • Event callbacks use the latest committed props. Ordinary rerenders do not create extra sessions. Inline entry skips React Strict Mode's discarded setup pass.
  • Unmounting closes the button's dialog or destroys inline entry and stops callbacks to the removed component. It does not delete a saved card or cancel a payment already submitted. Check status through your backend if interrupted.
  • Importing and server-rendering these components does not access browser APIs or create a session. Card entry starts only in the browser. No dynamic(..., { ssr: false }) is required.

Spring-hosted payment recovery remains preferred. These wrappers do not change the backend or bank-verification contract. Test real card entry, 3DS, redirects, keyboard access and your supported browsers with the configured backend before production use.

Maintaining and publishing

Source: packages/spring-payments-react/src/ in Spring's private repository. Edit TypeScript, not generated dist/ files. The local dev dependency links the shared SDK for development; the published runtime dependency uses its npm version.

Build the shared SDK first, then run from this directory:

npm ci
npm test
npm pack --dry-run
npm pack

Check that the archive contains only compiled JavaScript/declarations, README, MIT license and package metadata. Verify 'use client' remains the first directive in dist/index.js. Test the packed archive in a React 19 / Next.js app. Publish the compatible shared SDK first; then, with release authorization, publish the inspected archive using npm publish <archive.tgz> --access public. Never reuse a published version or put credentials in chat or the package.

MIT; see LICENSE. This license covers this package's Spring code, not backend services or trademarks. Stripe services retain their own terms.