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

@naturalpay/react

v1.0.0

Published

React component for Natural's embedded payment form

Readme

@naturalpay/react

Natural's embedded payment form as a React component. PaymentForm is a client component, so it works in the Next.js App Router.

The guide, Embed the payment form, has the server code, webhook setup, and every error code. Agents can read it as Markdown at https://docs.natural.com/guides/accept/embedded-checkout.md.

How a payment works

  1. Your server creates a payment intent with POST /payment-intents, through @naturalpay/sdk or any HTTP client. The response has the secret at data.attributes.clientSecret. Send it to the browser, and treat it like a password.
  2. Your page renders PaymentForm with the clientSecret. The payer pays inside the form.
  3. The form calls onComplete. Show your confirmation there.
  4. Your server gets the paymentIntent.completed webhook. Fulfill the order from the webhook, not from onComplete.

Add the form

npm install @naturalpay/react
import { PaymentForm } from "@naturalpay/react";

<PaymentForm clientSecret={clientSecret} onComplete={showConfirmation} onError={showError} />;

Props

  • clientSecret is the payment intent's clientSecret, or a Promise of it. It's required. A new value mounts a new form, so create a Promise once, not on every render.
  • theme is "light" (the default) or "dark", for a page with a dark background. A new value mounts a new form.
  • onComplete gets { paymentIntentId, status }, once, when the payer is done. A completed status means the payer paid. A processing status means the result arrives by webhook, and the payment can still fail.
  • onError gets a failed mount and every later error. Without it, errors go to the console.
  • className is set on the <div> that holds the form.

Set up your site

  • Serve your page over HTTPS. Plain http works only on localhost and 127.0.0.1, and only in Sandbox.
  • Start in Sandbox. There the form loads on any site.
  • Before you take live payments, add each site that shows the form, like https://shop.example.com, in the Natural dashboard under Developers → API keys → Checkout domains. In live mode, a site that isn't listed gets domain_not_allowed.
  • If your page sets a Content Security Policy, allow https://checkout.natural.com in script-src and frame-src.
  • If your page sends Cross-Origin-Opener-Policy: same-origin, send same-origin-allow-popups instead. Otherwise Google Pay fails.

Handle errors

An error is a plain { code, message } object, not an Error.

  • Match on code. A code is never renamed or removed, but new ones are added, so handle a code you don't know.
  • Log message. Its wording can change, so don't match on it or show it to payers.
  • After onError fires, the form can't take a payment. Render PaymentForm with a new key to let the payer try again.
  • A declined card shows inside the form. It doesn't call onError.

The guide lists every code. Changes are in CHANGELOG.md.

What your page must show

The form shows the merchant name, card fields, the authorization sentence, and your policies. Your page shows the rest:

  1. What the payer is buying.
  2. Each item, any tax or fee, and the total with its currency.
  3. Your country and a support email or phone, on the page or in your footer.
  4. Your delivery policy, if you ship goods.

Natural emails the payer a receipt.