How to close the razorpay webview after callback_url success response in react-native?

Viewed 1677

I am intergrating react-native-razorpay for payment in my react-native application. I could get the payment done and by providing the callback_url in the payment options to the RazorpayCheckOut i could even call my backend server and update the payment action but when the callback_url to server is providing the app with the success message there is no way that i could read the message and close the razorpay webview that is opened in my react-native app.

Is there any way that i can close the ebview of razorpay and move back to app on receiving the sucess message of callback_url?

1 Answers

Based on the sample code listed here https://github.com/razorpay/react-native-razorpay

RazorPay returns data.razorpay_payment_id as a response. You could use that payment_id to get the status of your payment from the back-end

I used the ruby gem in my backend API to get the payment status

Razorpay::Payment.fetch("payment_id")

https://razorpay.com/docs/server-integration/ruby/

<TouchableHighlight onPress={() => {
  var options = {
    description: 'Credits towards consultation',
    image: 'https://i.imgur.com/3g7nmJC.png',
    currency: 'INR',
    key: 'rzp_test_1DP5mmOlF5G5ag',
    amount: '5000',
    name: 'foo',
    prefill: {
      email: 'void@razorpay.com',
      contact: '9191919191',
      name: 'Razorpay Software'
    },
    theme: {color: '#F37254'}
  }
  RazorpayCheckout.open(options).then((data) => {
    // handle success
    alert(`Success: ${data.razorpay_payment_id}`);
  }).catch((error) => {
    // handle failure
    alert(`Error: ${error.code} | ${error.description}`);
  });
}}>
Related