feat: implement secure OTP-based payout workflow with dynamic fee calculation and improved authentication checks
This commit is contained in:
@@ -41,22 +41,15 @@ class _PayoutScreenState extends State<PayoutScreen> {
|
||||
if (didAuthenticate && mounted) {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
// 2. إرسال الطلب إلى السيرفر بالبيانات الجاهزة
|
||||
final result = await _payoutService.requestPayout(
|
||||
driverId:
|
||||
box.read(BoxName.driverID).toString(), // استبدله بـ box.read
|
||||
amount: widget.amountToWithdraw,
|
||||
payoutPhoneNumber: widget.payoutPhoneNumber,
|
||||
walletType: widget.walletType,
|
||||
);
|
||||
|
||||
// 2. طلب رمز التحقق OTP
|
||||
bool otpSent = await _payoutService.requestOtp(phone: widget.payoutPhoneNumber);
|
||||
setState(() => _isLoading = false);
|
||||
|
||||
if (result != null && result.contains("successfully")) {
|
||||
// 3. عرض رسالة النجاح النهائية
|
||||
_showSuccessDialog();
|
||||
if (otpSent) {
|
||||
// 3. عرض حوار إدخال الرمز
|
||||
_showOtpDialog();
|
||||
} else {
|
||||
_showErrorDialog(result ?? "حدث خطأ غير معروف.");
|
||||
_showErrorDialog("فشل في إرسال رمز التحقق. يرجى المحاولة لاحقاً.");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -66,6 +59,70 @@ class _PayoutScreenState extends State<PayoutScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void _showOtpDialog() {
|
||||
final TextEditingController otpController = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('أدخل رمز التحقق (OTP)'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('تم إرسال رمز تحقق إلى رقم هاتفك.'),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: otpController,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 4,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'رمز التحقق',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('إلغاء'),
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
),
|
||||
ElevatedButton(
|
||||
child: const Text('تأكيد'),
|
||||
onPressed: () {
|
||||
final otp = otpController.text.trim();
|
||||
if (otp.length >= 3) {
|
||||
Navigator.of(ctx).pop();
|
||||
_submitPayoutWithOtp(otp);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _submitPayoutWithOtp(String otp) async {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
final result = await _payoutService.requestPayout(
|
||||
driverId: box.read(BoxName.driverID).toString(),
|
||||
otp: otp,
|
||||
amount: widget.amountToWithdraw,
|
||||
payoutPhoneNumber: widget.payoutPhoneNumber,
|
||||
walletType: widget.walletType,
|
||||
);
|
||||
|
||||
setState(() => _isLoading = false);
|
||||
|
||||
if (result != null && result.contains("successfully")) {
|
||||
_showSuccessDialog();
|
||||
} else {
|
||||
_showErrorDialog(result ?? "حدث خطأ غير معروف.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// حساب المبلغ الإجمالي المخصوم
|
||||
|
||||
Reference in New Issue
Block a user