react-native-upi icon indicating copy to clipboard operation
react-native-upi copied to clipboard

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

Open prabhatm6 opened this issue 3 years ago • 8 comments

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

prabhatm6 avatar Jun 07 '21 19:06 prabhatm6

Just make convertStringToObject method in node_modules/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;
  },

jaiminbhut avatar Jun 28 '21 15:06 jaiminbhut

Can you please tell me what responseString you are getting

nitish24p avatar Jun 29 '21 21:06 nitish24p

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

Rohan-Rajesh avatar Aug 24 '21 11:08 Rohan-Rajesh

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

nitish24p avatar Aug 25 '21 09:08 nitish24p

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 !!

avinash-capsitech avatar Aug 31 '22 12:08 avinash-capsitech

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

nitish24p avatar Sep 01 '22 10:09 nitish24p

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

nitish24p avatar Sep 01 '22 11:09 nitish24p

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') "

avinash-capsitech avatar Sep 02 '22 07:09 avinash-capsitech