Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Stripe does not show/present payment sheet

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

like image 346
Dr_Usman Avatar asked Mar 10 '26 22:03

Dr_Usman


2 Answers

I check your backend response you are using "paymentIntent" instead of "client_secret", you should initialize your payment sheet as below

await Stripe.instance.initPaymentSheet(
  paymentSheetParameters: SetupPaymentSheetParameters(
    applePay: true,
    googlePay: true,
    style: ThemeMode.dark,
    testEnv: true,
    merchantCountryCode: 'US',
    merchantDisplayName: 'Prospects',
    customerId: paymentSheetData!['customer'],
    paymentIntentClientSecret: paymentSheetData['client_secret'],
    customerEphemeralKeySecret: paymentSheetData['ephemeralKey'],
));
like image 182
Kashif Niaz Avatar answered Mar 13 '26 17:03

Kashif Niaz


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

Wrong

paymentIntentClientSecret: paymentSheetData['paymentIntent'],

Correct

paymentIntentClientSecret: paymentIntentData!['client_secret'],
like image 22
Dr_Usman Avatar answered Mar 13 '26 17:03

Dr_Usman