richnologies / ngx-stripe

Angular 6+ wrapper for StripeJS
MIT License
219 stars 77 forks source link

Expose ElementsOptions.locale as two separate lists #95

Closed jayvdb closed 4 years ago

jayvdb commented 4 years ago

The list of available language locales which are supported is defined inside ElementsOptions.

It is nice for this to be type-checked, so that the developer is exposed to Stripe's limited locale support as soon as they fiddle with demo code.

It would be nice to have the supported locale codes as a separate exported type, as it is necessary to cast strings to this type, otherwise TypeScript will fail with:

error TS2322: Type 'string' is not assignable to type '"auto" | "no" | "da" | "de" | "en" | "es" | "fi" | "fr" | "it" | "ja" | "nl" | "sv" | "zh"'.

There is also the added complication of there being two lists of supported locale, with use of stripe.redirectToCheckout requiring the smaller list. The user should be able to access the larger list of supported Elements locale. Note that even the checkout-only supported locale list is different from those in ngx-stripe above, as it replaces no with nb (both are official forms of written Norwegian, and usually confused), and adds pl, pt & pt-BR.

Also it would be helpful to have a wrapper function to set the language/locale, so that the caller can provide any valid language code, even if it isnt recognised by Stripe, and the utility will determine if it is supported by the current stripe JS SDK version, and fall back to auto if not supported. This is easier to do in JS than in TS due to type-casting.

richnologies commented 4 years ago

I new major version of the library has been published. Now it uses the official @stripe/stripe-js package. I will close this issue now. But if the problem persists, please fell free to open it again