freshyo/apps/user-ui/hooks/usePhonepeSdk.ts
2026-01-24 00:13:15 +05:30

34 lines
947 B
TypeScript
Executable file

import { useEffect } from 'react';
import PhonePePaymentSDK from 'react-native-phonepe-pg';
export function usePhonepeSdk() {
// const { data: creds, isLoading, isError } = usePhonepeCreds();
const creds: any = {};
const isError = false;
const isLoading = false;
useEffect(() => {
if (creds && creds.clientId && creds.clientVersion) {
PhonePePaymentSDK.init('SANDBOX', creds.clientId, creds.clientId, true);
}
}, [creds]);
const startTransaction = async (orderId: string, token: string) => {
try {
const request = {
orderId,
token,
merchantId: creds?.merchantId,
paymentMode: { type: 'PAY_PAGE' }
};
const stringReq = JSON.stringify(request);
const response = await PhonePePaymentSDK.startTransaction(stringReq, null);
return response;
} catch (error) {
throw error;
}
};
return { startTransaction, isLoading, isError, creds };
}