A React Native Expo library for integrating UPI payments in Android apps.
- Open UPI payment apps using deep linking
- Show all available UPI apps installed on the device
- Track payment status (success/failure/cancelled)
- Works entirely on the client side (no backend required)
- Android only (UPI is not available on iOS)
npm install expo-upi-payment
# or
yarn add expo-upi-payment
This library requires custom native code, so you'll need to use either:
- Expo Development Builds
- EAS Build
- Expo prebuild workflow
Add the config plugin to your app.json/app.config.js:
{
"expo": {
"plugins": [
"expo-upi-payment"
]
}
}
Then rebuild your app:
npx expo prebuild --clean
# or
eas build
import UPIPayment from 'expo-upi-payment';
// Get list of UPI apps installed on the device
const getUPIApps = async () => {
try {
const apps = await UPIPayment.getInstalledUPIApps();
console.log('Installed UPI apps:', apps);
/*
[
{ packageName: 'net.one97.paytm', appName: 'Paytm' },
{ packageName: 'com.phonepe.app', appName: 'PhonePe' },
...
]
*/
} catch (error) {
console.error('Error getting UPI apps:', error);
}
};
const makePayment = async () => {
try {
const paymentParams = {
vpa: 'merchant@upi', // Payee UPI ID
name: 'Merchant Name', // Payee name
amount: '100.00', // Amount as string
transactionRef: 'TXN123456', // Unique reference ID
transactionNote: 'Payment for order #123', // Optional
currency: 'INR' // Optional (default: INR)
};
const result = await UPIPayment.initiatePayment(paymentParams);
console.log('Payment result:', result);
/*
{
status: 'SUCCESS', // or 'FAILURE', 'CANCELLED', 'SUBMITTED', 'UNKNOWN'
transactionRef: 'TXN123456',
transactionId: '...', // if available
responseCode: '...', // if available
approvalRefNo: '...', // if available
rawResponse: '...' // raw response string
}
*/
} catch (error) {
console.error('Payment error:', error);
}
};
const makePaymentWithApp = async (appPackage) => {
try {
const paymentParams = {
vpa: 'merchant@upi',
name: 'Merchant Name',
amount: '100.00',
transactionRef: 'TXN123456',
transactionNote: 'Payment for order #123',
};
// Example: Pay with Google Pay
const result = await UPIPayment.initiatePaymentWithApp(
paymentParams,
'com.google.android.apps.nbu.paisa.user'
);
console.log('Payment result:', result);
} catch (error) {
console.error('Payment error:', error);
}
};
- The library uses Android's Intent system to open UPI payment URLs
- When a payment is initiated, the user is taken to the UPI app
- After completing or cancelling the payment, the user returns to your app
- The library captures the result using Android's
onActivityResult
mechanism - The promise resolves with the payment status and details
-
SUCCESS
: Payment was successful -
FAILURE
: Payment failed -
CANCELLED
: User cancelled the payment -
SUBMITTED
: Payment request was submitted, but final status is unknown -
UNKNOWN
: Unable to determine payment status
- This library works only on Android devices with UPI apps installed
- No backend communication is needed for basic payment flow
- For production use, it's recommended to verify payments with your backend
- The UPI schemes may vary across different UPI apps, this library handles common patterns
MIT