Flutter Stripe

repository·main·Indexed 22 days ago

https://github.com/flutter-stripe/flutter_stripe

A comprehensive SDK for integrating Stripe payment capabilities into native Android, iOS, and Web Flutter applications. It provides pre-built UI components like Payment Sheets, CardField, and Card form to handle secure payment flows. The SDK includes platform-specific implementations such as stripe_android, stripe_ios, and experimental support for Flutter Web via flutter_stripe_web and stripe_js bindings for dart2js.

Tokens
31K
Snippets
87
Records
117
Agent score
77%

What's inside flutter_stripe

  1. Server-side requirements for Google Pay

    main

    Google Pay integration requires a server-side implementation to securely manage Stripe API objects. Your server must provide an endpoint that performs the following:

    1. Retrieve or Create a Customer: (Optional) Required if you want to save cards for future use.
    2. Create an Ephemeral Key: (Optional) Required if using a Customer object to grant the SDK temporary access to sensitive customer data.
    3. Create a PaymentIntent: Represents the intent to collect payment. You must pass the Customer ID if applicable.
    4. Return Data to App: The endpoint must return the PaymentIntent client secret, the Ephemeral Key secret, and the Customer ID to the Flutter app.
  2. Handle post-payment events via Webhooks

    main

    Do not rely solely on client-side callbacks to confirm a successful payment, as users might close the app or lose connection during the process.

    Instead, listen for the payment_intent.succeeded event using Stripe Webhooks on your server. This is the reliable way to trigger post-payment actions like sending order confirmation emails or updating your database.

  3. Customize AddressSheet behavior

    main

    You can control the behavior and appearance of the Address Sheet using the AddressSheetParams configuration object. Customization options include:

    • Setting default values for address fields.
    • Configuring which fields are required.
    • Customizing the visual appearance.
    • Setting specific country restrictions.
  4. Choose a card payment method

    main

    There are three primary ways to handle card payments. Stripe recommends using Payment Sheet for all new integrations.

    MethodEase of UseDescription
    Payment sheetEasyRecommended. Includes localization, animations, and error handling out-of-the-box.
    CardfieldMediumA single-line card field offering more flexibility but less built-in functionality.
    Card formMediumSimilar to CardField, but entry fields are spread across multiple lines.
  5. Handle post-payment ACH events

    main

    ACH Direct Debit is a delayed notification payment method; funds typically take around 4 days to transfer.

    Do not rely on client-side callbacks to confirm successful payments, as users may close the app before the callback executes. Instead, implement a server-side webhook to listen for the payment_intent.succeeded event. This is the reliable way to trigger post-payment workflows like order confirmations or shipping.

  6. Handle post-payment events with Webhooks

    main

    To securely finalize orders, listen for asynchronous Stripe events on your server rather than relying on client-side callbacks.

    When a payment completes, Stripe sends a payment_intent.succeeded event. Use this event to:

    • Send order confirmation emails.
    • Log sales in your database.
    • Trigger shipping workflows.

    This approach is more robust because it handles cases where the customer closes the browser or quits the app before the client-side redirect finishes.

  7. Handle post-payment events for Pay by Bank

    main
    Pay by Bank is an asynchronous redirect method. You must listen for Stripe webhook events, such as payment_intent.succeeded, on your server to confirm fulfillment. Do not rely solely on client-side callbacks to determine the final order state, as the payment process involves bank redirects that may happen outside the app's immediate lifecycle.
  8. Implement Customer Sheet server-side requirements

    main

    The Customer Sheet requires a backend endpoint to securely handle sensitive Stripe objects. Your server must provide the following three pieces of information to the client:

    1. SetupIntent client secret: From a SetupIntent object used to track the intent to collect payment methods.
    2. Customer ID: The ID of the Customer object to which payment methods will be attached.
    3. Customer Ephemeral Key secret: A temporary key that grants the mobile SDK secure, limited access to the Customer object.

    Note: If you do not intend to save cards for future use, you can omit the Customer and Ephemeral Key objects.

  9. Configure the Stripe publishable key

    main

    Before using the SDK, you must configure it with your Stripe publishable key during app initialization (usually in the main function). Use your test mode keys during development and live mode keys when publishing.

    void main() async {
      Stripe.publishableKey = stripePublishableKey;
      runApp(const App());
    }