Flutter — configuration
The Flutter SDK has two configuration tiers:
- Process-wide via
PdirectPay.init(PdirectPayConfig)— call once at app startup, locks for the process lifetime. - Per-checkout via
PdirectPayConfigs— passed to eachPdirectPayCheckoutwidget instance.
Process-wide: PdirectPayConfig
Section titled “Process-wide: PdirectPayConfig”Call exactly once. Throws StateError on a second call (use
PdirectPay.debugReset() in tests if you need to re-init).
import 'package:flutter/material.dart';import 'package:pdirect_pay/pdirect_pay.dart';
void main() { PdirectPay.init(const PdirectPayConfig( environment: PdirectPayEnvironment.production, defaultLocale: 'fr', requestTimeout: Duration(seconds: 60), logger: _onLog, googlePayMerchantId: 'merchant.com.example', googlePayGatewayMerchantId: 'gateway_id', applePayMerchantId: 'merchant.com.example.pay', )); runApp(const MyApp());}
void _onLog(String message) { // Wire to your existing logger (Sentry, Datadog, plain print). // SDK logs respect debug level — production builds are quieter. debugPrint('[pdirect_pay] $message');}| Field | Type | Default | Notes |
|---|---|---|---|
environment | PdirectPayEnvironment | (required) | .sandbox / .staging / .production. Resolves base URL. |
defaultLocale | String | 'fr' | ISO 639-1. Drives Accept-Language and i18n strings. |
requestTimeout | Duration? | 30 s (sandbox/staging), 60 s (production) | HTTP timeout for every request. |
logger | void Function(String)? | null | Wired into the SDK’s internal logger. Bodies are never logged regardless. |
googlePayMerchantId | String? | null | For Google Pay. Set this if you’ll surface the google_pay payment method. |
googlePayGatewayMerchantId | String? | null | Companion to the above. |
applePayMerchantId | String? | null | For Apple Pay. Same logic. |
Computed getters
Section titled “Computed getters”| Getter | Notes |
|---|---|
isProduction | true only when environment == .production. |
effectiveTimeout | Returns requestTimeout if set, else the env-specific default. |
apiBaseUrl | The full base URL the SDK uses internally. Read-only — cannot be overridden. |
apiVersion | Always 'v1'. |
apiUrl | <apiBaseUrl>/api/v1. |
pinnedSpkiSha256 | TLS certificate pin list. Currently empty for all environments — see Platform notes. |
Per-checkout: PdirectPayConfigs
Section titled “Per-checkout: PdirectPayConfigs”Passed to every PdirectPayCheckout widget. The session token comes
from your merchant backend; everything else is overrides.
PdirectPayConfigs( sessionToken: sessionTokenFromBackend, // from POST /internal/sessions/create acceptLanguage: 'en', // overrides defaultLocale for this checkout timeout: const Duration(seconds: 90), // overrides effectiveTimeout for this checkout googlePayMerchantId: '...', // overrides process-wide if set googlePayGatewayMerchantId: '...', applePayMerchantId: '...',)| Field | Type | Notes |
|---|---|---|
sessionToken | String | Required. Per-checkout token minted by your merchant backend. |
token | String (deprecated) | Legacy alias — forwards to sessionToken. Removed in 4.0. |
acceptLanguage | String | Defaults to the process-wide defaultLocale. |
timeout | Duration? | Override effectiveTimeout for this checkout. |
googlePayMerchantId etc. | String? | Override the process-wide values. |
Pass a PdirectPayThemeConfig to PdirectPayCheckout.themeConfig if
you want to brand the checkout chrome:
const themeConfig = PdirectPayThemeConfig( primaryColor: Color(0xFF2563EB), secondaryColor: Color(0xFF1E40AF), tertiaryColor: Color(0xFF3BFBDA), borderRadius: 12,);Or use one of the factory constructors:
PdirectPayThemeConfig.light() // clean white surface (default)PdirectPayThemeConfig.dark() // opt-in darkPdirectPayThemeConfig.system() // follows device brightnessPdirectPayThemeConfig.lightPdirectBrand() // legacy olive-greenThe widget wraps its child tree in Theme(...) so every screen reads
brand colours through Theme.of(context).colorScheme. Status colours
(success / error / warning) are intentionally not themeable —
they always render in semantic green / red / amber.
Language
Section titled “Language”Pass a PdirectPayLanguage enum to PdirectPayCheckout.language to
override the locale resolution for the widget:
PdirectPayCheckout( configs: configs, paymentBody: paymentBody, language: PdirectPayLanguage.english, onResponse: (r) {}, onError: (e) {},)Six languages ship: english, french, spanish, russian,
chinese, lingala.
See also
Section titled “See also”- Quickstart — both tiers wired together
- API reference — every public type
- Platform notes — TLS pinning, Mastercard, native pay