Update: 2026-06-11 21:53:27
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:siro_driver/constant/style.dart';
|
||||
import 'package:siro_driver/controller/firebase/firbase_messge.dart';
|
||||
import 'package:siro_driver/controller/firebase/local_notification.dart';
|
||||
import 'package:siro_driver/views/widgets/elevated_btn.dart';
|
||||
import 'package:siro_driver/views/widgets/error_snakbar.dart';
|
||||
@@ -12,9 +10,10 @@ import 'package:siro_driver/constant/box_name.dart';
|
||||
import 'package:siro_driver/constant/links.dart';
|
||||
import 'package:siro_driver/controller/functions/crud.dart';
|
||||
import 'package:siro_driver/main.dart';
|
||||
import 'package:siro_driver/views/widgets/mycircular.dart';
|
||||
|
||||
import '../../../views/widgets/mydialoug.dart';
|
||||
import '../../firebase/notification_service.dart';
|
||||
import '../../../views/home/my_wallet/payment_screen_mtn.dart';
|
||||
import '../../../views/home/my_wallet/payment_screen_cliq.dart';
|
||||
|
||||
class CaptainWalletController extends GetxController {
|
||||
bool isLoading = false;
|
||||
@@ -34,36 +33,57 @@ class CaptainWalletController extends GetxController {
|
||||
final cardBank = TextEditingController();
|
||||
final bankCode = TextEditingController();
|
||||
|
||||
double get transferFee {
|
||||
String country = box.read(BoxName.countryCode) ?? 'Jordan';
|
||||
if (country == 'Egypt') return 5.0;
|
||||
if (country == 'Syria') return 10.0;
|
||||
if (country == 'Jordan') return 0.25;
|
||||
return 5.0;
|
||||
}
|
||||
|
||||
double get minTransferAmount {
|
||||
String country = box.read(BoxName.countryCode) ?? 'Jordan';
|
||||
if (country == 'Egypt') return 10.0;
|
||||
if (country == 'Syria') return 100.0;
|
||||
if (country == 'Jordan') return 1.0;
|
||||
return 10.0;
|
||||
}
|
||||
payFromBudget() async {
|
||||
if (formKey.currentState!.validate()) {
|
||||
var pointFromBudget = int.parse((amountFromBudgetController.text));
|
||||
|
||||
// await getPaymentId('fromBudgetToPoints',
|
||||
// int.parse((amountFromBudgetController.text)) * -1);
|
||||
var paymentToken3 =
|
||||
await generateToken((pointFromBudget * -1).toString());
|
||||
var paymentID = await getPaymentId(
|
||||
'fromBudgetToPoints', (pointFromBudget * -1).toString());
|
||||
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
|
||||
'amount': (pointFromBudget * -1).toString(),
|
||||
'rideId': paymentID.toString(),
|
||||
'payment_method': 'myBudget',
|
||||
'passengerID': 'myBudgetToPoint',
|
||||
'token': paymentToken3,
|
||||
Get.dialog(const Center(child: MyCircularProgressIndicator()),
|
||||
barrierDismissible: false);
|
||||
var res = await CRUD()
|
||||
.postWallet(link: AppLink.convertBudgetToPoints, payload: {
|
||||
'amount': pointFromBudget.toString(),
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
});
|
||||
Future.delayed(const Duration(seconds: 1));
|
||||
await addDriverWallet(
|
||||
'fromBudget', pointFromBudget.toString(), pointFromBudget.toString());
|
||||
update();
|
||||
Get.back();
|
||||
await refreshCaptainWallet();
|
||||
NotificationController().showNotification(
|
||||
'You have successfully charged your account'.tr,
|
||||
'$pointFromBudget ${'has been added to your budget'.tr}',
|
||||
'tone1',
|
||||
'',
|
||||
);
|
||||
Get.back(); // close loading
|
||||
|
||||
if (res != 'failure') {
|
||||
late Map<String, dynamic> mapRes;
|
||||
if (res is String) {
|
||||
mapRes = json.decode(res);
|
||||
} else {
|
||||
mapRes = res;
|
||||
}
|
||||
|
||||
if (mapRes['status'] == 'success') {
|
||||
update();
|
||||
Get.back();
|
||||
await refreshCaptainWallet();
|
||||
NotificationController().showNotification(
|
||||
'You have successfully charged your account'.tr,
|
||||
'$pointFromBudget ${'has been added to your budget'.tr}',
|
||||
'tone1',
|
||||
'',
|
||||
);
|
||||
} else {
|
||||
mySnackeBarError(mapRes['message']?.toString() ?? 'Error');
|
||||
}
|
||||
} else {
|
||||
mySnackeBarError('Error processing request'.tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,71 +282,45 @@ class CaptainWalletController extends GetxController {
|
||||
}
|
||||
|
||||
Future addTransferDriversWallet(String paymentMethod1, paymentMethod2) async {
|
||||
var paymentID =
|
||||
await getPaymentId(paymentMethod1, amountFromBudgetController.text);
|
||||
paymentToken = await generateToken(
|
||||
(int.parse(amountFromBudgetController.text) * -1).toString());
|
||||
|
||||
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
|
||||
'amount': (int.parse(amountFromBudgetController.text) * -1).toString(),
|
||||
'rideId': paymentID.toString(),
|
||||
'payment_method': paymentMethod1,
|
||||
'passengerID': 'To ${amountToNewDriverMap[0]['id']}',
|
||||
'token': paymentToken,
|
||||
Get.dialog(const Center(child: CircularProgressIndicator()),
|
||||
barrierDismissible: false);
|
||||
var res =
|
||||
await CRUD().postWallet(link: AppLink.transferWalletDriver, payload: {
|
||||
'amount': amountFromBudgetController.text,
|
||||
'receiverPhone': amountToNewDriverMap[0]['phone'].toString(),
|
||||
'country': box.read(BoxName.countryCode) ?? 'Egypt',
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
});
|
||||
Get.back();
|
||||
|
||||
paymentID = await getPaymentId(paymentMethod2,
|
||||
(int.parse(amountFromBudgetController.text) - 5).toString());
|
||||
paymentToken = await generateToken(amountFromBudgetController.text);
|
||||
var res1 =
|
||||
await CRUD().postWallet(link: AppLink.addDriversWalletPoints, payload: {
|
||||
'driverID': amountToNewDriverMap[0]['id'].toString(),
|
||||
'paymentID': paymentID.toString(),
|
||||
'amount': ((int.parse(amountFromBudgetController.text) - 5))
|
||||
// kazan) // double.parse(kazan) .08 for egypt
|
||||
.toStringAsFixed(
|
||||
0), // this will convert buddget to poitns by kazan .08
|
||||
if (res != 'failure') {
|
||||
late Map<String, dynamic> mapRes;
|
||||
if (res is String) {
|
||||
mapRes = json.decode(res);
|
||||
} else {
|
||||
mapRes = res;
|
||||
}
|
||||
|
||||
'token': paymentToken,
|
||||
'paymentMethod': paymentMethod2.toString(),
|
||||
});
|
||||
if (res1 != 'failure') {
|
||||
// Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
|
||||
// 'Transfer',
|
||||
// '${'You have transfer to your wallet from'.tr}'
|
||||
// '${box.read(BoxName.nameDriver)}',
|
||||
// amountToNewDriverMap[0]['token'].toString(),
|
||||
// [],
|
||||
// 'order1.wav');
|
||||
NotificationService.sendNotification(
|
||||
target: amountToNewDriverMap[0]['token'].toString(),
|
||||
title: 'Transfer'.tr,
|
||||
body: '${'You have transfer to your wallet from'.tr}'
|
||||
'${box.read(BoxName.nameDriver)}',
|
||||
|
||||
isTopic: false, // Important: this is a token
|
||||
tone: 'ding',
|
||||
driverList: [], category: 'Transfer',
|
||||
);
|
||||
await addSeferWallet('payout fee', '5');
|
||||
|
||||
Get.defaultDialog(
|
||||
title: 'transfer Successful'.tr,
|
||||
middleText: '',
|
||||
titleStyle: AppStyle.title,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
Get.back();
|
||||
|
||||
await refreshCaptainWallet();
|
||||
}));
|
||||
if (mapRes['status'] == 'success') {
|
||||
Get.defaultDialog(
|
||||
title: 'transfer Successful'.tr,
|
||||
middleText: '',
|
||||
titleStyle: AppStyle.title,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
Get.back();
|
||||
await refreshCaptainWallet();
|
||||
}));
|
||||
} else {
|
||||
mySnackeBarError(mapRes['message']?.toString() ?? 'Error');
|
||||
}
|
||||
} else {
|
||||
mySnackeBarError('Error processing request'.tr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getKazanPercent() async {
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.getKazanPercent,
|
||||
@@ -354,4 +348,110 @@ class CaptainWalletController extends GetxController {
|
||||
await refreshCaptainWallet();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
Future<void> payWithMTNWallet(
|
||||
BuildContext context, String amount, String currency) async {
|
||||
try {
|
||||
final phone = phoneWallet.text.trim();
|
||||
if (phone.isEmpty) {
|
||||
Get.defaultDialog(
|
||||
title: 'Error'.tr, content: Text('Please enter phone number'.tr));
|
||||
return;
|
||||
}
|
||||
|
||||
Get.dialog(const Center(child: CircularProgressIndicator()),
|
||||
barrierDismissible: false);
|
||||
|
||||
var res = await CRUD().postWalletMtn(
|
||||
link: AppLink.createMtnInvoice,
|
||||
payload: {
|
||||
"amount": amount,
|
||||
"user_id": box.read(BoxName.driverID).toString(),
|
||||
"user_type": "driver",
|
||||
"mtn_phone": phone,
|
||||
},
|
||||
);
|
||||
|
||||
Get.back(); // close loading
|
||||
|
||||
late final Map<String, dynamic> resMap;
|
||||
if (res is Map<String, dynamic>) {
|
||||
resMap = res;
|
||||
} else if (res is String) {
|
||||
resMap = json.decode(res) as Map<String, dynamic>;
|
||||
} else {
|
||||
throw Exception("Unexpected response type");
|
||||
}
|
||||
|
||||
if (resMap['status'] == 'success') {
|
||||
Get.to(() => PaymentScreenMtn(
|
||||
invoiceNumber: resMap['invoice_number'],
|
||||
mtnNumber: resMap['mtn_payment_number'] ?? '---',
|
||||
amount: double.parse(amount),
|
||||
));
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: 'Error'.tr,
|
||||
content: Text(
|
||||
resMap['message']?.toString() ?? 'Failed to create invoice'.tr),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (Get.isDialogOpen ?? false) Get.back();
|
||||
Get.defaultDialog(title: 'Error'.tr, content: Text(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> payWithClickWallet(
|
||||
BuildContext context, String amount, String currency) async {
|
||||
try {
|
||||
final phone = phoneWallet.text.trim();
|
||||
if (phone.isEmpty) {
|
||||
Get.defaultDialog(
|
||||
title: 'Error'.tr, content: Text('Please enter phone number'.tr));
|
||||
return;
|
||||
}
|
||||
|
||||
Get.dialog(const Center(child: CircularProgressIndicator()),
|
||||
barrierDismissible: false);
|
||||
|
||||
var res = await CRUD().postWalletMtn(
|
||||
link: AppLink.createCliqInvoice,
|
||||
payload: {
|
||||
"amount": amount,
|
||||
"user_id": box.read(BoxName.driverID).toString(),
|
||||
"user_type": "driver",
|
||||
"click_phone": phone,
|
||||
},
|
||||
);
|
||||
|
||||
Get.back(); // close loading
|
||||
|
||||
late final Map<String, dynamic> resMap;
|
||||
if (res is Map<String, dynamic>) {
|
||||
resMap = res;
|
||||
} else if (res is String) {
|
||||
resMap = json.decode(res) as Map<String, dynamic>;
|
||||
} else {
|
||||
throw Exception("Unexpected response type");
|
||||
}
|
||||
|
||||
if (resMap['status'] == 'success') {
|
||||
Get.to(() => PaymentScreenCliq(
|
||||
invoiceNumber: resMap['invoice_number'],
|
||||
cliqAlias: resMap['cliq_alias'] ?? '---',
|
||||
amount: double.parse(amount),
|
||||
));
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: 'Error'.tr,
|
||||
content: Text(
|
||||
resMap['message']?.toString() ?? 'Failed to create invoice'.tr),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (Get.isDialogOpen ?? false) Get.back();
|
||||
Get.defaultDialog(title: 'Error'.tr, content: Text(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user