ezetap-razorpay-pos-expo
v1.0.24
Published
A simple React hook for integrating Razorpay POS (Ezetap) payments in your expo apps. Handles payment initiation, status polling, and cancellation with a single hook.
Downloads
14
Maintainers
Readme
ezetap-razorpay-pos-expo
A simple React hook for integrating Razorpay POS (Ezetap) payments in your expo 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-pos-expoor
yarn add ezetap-razorpay-pos-expo💬 Usage
import React, { useState } from "react";
import { View, Text, TextInput, Button, StyleSheet } from "react-native";
import { useRazorpayPOS } from "ezetap-razorpay-pos-expo";
const initialConfig = {
testMode: true,
apiKey: "YOUR_API_KEY",
username: "YOUR_USERNAME",
terminalId: "YOUR_TERMINAL_ID",
allowedPaymentModes: "ALL",
};
export default function MyPaymentScreen() {
const [amount, setAmount] = useState(100);
const { status, error, result, sendPaymentRequest, cancelPayment } = useRazorpayPOS(initialConfig);
return (
<View style={styles.container}>
<Text style={styles.title}>Razorpay POS Demo</Text>
<TextInput
style={styles.input}
value={amount.toString()}
onChangeText={text => setAmount(Number(text))}
keyboardType="numeric"
placeholder="Amount"
/>
<Button title="Start Payment" onPress={() => sendPaymentRequest(amount)} />
<Text>Status: {status}</Text>
{error ? <Text style={styles.error}>Error: {error}</Text> : null}
{result ? <Text style={styles.result}>{JSON.stringify(result, null, 2)}</Text> : null}
<Button title="Cancel Payment" onPress={cancelPayment} color="#b91c1c" />
</View>
);
}
const styles = StyleSheet.create({
container: { flex: 1, padding: 24, justifyContent: "center" },
title: { fontSize: 22, fontWeight: "bold", marginBottom: 16 },
input: { borderWidth: 1, borderColor: "#ccc", padding: 8, marginBottom: 16, borderRadius: 4 },
error: { color: "red", marginTop: 8 },
result: { fontFamily: "monospace", marginTop: 8 },
});🧩 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
