diff --git a/packages/stripe/lib/src/stripe.dart b/packages/stripe/lib/src/stripe.dart index df70646d..c93665f8 100644 --- a/packages/stripe/lib/src/stripe.dart +++ b/packages/stripe/lib/src/stripe.dart @@ -97,6 +97,20 @@ class Stripe { instance.markNeedsSettings(); } + /// Retrieves the locale. + /// For now works on web only. + static String? get locale => instance._locale; + + /// Sets the locale. + /// For now works on web only. + static set locale(String? value) { + if (value == instance._locale) { + return; + } + instance._locale = value; + instance.markNeedsSettings(); + } + /// Reconfigures the Stripe platform by applying the current values for /// [publishableKey], [merchantIdentifier], [stripeAccountId], /// [threeDSecureParams], [urlScheme], [setReturnUrlSchemeOnAndroid] @@ -107,6 +121,7 @@ class Stripe { threeDSecureParams: threeDSecureParams, urlScheme: urlScheme, setReturnUrlSchemeOnAndroid: setReturnUrlSchemeOnAndroid, + locale: locale, ); /// Exposes a [ValueListenable] whether or not GooglePay (on Android) or Apple Pay (on iOS) @@ -706,6 +721,7 @@ class Stripe { String? _merchantIdentifier; String? _urlScheme; bool? _setReturnUrlSchemeOnAndroid; + String? _locale; static StripePlatform? __platform; @@ -732,6 +748,7 @@ class Stripe { String? merchantIdentifier, String? urlScheme, bool? setReturnUrlSchemeOnAndroid, + String? locale, }) async { _needsSettings = false; await _platform.initialise( @@ -741,6 +758,7 @@ class Stripe { merchantIdentifier: merchantIdentifier, urlScheme: urlScheme, setReturnUrlSchemeOnAndroid: setReturnUrlSchemeOnAndroid, + locale: locale, ); } diff --git a/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart b/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart index fd9f628e..9ac60e37 100644 --- a/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart +++ b/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart @@ -53,6 +53,7 @@ class MethodChannelStripe extends StripePlatform { String? merchantIdentifier, String? urlScheme, bool? setReturnUrlSchemeOnAndroid, + String? locale, }) async { await _methodChannel.invokeMethod('initialise', { 'publishableKey': publishableKey, @@ -62,6 +63,7 @@ class MethodChannelStripe extends StripePlatform { 'threeDSecureParams': threeDSecureParams, 'urlScheme': urlScheme, 'setReturnUrlSchemeOnAndroid': setReturnUrlSchemeOnAndroid, + 'locale': locale, }); _methodChannel.setMethodCallHandler((call) async { diff --git a/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart b/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart index 716c929d..d5ba8f28 100644 --- a/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart +++ b/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart @@ -32,6 +32,7 @@ abstract class StripePlatform extends PlatformInterface { String? merchantIdentifier, String? urlScheme, bool? setReturnUrlSchemeOnAndroid, + String? locale, }); Future createPaymentMethod( diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index d7f57df4..dc707d74 100644 --- a/packages/stripe_web/lib/src/web_stripe.dart +++ b/packages/stripe_web/lib/src/web_stripe.dart @@ -52,16 +52,23 @@ class WebStripe extends StripePlatform { String? merchantIdentifier, String? urlScheme, bool? setReturnUrlSchemeOnAndroid, + String? locale, }) async { _urlScheme = urlScheme; if (__stripe != null) { - // Check if the new stripeAccountId is different - if (__stripe!.stripeAccount != stripeAccountId) { - // Re-initialize with new stripeAccountId + // Check if the new stripeAccountId or locale is different + if (__stripe!.stripeAccount != stripeAccountId || __stripe!.locale != locale) { + // Re-initialize with new stripeAccountId or locale await stripe_js.loadStripe(); var stripeOption = stripe_js.StripeOptions(); - stripeOption.stripeAccount = stripeAccountId; + if (__stripe!.stripeAccount != stripeAccountId) { + stripeOption.stripeAccount = stripeAccountId; + } + if (locale != null && __stripe!.locale != locale) { + stripeOption.locale = locale; + } + __stripe = stripe_js.Stripe(publishableKey, stripeOption); } return; @@ -72,6 +79,9 @@ class WebStripe extends StripePlatform { if (stripeAccountId != null) { stripeOption.stripeAccount = stripeAccountId; } + if (locale != null) { + stripeOption.locale = locale; + } __stripe = stripe_js.Stripe(publishableKey, stripeOption); }