import { NativeModules, Platform } from 'react-native'; import packageJson from '../package.json'; // Ensure this path correctly points to your package.json const reactNativeVersion = packageJson.version; const LINKING_ERROR = `The package 'react-native-paygilant-wrapper' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; // @ts-expect-error const isTurboModuleEnabled = global.__turboModuleProxy != null; const PaygilantWrapperModule = isTurboModuleEnabled ? require('./NativePaygilantWrapper').default : NativeModules.PaygilantWrapper; const PaygilantWrapper = PaygilantWrapperModule ? PaygilantWrapperModule : new Proxy( {}, { get() { throw new Error(LINKING_ERROR); }, } ); // Consolidate all functions into a single `Paygilant` object const Paygilant = { initialize: (serverURL: string, clientSessionId?: string, toAskPermissions?: boolean): Promise => { Paygilant.setReactNativeVersion(reactNativeVersion); return PaygilantWrapper.initialize(serverURL, clientSessionId ?? null, toAskPermissions ?? false); }, getSessionId: (): Promise => { return PaygilantWrapper.getSessionId(); }, isApprovePolicy: (): Promise => { return PaygilantWrapper.isApprovePolicy(); }, askPaygilantPermissions: (): Promise => { return PaygilantWrapper.askPaygilantPermissions(); }, setApprovePolicy: (approvePolicy: boolean): Promise => { return PaygilantWrapper.setApprovePolicy(approvePolicy); }, setReactNativeVersion: (version: string): Promise => { return PaygilantWrapper.setReactNativeVersion(version); }, logout: (): Promise => { return PaygilantWrapper.logout(); }, setUserId: (_userId: string): Promise => { console.log("Paygilant setUserId is deprecated and no longer necessary."); return Promise.resolve(); }, getDeviceId: (): Promise => { console.log("Paygilant getDeviceId is deprecated and no longer necessary, Paygilant will sent no_device_id."); return PaygilantWrapper.getDeviceId(); }, pauseListenToSensors: (): Promise => { console.log("Paygilant pauseListenToSensors is deprecated and no longer necessary."); return Promise.resolve(); }, initializeDeviceId: (): Promise => { console.log("Paygilant initializeDeviceId is deprecated and no longer necessary."); return Promise.resolve(); }, startNewScreenListener:(type: string, screenId: number): Promise => { console.log("Paygilant startNewScreenListener is deprecated and no longer necessary."); console.log("This method will now invoke setApprovePolicy(true) in the first time startNewScreenListener, instead of its previous functionality.") return PaygilantWrapper.startNewScreenListener(type,screenId); }, onRequestPermissionsResult: ( _typePermission: string | number, _permissionList?: any[], _permissionResult?: any[] ): Promise => { console.log("Paygilant onRequestPermissionsResult is deprecated and no longer necessary."); return Promise.resolve(); }, startUserVerification: (userId: string): Promise => { return PaygilantWrapper.startUserVerification(userId); }, /** * Send your generated clientSessionId to the native SDK. * @param clientSessionId Unique string from your backend or UI. * @returns Promise resolving to: * • actual session ID from the SDK * • "no_session_id" if the SDK didn’t return one * @throws Error with code "error" and message from native if something went wrong. */ setClientSessionId: (clientSessionId: string): Promise => { return PaygilantWrapper.setClientSessionId(clientSessionId); }, ScreenListenerType: { REGISTRATION_FORM: 'REGISTRATION_FORM', LOGIN_FORM: 'LOGIN_FORM', LOGIN: 'LOGIN', MAIN_SCREEN: 'MAIN_SCREEN', CATALOG_SCREEN: 'CATALOG_SCREEN', SEARCH_SCREEN: 'SEARCH_SCREEN', PRODUCT_SCREEN: 'PRODUCT_SCREEN', GENERAL_FORM: 'GENERAL_FORM', PINCODE: 'PINCODE', TRANSACTION_DETAILS: 'TRANSACTION_DETAILS', CONTACTS: 'CONTACTS', PAYMENT_SCREEN: 'PAYMENT_SCREEN', EMULATOR_CHECK: 'EMULATOR_CHECK', GENERAL: 'GENERAL', ADD_PAYMENT_SCREEN: 'ADD_PAYMENT_SCREEN', WITHDRAW_SCREEN: 'WITHDRAW_SCREEN', DEPOSIT_SCREEN: 'DEPOSIT_SCREEN', NOTIFICATION: 'NOTIFICATION', CARD_SCREEN: 'CARD_SCREEN' }, }; // Export the Paygilant object as the default export export default Paygilant;