25-3/18/1
This commit is contained in:
185
lib/controller/auth/captin/invit_controller.dart
Normal file → Executable file
185
lib/controller/auth/captin/invit_controller.dart
Normal file → Executable file
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:sefer_driver/constant/box_name.dart';
|
||||
import 'package:sefer_driver/constant/links.dart';
|
||||
import 'package:sefer_driver/controller/firebase/local_notification.dart';
|
||||
@@ -153,55 +154,79 @@ Download the Tripz app now and enjoy your ride!
|
||||
: 'You deserve the gift'.tr,
|
||||
'${EncryptionHelper.instance.decryptData(driverInvitationData[index]['invitorName'])} ${(driverInvitationData[index]['countOfInvitDriver'])} / 100 ${'Trip'.tr}',
|
||||
() async {
|
||||
bool isAvailable = await LocalAuthentication().isDeviceSupported();
|
||||
if (int.parse((driverInvitationData[index]['countOfInvitDriver'])) <
|
||||
100) {
|
||||
Get.back();
|
||||
} else {
|
||||
//claim your gift
|
||||
if ((driverInvitationData[index]['isGiftToken']).toString() == '0') {
|
||||
Get.back();
|
||||
await CRUD().post(link: AppLink.updateInviteDriver, payload: {
|
||||
'id': EncryptionHelper.instance
|
||||
.encryptData(driverInvitationData[index]['id'])
|
||||
});
|
||||
await Get.find<CaptainWalletController>().addDriverPayment(
|
||||
'paymentMethod',
|
||||
EncryptionHelper.instance.encryptData('500'),
|
||||
'',
|
||||
);
|
||||
// add for invitor too
|
||||
await Get.find<CaptainWalletController>().addDriverWalletToInvitor(
|
||||
'paymentMethod',
|
||||
EncryptionHelper.instance
|
||||
.encryptData(driverInvitationData[index]['driverInviterId']),
|
||||
EncryptionHelper.instance.encryptData('500'),
|
||||
);
|
||||
await Get.find<CaptainWalletController>().addSeferWallet(
|
||||
'giftInvitation',
|
||||
EncryptionHelper.instance.encryptData('-1000'));
|
||||
NotificationCaptainController().addNotificationCaptain(
|
||||
driverInvitationData[index]['driverInviterId'].toString(),
|
||||
"You have got a gift for invitation".tr,
|
||||
'${"You have 500".tr} ${'LE'}',
|
||||
false);
|
||||
NotificationController().showNotification(
|
||||
"You have got a gift for invitation".tr,
|
||||
'${"You have 500".tr} ${'LE'}',
|
||||
'tone1',
|
||||
'');
|
||||
} else
|
||||
//claim your gift
|
||||
|
||||
if (isAvailable) {
|
||||
// Authenticate the user
|
||||
bool didAuthenticate = await LocalAuthentication().authenticate(
|
||||
localizedReason: 'Use Touch ID or Face ID to confirm payment',
|
||||
options: AuthenticationOptions(
|
||||
biometricOnly: true,
|
||||
sensitiveTransaction: true,
|
||||
));
|
||||
if (didAuthenticate) {
|
||||
if ((driverInvitationData[index]['isGiftToken']).toString() ==
|
||||
'0') {
|
||||
Get.back();
|
||||
await CRUD().post(link: AppLink.updateInviteDriver, payload: {
|
||||
'id': EncryptionHelper.instance
|
||||
.encryptData(driverInvitationData[index]['id'])
|
||||
});
|
||||
await Get.find<CaptainWalletController>().addDriverPayment(
|
||||
'paymentMethod',
|
||||
('500'),
|
||||
'',
|
||||
);
|
||||
// add for invitor too
|
||||
await Get.find<CaptainWalletController>()
|
||||
.addDriverWalletToInvitor(
|
||||
'paymentMethod',
|
||||
EncryptionHelper.instance.encryptData(
|
||||
driverInvitationData[index]['driverInviterId']),
|
||||
('500'),
|
||||
);
|
||||
await Get.find<CaptainWalletController>()
|
||||
.addSeferWallet('giftInvitation', ('-1000'));
|
||||
NotificationCaptainController().addNotificationCaptain(
|
||||
driverInvitationData[index]['driverInviterId'].toString(),
|
||||
"You have got a gift for invitation".tr,
|
||||
'${"You have 500".tr} ${'LE'}',
|
||||
false);
|
||||
NotificationController().showNotification(
|
||||
"You have got a gift for invitation".tr,
|
||||
'${"You have 500".tr} ${'LE'}',
|
||||
'tone1',
|
||||
'');
|
||||
} else {
|
||||
Get.back();
|
||||
MyDialog().getDialog("You have got a gift".tr,
|
||||
"Share the app with another new driver".tr, () {
|
||||
Get.back();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Get.back();
|
||||
MyDialog().getDialog("You have got a gift".tr,
|
||||
"Share the app with another new driver".tr, () {
|
||||
// Authentication failed, handle accordingly
|
||||
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
|
||||
Get.back();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
MyDialog().getDialog('Biometric Authentication'.tr,
|
||||
'You should use Touch ID or Face ID to confirm payment'.tr, () {
|
||||
Get.back();
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void onSelectPassengerInvitation(int index) async {
|
||||
bool isAvailable = await LocalAuthentication().isDeviceSupported();
|
||||
MyDialog().getDialog(
|
||||
int.parse(driverInvitationDataToPassengers[index]['countOfInvitDriver']
|
||||
.toString()) <
|
||||
@@ -215,43 +240,61 @@ Download the Tripz app now and enjoy your ride!
|
||||
.toString()) <
|
||||
3) {
|
||||
Get.back();
|
||||
} else {
|
||||
// Claim the gift if 100 trips are completed
|
||||
if (driverInvitationDataToPassengers[index]['isGiftToken']
|
||||
.toString() ==
|
||||
'0') {
|
||||
Get.back();
|
||||
// Add wallet to the inviter
|
||||
await Get.find<CaptainWalletController>()
|
||||
.addDriverWallet('paymentMethod', '50', '50');
|
||||
// add for invitor too
|
||||
await Get.find<CaptainWalletController>().addDriverWalletToInvitor(
|
||||
'paymentMethod',
|
||||
driverInvitationData[index]['driverInviterId'],
|
||||
'50');
|
||||
// Update invitation as claimed
|
||||
await CRUD().post(
|
||||
link: AppLink.updatePassengerGift,
|
||||
payload: {'id': driverInvitationDataToPassengers[index]['id']},
|
||||
);
|
||||
// Notify the inviter
|
||||
NotificationCaptainController().addNotificationCaptain(
|
||||
driverInvitationDataToPassengers[index]['passengerInviterId']
|
||||
.toString(),
|
||||
"You have got a gift for invitation".tr,
|
||||
'${"You have 50".tr} ${'LE'}',
|
||||
false,
|
||||
);
|
||||
} else if (isAvailable) {
|
||||
// Authenticate the user
|
||||
bool didAuthenticate = await LocalAuthentication().authenticate(
|
||||
localizedReason: 'Use Touch ID or Face ID to confirm payment',
|
||||
options: AuthenticationOptions(
|
||||
biometricOnly: true,
|
||||
sensitiveTransaction: true,
|
||||
));
|
||||
if (didAuthenticate) {
|
||||
// Claim the gift if 100 trips are completed
|
||||
if (driverInvitationDataToPassengers[index]['isGiftToken']
|
||||
.toString() ==
|
||||
'0') {
|
||||
Get.back();
|
||||
// Add wallet to the inviter
|
||||
await Get.find<CaptainWalletController>()
|
||||
.addDriverWallet('paymentMethod', '50', '50');
|
||||
// add for invitor too
|
||||
await Get.find<CaptainWalletController>()
|
||||
.addDriverWalletToInvitor('paymentMethod',
|
||||
driverInvitationData[index]['driverInviterId'], '50');
|
||||
// Update invitation as claimed
|
||||
await CRUD().post(
|
||||
link: AppLink.updatePassengerGift,
|
||||
payload: {'id': driverInvitationDataToPassengers[index]['id']},
|
||||
);
|
||||
// Notify the inviter
|
||||
NotificationCaptainController().addNotificationCaptain(
|
||||
driverInvitationDataToPassengers[index]['passengerInviterId']
|
||||
.toString(),
|
||||
"You have got a gift for invitation".tr,
|
||||
'${"You have 50".tr} ${'LE'}',
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
Get.back();
|
||||
MyDialog().getDialog(
|
||||
"You have got a gift".tr,
|
||||
"Share the app with another new passenger".tr,
|
||||
() {
|
||||
Get.back();
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Get.back();
|
||||
MyDialog().getDialog(
|
||||
"You have got a gift".tr,
|
||||
"Share the app with another new passenger".tr,
|
||||
() {
|
||||
Get.back();
|
||||
},
|
||||
);
|
||||
// Authentication failed, handle accordingly
|
||||
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
|
||||
Get.back();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
MyDialog().getDialog('Biometric Authentication'.tr,
|
||||
'You should use Touch ID or Face ID to confirm payment'.tr, () {
|
||||
Get.back();
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user