stripe-terminal-react-native icon indicating copy to clipboard operation
stripe-terminal-react-native copied to clipboard

Mismatch between TypeScript and returned value

Open dakkor71 opened this issue 1 year ago • 1 comments

Describe the bug collectPaymentMethod method (I would also check other methods in this hook) from useStripeTerminal returns an object containing a prop error typed as error: StripeError; and it should return values from:

export type StripeError<T = CommonError> = {
  code: T;
  message: string;
};

export enum CommonError {
  Failed = 'Failed',
  Canceled = 'Canceled',
  Unknown = 'Unknown',
}

In the real world, it is returning:

{"code": "USER_ERROR.CANCELED", "message": "Contactless transaction was canceled"}

Because of this issue, we can't use CommonError to check which error was returned.

Stripe Terminal React Native SDK version

  • ^0.0.1-beta.13
  • ^0.0.1-beta.12

dakkor71 avatar Sep 14 '23 08:09 dakkor71

Confirmed this is still the case in ^0.0.10-beta.15

// OK
if (discoverReadersError.code === 'Canceled') return;
// This comparison appears to be unintentional because the types 'CommonError.Failed | CommonError.Unknown' and '"AlreadyDiscovering"' have no overlap.ts(2367)
if (discoverReadersError.code === 'AlreadyDiscovering') {}
// This comparison appears to be unintentional because the types 'CommonError.Failed | CommonError.Unknown' and '"READER_ERROR.READER_BUSY"' have no overlap.
if (discoverReadersError.code === 'READER_ERROR.READER_BUSY') { }

This is also related to https://github.com/stripe/stripe-terminal-react-native/issues/634

alexdunae avatar Mar 15 '24 18:03 alexdunae