From 5c92c14743984b42cbc11f987c6078e80f92e2ca Mon Sep 17 00:00:00 2001 From: Dennis Cornwell Date: Mon, 18 Dec 2023 10:09:31 -0500 Subject: [PATCH] Move payment request handlers formally ahead of the call to `show` * Call to show is inside async block anyway, so logistically, nothing really changes here, but the intent of the code reads better with these declared before 'show' * --- packages/stripe_web/lib/src/web_stripe.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index 436171d65..350b0a2c7 100644 --- a/packages/stripe_web/lib/src/web_stripe.dart +++ b/packages/stripe_web/lib/src/web_stripe.dart @@ -537,6 +537,13 @@ class WebStripe extends StripePlatform { Completer completer = Completer(); stripe_js.PaymentRequest paymentRequest = js.paymentRequest(params.options.toJS()); + paymentRequest.onPaymentMethod((response) { + completer.complete(response.paymentMethod.parse()); + response.complete('success'); + }); + paymentRequest.onCancel(() { + completer.completeError(CancellationError('Payment request cancelled')); + }); paymentRequest.isPaymentAvailable.then((available) { if (available) { paymentRequest.show(); @@ -545,13 +552,6 @@ class WebStripe extends StripePlatform { "No enabled wallets are available for payment method creation")); } }); - paymentRequest.onPaymentMethod((response) { - completer.complete(response.paymentMethod.parse()); - response.complete('success'); - }); - paymentRequest.onCancel(() { - completer.completeError(CancellationError('Payment request cancelled')); - }); return completer.future; }