25-4-29/1
This commit is contained in:
@@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user