Skip to content

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 each PdirectPayCheckout widget instance.

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');
}
FieldTypeDefaultNotes
environmentPdirectPayEnvironment(required).sandbox / .staging / .production. Resolves base URL.
defaultLocaleString'fr'ISO 639-1. Drives Accept-Language and i18n strings.
requestTimeoutDuration?30 s (sandbox/staging), 60 s (production)HTTP timeout for every request.
loggervoid Function(String)?nullWired into the SDK’s internal logger. Bodies are never logged regardless.
googlePayMerchantIdString?nullFor Google Pay. Set this if you’ll surface the google_pay payment method.
googlePayGatewayMerchantIdString?nullCompanion to the above.
applePayMerchantIdString?nullFor Apple Pay. Same logic.
GetterNotes
isProductiontrue only when environment == .production.
effectiveTimeoutReturns requestTimeout if set, else the env-specific default.
apiBaseUrlThe full base URL the SDK uses internally. Read-only — cannot be overridden.
apiVersionAlways 'v1'.
apiUrl<apiBaseUrl>/api/v1.
pinnedSpkiSha256TLS certificate pin list. Currently empty for all environments — see Platform notes.

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: '...',
)
FieldTypeNotes
sessionTokenStringRequired. Per-checkout token minted by your merchant backend.
tokenString (deprecated)Legacy alias — forwards to sessionToken. Removed in 4.0.
acceptLanguageStringDefaults to the process-wide defaultLocale.
timeoutDuration?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 dark
PdirectPayThemeConfig.system() // follows device brightness
PdirectPayThemeConfig.lightPdirectBrand() // legacy olive-green

The 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.

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.