Skip to main content

Overview

The Moment Flutter SDK enables seamless payment integration into any Flutter application. The SDK provides a simple, unified API to handle the entire payment flow through a native bottom sheet experience. Built with pure Dart (minimal dependencies), the SDK works across both iOS and Android platforms. Moment Mobile SDK

Key Features

  • Native Experience – Bottom sheet presentation feels native on both platforms
  • Flexible Callbacks – Handle success, failure, cancellation, retry, and expiry events
  • Secure – Sensitive payment data handled entirely in Moment’s secure WebView
  • Minimal Dependencies – Single package, easy to integrate
  • PCI Compliant – No card data ever touches your application

How It Works

  1. App startsMoment(clientKey: ...) creates an SDK instance; moment.checkout() is called to create a checkout instance with your fetchClientToken, fetchSessionStatus, and event callbacks (onSuccess, onFailure, etc.)
  2. Customer taps Paycheckout.launch() is called
  3. SDK calls fetchClientToken — your callback creates a session on your backend (with a success_url) and returns the client_token
  4. Checkout opens in a native bottom sheet
  5. Customer submits payment — Moment takes over and redirects to the authentication page
  6. Customer completes authentication on the external page
  7. Customer is redirected back to your app via link with ?session_id=abc123
  8. SDK detects the link and calls your fetchSessionStatus('abc123') callback automatically
  9. Your callback fetches the status from your backend, which queries Moment API
  10. SDK routes to the right handleronSuccess, onFailure, onExpired, or onCancel
  11. Webhooks are delivered to your backend regardless of outcome

Installation

1. Add Dependencies

Add the following to your pubspec.yaml:

2. Import the SDK


Platform Configuration

iOS

Add to ios/Runner/Info.plist:

Android

Add to android/app/src/main/AndroidManifest.xml:
Ensure minimum SDK version in android/app/build.gradle:

Quick Start

1. Initialize the SDK

Call Moment(clientKey: ...) once when your app starts to create an SDK instance. Then call moment.checkout() with your fetch callbacks and event handlers — it returns a checkout instance, and the SDK calls your callbacks automatically at the right moments, so you never manage tokens or session IDs manually. Backend endpoints:
server.js
Flutter — initialize once on app start:
main.dart

2. Open Checkout

checkout.dart

API Reference

Moment(clientKey)

Factory constructor — creates an isolated SDK instance scoped to your publishable key. Returns an object with product namespaces (checkout, and more in the future). Throws immediately if clientKey is invalid.

moment.checkout(config)

Creates and returns a checkout instance for this SDK. Typically called in main() or your root widget’s initState(). Returns a checkout object with launch and close methods.

checkout.launch()

Opens the payment checkout in a native bottom sheet. Internally calls your fetchClientToken to retrieve a fresh token.

checkout.close()

Manually closes the bottom sheet checkout.

Complete Example


Security Best Practices

  1. Never expose your secret key (sk_...) in your Flutter app
  2. Always create sessions server-side via your backend
  3. Validate webhooks to confirm payment state before fulfilling orders
  4. Use HTTPS for all backend communication
  5. Handle token expiry — the SDK calls fetchClientToken on every launch(), so tokens are always fresh
  6. Check mounted before updating widget state after async operations

Next Steps