From b34e5b09c43dc2d022a441b75a43ffadf9a93b95 Mon Sep 17 00:00:00 2001 From: artem Date: Mon, 24 Nov 2025 13:37:57 +0200 Subject: [PATCH 1/2] Add locale selection for flutter web --- packages/stripe/lib/src/stripe.dart | 18 ++++++++++++++++++ .../lib/src/method_channel_stripe.dart | 2 ++ .../lib/src/stripe_platform_interface.dart | 1 + packages/stripe_web/lib/src/web_stripe.dart | 14 ++++++++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) 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..65b97f5a 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) { + if (__stripe!.stripeAccount != stripeAccountId || __stripe!.locale != locale) { // Re-initialize with new stripeAccountId 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); } From 3588ebb53f20c11bbcc8ac76bc50b168524445df Mon Sep 17 00:00:00 2001 From: artem Date: Mon, 24 Nov 2025 13:39:03 +0200 Subject: [PATCH 2/2] Update comments for locale selection for flutter web --- packages/stripe_web/lib/src/web_stripe.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index 65b97f5a..dc707d74 100644 --- a/packages/stripe_web/lib/src/web_stripe.dart +++ b/packages/stripe_web/lib/src/web_stripe.dart @@ -57,9 +57,9 @@ class WebStripe extends StripePlatform { _urlScheme = urlScheme; if (__stripe != null) { - // Check if the new stripeAccountId is different + // Check if the new stripeAccountId or locale is different if (__stripe!.stripeAccount != stripeAccountId || __stripe!.locale != locale) { - // Re-initialize with new stripeAccountId + // Re-initialize with new stripeAccountId or locale await stripe_js.loadStripe(); var stripeOption = stripe_js.StripeOptions(); if (__stripe!.stripeAccount != stripeAccountId) {