Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
React native firebase handling payment flow

I am integrating payment api, I'm using firebase cloud functions as my backend and react-native in frontend, so right now i have the following code:

In react-native side:

const PaymentScreen = () => {
  setLoading(true);
  const onPay = () => {
    const onPaymentCall = firebase.functions().httpsCallable('onPayment');
    onPaymentCall(productsData)
    .then(res => {
      setLoading(false);
      if (res?.data?.statusCode === 200) {
        const paymentReceivedData = {
          transactionId: res?.data?.transactionId,
          paymentDate: new Date().now(),
          totalPrice: res?.data?.totalPrice
        }
        navigator.navigate('ReceiptScreen', { paymentReceivedData });
      }
    })
  }
  return (
    <TouchableOpacity onPress={onPay}>PAY</TouchableOpacity>
  )
}

firebase function to handle payment:

export const onPayment = functions
    .runWith({ timeoutSeconds: 300 })
    .https.onCall(async (data: any, context: any) => {
      if (!context.auth) {
            throw new functions.https.HttpsError(
                'failed-precondition',
                'The function must be called while authenticated.'
            );
        }
      try {
        const paymentResult = await paymentThroughApi(data);
        await admin.firestore().collection('wallet').add({...paymentResult});
        const response = {
          statusCode: 200,
          totalPrice: paymentResult.totalPrice,
          transactionId: paymentResult.transactionId,
        }
        return response;
      } catch (error) {
        const response = {
          statusCode: 400,
          message: 'Payment unsuccessful',
          transactionId: null,
        }
        return response;
      }

So the question is, how can I handle long-time response/timeout error/network-loss etc in react-native side, like how should I make it more robust? especially handling long-time responses, timeout errors, payment failures etc? Which packages should I use? like NetInfo to check internet connectivity but what is the best way to make payment flow robust?

So can anyone guide me or suggest any code snippets to add on to my current code?

Thank you!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!