nitish24p / react-native-upi

A tiny module for Adding payments via UPI in your react native apps ❤️
MIT License
72 stars 29 forks source link

TypeError: undefined is not an object (evaluating 'responseString.split') #28

Open prabhatm6 opened 3 years ago

prabhatm6 commented 3 years ago

TypeError: undefined is not an object (evaluating 'responseString.split') on google pay

jaiminbhut commented 3 years ago

Just make convertStringToObject method in _nodemodules/react-native-upi-payment/android/src/main/java/com/upi/payment/UpiPaymentModule.java like,

 convertStringToObject(responseString: string) {
    let object = {};
    const stringArray = responseString?.split('&');
    object = stringArray?.reduce((accumulator, current) => {
      const currentArray = current?.split('=');
      accumulator[currentArray[0]] = currentArray[1];
      return accumulator;
    }, {});

    return object;
  },
nitish24p commented 3 years ago

Can you please tell me what responseString you are getting

Rohan-Rajesh commented 2 years ago

To anyone facing this issue in the future, please note that @jaiminbhut's answer is correct but the file that you should edit is: node_modules/react-native-upi-payment/lib/UpiPayment.js

nitish24p commented 2 years ago

I think this has been done already.. Else you can give me a PR and will update a version

avinash-capsitech commented 1 year ago

Replace your fucntion with this

convertStringToObject(responseString: string) { if(responseString === undefined){ return "" } else{ let object = {}; const stringArray = responseString.split('&'); object = stringArray.reduce((accumulator, current) => { const currentArray = current.split('='); accumulator[currentArray[0]] = currentArray[1]; return accumulator; }, {});

return object;

}},

it's worked for me !!

nitish24p commented 1 year ago

But why are you getting undefined from the responseString in the first place..

nitish24p commented 1 year ago

Also thanks for the suggestion. You can make a PR if youd want to

avinash-capsitech commented 1 year ago

But why are you getting undefined from the responseString in the first place..

in my case if i don't set this thing and click on Gpay form chooser then app will crash and show the "TypeError: undefined is not an object (evaluating 'responseString.split') "