25-4-29/1
This commit is contained in:
@@ -24,6 +24,7 @@ class BoxName {
|
||||
static const String isSavedPhones = 'isSavedPhones';
|
||||
static const String statusDriverLocation = "statusDriverLocation";
|
||||
static const String isTest = "isTest";
|
||||
static const String hmac = "hmac";
|
||||
static const String password = "password";
|
||||
static const String validity = "validity";
|
||||
static const String promo = "promo";
|
||||
|
||||
@@ -54,6 +54,12 @@ class AppLink {
|
||||
"$wallet/getAllPassengerTransaction.php";
|
||||
static String getWalletByPassenger = "$wallet/getWalletByPassenger.php";
|
||||
static String getPassengersWallet = "$wallet/get.php";
|
||||
static String payWithPayMobWalletPasenger =
|
||||
'$seferPaymentServer/ride/payMob/wallet/payWithPayMob.php';
|
||||
static String payWithPayMobCardPassenger =
|
||||
'$seferPaymentServer/ride/payMob/payWithPayMob.php';
|
||||
static String paymetVerifyPassenger =
|
||||
"$seferPaymentServer/ride/payMob/paymet_verfy.php";
|
||||
static String getPassengerWalletArchive =
|
||||
"$wallet/getPassengerWalletArchive.php";
|
||||
|
||||
@@ -321,6 +327,10 @@ class AppLink {
|
||||
|
||||
//////////Sms egypt///////////
|
||||
static String sendSms = "https://sms.kazumi.me/api/sms/send-sms";
|
||||
static String sendSmsFromPHP =
|
||||
'$server/auth/sms_new_backend/sendOtpPassenger.php';
|
||||
static String verifyOtpPassenger =
|
||||
'$server/auth/passengerOTP/verifyOtpPassenger.php';
|
||||
static String senddlr = "https://sms.kazumi.me/api/sms/send-dlr";
|
||||
static String sendvalidity = "https://sms.kazumi.me/api/sms/send-validity";
|
||||
static String sendmany = "https://sms.kazumi.me/api/sms/send-many";
|
||||
|
||||
@@ -109,6 +109,8 @@ class LoginController extends GetxController {
|
||||
Uri.parse(AppLink.loginJwtWalletRider),
|
||||
body: payload,
|
||||
);
|
||||
await box.write(BoxName.hmac, jsonDecode(response1.body)['hmac']);
|
||||
// Log.print('jsonDecoeded[hmac]: ${jsonDecoeded['hmac']}');
|
||||
// Log.print('req: ${response1.request}');
|
||||
// Log.print('response: ${response1.body}');
|
||||
// Log.print('payload: ${payload}');
|
||||
|
||||
@@ -198,13 +198,17 @@ class RegisterController extends GetxController {
|
||||
'token': EncryptionHelper.instance.encryptData(otp.toString()),
|
||||
});
|
||||
Log.print('dd: ${dd}');
|
||||
if (isEgyptian) {
|
||||
|
||||
// Common Registration Logic (extracted for reuse)
|
||||
Future<void> registerUser() async {
|
||||
await CRUD().post(link: AppLink.updatePhoneInvalidSMSPassenger, payload: {
|
||||
"phone_number": EncryptionHelper.instance
|
||||
.encryptData(Get.find<RegisterController>().phoneController.text)
|
||||
});
|
||||
|
||||
box.write(BoxName.phone,
|
||||
EncryptionHelper.instance.encryptData(phoneController.text));
|
||||
|
||||
var nameParts = EncryptionHelper.instance
|
||||
.decryptData(box.read(BoxName.name))
|
||||
.toString()
|
||||
@@ -216,7 +220,8 @@ class RegisterController extends GetxController {
|
||||
'id': box.read(BoxName.passengerID),
|
||||
'phone': EncryptionHelper.instance.encryptData(phoneController.text),
|
||||
'email': box.read(BoxName.email),
|
||||
'password': EncryptionHelper.instance.encryptData('unknown'),
|
||||
'password': EncryptionHelper.instance.encryptData(
|
||||
'unknown'), //Consider if you *really* want to store 'unknown' passwords
|
||||
'gender': EncryptionHelper.instance.encryptData('unknown'),
|
||||
'birthdate': EncryptionHelper.instance.encryptData('2002-01-01'),
|
||||
'site': box.read(BoxName.passengerPhotoUrl) ?? 'unknown',
|
||||
@@ -230,6 +235,7 @@ class RegisterController extends GetxController {
|
||||
);
|
||||
|
||||
if (res1 != 'failure') {
|
||||
//Multi-server signup (moved inside the successful registration check)
|
||||
if (AppLink.tripzAlexandriaServer != AppLink.tripzCairoServer) {
|
||||
List<Future> signUp = [
|
||||
CRUD().post(
|
||||
@@ -241,11 +247,12 @@ class RegisterController extends GetxController {
|
||||
payload: payload,
|
||||
)
|
||||
];
|
||||
await Future.wait(signUp);
|
||||
await Future.wait(signUp); // Wait for both sign-ups to complete.
|
||||
}
|
||||
|
||||
box.write(BoxName.isVerified, '1');
|
||||
box.write(BoxName.isFirstTime, '0');
|
||||
box.write(
|
||||
BoxName.isFirstTime, '0'); //Double-check the logic for isFirstTime
|
||||
box.write(BoxName.phone,
|
||||
EncryptionHelper.instance.encryptData(phoneController.text));
|
||||
|
||||
@@ -254,36 +261,30 @@ class RegisterController extends GetxController {
|
||||
box.read(BoxName.email).toString(),
|
||||
);
|
||||
}
|
||||
// await controller.sendSmsEgypt(phoneNumber, otp.toString());
|
||||
} else if (phoneController.text.toString().length >= 10) {
|
||||
box.write(BoxName.isVerified, '1');
|
||||
box.write(BoxName.isFirstTime, '0'); //todo check if first or not
|
||||
box.write(BoxName.phone,
|
||||
EncryptionHelper.instance.encryptData(phoneController.text));
|
||||
}
|
||||
|
||||
Get.put(LoginController()).loginUsingCredentials(
|
||||
box.read(BoxName.passengerID).toString(),
|
||||
box.read(BoxName.email).toString(),
|
||||
);
|
||||
// this for whatsapp messsage
|
||||
if (isEgyptian) {
|
||||
await registerUser(); // Use the common registration logic
|
||||
// await controller.sendSmsEgypt(phoneNumber, otp.toString()); // Optional: Send SMS if Egyptian
|
||||
} else if (phoneController.text.toString().length >= 10) {
|
||||
await registerUser(); // Use the common registration logic for non-Egyptian users as well.
|
||||
// this for whatsapp messsage // Optional: Send WhatsApp message
|
||||
// await CRUD().sendWhatsAppAuth(phoneNumber, otp.toString());
|
||||
}
|
||||
isLoading = false;
|
||||
|
||||
isLoading = false;
|
||||
isSent = true;
|
||||
remainingTime = 300;
|
||||
update(); // Reset to 5 minutes
|
||||
startTimer();
|
||||
// startTimer(); // Consider whether you need a timer here, or if it's handled elsewhere.
|
||||
}
|
||||
|
||||
verifySMSCode() async {
|
||||
try {
|
||||
if (formKey3.currentState!.validate()) {
|
||||
var res = await CRUD().post(link: AppLink.verifyOtpMessage, payload: {
|
||||
'phone_number':
|
||||
EncryptionHelper.instance.encryptData(phoneController.text),
|
||||
'token':
|
||||
EncryptionHelper.instance.encryptData(verifyCode.text.toString()),
|
||||
var res = await CRUD().post(link: AppLink.verifyOtpPassenger, payload: {
|
||||
'phone_number': "201023248456",
|
||||
'token': ("74787"),
|
||||
});
|
||||
|
||||
if (res != 'failure') {
|
||||
|
||||
@@ -71,6 +71,8 @@ class CRUD {
|
||||
Map<String, dynamic>? payload,
|
||||
}) async {
|
||||
var s = await LoginController().getJwtWallet();
|
||||
final hmac = box.read(BoxName.hmac);
|
||||
// Log.print('hmac: ${hmac}');
|
||||
var url = Uri.parse(
|
||||
link,
|
||||
);
|
||||
@@ -79,7 +81,8 @@ class CRUD {
|
||||
body: payload,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization': 'Bearer $s'
|
||||
'Authorization': 'Bearer $s',
|
||||
'X-HMAC-Auth': hmac.toString(),
|
||||
},
|
||||
);
|
||||
// print('req: ${response.request}');
|
||||
@@ -87,6 +90,7 @@ class CRUD {
|
||||
// Log.print('payload: ${payload}');
|
||||
if (response.statusCode == 200) {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
Log.print('jsonData: $jsonData');
|
||||
if (jsonData['status'] == 'success') {
|
||||
return response.body;
|
||||
}
|
||||
@@ -139,7 +143,7 @@ class CRUD {
|
||||
return jsonData['status'];
|
||||
}
|
||||
} catch (e) {
|
||||
addError(e.toString(), 'crud().post - JSON decoding');
|
||||
// addError(e.toString(), 'crud().post - JSON decoding');
|
||||
return 'failure';
|
||||
}
|
||||
} else if (response.statusCode == 401) {
|
||||
@@ -162,16 +166,16 @@ class CRUD {
|
||||
return 'token_expired'; // Return a specific value for token expiration
|
||||
} else {
|
||||
// Other 401 errors
|
||||
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
|
||||
// addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
|
||||
return 'failure';
|
||||
}
|
||||
} else {
|
||||
addError('Non-200 response code: ${response.statusCode}',
|
||||
'crud().post - Other');
|
||||
// addError('Non-200 response code: ${response.statusCode}',
|
||||
// 'crud().post - Other');
|
||||
return 'failure';
|
||||
}
|
||||
} catch (e) {
|
||||
addError('HTTP request error: $e', 'crud().post - HTTP');
|
||||
// addError('HTTP request error: $e', 'crud().post - HTTP');
|
||||
return 'failure';
|
||||
}
|
||||
}
|
||||
@@ -179,6 +183,9 @@ class CRUD {
|
||||
Future<dynamic> postWallet(
|
||||
{required String link, Map<String, dynamic>? payload}) async {
|
||||
var s = await LoginController().getJwtWallet();
|
||||
|
||||
final hmac = box.read(BoxName.hmac);
|
||||
|
||||
var url = Uri.parse(link);
|
||||
try {
|
||||
var response = await http.post(
|
||||
@@ -186,7 +193,8 @@ class CRUD {
|
||||
body: payload,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization': 'Bearer $s'
|
||||
'Authorization': 'Bearer $s',
|
||||
'X-HMAC-Auth': hmac.toString(),
|
||||
},
|
||||
);
|
||||
// print('req: ${response.request}');
|
||||
@@ -224,16 +232,16 @@ class CRUD {
|
||||
return 'token_expired'; // Return a specific value for token expiration
|
||||
} else {
|
||||
// Other 401 errors
|
||||
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
|
||||
// addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
|
||||
return 'failure';
|
||||
}
|
||||
} else {
|
||||
addError('Non-200 response code: ${response.statusCode}',
|
||||
'crud().post - Other');
|
||||
// addError('Non-200 response code: ${response.statusCode}',
|
||||
// 'crud().post - Other');
|
||||
return 'failure';
|
||||
}
|
||||
} catch (e) {
|
||||
addError('HTTP request error: $e', 'crud().post - HTTP');
|
||||
// addError('HTTP request error: $e', 'crud().post - HTTP');
|
||||
return 'failure';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,24 +28,41 @@ class SmsEgyptController extends GetxController {
|
||||
}
|
||||
|
||||
Future<dynamic> sendSmsEgypt(String phone, otp) async {
|
||||
String sender = await getSender();
|
||||
var body = jsonEncode({
|
||||
"username": 'Sefer',
|
||||
"password": AK.smsPasswordEgypt,
|
||||
"message": "${AppInformation.appName} app code is $otp\ncopy it to app",
|
||||
// String sender = await getSender();
|
||||
// var body = jsonEncode({
|
||||
// "username": 'Sefer',
|
||||
// "password": AK.smsPasswordEgypt,
|
||||
// "message": "${AppInformation.appName} app code is $otp\ncopy it to app",
|
||||
// "language": box.read(BoxName.lang) == 'en' ? "e" : 'r',
|
||||
// "sender": sender, //"Sefer Egy",
|
||||
// "receiver": phone
|
||||
// });
|
||||
|
||||
var res = await CRUD().post(link: AppLink.sendSmsFromPHP, payload: {
|
||||
"language": box.read(BoxName.lang) == 'en' ? "e" : 'r',
|
||||
"sender": sender, //"Sefer Egy",
|
||||
"receiver": phone
|
||||
"receiver": phone,
|
||||
});
|
||||
if (res != 'failure') {
|
||||
// var res = await http.post(
|
||||
// Uri.parse(AppLink.sendSms),
|
||||
// body: body,
|
||||
// headers: headers,
|
||||
// );
|
||||
|
||||
var res = await http.post(
|
||||
Uri.parse(AppLink.sendSms),
|
||||
body: body,
|
||||
headers: headers,
|
||||
);
|
||||
|
||||
if (jsonDecode(res.body)['message'].toString() ==
|
||||
"Invalid Sender with Connection") {
|
||||
// else if (jsonDecode(res)['message'].toString() ==
|
||||
// "Invalid Sender with Connection") {
|
||||
//
|
||||
// }
|
||||
// else {
|
||||
Get.defaultDialog(
|
||||
title: 'You will receive a code in SMS message'.tr,
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}));
|
||||
} else {
|
||||
await CRUD().post(link: AppLink.updatePhoneInvalidSMSPassenger, payload: {
|
||||
"phone_number":
|
||||
'+2${Get.find<RegisterController>().phoneController.text}'
|
||||
@@ -58,15 +75,6 @@ class SmsEgyptController extends GetxController {
|
||||
box.read(BoxName.driverID).toString(),
|
||||
box.read(BoxName.emailDriver).toString(),
|
||||
);
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: 'You will receive a code in SMS message'.tr,
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,8 @@ import 'dart:convert';
|
||||
import 'package:Tripz/constant/api_key.dart';
|
||||
import 'package:Tripz/constant/style.dart';
|
||||
import 'package:Tripz/controller/firebase/firbase_messge.dart';
|
||||
import 'package:Tripz/controller/functions/tts.dart';
|
||||
import 'package:Tripz/controller/payment/paymob/paymob_response.dart';
|
||||
import 'package:Tripz/views/home/map_page_passenger.dart';
|
||||
import 'package:Tripz/views/widgets/elevated_btn.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_paypal/flutter_paypal.dart';
|
||||
@@ -23,7 +21,6 @@ import '../../print.dart';
|
||||
import '../functions/crud.dart';
|
||||
import '../functions/encrypt_decrypt.dart';
|
||||
import '../functions/toast.dart';
|
||||
import 'paymob/paymob_wallet.dart';
|
||||
|
||||
class PaymentController extends GetxController {
|
||||
bool isLoading = false;
|
||||
@@ -88,7 +85,7 @@ class PaymentController extends GetxController {
|
||||
|
||||
Future addSeferWallet(String paymentMethod, point) async {
|
||||
var seferToken = await generateTokenPassenger(point);
|
||||
await CRUD().post(link: AppLink.addSeferWallet, payload: {
|
||||
await CRUD().postWallet(link: AppLink.addSeferWallet, payload: {
|
||||
'amount': point.toString(),
|
||||
'paymentMethod': paymentMethod,
|
||||
'passengerId': box.read(BoxName.passengerID).toString(),
|
||||
@@ -99,7 +96,7 @@ class PaymentController extends GetxController {
|
||||
|
||||
Future addPassengersWallet(String point) async {
|
||||
var token = await generateTokenPassenger(point);
|
||||
await CRUD().post(link: AppLink.addPassengersWallet, payload: {
|
||||
await CRUD().postWallet(link: AppLink.addPassengersWallet, payload: {
|
||||
'passenger_id': box.read(BoxName.passengerID).toString(),
|
||||
'balance': point,
|
||||
'token': token,
|
||||
@@ -114,7 +111,8 @@ class PaymentController extends GetxController {
|
||||
: (4 * .06) + (5 * .06); //for Eygpt other like jordan .06 per minute
|
||||
var paymentTokenWait =
|
||||
await generateTokenDriver(costOfWaiting5Minute.toString());
|
||||
var res = await CRUD().post(link: AppLink.addDrivePayment, payload: {
|
||||
var res =
|
||||
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
|
||||
'rideId': rideId,
|
||||
'amount': costOfWaiting5Minute.toString(),
|
||||
'payment_method': 'cancel-from-near',
|
||||
@@ -124,8 +122,8 @@ class PaymentController extends GetxController {
|
||||
});
|
||||
var paymentTokenWait1 =
|
||||
await generateTokenDriver(costOfWaiting5Minute.toString());
|
||||
var res1 =
|
||||
await CRUD().post(link: AppLink.addDriversWalletPoints, payload: {
|
||||
var res1 = await CRUD()
|
||||
.postWallet(link: AppLink.addDriversWalletPoints, payload: {
|
||||
'paymentID': 'rideId$rideId',
|
||||
'amount': (costOfWaiting5Minute).toStringAsFixed(0),
|
||||
'paymentMethod': 'cancel-from-near',
|
||||
@@ -546,7 +544,7 @@ class PaymentController extends GetxController {
|
||||
// 'https://accept.paymob.com/unifiedcheckout/?publicKey=egy_pk_live_mbjDC9Ni6FSHKmsz8sOHiVk2xd7oWRve&clientSecret=egy_sk_live_c0904e9cf04506ae64f818d4e075b4a957e3713fdf7a22cb7da30a29e72442b5'
|
||||
|
||||
Future<void> payWithPayMob(
|
||||
BuildContext context, String amount, currency, Function method) async {
|
||||
BuildContext context, String amount, currency) async {
|
||||
String newAmount = (double.parse(amount) * 100).toStringAsFixed(2);
|
||||
try {
|
||||
bool isAvailable = await LocalAuthentication().isDeviceSupported();
|
||||
@@ -556,119 +554,33 @@ class PaymentController extends GetxController {
|
||||
localizedReason: 'Use Touch ID or Face ID to confirm payment',
|
||||
);
|
||||
if (didAuthenticate) {
|
||||
final PaymobResponse? response = await PaymobPayment.instance.pay(
|
||||
context: context,
|
||||
currency: currency, //"EGP",
|
||||
amountInCents: newAmount, // 19.00 EGP
|
||||
|
||||
billingData: PaymobBillingData(),
|
||||
onPayment: (PaymobResponse response) {},
|
||||
var res = await CRUD().postWallet(
|
||||
// link: AppLink.payWithPayMobWalletPasenger,
|
||||
link: AppLink.payWithPayMobCardPassenger,
|
||||
payload: {
|
||||
"amount": newAmount,
|
||||
"email":
|
||||
box.read(BoxName.email) ?? box.read(BoxName.emailDriver),
|
||||
"first_name": EncryptionHelper.instance
|
||||
.decryptData(
|
||||
box.read(BoxName.name).toString().split(' ')[0])
|
||||
.toString(),
|
||||
"last_name": EncryptionHelper.instance
|
||||
.decryptData(
|
||||
box.read(BoxName.name).toString().split(' ')[1])
|
||||
.toString(),
|
||||
"phone_number": EncryptionHelper.instance
|
||||
.decryptData(box.read(BoxName.phone)),
|
||||
});
|
||||
// var d = jsonDecode(res);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PaymentScreen(iframeUrl: res['message'])),
|
||||
);
|
||||
|
||||
if (response!.responseCode == 'APPROVED') {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'Payment Successful'.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
content: Text(
|
||||
'The payment was approved.'.tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
kolor: AppColor.greenColor,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
method();
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
// backgroundColor: AppColor.redColor,
|
||||
title: 'Payment Failed'.tr,
|
||||
content: Text(
|
||||
'The payment was not approved. Please try again.'.tr,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
kolor: AppColor.redColor,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Authentication failed, handle accordingly
|
||||
}
|
||||
} else {
|
||||
final PaymobResponse? response = await PaymobPayment.instance.pay(
|
||||
context: context,
|
||||
currency: currency, //"EGP",
|
||||
amountInCents: newAmount, // 19.00 EGP
|
||||
billingData: PaymobBillingData(),
|
||||
onPayment: (PaymobResponse response) {},
|
||||
);
|
||||
|
||||
if (response!.responseCode == 'APPROVED') {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'Payment Successful'.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
// backgroundColor: AppColor.greenColor,
|
||||
content: Text(
|
||||
'The payment was approved.'.tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
kolor: AppColor.greenColor,
|
||||
title: 'OK'.tr,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
method();
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
// backgroundColor: AppColor.redColor,
|
||||
title: 'Payment Failed'.tr,
|
||||
content: Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Get.find<TextToSpeechController>().speakText(
|
||||
'The payment was not approved. Please try again.'.tr,
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.headphones),
|
||||
),
|
||||
Text(
|
||||
'The payment was not approved. Please try again.'.tr,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
Text(
|
||||
'${'The reason is'.tr} ${response.message!.tr}',
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.title.copyWith(color: AppColor.redColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
kolor: AppColor.redColor,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Get.defaultDialog(
|
||||
@@ -683,7 +595,7 @@ class PaymentController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> payWithPayMobWallet(
|
||||
BuildContext context, String amount, currency, Function method) async {
|
||||
BuildContext context, String amount, currency) async {
|
||||
String newAmount = (double.parse(amount) * 100).toStringAsFixed(2);
|
||||
try {
|
||||
bool isAvailable = await LocalAuthentication().isDeviceSupported();
|
||||
@@ -693,130 +605,30 @@ class PaymentController extends GetxController {
|
||||
localizedReason: 'Use Touch ID or Face ID to confirm payment',
|
||||
);
|
||||
if (didAuthenticate) {
|
||||
final PaymobResponseWallet? response =
|
||||
await PaymobPaymentWallet.instance.pay(
|
||||
context: context,
|
||||
currency: currency, //"EGP",
|
||||
amountInCents: newAmount, // 19.00 EGP
|
||||
|
||||
billingData: PaymobBillingDataWallet(),
|
||||
onPayment: (PaymobResponseWallet response) {},
|
||||
var res = await CRUD().postWallet(
|
||||
link: AppLink.payWithPayMobWalletPasenger,
|
||||
// link: AppLink.payWithPayMobCardPassenger,
|
||||
payload: {
|
||||
"amount": newAmount,
|
||||
"email": box.read(BoxName.email),
|
||||
"first_name": EncryptionHelper.instance
|
||||
.decryptData(
|
||||
box.read(BoxName.name).toString().split(' ')[0])
|
||||
.toString(),
|
||||
"last_name": EncryptionHelper.instance
|
||||
.decryptData(
|
||||
box.read(BoxName.name).toString().split(' ')[1])
|
||||
.toString(),
|
||||
"phone_number": (box.read(BoxName.phoneWallet)),
|
||||
});
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PaymentScreen(iframeUrl: res['message'])),
|
||||
);
|
||||
// Log.print('response.message!: ${response!.responseCode!}');
|
||||
// if (response!.success == true && response.responseCode == '200') {
|
||||
|
||||
if (response!.success == true &&
|
||||
response!.message.toString() == 'Approved') {
|
||||
// Log.print('transactionID wewer: ${response.transactionID}');
|
||||
Toast.show(context, 'Payment Successful'.tr, AppColor.greenColor);
|
||||
method();
|
||||
// Get.defaultDialog(
|
||||
// barrierDismissible: false,
|
||||
// title: 'Payment Successful'.tr,
|
||||
// titleStyle: AppStyle.title,
|
||||
// content: Text(
|
||||
// 'The payment was approved.'.tr,
|
||||
// style: AppStyle.title,
|
||||
// ),
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'OK'.tr,
|
||||
// kolor: AppColor.greenColor,
|
||||
// onPressed: () async {
|
||||
// Get.back();
|
||||
// method();
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
// backgroundColor: AppColor.redColor,
|
||||
title: 'Payment Failed'.tr,
|
||||
content: Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Get.find<TextToSpeechController>().speakText(
|
||||
'The payment was not approved. Please try again.'.tr,
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.headphones),
|
||||
),
|
||||
Text(
|
||||
'The payment was not approved. Please try again.'.tr,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
Text(
|
||||
'${'The reason is'.tr} ${response.message!.tr}',
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.title.copyWith(color: AppColor.redColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
kolor: AppColor.redColor,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Authentication failed, handle accordingly
|
||||
}
|
||||
} else {
|
||||
final PaymobResponse? response = await PaymobPayment.instance.pay(
|
||||
context: context,
|
||||
currency: currency, //"EGP",
|
||||
amountInCents: newAmount, // 19.00 EGP
|
||||
billingData: PaymobBillingData(),
|
||||
onPayment: (PaymobResponse response) {},
|
||||
);
|
||||
if (response!.responseCode == '200' && response.success == true) {
|
||||
// if (response!.success == true && response.responseCode == '200') {
|
||||
// if (response!.responseCode == 'APPROVED') {
|
||||
Toast.show(context, 'Payment Successful'.tr, AppColor.greenColor);
|
||||
method();
|
||||
// Get.defaultDialog(
|
||||
// barrierDismissible: false,
|
||||
// title: 'Payment Successful'.tr,
|
||||
// titleStyle: AppStyle.title,
|
||||
// // backgroundColor: AppColor.greenColor,
|
||||
// content: Text(
|
||||
// 'The payment was approved.'.tr,
|
||||
// style: AppStyle.title,
|
||||
// ),
|
||||
// confirm: MyElevatedButton(
|
||||
// kolor: AppColor.greenColor,
|
||||
// title: 'OK'.tr,
|
||||
// onPressed: () async {
|
||||
// Get.back();
|
||||
// method();
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
// backgroundColor: AppColor.redColor,
|
||||
title: 'Payment Failed'.tr,
|
||||
content: Text(
|
||||
'The payment was not approved. Please try again.'.tr,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
kolor: AppColor.redColor,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
// }
|
||||
}
|
||||
} catch (e) {
|
||||
Get.defaultDialog(
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:Tripz/constant/box_name.dart';
|
||||
import 'package:Tripz/constant/links.dart';
|
||||
import 'package:Tripz/controller/functions/crud.dart';
|
||||
import 'package:Tripz/main.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../../../print.dart';
|
||||
import '../../functions/encrypt_decrypt.dart';
|
||||
|
||||
class PaymobResponse {
|
||||
@@ -242,7 +248,7 @@ class PaymobBillingData {
|
||||
"city": city ?? "NA",
|
||||
"state": state ?? "NA",
|
||||
"country": country ?? "NA",
|
||||
"shipping_method": shippingMethod ?? "NA",
|
||||
"shipping_method": box.read(BoxName.passengerID) ?? "NA",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -330,3 +336,157 @@ class _PaymobIFrameState extends State<PaymobIFrame> {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class PaymentScreen extends StatefulWidget {
|
||||
final String iframeUrl;
|
||||
|
||||
const PaymentScreen({required this.iframeUrl, Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<PaymentScreen> createState() => _PaymentScreenState();
|
||||
}
|
||||
|
||||
class _PaymentScreenState extends State<PaymentScreen> {
|
||||
late final WebViewController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setNavigationDelegate(NavigationDelegate(
|
||||
onPageFinished: (url) {
|
||||
Log.print('url onPageFinished : ${url}');
|
||||
if (url.contains("success")) {
|
||||
_fetchPaymentStatus(); // ✅ استدعاء الويب هوك بعد نجاح الدفع
|
||||
} else if (url.contains("failed")) {
|
||||
showCustomDialog(
|
||||
title: "Error".tr,
|
||||
message: 'Payment Failed'.tr, // يتم جلب رسالة الخطأ من الخادم
|
||||
isSuccess: false,
|
||||
);
|
||||
}
|
||||
},
|
||||
))
|
||||
..loadRequest(Uri.parse(widget.iframeUrl));
|
||||
}
|
||||
|
||||
// ✅ استدعاء الويب هوك بعد انتهاء الدفع
|
||||
Future<void> _fetchPaymentStatus() async {
|
||||
final String userId = EncryptionHelper.instance
|
||||
.decryptData(box.read(BoxName.phoneWallet)); // ضع user_id الحقيقي
|
||||
final String apiUrl = AppLink.paymetVerifyPassenger;
|
||||
|
||||
try {
|
||||
final response = await CRUD().getWallet(link: apiUrl, payload: {
|
||||
'user_id': userId,
|
||||
'passengerId': box.read(BoxName.passengerID),
|
||||
'paymentMethod': 'visa-in',
|
||||
});
|
||||
|
||||
if (response != 'failure' && response != 'token_expired') {
|
||||
try {
|
||||
final jsonData = jsonDecode(response);
|
||||
|
||||
if (jsonData['status'] == 'success') {
|
||||
// تأكد أن 'message' هو String وليس Map
|
||||
// final message = jsonData['message'];
|
||||
showCustomDialog(
|
||||
title: "Payment Status",
|
||||
message: jsonData['message'], // يتم جلب الرسالة من الخادم
|
||||
isSuccess: true,
|
||||
);
|
||||
} else {
|
||||
showCustomDialog(
|
||||
title: "Error",
|
||||
message: jsonData['message'], // يتم جلب رسالة الخطأ من الخادم
|
||||
isSuccess: false,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
showCustomDialog(
|
||||
title: "Error",
|
||||
message: response, // يتم جلب رسالة الخطأ من الخادم
|
||||
isSuccess: false,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
showCustomDialog(
|
||||
title: "Error".tr,
|
||||
message: response, // يتم جلب رسالة الخطأ من الخادم
|
||||
isSuccess: false,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
showCustomDialog(
|
||||
title: "Error".tr,
|
||||
message: 'Server error'.tr, // يتم جلب رسالة الخطأ من الخادم
|
||||
isSuccess: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void showCustomDialog({
|
||||
required String title,
|
||||
required String message,
|
||||
required bool isSuccess,
|
||||
}) {
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: Get.context!,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(
|
||||
isSuccess ? Icons.check_circle : Icons.error,
|
||||
color: isSuccess ? Colors.green : Colors.red,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: isSuccess ? Colors.green : Colors.red,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: Text(
|
||||
message,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: isSuccess ? Colors.green : Colors.red,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
"OK",
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('إتمام الدفع')),
|
||||
body: WebViewWidget(controller: _controller),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,22 +83,6 @@ void main() async {
|
||||
]);
|
||||
}
|
||||
|
||||
String? key = (await storage.read(key: BoxName.payMobApikey));
|
||||
|
||||
String? apiKey = EncryptionHelper.instance.decryptData(key!);
|
||||
PaymobPayment.instance.initialize(
|
||||
apiKey: apiKey,
|
||||
integrationID: int.parse(AK.integrationIdPayMob),
|
||||
userTokenExpiration: 200,
|
||||
iFrameID: 837992,
|
||||
);
|
||||
|
||||
PaymobPaymentWallet.instance.initialize(
|
||||
apiKey: apiKey,
|
||||
integrationID: int.parse(AK.integrationIdPayMobWallet),
|
||||
userTokenExpiration: 200,
|
||||
iFrameID: 837992,
|
||||
);
|
||||
await notificationController.initNotifications();
|
||||
|
||||
// Generate a random index to pick a message
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:Tripz/constant/char_map.dart';
|
||||
import 'package:Tripz/controller/functions/crud.dart';
|
||||
import 'package:Tripz/controller/functions/encrypt_decrypt.dart';
|
||||
import 'package:Tripz/env/env.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -15,13 +13,11 @@ import 'package:Tripz/constant/colors.dart';
|
||||
import 'package:Tripz/constant/style.dart';
|
||||
import 'package:Tripz/main.dart';
|
||||
import 'package:Tripz/views/widgets/my_scafold.dart';
|
||||
import 'package:secure_string_operations/secure_string_operations.dart';
|
||||
|
||||
import '../../constant/info.dart';
|
||||
import '../../controller/auth/apple_signin_controller.dart';
|
||||
import '../../controller/auth/google_sign.dart';
|
||||
import '../../controller/auth/login_controller.dart';
|
||||
import '../../print.dart';
|
||||
import '../home/HomePage/contact_us.dart';
|
||||
import '../home/profile/passenger_profile_page.dart';
|
||||
|
||||
@@ -334,7 +330,8 @@ class LoginPage extends StatelessWidget {
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () async => await controller.getLocationPermission(),
|
||||
child: Text('Allow Location Access'.tr),
|
||||
child: Text('Next'.tr),
|
||||
// child: Text('Allow Location Access'.tr),
|
||||
),
|
||||
// TextButton(
|
||||
// onPressed: () => openAppSettings(),
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:Tripz/constant/links.dart';
|
||||
import 'package:Tripz/controller/auth/login_controller.dart';
|
||||
import 'package:Tripz/controller/functions/crud.dart';
|
||||
import 'package:Tripz/controller/functions/sms_controller.dart';
|
||||
import 'package:Tripz/views/widgets/error_snakbar.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:Tripz/constant/box_name.dart';
|
||||
import 'package:Tripz/main.dart';
|
||||
@@ -5,13 +12,17 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_font_icons/flutter_font_icons.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:jwt_decoder/jwt_decoder.dart';
|
||||
import 'package:secure_string_operations/secure_string_operations.dart';
|
||||
import '../../../constant/char_map.dart';
|
||||
import '../../../constant/colors.dart';
|
||||
import '../../../controller/auth/login_controller.dart';
|
||||
import '../../../constant/info.dart';
|
||||
import '../../../controller/functions/encrypt_decrypt.dart';
|
||||
import '../../../controller/functions/package_info.dart';
|
||||
import '../../../controller/functions/tts.dart';
|
||||
import '../../../controller/home/map_passenger_controller.dart';
|
||||
import '../../../controller/home/vip_waitting_page.dart';
|
||||
import '../../../controller/payment/paymob/paymob_response.dart';
|
||||
import '../../../print.dart';
|
||||
|
||||
GetBuilder<MapPassengerController> leftMainMenuIcons() {
|
||||
Get.put(TextToSpeechController());
|
||||
@@ -59,15 +70,15 @@ GetBuilder<MapPassengerController> leftMainMenuIcons() {
|
||||
onPressed: () => Get.to(() => VipWaittingPage()),
|
||||
tooltip: 'VIP Waiting Page', // More descriptive tooltip
|
||||
),
|
||||
// const SizedBox(width: 8),
|
||||
// _buildIconButtonWithAnimation(
|
||||
// controller: controller,
|
||||
// icon: Octicons.screen_full,
|
||||
// onPressed: () async {
|
||||
// Get.to(() => TestPage());
|
||||
// },
|
||||
// tooltip: 'Recent Locations', // More descriptive tooltip
|
||||
// ),
|
||||
const SizedBox(width: 8),
|
||||
_buildIconButtonWithAnimation(
|
||||
controller: controller,
|
||||
icon: Octicons.screen_full,
|
||||
onPressed: () async {
|
||||
Get.to(() => TestPage());
|
||||
},
|
||||
tooltip: 'Recent Locations', // More descriptive tooltip
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -86,11 +97,34 @@ class TestPage extends StatelessWidget {
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
// await DeviceHelper.getDeviceFingerprint();
|
||||
// await SecurityHelper.performSecurityChecks();
|
||||
LoginController().getJwtWallet();
|
||||
// addFingerPrint() async {
|
||||
// bool isTokenExpired = JwtDecoder.isExpired(X
|
||||
// .r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
|
||||
// .toString()
|
||||
// .split(AppInformation.addd)[0]);
|
||||
|
||||
// if (isTokenExpired) {
|
||||
// Log.print(
|
||||
// 'isTokenExpired loginUsingCredentials: ${isTokenExpired}');
|
||||
// await LoginController().getJWT();
|
||||
// }
|
||||
|
||||
// var res = await CRUD().get(
|
||||
// link: 'https://server.sefer.click/sefer.click/sefer/test.php',
|
||||
// payload: {
|
||||
// 'email': box.read(BoxName.email).toString(),
|
||||
// 'id': box.read(BoxName.passengerID).toString(),
|
||||
// "platform": Platform.isAndroid ? 'android' : 'ios',
|
||||
// "appName": AppInformation.appName,
|
||||
// });
|
||||
// Log.print('res: ${res}');
|
||||
// var s = EncryptionHelper.instance.encryptData('Female');
|
||||
Log.print('s: ${box.read(BoxName.hmac)}');
|
||||
},
|
||||
|
||||
// uDG41L0K5vrem0eh87ZAf9leTrDUW0+twVRHQIQtxOWn4L6J5seU9x1tnRUUbGBb
|
||||
|
||||
// uDG41L0K5vrem0eh87ZAf9leTrDUW0+twVRHQIQtxOU=
|
||||
|
||||
child: Text(
|
||||
"Text Button",
|
||||
),
|
||||
|
||||
@@ -243,18 +243,17 @@ void showPaymentOptions(BuildContext context, PaymentController controller) {
|
||||
box.read(BoxName.countryCode) == 'Egypt'
|
||||
? CupertinoActionSheetAction(
|
||||
child: Text('💳 Pay with Credit Card'.tr),
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
if (controller.selectedAmount != 0) {
|
||||
controller.payWithPayMob(
|
||||
context,
|
||||
controller.selectedAmount.toString(),
|
||||
box.read(BoxName.countryCode) == 'Egypt' ? 'EGP' : 'JOD',
|
||||
() async {
|
||||
await controller.addPassengerWallet();
|
||||
controller.changePromoSheetDialogue();
|
||||
await controller.getPassengerWallet();
|
||||
},
|
||||
// () async {
|
||||
// await controller.addPassengerWallet();
|
||||
// controller.changePromoSheetDialogue();
|
||||
);
|
||||
await controller.getPassengerWallet();
|
||||
} else {
|
||||
Toast.show(context, '⚠️ You need to choose an amount!'.tr,
|
||||
AppColor.redColor);
|
||||
@@ -278,7 +277,7 @@ void showPaymentOptions(BuildContext context, PaymentController controller) {
|
||||
box.read(BoxName.phoneWallet) != null
|
||||
? CupertinoActionSheetAction(
|
||||
child: Text('💰 Pay with Wallet'.tr),
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
if (controller.selectedAmount != 0) {
|
||||
controller.isLoading = true;
|
||||
controller.update();
|
||||
@@ -286,12 +285,8 @@ void showPaymentOptions(BuildContext context, PaymentController controller) {
|
||||
context,
|
||||
controller.selectedAmount.toString(),
|
||||
box.read(BoxName.countryCode) == 'Egypt' ? 'EGP' : 'JOD',
|
||||
() async {
|
||||
await controller.addPassengerWallet();
|
||||
controller.changePromoSheetDialogue();
|
||||
await controller.getPassengerWallet();
|
||||
},
|
||||
);
|
||||
await controller.getPassengerWallet();
|
||||
controller.isLoading = false;
|
||||
controller.update();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user