SDK Flutter كامل مع وحدة تحكم البوابة وعميل واجهة برمجة التطبيقات لتطبيقات Android و iOS.
أضف إيصالات Flutter SDK إلى مشروعك. يتطلب SDK إصدار Flutter 3.0.0 أو أعلى.
أضف إلى pubspec.yaml الخاص بك:
dependencies:
esaalat: ^1.0.0ثم قم بتشغيل:
flutter pub get📱 ملاحظة: يوفر هذا SDK ميزتين رئيسيتين:
أضف إذن الإنترنت إلى android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />استخدم إيصالاتClient للتفاعل مع واجهة برمجة التطبيقات الخلفية لإنشاء الطلبات وجلب الاشتراكات.
import 'package:esaalat/esaalat.dart';
final client = EsaalatClient(
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
baseUrl: 'https://api.esaalat.com', // api.sandbox.esaalat.com for sandbox
);// Get all subscriptions
final subscriptions = await client.getSubscriptions();
// Find active subscription
final activeSub = subscriptions.firstWhere(
(s) => s.isActive && s.canReceive,
);
print('Using: ${activeSub.providerName}');final orderId = await client.createOrder(
CreateOrderParams(
subscriptionId: activeSub.id,
items: [
OrderItem(
name: 'Premium T-Shirt',
description: '100% cotton, size L',
price: 29.99,
quantity: 2,
),
],
currency: Currency.usd,
),
);
print('Order created: $orderId');final order = await client.getOrder(orderId);
if (order.status == 'COMPLETED') {
print('Payment completed!');
} else if (order.status == 'PENDING') {
print('Waiting for payment...');
}استخدم تعداد Currency لاختيار العملة بأمان:
// Available currencies
Currency.usd // US Dollar
Currency.yer // Yemen Rial
// Get string value
final currencyCode = Currency.usd.value; // "USD"استخدم PortalController.launch() لفتح واجهة الدفع في WebView. يتعامل مع جميع تفاعلات الدفع ويوفر ردود نداء للأحداث.
import 'package:esaalat/esaalat.dart';
// Launch checkout portal
await PortalController.launch(
context,
config: PortalConfig(
baseUrl: 'https://checkout.esaalat.com', // api.sandbox.esaalat.com for sandbox
orderId: orderId,
events: PortalEvents(
onComplete: () {
print('Payment completed!');
Navigator.pop(context);
},
onClose: () {
print('Portal closed');
},
onSuspicious: () {
print('Suspicious activity detected');
},
),
),
);onSuccessيتم استدعاؤه عند نجاح الدفع
onCompleteيتم استدعاؤه عند اكتمال الدفع
onCloseيتم استدعاؤه عند إغلاق البوابة
onSuspiciousيتم استدعاؤه عند اكتشاف نشاط مشبوه
إليك مثال كامل يوضح تدفق الدفع الكامل من إنشاء الطلب إلى التحقق من الدفع:
import 'package:flutter/material.dart';
import 'package:esaalat/esaalat.dart';
class CheckoutScreen extends StatefulWidget {
_CheckoutScreenState createState() => _CheckoutScreenState();
}
class _CheckoutScreenState extends State<CheckoutScreen> {
final client = EsaalatClient(
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
baseUrl: 'https://api.esaalat.com', // api.sandbox.esaalat.com for sandbox
);
Future<void> _startCheckout() async {
try {
// 1. Get subscriptions
final subscriptions = await client.getSubscriptions();
final activeSub = subscriptions.firstWhere(
(s) => s.isActive && s.canReceive,
);
// 2. Create order
final orderId = await client.createOrder(
CreateOrderParams(
subscriptionId: activeSub.id,
items: [
OrderItem(
name: 'Premium T-Shirt',
description: '100% cotton, size L',
price: 29.99,
quantity: 2,
),
],
currency: Currency.usd,
),
);
// 3. Open portal
await PortalController.launch(
context,
config: PortalConfig(
baseUrl: 'https://checkout.esaalat.com', // api.sandbox.esaalat.com for sandbox
orderId: orderId,
events: PortalEvents(
onComplete: () async {
// 4. Verify order status
final order = await client.getOrder(orderId);
if (order.status == 'COMPLETED') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Payment successful!')),
);
}
},
onSuspicious: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Suspicious activity detected')),
);
},
),
),
);
} on ValidationException catch (e) {
print('Validation error: $e');
} on AuthenticationException catch (e) {
print('Auth error: $e');
} catch (e) {
print('Error: $e');
}
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Checkout')),
body: Center(
child: ElevatedButton(
onPressed: _startCheckout,
child: Text('Start Checkout'),
),
),
);
}
}يوفر SDK أنواع استثناء محددة لسيناريوهات مختلفة:
import 'package:esaalat/esaalat.dart';
final client = EsaalatClient(
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
baseUrl: 'https://api.esaalat.com', // api.sandbox.esaalat.com for sandbox
);
try {
await client.createOrder(params);
} on ValidationException catch (e) {
print('Validation error: $e');
// Handle invalid input
} on AuthenticationException catch (e) {
print('Auth error: $e');
// Handle authentication failure
} on OrderNotFoundException catch (e) {
print('Order not found: $e');
// Handle missing order
} on NetworkException catch (e) {
print('Network error: $e');
// Handle network issues
} on APIException catch (e) {
print('API error: $e');
// Handle API errors
} catch (e) {
print('Unexpected error: $e');
// Handle other errors
}ValidationExceptionيتم رميه عند فشل التحقق من الإدخال (سعر غير صالح، كمية، إلخ)
AuthenticationExceptionيتم رميه عند فشل المصادقة (بيانات اعتماد غير صالحة)
OrderNotFoundExceptionيتم رميه عند عدم العثور على طلب (404)
APIExceptionيتم رميه عند فشل طلب واجهة برمجة التطبيقات
NetworkExceptionيتم رميه عند فشل طلب الشبكة (انتهاء المهلة، خطأ في الاتصال)
يرمي AuthenticationException. تحقق من صحة معرف العميل والسر الخاص بك.
يرمي ValidationException. تحقق من أن الأسعار إيجابية، والكميات أعداد صحيحة، والسلاسل ليست فارغة.
يرمي NetworkException. تحقق من اتصال الإنترنت وتوفر واجهة برمجة التطبيقات.