Files
intaleq/intaleq_driver/lib/controller/payment/paymob.dart
T
Hamza-AyedandClaude Opus 5 0aab85c732 refactor: إعادة تسمية التطبيقات الأربعة siro_* → intaleq_*
المجلدات وأسماء حزم dart واستيراداتها:
  siro_rider → intaleq_rider    siro_driver  → intaleq_driver
  siro_admin → intaleq_admin    siro_service → intaleq_service

شمل ذلك `name:` في كل pubspec وكل `package:siro_*` في الاستيرادات
(115 ملفاً في rider وحده)، وإشارات أسماء المجلدات في docs/ وتعليق في
backend/Admin/notifications/broadcast.php. لم تبقَ إشارة واحدة (تحقّقت).

+ ضُمّت حزم get و get_storage داخل intaleq_driver/packages/ وحُوّلت
مساراتها الثلاثة من `../../Intaleq/packages/*` إلى `./packages/*`. كانت
تُحل عرضاً إلى مجلد App/Intaleq القديم المجاور — تبعية خارج المستودع
تنكسر بأول نقل. لم يبقَ في أي تطبيق تبعية مسار خارج الشجرة.

⚠️ لم تُمسّ بعد: هويات المتاجر (applicationId · PRODUCT_BUNDLE_IDENTIFIER ·
shorebird app_id) ولا الألوان ولا النصوص المرئية ولا النطاقات — كل منها
كوميت منفصل، والهويات تحتاج قرار المالك.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 16:10:58 +03:00

155 lines
4.7 KiB
Dart
Executable File

import 'package:intaleq_driver/constant/box_name.dart';
import 'package:dio/dio.dart' as dio;
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../constant/api_key.dart';
import '../../main.dart';
import '../functions/encrypt_decrypt.dart';
class PaymobManager extends GetxController {
String authanticationToken1 = "";
String orderId1 = "";
Future<String> getPaymentKey(int amount, String currency) async {
try {
String authanticationToken = await _getAuthanticationToken();
int orderId = await _getOrderId(
authanticationToken: authanticationToken,
amount: (100 * amount).toString(),
currency: currency,
);
String paymentKey = await _getPaymentKey(
authanticationToken: authanticationToken,
amount: (100 * amount).toString(),
currency: currency,
orderId: orderId.toString(),
);
authanticationToken1 = authanticationToken.toString();
orderId1 = orderId.toString();
update();
return paymentKey;
} catch (e) {
throw Exception();
}
}
Future<void> payWithPayMob(int amount, String currency) async {
// 1. Fetch Payment Key (Assuming PaymobManager is a custom class)
String paymentToken;
try {
paymentToken = await PaymobManager().getPaymentKey(amount, currency);
} on Exception catch (e) {
// Handle errors gracefully, e.g., display error message to user
return;
}
// 2. Prepare Payment Data Payload
final Map<String, dynamic> data = {
"source": {
"identifier": "01010101010", // Replace with actual source identifier
"subtype": "WALLET",
},
"payment_token": paymentToken,
};
// 3. Make Payment Request using Dio
final dio = Dio();
try {
final response = await dio.post(
'https://accept.paymobsolutions.com/api/acceptance/payments/pay',
data: data,
);
// 4. Handle Payment Response
if (response.statusCode == 200) {
final paymentData = response.data; // Assuming JSON response
// Navigate to success screen or display success message
launchUrl(Uri.parse(paymentData['iframe_redirection_url']));
} else {
// Payment failed: Handle errors (e.g., display error message)
}
} on DioError catch (e) {
// Handle network or Dio-related errors
}
}
Future<String> _getStatusAfterPaid() async {
final dio.Response response = await Dio().post(
"https://accept.paymob.com/api/ecommerce/orders/transaction_inquiry",
data: {
"auth_token": authanticationToken1,
"merchant_order_id": "970960",
"order_id": orderId1
});
return response.data["success"];
}
Future<String> _getAuthanticationToken() async {
final dio.Response response =
await Dio().post("https://accept.paymob.com/api/auth/tokens", data: {
"api_key": AK.payMobApikey,
'username': AK.usernamePayMob,
"password": AK.passwordPayMob,
});
return response.data["token"];
}
Future<int> _getOrderId({
required String authanticationToken,
required String amount,
required String currency,
}) async {
final dio.Response response = await Dio()
.post("https://accept.paymob.com/api/ecommerce/orders", data: {
"auth_token": authanticationToken,
"amount_cents": amount,
"currency": currency,
"delivery_needed": "false",
"items": [],
});
return response.data["id"];
}
Future<String> _getPaymentKey({
required String authanticationToken,
required String orderId,
required String amount,
required String currency,
}) async {
final dio.Response response = await Dio()
.post("https://accept.paymob.com/api/acceptance/payment_keys", data: {
"expiration": 200,
"auth_token": authanticationToken.toString(),
"order_id": orderId.toString(),
"integration_id":
4556056, ////todo wallet or online card int.parse(AK.integrationIdPayMob),
"lock_order_when_paid": "false",
"amount_cents": amount,
"currency": currency,
"billing_data": {
"first_name": (box.read(BoxName.nameDriver)),
"last_name": (box.read(BoxName.lastNameDriver)),
"email": (box.read(BoxName.emailDriver)),
"phone_number": (box.read(BoxName.phoneDriver)),
"apartment": "NA",
"floor": "NA",
"street": "NA",
"building": "NA",
"shipping_method": "NA",
"postal_code": "NA",
"city": "NA",
"country": box.read(BoxName.countryCode),
"state": "NA"
},
});
return response.data["token"];
}
}