Eilya OTP - Flutter SDK

Official Flutter/Dart SDK for Eilya OTP -- WhatsApp-first OTP verification with SMS fallback.

Installation

Add to your pubspec.yaml:

dependencies:
  eilya_otp: ^1.0.0

Then run:

flutter pub get

Quick Start

import 'package:eilya_otp/eilya_otp.dart';

// Initialize with your API key
final otp = EilyaOtp.initialize(
  apiKey: 'ek_live_your_api_key_here',
);

// Request OTP
final pipeline = await otp.requestOtp(phone: '+964XXXXXXXXXX');
print('OTP sent via ${pipeline.channelUsed}');

// Verify OTP (code entered by user)
try {
  final result = await otp.verifyOtp(
    pipelineId: pipeline.pipelineId,
    otp: '123456',
  );
  print('Verified! Auth token: ${result.authToken}');
} on InvalidOtpException catch (e) {
  print('Wrong code. Attempts remaining: ${e.attemptsRemaining}');
} on PipelineExpiredException {
  print('OTP expired. Request a new one.');
}

Sandbox Mode

Use a test API key (prefix ek_test_) for development. In sandbox mode:

  • No real messages are sent
  • Use OTP code 123456 to verify
final otp = EilyaOtp.initialize(
  apiKey: 'ek_test_your_test_key_here',
);

Configuration

final otp = EilyaOtp.initialize(
  apiKey: 'ek_live_...',
  config: EilyaConfig(
    locale: 'en',              // 'ar' (default) or 'en'
    otpLength: 6,              // 4 or 6 (default: 6)
    expirySeconds: 300,        // 60-600 (default: 300)
    fallbackChannels: ['sms'], // Fallback if WhatsApp fails
    timeout: Duration(seconds: 30),
  ),
);

API Reference

EilyaOtp.initialize(apiKey, config?)

Creates a new SDK instance.

requestOtp(phone, locale?, otpLength?, expirySeconds?, fallbackChannels?, metadata?)

Sends an OTP to the given phone number. Returns a Pipeline.

verifyOtp(pipelineId, otp)

Verifies the OTP code. Returns a VerifyResult with an auth token on success.

resendOtp(pipelineId, channel?)

Resends the OTP. Must wait 60 seconds between resends.

getPipeline(pipelineId)

Retrieves the current status of a pipeline.

dispose()

Closes the HTTP client. Call when done.

Error Handling

All errors extend EilyaException:

Exception Code When
InvalidOtpException INVALID_OTP Wrong OTP code
PipelineExpiredException PIPELINE_EXPIRED OTP timed out
PipelineNotFoundException PIPELINE_NOT_FOUND Invalid pipeline ID
PipelineNotPendingException PIPELINE_NOT_PENDING Pipeline already verified/failed
QuotaExceededException QUOTA_EXCEEDED Account quota reached
RateLimitedException RATE_LIMITED Too many requests
DeliveryFailedException DELIVERY_FAILED All delivery channels failed
UnauthorizedException UNAUTHORIZED Invalid API key
ForbiddenException FORBIDDEN Access denied
NetworkException NETWORK_ERROR Connection failure

License

Proprietary -- Eilya Technologies

Libraries

eilya_otp
Official Flutter/Dart SDK for Eilya OTP.