ezetap-razorpay-pos
v1.0.33
Published
A simple React hook for integrating Razorpay POS (Ezetap) payments in your React apps. Handles payment initiation, status polling, and cancellation with a single hook.
Maintainers
Readme
ezetap-razorpay-pos
A simple React hook for integrating Razorpay POS (Ezetap) payments in your React apps. Handles payment initiation, status polling, and cancellation with a single hook.
🚀 Features
- Easy Integration: Just use the
useRazorpayPOShook. - Status Tracking: Get real-time payment status (
processing,waiting,success,error, etc.). - Cancellation: Cancel pending payments with one function.
- TypeScript Support: Fully typed for maximum safety.
- Custom Endpoints: Use your own test/live endpoints if needed.
🛠️ Installation
npm install ezetap-razorpay-posor
yarn add ezetap-razorpay-pos💬 Usage
import React, { useState } from "react";
import { useRazorpayPOS } from "ezetap-razorpay-pos";
const initialConfig = {
testMode: true,
apiKey: "YOUR_API_KEY",
username: "YOUR_USERNAME",
terminalId: "YOUR_TERMINAL_ID",
allowedPaymentModes: "ALL",
};
export default function MyPaymentComponent() {
const [amount, setAmount] = useState(100);
const { status, error, result, sendPaymentRequest, cancelPayment } = useRazorpayPOS(initialConfig);
return (
<div>
<input
type="number"
value={amount}
onChange={e => setAmount(Number(e.target.value))}
placeholder="Amount"
/>
<button onClick={() => sendPaymentRequest(amount)}>Start Payment</button>
{status && <div>Status: {status}</div>}
{error && <div>Error: {error}</div>}
{result && <pre>{JSON.stringify(result, null, 2)}</pre>}
<button onClick={cancelPayment}>Cancel Payment</button>
</div>
);
}
🧩 Configuration
Pass a config object to the hook with these options:
| Name | Type | Required | Default | Description |
| :-- | :-- | :-- | :-- | :-- |
| testMode | boolean | No | true | Use test or live mode |
| apiKey | string | Yes | | Your Razorpay API key |
| username | string | Yes | | Your Razorpay username |
| terminalId | string | Yes | | Your POS terminal ID |
| allowedPaymentModes | string | No | "CASH" \| "CARD" \| "UPI" \| "BHARATQR" \| "ALL" | Allowed payment modes (comma-separated) |
| testEndpoint | string | No | | Custom test endpoint URL |
| liveEndpoint | string | No | | Custom live endpoint URL |
🧑💻 Hook API
The hook returns:
status:'idle' | 'processing' | 'waiting' | 'success' | 'error' | 'force_done'error: error message (if any)result: full Razorpay response (on success)sendPaymentRequest(amount: number): Start a paymentcancelPayment(): Cancel the current payment
📄 Types
RazorpayPosConfig
interface RazorpayPosConfig {
testMode?: boolean;
apiKey: string;
username: string;
terminalId: string;
allowedPaymentModes?: string;
testEndpoint?: string;
liveEndpoint?: string;
}RazorpayResponse
interface RazorpayResponse {
success?: boolean;
errorCode?: string;
p2pRequestId?: string;
status?: string;
authCode?: string;
cardLastFourDigit?: string;
externalRefNumber?: string;
reverseReferenceNumber?: string;
txnId?: string;
paymentMode?: string;
paymentCardType?: string;
paymentCardBrand?: string;
nameOnCard?: string;
acquirerCode?: string;
createdTime?: string;
messageCode?: string;
errorMessage?: string;
message?: string;
}🖥️ Compatibility
Razorpay POS Terminal:
Fully supported for seamless payment initiation, status polling, and cancellation.Kotak POS Terminal:
Compatible and tested for all major payment flows.
Note: This hook is designed to work with both Razorpay and Kotak POS terminals, ensuring flexibility for merchants using either device.
📢 Support & Contributing
- Issues and PRs are welcome!
- For questions, please open an issue on GitHub.
📜 License
MIT
