Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/stripe/lib/src/stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down Expand Up @@ -706,6 +721,7 @@ class Stripe {
String? _merchantIdentifier;
String? _urlScheme;
bool? _setReturnUrlSchemeOnAndroid;
String? _locale;

static StripePlatform? __platform;

Expand All @@ -732,6 +748,7 @@ class Stripe {
String? merchantIdentifier,
String? urlScheme,
bool? setReturnUrlSchemeOnAndroid,
String? locale,
}) async {
_needsSettings = false;
await _platform.initialise(
Expand All @@ -741,6 +758,7 @@ class Stripe {
merchantIdentifier: merchantIdentifier,
urlScheme: urlScheme,
setReturnUrlSchemeOnAndroid: setReturnUrlSchemeOnAndroid,
locale: locale,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class MethodChannelStripe extends StripePlatform {
String? merchantIdentifier,
String? urlScheme,
bool? setReturnUrlSchemeOnAndroid,
String? locale,
}) async {
await _methodChannel.invokeMethod('initialise', {
'publishableKey': publishableKey,
Expand All @@ -62,6 +63,7 @@ class MethodChannelStripe extends StripePlatform {
'threeDSecureParams': threeDSecureParams,
'urlScheme': urlScheme,
'setReturnUrlSchemeOnAndroid': setReturnUrlSchemeOnAndroid,
'locale': locale,
});

_methodChannel.setMethodCallHandler((call) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract class StripePlatform extends PlatformInterface {
String? merchantIdentifier,
String? urlScheme,
bool? setReturnUrlSchemeOnAndroid,
String? locale,
});

Future<PaymentMethod> createPaymentMethod(
Expand Down
18 changes: 14 additions & 4 deletions packages/stripe_web/lib/src/web_stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
Loading