UPI Payments Plugin that uses EasyUpiPayment library.
This Plugin implements the EasyUpiPayment library to initiate UPI payment and handle events.
- Android
npm i capacitor-gray-upi
ionic build
npx cap copy
npx cap sync
npx cap open android
[extra step]
in android case we need to tell Capacitor to initialise the plugin:
on your
MainActivity.java
file addimport com.grayhat.upi.GrayUPI;
and then inside the init callbackadd(GrayUPI.class);
Now you should be set to go. Try to run your client using npx cap open android
.
Tip: every time you change a native code you may need to clean up the cache (Build > Clean Project | Build > Rebuild Project) and then run the app again.
import { Plugins } from '@capacitor/core';
import 'capacitor-gray-upi';
const { GrayUPI } = Plugins;
// ...code
//function to start payment (handle errors yourself)
startPayment = async () => {
GrayUPI.addListener('onTransactionCompleted', (res: any) => {
alert(JSON.stringify(res));
});
GrayUPI.addListener('onTransactionCancelled', (res: any) => {
alert(JSON.stringify(res));
});
GrayUPI.initialise({
transID: "**********",
transRefID: "**********",
amount: '1.00',
description: 'Test Payment',
vpa: '1234567890@service',
name: 'Sample Name',
})
.then(() => {
GrayUPI.startPayment();
})
.catch((err: any) => {
alert(JSON.stringify(err));
});
};
This initialises the UPI Plugin and prepares it for startPayment()
call.
Returns Promise<void>
interface Transaction {
vpa: string;
name: string;
transID: string;
transRefID: string;
description: string;
amount: string; // decimal format
}
This starts the payment intent on Android where the user chooses an App for UPI Payment and proceeds.
Returns Promise<void>
listener : (transaction:TransactionDetails) => void
Transaction Completed with "SUBMITTED"|"SUCCESS"|"FAILURE"
status
SUBMITTED
: Transaction is in PENDING state. Money might get deducted from user’s account but not yet deposited in payee’s account.SUCCESS
: Transaction is successful.FAILURE
: Transaction is failed.
interface TransactionDetails {
transID : string;
responseCode : string;
approvalRefNo : string;
transactionStatus : "SUBMITTED"|"SUCCESS"|"FAILURE";
transactionRefId : string;
amount : string;
}
listener : () => void
User cancelled transaction or transaction failed
Manually tested against the following platforms:
- Android device 10.0 (API Level 29)