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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pagedotapp/page-pay-button

v0.0.0-alpha.13

Published

PagePayButton - A reusable React component

Downloads

32

Readme

PagePayButton

A payment button component that integrates with Stripe Express Checkout for easy one-time payments and subscriptions.

Installation

npm install @pagedotapp/page-pay-button

Usage

import { PagePayButton } from "@pagedotapp/page-pay-button"

function App() {
	return (
		<PagePayButton
			service="stripe"
			mode="payment"
			stripeKey="pk_test_..."
			apiEndpoint="https://api.example.com/create-payment-intent"
			items={[
				{
					id: "prod_123",
					name: "Premium Subscription",
					price: 999, // $9.99
					currency: "usd",
					quantity: 1,
				},
			]}
			onSuccess={(details) => console.log("Payment successful!", details)}
			onError={(error) => console.error("Payment failed:", error)}
		/>
	)
}

Props

| Prop | Type | Default | Description | | ----------------- | ----------------------------- | ----------- | ----------------------------------------------------- | | service | 'stripe' \| 'paypal' | 'stripe' | Payment service provider (only Stripe is implemented) | | mode | 'payment' \| 'subscription' | 'payment' | Payment mode | | items | PaymentItem[] | - | Items to purchase (required) | | stripeKey | string | - | Stripe publishable key (required for Stripe) | | apiEndpoint | string | - | API endpoint for creating payment intents (required) | | metadata | Record<string, any> | - | Additional metadata to send with the payment | | onSuccess | function | - | Callback when payment succeeds | | onError | function | - | Callback when payment fails | | onCancel | function | - | Callback when payment is cancelled | | buttonHeight | number | 40 | Custom button height | | className | string | '' | Additional CSS class name | | isAuthenticated | boolean | false | Whether the user is authenticated | | onAuthRequired | function | - | Callback to handle authentication | | apiHeaders | Record<string, string> | {} | Custom headers for API requests |

PaymentItem Type

interface PaymentItem {
	id: string // Unique identifier
	name: string // Display name
	description?: string // Optional description
	price: number // Price in cents (e.g., $10.00 = 1000)
	currency: string // Currency code (e.g., 'usd')
	quantity?: number // Quantity (default: 1)
	image?: string // Optional image URL
}

Examples

One-time Payment

<PagePayButton
	service="stripe"
	mode="payment"
	stripeKey={process.env.REACT_APP_STRIPE_KEY}
	apiEndpoint="/api/create-payment-intent"
	items={[
		{
			id: "book_123",
			name: "JavaScript Book",
			price: 2999, // $29.99
			currency: "usd",
			quantity: 1,
		},
	]}
	onSuccess={(details) => {
		console.log("Payment successful!", details)
		// Redirect to success page
	}}
/>

Subscription

<PagePayButton
	service="stripe"
	mode="subscription"
	stripeKey={stripeKey}
	apiEndpoint="/api/create-subscription"
	items={[
		{
			id: "price_monthly",
			name: "Monthly Subscription",
			description: "Billed monthly",
			price: 1999, // $19.99/month
			currency: "usd",
		},
	]}
	metadata={{
		planType: "premium",
		billingCycle: "monthly",
	}}
	onSuccess={(details) => {
		// Handle successful subscription
	}}
/>

Multiple Items

<PagePayButton
	items={[
		{
			id: "course_001",
			name: "React Course",
			price: 4999,
			currency: "usd",
			quantity: 1,
		},
		{
			id: "book_002",
			name: "React Handbook",
			price: 2499,
			currency: "usd",
			quantity: 2,
		},
	]}
	// ... other props
/>

With Authentication

<PagePayButton
	items={items}
	isAuthenticated={user.isLoggedIn}
	onAuthRequired={async () => {
		// Show login modal
		const success = await showLoginModal()
		return success
	}}
	// ... other props
/>

Custom API Headers

<PagePayButton
	items={items}
	apiHeaders={{
		Authorization: `Bearer ${authToken}`,
		"X-Custom-Header": "value",
	}}
	// ... other props
/>

API Endpoint Requirements

Your API endpoint should:

  1. Accept a POST request with the following body:
{
  "mode": "payment" | "subscription",
  "amount": 1000,
  "currency": "usd",
  "items": [...],
  "metadata": {...}
}
  1. Return a response with:
{
	"clientSecret": "pi_..._secret_..." // or "client_secret"
}

Styling

The component uses CSS modules for styling. The Stripe Express Checkout button will automatically adapt to fit the container width.

/* Custom styling example */
.paymentContainer {
	max-width: 400px;
	margin: 0 auto;
}

Error Handling

The component validates all required props and will return null if:

  • No items are provided
  • Stripe key is missing (for Stripe service)
  • API endpoint is missing
  • Total amount is zero
  • Service is set to 'paypal' (not implemented)

Development

To run the component in development mode:

npm run storybook

To run tests:

npm run test

To lint the component:

npm run lint

Notes

  • PayPal integration is not yet implemented. The component returns null when service="paypal"
  • Prices should be provided in cents (e.g., $10.00 = 1000)
  • The component handles both one-time payments and subscriptions
  • Stripe Express Checkout provides Apple Pay, Google Pay, and card payment options