Stripe PaymentSheet
package:flutter_stripe · Stripe.instance
Overview
Direct integration with flutter_stripe's PaymentSheet. CheckoutController hands a clientSecret to initPaymentSheet and presentPaymentSheet handles every UI/UX detail (card entry, Apple Pay, 3DS).
User Flow
- Stripe.publishableKey is set once in main.dart from STRIPE_PUBLISHABLE_KEY (.env).
- createPaymentSession returns a clientSecret stored in CheckoutState.
- initPaymentSheet receives the clientSecret + merchantDisplayName.
- presentPaymentSheet awaits user interaction; success → continue, cancel → StripeException(Canceled).
Cases & Edge Cases
- Style is fixed to ThemeMode.light — even when the app is in dark mode the sheet stays light (Stripe limitation we accepted).
- Cancellation surfaces as a SnackBar, not a state.error — the user can simply retap Pay.
- Re-presenting the sheet after a network error requires a fresh clientSecret — re-call createPaymentSession.
Code References
- lib/main.dart // Stripe.publishableKey
- lib/src/features/shared/checkout/controllers/checkout_controller.dart:360 // initPaymentSheet
- lib/src/features/shared/checkout/controllers/checkout_controller.dart:371 // presentPaymentSheet
API Calls
Notes
flutter_stripe is imported with `hide Address` so its `Address` type doesn't collide with the local Address model — leave the import as-is. Native SDK contracts (no HTTP; embedded native plugin): • Stripe.instance.initPaymentSheet(SetupPaymentSheetParameters { paymentIntentClientSecret, merchantDisplayName, style: ThemeMode.light }) → void — screen: lib/src/features/shared/checkout/views/checkout_screen.dart • Stripe.instance.presentPaymentSheet() → success | StripeException(FailureCode.Canceled | …) — screen: lib/src/features/shared/checkout/views/checkout_screen.dart • Pre-step: read clientSecret from CheckoutState (populated by /store/payment-collections/{id}/payment-sessions response).