stripe / stripe-terminal-react-native

React Native SDK for Stripe Terminal
https://stripe.com/docs/terminal/payments/setup-integration?terminal-sdk-platform=react-native
MIT License
106 stars 50 forks source link

Mismatch between TypeScript and returned value #543

Open dakkor71 opened 1 year ago

dakkor71 commented 1 year ago

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

alexdunae commented 6 months ago

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