From 528dac46e54fa766fc7fd131b8b4ba3eae56bed6 Mon Sep 17 00:00:00 2001 From: Josefpa <67612575+Josefpa@users.noreply.github.com> Date: Fri, 21 Jun 2024 06:29:07 -0400 Subject: [PATCH] Fix: Apply dynamic Stripe account ID to confirmPayment method in WebStripe (#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(); --- packages/stripe_web/lib/src/web_stripe.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index 39c1e01df..a33f01f55 100644 --- a/packages/stripe_web/lib/src/web_stripe.dart +++ b/packages/stripe_web/lib/src/web_stripe.dart @@ -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; }