I am trying to integrate paypal in my react native app. I tried the REST API method as per the paypal docs directly in the app (RN frontend) and its working. Below is the code
Button component
let baseUrl = 'https://api-m.sandbox.paypal.com';........<ButtonComp onPress={onPressPaypal} disabled={false} btnStyle={{backgroundColor: '#0f4fa3', marginVertical: 16}} text="PayPal" isLoading={isLoading} />
on press function
const onPressPaypal = async () => { setLoading(true); try { const token = await paypalApi.generateToken(); const res = await paypalApi.createOrder(token); setAccessToken(token); setLoading(false); if (!!res?.links) { const findUrl = res.links.find(data => data?.rel == 'approve'); setPaypalUrl(findUrl.href); } } catch (error) { console.log('error', error); setLoading(false); } };
But instead this direct implementation in the frontend, I need to setup a node/express backend and create endpoints and consume those endpoints in the frontend (react native app). Is it possible ? or I need to directly use the paypal api in frontend ? Is there any npm packages for this implementation ?
I see there is one package called react-native-paypal but its not maintained