fromPlatformException static method

ZeroSettleException fromPlatformException(
  1. PlatformException e
)

Maps a PlatformException from the native bridge to a typed ZeroSettleException.

Implementation

static ZeroSettleException fromPlatformException(PlatformException e) {
  return switch (e.code) {
    'not_configured' => ZSNotConfiguredException(e.message ?? 'SDK not configured'),
    'cancelled' => ZSCancelledException(e.message ?? 'User cancelled'),
    'product_not_found' => ZSProductNotFoundException(e.message ?? 'Product not found'),
    'checkout_failed' => ZSCheckoutFailedException(e.message ?? 'Checkout failed'),
    'api_error' => ZSApiException(e.message ?? 'API error'),
    'user_id_required' => ZSUserIdRequiredException(e.message ?? 'User ID required'),
    'web_checkout_disabled' => ZSWebCheckoutDisabledException(e.message ?? 'Web checkout disabled'),
    'checkout_not_started' => ZSCheckoutNotStartedException(e.message ?? 'Checkout not started'),
    'invalid_publishable_key' => ZSInvalidPublishableKeyException(e.message ?? 'Invalid publishable key'),
    'checkout_config_expired' => ZSCheckoutConfigExpiredException(e.message ?? 'Checkout config expired'),
    'transaction_verification_failed' => ZSTransactionVerificationFailedException(e.message ?? 'Transaction verification failed'),
    'purchase_pending' => ZSPurchasePendingException(e.message ?? 'Purchase pending'),
    'user_not_identified' => ZSUserNotIdentifiedException(e.message ?? 'User not identified'),
    'apple_pay_unavailable' => ZSApplePayUnavailableException(e.message ?? 'Apple Pay unavailable'),
    'apple_pay_setup_required' => ZSApplePaySetupRequiredException(
          e.message ?? 'Apple Pay setup required',
          autoPresentedSetup: _readAutoPresentedSetup(e),
        ),
    _ => ZSApiException(e.message ?? 'Unknown error: ${e.code}'),
  };
}