Skip to content

Commit 903f367

Browse files
flt-phyremonh87
andauthored
Feat: web language (#2267)
* Add locale selection for flutter web * Update comments for locale selection for flutter web --------- Co-authored-by: Rémon <[email protected]>
1 parent 93925fe commit 903f367

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

packages/stripe/lib/src/stripe.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ class Stripe {
9898
instance.markNeedsSettings();
9999
}
100100

101+
/// Retrieves the locale.
102+
/// For now works on web only.
103+
static String? get locale => instance._locale;
104+
105+
/// Sets the locale.
106+
/// For now works on web only.
107+
static set locale(String? value) {
108+
if (value == instance._locale) {
109+
return;
110+
}
111+
instance._locale = value;
112+
instance.markNeedsSettings();
113+
}
114+
101115
/// Reconfigures the Stripe platform by applying the current values for
102116
/// [publishableKey], [merchantIdentifier], [stripeAccountId],
103117
/// [threeDSecureParams], [urlScheme], [setReturnUrlSchemeOnAndroid]
@@ -108,6 +122,7 @@ class Stripe {
108122
threeDSecureParams: threeDSecureParams,
109123
urlScheme: urlScheme,
110124
setReturnUrlSchemeOnAndroid: setReturnUrlSchemeOnAndroid,
125+
locale: locale,
111126
);
112127

113128
/// Exposes a [ValueListenable] whether or not GooglePay (on Android) or Apple Pay (on iOS)
@@ -707,6 +722,7 @@ class Stripe {
707722
String? _merchantIdentifier;
708723
String? _urlScheme;
709724
bool? _setReturnUrlSchemeOnAndroid;
725+
String? _locale;
710726

711727
static StripePlatform? __platform;
712728

@@ -733,6 +749,7 @@ class Stripe {
733749
String? merchantIdentifier,
734750
String? urlScheme,
735751
bool? setReturnUrlSchemeOnAndroid,
752+
String? locale,
736753
}) async {
737754
_needsSettings = false;
738755
await _platform.initialise(
@@ -742,6 +759,7 @@ class Stripe {
742759
merchantIdentifier: merchantIdentifier,
743760
urlScheme: urlScheme,
744761
setReturnUrlSchemeOnAndroid: setReturnUrlSchemeOnAndroid,
762+
locale: locale,
745763
);
746764
}
747765

packages/stripe_platform_interface/lib/src/method_channel_stripe.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class MethodChannelStripe extends StripePlatform {
5353
String? merchantIdentifier,
5454
String? urlScheme,
5555
bool? setReturnUrlSchemeOnAndroid,
56+
String? locale,
5657
}) async {
5758
await _methodChannel.invokeMethod('initialise', {
5859
'publishableKey': publishableKey,
@@ -62,6 +63,7 @@ class MethodChannelStripe extends StripePlatform {
6263
'threeDSecureParams': threeDSecureParams,
6364
'urlScheme': urlScheme,
6465
'setReturnUrlSchemeOnAndroid': setReturnUrlSchemeOnAndroid,
66+
'locale': locale,
6567
});
6668

6769
_methodChannel.setMethodCallHandler((call) async {

packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class StripePlatform extends PlatformInterface {
3232
String? merchantIdentifier,
3333
String? urlScheme,
3434
bool? setReturnUrlSchemeOnAndroid,
35+
String? locale,
3536
});
3637

3738
Future<PaymentMethod> createPaymentMethod(

packages/stripe_web/lib/src/web_stripe.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,23 @@ class WebStripe extends StripePlatform {
5252
String? merchantIdentifier,
5353
String? urlScheme,
5454
bool? setReturnUrlSchemeOnAndroid,
55+
String? locale,
5556
}) async {
5657
_urlScheme = urlScheme;
5758

5859
if (__stripe != null) {
59-
// Check if the new stripeAccountId is different
60-
if (__stripe!.stripeAccount != stripeAccountId) {
61-
// Re-initialize with new stripeAccountId
60+
// Check if the new stripeAccountId or locale is different
61+
if (__stripe!.stripeAccount != stripeAccountId || __stripe!.locale != locale) {
62+
// Re-initialize with new stripeAccountId or locale
6263
await stripe_js.loadStripe();
6364
var stripeOption = stripe_js.StripeOptions();
64-
stripeOption.stripeAccount = stripeAccountId;
65+
if (__stripe!.stripeAccount != stripeAccountId) {
66+
stripeOption.stripeAccount = stripeAccountId;
67+
}
68+
if (locale != null && __stripe!.locale != locale) {
69+
stripeOption.locale = locale;
70+
}
71+
6572
__stripe = stripe_js.Stripe(publishableKey, stripeOption);
6673
}
6774
return;
@@ -72,6 +79,9 @@ class WebStripe extends StripePlatform {
7279
if (stripeAccountId != null) {
7380
stripeOption.stripeAccount = stripeAccountId;
7481
}
82+
if (locale != null) {
83+
stripeOption.locale = locale;
84+
}
7585
__stripe = stripe_js.Stripe(publishableKey, stripeOption);
7686
}
7787

0 commit comments

Comments
 (0)