Skip to content

Commit

Permalink
Move payment request handlers formally ahead of the call to show
Browse files Browse the repository at this point in the history
* 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'

*
  • Loading branch information
cornwe19 committed Jan 24, 2024
1 parent 524905b commit 5c92c14
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/stripe_web/lib/src/web_stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,13 @@ class WebStripe extends StripePlatform {
Completer<PaymentMethod> 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();
Expand All @@ -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;
}
Expand Down

0 comments on commit 5c92c14

Please sign in to comment.