1.2.0 • Published 5 months ago

razorpay-react-sdk v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Razorpay Client for React & Next.js

A TypeScript-based npm package to simplify Razorpay payment gateway integration in React and Next.js applications.

🚀 Features

  • Lightweight and easy to use.
  • Supports both React Hooks and Provider-based integration.
  • Fully typed with TypeScript.
  • Customizable checkout options.

📦 Installation

npm install razorpay-client-ts
# or
yarn add razorpay-client-ts

🛠 Usage

✅ Using useRazorpay Hook

import {useRazorpay} from "razorpay-client-ts";

function PaymentButton() {
  const openPayment = useRazorpay({
    key: "rzp_test_xxxxxxxx",
    amount: 50000, // ₹500
    currency: "INR",
    name: "Acme Corp",
    description: "Purchase Order #12345",
    image: "https://example.com/logo.png",
    order_id: "order_9A33XWu170gUtm",
    prefill: {
      name: "John Doe",
      email: "john@example.com",
      contact: "9999999999",
    },
    theme: {
      color: "#3399cc",
    },
    handler: (response) => {
      console.log("Payment Successful!", response);
    },
  });

  return <button onClick={openPayment}>Pay Now</button>;
}

✅ Using RazorpayProvider

import {RazorpayProvider, useRazorpayFromProvider} from "razorpay-client-ts";

function PaymentButton() {
  const openPayment = useRazorpayFromProvider();
  return <button onClick={openPayment}>Pay Now</button>;
}

export default function App() {
  return (
    <RazorpayProvider
      options={{
        key: "rzp_test_xxxxxxxx",
        amount: 50000,
        currency: "INR",
        name: "Acme Corp",
      }}
    >
      <PaymentButton />
    </RazorpayProvider>
  );
}

🔧 API Reference

RazorpayOptions

PropertyTypeDescription
keystringRazorpay API key.
amountnumberPayment amount (in smallest currency unit).
currencystringTransaction currency (default: INR).
namestringBusiness or app name.
descriptionstringShort description of the transaction.
imagestringURL of the business logo.
order_idstringRazorpay order ID.
prefillobjectPrefilled user details.
themeobjectCustom styling options.
handler(response) => voidCallback for successful payment.
callback_urlstringURL to redirect after successful payment.
modalobjectCustom modal settings.

🛠 Development & Testing

To test the package locally:

  1. Clone the repo and install dependencies:
    git clone https://github.com/your-repo/razorpay-client-ts.git
    cd razorpay-client-ts
    npm install
  2. Build the package:
    npm run build
  3. Link the package locally for testing:
    npm link
  4. Use it in a test project:
    cd ../your-test-app
    npm link razorpay-client-ts

📜 License

MIT License © 2025 Piyush Soni

1.2.0

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago