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

@one-payments/react

v1.7.0

Published

React wrapper for One Payments SDK

Readme

@one-payments/react

React wrapper component for One Payments SDK. Use this package to integrate One Payments into your React applications with a native React component API.

Features

  • Native React component wrapping One Payments web component
  • Full TypeScript support with type definitions
  • React event handlers instead of DOM events
  • Seamless integration with React hooks and lifecycle

Installation

npm install @one-payments/react @one-payments/adapters-web
# or
yarn add @one-payments/react @one-payments/adapters-web
# or
pnpm add @one-payments/react @one-payments/adapters-web

Usage

Basic Example

import React from 'react';
import { OnePayment } from '@one-payments/react';
import { PaymentConfig } from '@one-payments/core';
import { createWebAdapters } from '@one-payments/adapters-web';
import type { PaymentSucceededPayload, PaymentFailedPayload } from '@one-payments/react';

function CheckoutPage() {
  // Create config using PaymentConfig class (recommended for type safety and validation)
  const config = new PaymentConfig({
    apiKey: 'your-api-key',
    secretKey: 'your-secret-key',
    environment: 'demo'
  });

  const adapters = createWebAdapters();

  const handleSuccess = (event: CustomEvent<PaymentSucceededPayload>) => {
    console.log('Payment successful!', event.detail);
    // Navigate to success page or show confirmation
  };

  const handleError = (event: CustomEvent<PaymentFailedPayload>) => {
    console.error('Payment failed:', event.detail);
    // Show error message to user
  };

  return (
    <div className="checkout">
      <h1>Complete Your Payment</h1>
      <OnePayment
        config={config}
        adapters={adapters}
        amount={5000}
        currency="SGD"
        orderId={`order-${Date.now()}`}
        firstName="John"
        lastName="Doe"
        email="[email protected]"
        onPaymentSuccess={handleSuccess}
        onPaymentError={handleError}
      />
    </div>
  );
}

export default CheckoutPage;

Note: You can also pass a plain config object instead of using PaymentConfig:

config={{
  apiKey: 'your-api-key',
  secretKey: 'your-secret-key',
  environment: 'demo'
}}

However, PaymentConfig is recommended as it provides validation and better TypeScript support.

With State Management

import React, { useState } from 'react';
import { OnePayment } from '@one-payments/react';
import { createWebAdapters } from '@one-payments/adapters-web';
import type {
  PaymentSucceededPayload,
  PaymentFailedPayload,
  StateChangedPayload
} from '@one-payments/react';

function CheckoutWithState() {
  const [paymentStatus, setPaymentStatus] = useState<'idle' | 'processing' | 'success' | 'error'>('idle');
  const [errorMessage, setErrorMessage] = useState<string>('');

  const adapters = createWebAdapters();

  const handleSuccess = (event: CustomEvent<PaymentSucceededPayload>) => {
    setPaymentStatus('success');
    console.log('Payment Intent ID:', event.detail.paymentIntentId);
  };

  const handleError = (event: CustomEvent<PaymentFailedPayload>) => {
    setPaymentStatus('error');
    setErrorMessage(event.detail.message);
  };

  const handleStateChange = (event: CustomEvent<StateChangedPayload>) => {
    console.log('Payment state:', event.detail.status);
    if (event.detail.status === 'processing') {
      setPaymentStatus('processing');
    }
  };

  if (paymentStatus === 'success') {
    return <div>Payment successful! Thank you for your order.</div>;
  }

  return (
    <div>
      {paymentStatus === 'error' && (
        <div className="error">{errorMessage}</div>
      )}
      {paymentStatus === 'processing' && (
        <div className="processing">Processing your payment...</div>
      )}
      <OnePayment
        config={{
          apiKey: process.env.REACT_APP_ONE_PAYMENTS_API_KEY!,
          secretKey: process.env.REACT_APP_ONE_PAYMENTS_SECRET_KEY!,
          environment: 'prod'
        }}
        adapters={adapters}
        amount={5000}
        currency="SGD"
        orderId={`order-${Date.now()}`}
        metadata={{
          userId: '12345',
          productId: 'product-abc'
        }}
        onPaymentSuccess={handleSuccess}
        onPaymentError={handleError}
        onStateChange={handleStateChange}
      />
    </div>
  );
}

With React Router

import React from 'react';
import { useNavigate } from 'react-router-dom';
import { OnePayment } from '@one-payments/react';
import { createWebAdapters } from '@one-payments/adapters-web';

function CheckoutPage() {
  const navigate = useNavigate();
  const adapters = createWebAdapters();

  return (
    <OnePayment
      config={{
        apiKey: process.env.REACT_APP_ONE_PAYMENTS_API_KEY!,
        secretKey: process.env.REACT_APP_ONE_PAYMENTS_SECRET_KEY!,
        environment: 'prod'
      }}
      adapters={adapters}
      amount={5000}
      currency="SGD"
      orderId={`order-${Date.now()}`}
      onPaymentSuccess={(event) => {
        navigate('/success', {
          state: { paymentId: event.detail.paymentIntentId }
        });
      }}
      onPaymentError={(event) => {
        navigate('/error', {
          state: { error: event.detail.message }
        });
      }}
    />
  );
}

API Reference

OnePayment Props

| Prop | Type | Required | Description | |------|------|----------|-------------| | config | SDKConfig \| PaymentConfig | Yes | SDK configuration - use new PaymentConfig({...}) (recommended) or plain object | | adapters | Adapters | Yes | Platform adapters (use createWebAdapters() for web) | | amount | number | Yes | Payment amount in smallest currency unit (e.g., cents for USD, SGD) | | currency | string | Yes | ISO 4217 currency code (e.g., "USD", "EUR", "SGD") | | orderId | string | Yes | Unique order identifier from your system | | firstName | string | Yes | Customer's first name (required for all payments) | | lastName | string | Yes | Customer's last name (required for all payments) | | email | string | Yes | Customer's email address (required for all payments) | | excludePaymentMethods | PaymentMethodId[] | No | Array of payment method IDs to exclude from display | | width | string | No | Custom width (e.g., "100%", "500px") | | maxWidth | string | No | Maximum width constraint (e.g., "600px") | | onPaymentSuccess | (event: CustomEvent<PaymentSucceededPayload>) => void | No | Callback when payment succeeds | | onPaymentError | (event: CustomEvent<PaymentFailedPayload>) => void | No | Callback when payment fails | | onStateChange | (event: CustomEvent<StateChangedPayload>) => void | No | Callback when payment state changes |

Types

interface SDKConfig {
  apiKey: string;
  secretKey: string;
  environment: 'dev' | 'staging' | 'prod';
}

interface PaymentSucceededPayload {
  paymentIntentId: string;
  amount: number;
  currency: string;
  status: 'succeeded';
  metadata?: Record<string, unknown>;
}

interface PaymentFailedPayload {
  code: string;
  message: string;
  details?: Record<string, unknown>;
}

interface StateChangedPayload {
  status: 'idle' | 'initializing' | 'ready' | 'processing' | 'requires_action' | 'succeeded' | 'failed';
  [key: string]: unknown;
}

Next.js Integration

Using this package with Next.js requires special handling for Server-Side Rendering (SSR). See our comprehensive Next.js Integration Guide for detailed instructions.

Quick Summary for Next.js

// Use dynamic import with ssr: false
import dynamic from 'next/dynamic';

const OnePayment = dynamic(
  () => import('@one-payments/react').then((mod) => mod.OnePayment),
  { ssr: false }
);

// Initialize adapters on client-side only
useEffect(() => {
  import('@one-payments/adapters-web').then(({ createWebAdapters }) => {
    setAdapters(createWebAdapters());
  });
}, []);

→ Full Next.js Integration Guide

Requirements

  • React >= 16.8.0 (hooks support)
  • React 19+ supported
  • TypeScript >= 5.0.0 (for TypeScript projects)

Related Packages

License

MIT