flutter_stripe
flutter_stripe copied to clipboard
WebStripe().confirmPaymentElement() returns void
https://github.com/flutter-stripe/flutter_stripe/blob/d114816e436737d1019dffa6861b9f9674b27410/example/lib/screens/payment_sheet/payment_element/platforms/payment_element_web.dart#L7
I followed the integration in the guide above. Turns out, even for bad inputs, the promise await WebStripe().confirmPaymentElement()
never fails.
Here is the integration code
Future<void> showWebPaymentBS(
BuildContext context,
String clientSecret,
) async
{
bool success = false;
String? error;
bool paying = false;
await showAppBottomSheet(
context,
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
PaymentElement(
style: CardStyle(backgroundColor: Theme.of(context).scaffoldBackgroundColor),
autofocus: true,
enablePostalCode: true,
onCardChanged: (_) {},
clientSecret: clientSecret
),
gap8(v: true),
buttonPrimary(context, 'Pay',
onPress: () async
{
if (!paying)
{
paying = true;
try
{
//
//
//THIS NEVER FAILS
//
//
//
await WebStripe().confirmPaymentElement(
ConfirmPaymentElementOptions(
redirect: PaymentConfirmationRedirect.if_required,
confirmParams: ConfirmPaymentParams(return_url: ''),
)
);
success = true;
}
catch(e)
{
if (e is StripeException)
{
error = '${e.error.localizedMessage}!';
}
else
{
error = e.toString();
}
}
paying = false;
Navigator.of(context).pop();
}
})
],
)
);
if (error?.isNotEmpty ?? false)
{
return Future.error(Exception(error));
}
else if (!success)
{
return Future.error(Exception('Payment cancelled'));
}
}
Hi, hope I'm not being a bother. But, any update here?
Hi @zzxoto :) , could you check if the param error from the response is not null?. Probably sending an empty return_url would not be valid for the stripe js library
final result = await WebStripe().confirmPaymentElement(
ConfirmPaymentElementOptions(
redirect: PaymentConfirmationRedirect.if_required,
confirmParams: ConfirmPaymentParams(return_url: ''),
)
);
final error = response.error:
Appreciate your response @jamesblasco. When trying your solution, I found out that confirmPaymentElment returns void, which should've been PaymentIntentResponse
. This might demand a new issue, but I just wrote it as a reply to your comment.
https://github.com/flutter-stripe/flutter_stripe/blob/b82fa07684f5a1199ea665aa1e9e8c220cf5c6e6/packages/stripe_web/lib/src/web_stripe.dart#L344
Could you upgrade to flutter_stripe_web: 4.2.0
and let me know if that fixes it for u?
https://pub.dev/packages/flutter_stripe_web