Skip to content

Commit

Permalink
Fix: Apply dynamic Stripe account ID to confirmPayment method in WebS…
Browse files Browse the repository at this point in the history
…tripe (#1798)

Fixes a bug where updating the Stripe account ID using await Stripe.instance.applySettings(); did not apply to the confirmPayment() method on web platforms.

Bug Description:
- Using await Stripe.instance.applySettings(); to update an account ID shows the updated account ID when printed but does not apply to the confirmPayment() method.
- This issue occurs when attempting to update Stripe.stripeAccountId within the app, such as on the payment page.

Steps to Reproduce:
1. Initialize a Stripe instance within main.dart, setting the Stripe publisher key (no account ID set).
2. Have a page within the app that initializes Stripe and adds the Stripe connect ID:
   ```dart
   Stripe.stripeAccountId = id;
   await Stripe.instance.applySettings();
  • Loading branch information
Josefpa authored Jun 21, 2024
1 parent 19fe9d7 commit 528dac4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/stripe_web/lib/src/web_stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ class WebStripe extends StripePlatform {
bool? setReturnUrlSchemeOnAndroid,
}) async {
this._urlScheme = urlScheme;

if (__stripe != null) {
__stripe!.stripeAccount = stripeAccountId;
// Check if the new stripeAccountId is different
if (__stripe!.stripeAccount != stripeAccountId) {
// Re-initialize with new stripeAccountId
await stripe_js.loadStripe();
var stripeOption = stripe_js.StripeOptions();
stripeOption.stripeAccount = stripeAccountId;
__stripe = stripe_js.Stripe(publishableKey, stripeOption);
}
return;
}

await stripe_js.loadStripe();
final stripeOption = stripe_js.StripeOptions();
var stripeOption = stripe_js.StripeOptions();
if (stripeAccountId != null) {
stripeOption.stripeAccount = stripeAccountId;
}
Expand Down

0 comments on commit 528dac4

Please sign in to comment.