How to solve: Flutter Stripe does not show/present payment sheet

Question

Asked by Dr_Usman on December 13, 2021 (source).

In my flutter project, I'm attempting to integrate a Stripe payment using flutter_stripe package.
I've intialize and configured correctly. But when trying to present paymentSheet nothing showing or happen. There's also no error cause. As it stuck at the line and not run code after that. I've also tried plugin simple example code as well but not work as i want. Any help will be appreciated.

main.dart


  Stripe.publishableKey = StripeService.publishableKey;
  Stripe.merchantIdentifier = 'merchant.flutter.stripe.test';
  Stripe.urlScheme = 'flutterstripe';
  await Stripe.instance.applySettings();
  runApp(const MyApp());
}

service.dart

Future<void> initPaymentSheet() async {
try {
  // 1. create payment intent on the server
  final paymentSheetData = await createPaymentIntent("1200", 'usd');
  print("payment intent created");

  // create some billingdetails
  final billingDetails = BillingDetails(
    email: '[email protected]',
    phone: '+48888000888',
    address: Address(
      city: 'Houston',
      country: 'US',
      line1: '1459  Circle Drive',
      line2: '',
      state: 'Texas',
      postalCode: '77063',
    ),
  ); // mocked data for tests

 // 2. initialize the payment sheet
  await Stripe.instance.initPaymentSheet(
      paymentSheetParameters: SetupPaymentSheetParameters(
    applePay: true,
    googlePay: true,
    style: ThemeMode.dark,
    testEnv: true,
    merchantCountryCode: 'US',
    merchantDisplayName: 'Prospects',
    customerId: paymentSheetData!['customer'],
    paymentIntentClientSecret: paymentSheetData['paymentIntent'],
    customerEphemeralKeySecret: paymentSheetData['ephemeralKey'],
  ));
  print("payment sheet created");

  await Stripe.instance.presentPaymentSheet();

  print("after payment sheet presented");
} on Exception catch (e) {
  if (e is StripeException) {
    print("Error from Stripe: ${e.error.localizedMessage}");
  } else {
    print("Unforeseen error: ${e}");
  }
  rethrow;
}

}

output

I/flutter (14987): payment intent created
I/flutter (14987): payment sheet created

Answer

Question answered by Dr_Usman (source).

I got the solution, there's something incorrect parameter value while initialize the payment sheet

Wrong

paymentIntentClientSecret: paymentSheetData['paymentIntent'],

Correct

paymentIntentClientSecret: paymentIntentData!['client_secret'],
DART FLUTTER STRIPE-PAYMENTS STRIPES
SHARE: