How to make the Stripe payment sheet for iOS in Flutter barrierDismissible: false?

Advertisements

I am using Stripe for iOS in my Flutter app and I want to disable the ability for the user to dismiss the payment sheet by tapping outside of it. Currently, when the user taps outside of the payment sheet, I am receiving an error from Stripe. I know that the barrierDismissible option is not available for the presentPaymentSheet() method, but I am wondering if there is some other way to enable this behavior for the payment sheet.

Here is my code demonstrating how I am currently displaying the payment sheet:

Future<void> makePayment(String amount, String currency) async {
    try {
      paymentIntentData = await createPaymentIntent(amount, currency);

      if (paymentIntentData != null) {
        await Stripe.instance.initPaymentSheet(
          paymentSheetParameters: SetupPaymentSheetParameters(
            billingDetails: BillingDetails(
              name: _nameController.text,
              phone: _phoneController.text,
              email: _emailController.text,
            ),
            allowsDelayedPaymentMethods: false,
            customerEphemeralKeySecret: paymentIntentData!['ephemeralkey'],
            paymentIntentClientSecret: paymentIntentData!['client_secret'],
            customerId: paymentIntentData!['customer'],
            style: ThemeMode.dark,
            merchantDisplayName: 'company',
          ),
        );
      }

      //Payment Sheet

      ///now finally display payment sheet
      displayPaymentSheet();
      //displayPaymentSheet();
    } catch (e, s) {
      print('ERROR exception:$e$s');
    }
  }


displayPaymentSheet() async {
  try {
    await Stripe.instance.presentPaymentSheet().then((value) async {
      // Code to handle the result of the payment
    }).onError((error, stackTrace) {
      print('Error is:--->$error $stackTrace');
    });
  } on StripeException catch (e) {
    print('StripeException Error is:---> $e');
    showDialog(
      context: context,
      builder: (_) => const AlertDialog(
        content: Text("Cancelled "),
      ));
  } catch (e) {
    print('$e');
  }
}

Is there any way to make the payment sheet barrierDismissible: false using the presentPaymentSheet() method or some other method in Stripe for iOS in Flutter?

>Solution :

The flutter_stripe package does provide native integration of the Stripe payment sheet within your Flutter app, it is not a flutter’s bottom sheet widget, so you can’t actually control and make such as change like this to the presentPaymentSheet() bottom sheet.

Also other Stripe‘s CardField() and CardFormField() are technically native platform-specific views integrated inside the flutter app.

Leave a ReplyCancel reply