Skip to content

Flutter — API reference

The Flutter SDK exports its public surface from lib/pdirect_pay.dart. Everything below is exported; anything in lib/src/... that isn’t re-exported from the barrel is private and may change without notice.

Process-wide singleton. Initialise once at app startup.

MemberSignature
static PdirectPay init(PdirectPayConfig config)Locks the config for the process lifetime. Throws StateError if called twice.
static PdirectPay get instanceActive singleton. Throws StateError if not yet initialised.
static bool get isInitializedCheap check.
@visibleForTesting static void debugReset()Resets the singleton — debug/profile builds only.
final PdirectPayConfig configThe locked config.
Future<String?> getPlatformVersion()Native version probe (used in the example app).

→ Maps to the API: not directly. Indirectly drives every /payments/* call by way of session-token plumbing.

Immutable, process-wide configuration.

const PdirectPayConfig({
required PdirectPayEnvironment environment,
String defaultLocale = 'fr',
Duration? requestTimeout,
void Function(String message)? logger,
String? googlePayMerchantId,
String? googlePayGatewayMerchantId,
String? applePayMerchantId,
});

Computed getters: isProduction, effectiveTimeout, apiBaseUrl, apiVersion, apiUrl, pinnedSpkiSha256, debugMode, defaultHeaders. See Configuration.

Per-checkout configuration.

PdirectPayConfigs({
String? sessionToken,
@Deprecated('Use sessionToken (Auth-v3). Removed in 4.x.') String? token,
Duration? timeout,
String acceptLanguage = 'fr',
String? googlePayMerchantId,
String? googlePayGatewayMerchantId,
String? applePayMerchantId,
});

The collect-payment request body. With Auth-v3, customerReference, amount, and currency are bound to the session_token at mint time — leave them unset and the SDK omits them on the wire. They remain on the type as optional fields for legacy callers that still want to echo the bound values; the gateway soft-checks any value sent and returns 400 on drift.

Defaults: paymentMethod = 'wallet', userInfo = 'full', paymentMethodInfo = 'full', feeCoveredBy = 'buyer', deliveryBehaviour = 'direct_delivery'.

Method-specific fields are optional at the type level — the gateway enforces presence based on the chosen paymentMethod. See Payment methods for the conditional table.

→ Maps to the API: POST /payments/collect.

PdirectPayCheckout({
Key? key,
required PdirectPayConfigs configs,
required PdirectPaymentBody paymentBody,
required Function(PdirectPayOnResponse response) onResponse,
required Function(PdirectPayOnError error) onError,
PdirectPayThemeConfig? themeConfig,
PdirectPayLanguage? language,
Color? backgroundColor,
})

Drop-in checkout widget. Pushes through method selection → method form → confirmation → processing → result internally. You only need to handle the two callbacks.

Returned to onResponse on success. Fields: message, title, customRef, amount, apiResponseCode, currency, paymentStatus, systemRef, transactionId, identifier, customerReference, successRedirectUrl, failRedirectUrl, timestamp.

Returned to onError. Fields: message, title, errorCode, identifier, customerReference, systemReference, amount, currency, successRedirectUrl, failRedirectUrl, timestamp.

Theming primitives.

const PdirectPayThemeConfig({
PdirectPayTheme theme = PdirectPayTheme.light,
Color? primaryColor,
Color? secondaryColor,
Color? tertiaryColor,
Color? backgroundColor,
Color? surfaceColor,
Color? textColor,
Color? secondaryTextColor,
Color? borderColor,
Color? errorColor,
Color? successColor,
double? borderRadius,
EdgeInsetsGeometry? inputPadding,
});

Factory constructors: .light(), .dark(), .system(), .lightPdirectBrand(). The instance method buildThemeData(BuildContext) returns a Material 3 ThemeData.

Branding shown in the checkout chrome.

const PdirectMerchantInfo({
required String name,
String? url,
String? logo,
});

When the drop-in widget isn’t enough, drive the flow yourself:

Singleton wrapping Dio. Auto-attaches Idempotency-Key (UUID v4) on every POST and X-Device-Fingerprint on every authenticated request.

MethodNotes
static PdirectHttpClient get instance
void setSessionToken(String token)Sets Authorization: Bearer ….
void clearSessionToken()
void setAcceptLanguage(String lang)
Future<PdirectHttpResponse<T>> get<T>(String path, {...})
Future<PdirectHttpResponse<T>> post<T>(String path, {dynamic data, ...})
Future<PdirectHttpResponse<T>> put<T>(String path, {...})
Future<PdirectHttpResponse<T>> delete<T>(String path, {...})
Dio get dioEscape hatch.

Deprecated v2 aliases (setAppKey, setAuthToken, etc.) still work in 3.x with a deprecation warning.

Higher-level orchestration. Each method maps to one HTTP endpoint.

MethodAPI endpoint
createPayment(request)POST /payments/collect
getTransactionDetails(id)GET /payments/transaction/{id}
submitPaymentDetails(request)POST /payments/submit
verifyOtp(request)POST /payments/verify-otp
resendOtp(request)POST /payments/resend-otp

Convenience wrapper around PdirectPaymentService for e-wallet flows. Same five methods, same endpoint mappings.

Reactive state singleton (RxDart streams) plus a few utility calls.

MethodAPI endpoint
fetchAvailableBanks()GET /payments/get-config-bank

Streams (BehaviorSubject):

  • Stream<bool> spinnerStream
  • Stream<PdirectPayRequestResponse?> paymentProcessInfoStream
  • Stream<PdirectPayResponseMessage?> paymentMessageStream
  • Stream<PdirectPayScreenNavigation> paymentScreenStream

sandbox, staging, production.

Payment-method channels (close to but not identical to the API’s payment_method literal):

none, all, eflash, ewallet, card, mobileMoney, ewalletOtp, pdirectWallet, virtualCard, bankTransfer, googlePay, applePay. Extension PdirectPayChannelExtension adds displayName and iconPath.

none, full, partial.

pending, processing, approved, declined, failed, cancelled, expired, refunded, pendingBankProofUpload. Extension PdirectPaymentStatusExtension adds isSuccess, isFailure, isPending, plus a fromString(String) static.

The summary classification (one of nine):

lok000 (Success), lok001 (General error), lok002 (Invalid params), lok003 (Auth failed), lok004 (Method unavailable), lok005 (Insufficient funds), lok006 (Limit exceeded), lok007 (Network error), lok008 (Timeout), lok009 (Service unavailable).

For the underlying four-digit gateway codes (10011599), use PdirectHttpClient directly and read the response envelope. See Errors.

english (en), french (fr), spanish (es), russian (ru), chinese (zh), lingala (ln).

Static helpers: fromCode(String), supportedLocales, getAllLanguages().

light, dark, system.

successScreen, errorScreen, warningScreen, infoScreen.

Internal navigation states. Useful only if you’re driving the SDK without the drop-in widget. Full enum: defaultScreen, loadingScreen, paymentMethodSelectionScreen, paymentFormScreen, ewalletFormScreen, mobilemoneyFormScreen, cardFormScreen, flashFormScreen, bankTransferFormScreen, nativePayScreen, paymentConfirmationScreen, processingScreen, mobileMoneyProcessingScreen, ewalletOtpScreen, successScreen, errorScreen, warningScreen, infoScreen.

Static helpers for amount formatting, card validation (Luhn), and basic email regex.

Tagged logger. Calls into PdirectPayConfig.logger if set; bodies are never logged.

static Future<String> get();

SHA-256 hex of stable device attributes. Cached after first computation. Used internally by PdirectHttpClient to attach X-Device-Fingerprint. You don’t normally call this yourself.