razorpay / react-native-razorpay

React Native wrapper for Razorpay's mobile SDKs
https://www.npmjs.com/package/react-native-razorpay
MIT License
121 stars 107 forks source link

Getting undefined error when closing the razorpay screen (user cancelling the payment) and app is crashing. #414

Open bavarnasivakumar opened 1 year ago

bavarnasivakumar commented 1 year ago

Description

Razorpay Package Version :

2.2.9

types version: 2.2.0

What you did:

I called Razorpaycheckout.open method and when the Razorpay screen is displayed, I closed the screen using close icon on top right.

What happened:

This is causing app crash and getting following error.

TypeError: undefined is not an object (evaluating 'errorResponse.metadata.order_id')

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Add razorpay package and its types
  2. call checkout.open
  3. close the window using close icon

Suggested solution:

This happens when using types. Make metadata of ErrorResponse to be optional. This is not returned as part of ErrorResponse when user cancels the operation.

Code example, screenshot, or link to a repository:

import RazorpayCheckout, { ErrorResponse, SuccessResponse } from 'react-native-razorpay';

export const makePayment = () => { var options = { description: 'Credits towards consultation', currency: 'INR', key: RAZOR_PAY_KEY, amount: 5000, // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise name: 'Acme Corp', order_id: 'xxxxxxxx', };

RazorpayCheckout.open( options, (data: SuccessResponse) => { console.log('success data : ' + data.razorpay_order_id); }, (errorResponse: ErrorResponse) => { // console.log('failure data ', errorResponse.metadata.order_id); }, );

};

kkyusufk commented 1 year ago

Hi, Thanks for reaching out with this issue. We do not expose types for this package from this repository, it actually comes from here https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-native-razorpay I will make sure we amend this from that repo ( in future we should try to expose these types from this repo only)