initialize static method
void
initialize({
- required KashierMode mode,
- KashierLanguage language = KashierLanguage.en,
- String? appleMerchantId,
Initializes the Kashier SDK.
Must be called once before any other SDK methods. Call again whenever the host app's language changes so the SDK UI stays in sync.
mode controls which Kashier API environment is used (test or live).
language sets the language used to render the SDK's payment sheets.
Defaults to KashierLanguage.en when omitted.
appleMerchantId is the merchant's own Apple Pay Merchant ID
(e.g. merchant.com.yourcompany.app). Required only to enable Apple Pay;
it must match the Merchant ID configured in the app's Xcode entitlement.
When omitted, Apple Pay is not offered.
Implementation
static void initialize({
required KashierMode mode,
KashierLanguage language = KashierLanguage.en,
String? appleMerchantId,
}) {
// Clean up previous instance if re-initializing.
_api?.dispose();
_handlerFactories.clear();
_mode = mode;
_language = language;
_appleMerchantId = appleMerchantId;
_api = KashierApi(mode: mode);
_bridge = KashierBridge();
// Begin observing network link status. Pre-flight checks inside
// [KashierApi] rely on this to fail fast when the device is offline.
KashierConnectivity.instance.start();
// Register payment method factories.
// Each factory creates a fresh handler instance — handlers are stateful
// (they hold callbacks, polling timers, etc.) so they must not be shared.
_registerHandler(
'applePay',
() => KashierApplePayHandler(
api: _api!,
bridge: _bridge!,
appleMerchantId: _appleMerchantId,
),
);
_registerHandler(
'wallet',
() => KashierWalletHandler(api: _api!),
);
_registerHandler(
'card',
() => KashierCardHandler(api: _api!),
);
}