diff --git a/lib/controller/local/translations.dart b/lib/controller/local/translations.dart index 3bacb12..3861358 100644 --- a/lib/controller/local/translations.dart +++ b/lib/controller/local/translations.dart @@ -517,6 +517,14 @@ class MyTranslation extends Translations { 'اربح 300 جنيه ! كل 300 نقطة تمنحك 300 جنيه. اذهب واستفد من نقاطك!', 'the 300 points equal 300 L.E': 'الـ 300 نقطة تساوي 30 جنيه بالنسبة لك ', + 'The payment was not approved. Please try again.': + 'لم يتم الموافقة على الدفع. الرجاء المحاولة مرة أخرى.', + 'Payment Failed': 'فشل الدفع', + 'Error': 'خطأ', + 'An error occurred during the payment process.': + 'حدث خطأ أثناء عملية الدفع.', + 'The payment was approved.': 'تمت الموافقة على الدفع.', + 'Payment Successful': 'نجح الدفع', 'No ride found yet': '‏لا يوجد طلبات متوفرة حاليا', 'Accept Order': "‏اقبل الطلب", 'reject your order.': "رفض طلبك.", @@ -609,7 +617,7 @@ class MyTranslation extends Translations { 'insert amount': "إدراج المبلغ", 'You can buy Points to let you online\nby this list below': "يمكنك شراء النقاط للبقاء على وضع الاتصال\nمن خلال القائمة أدناه", - 'Create Wallet to recive your money': "إنشاء محفظة لاستلام أموالك", + 'Create Wallet to receive your money': "إنشاء محفظة لاستلام أموالك", 'Enter your feedback here': "أدخل تعليقاتك هنا", 'Please enter your feedback.': "الرجاء إدخال تعليقاتك.", 'Feedback': "تعليق", diff --git a/lib/controller/payment/passenger_wallet_history_controller.dart b/lib/controller/payment/passenger_wallet_history_controller.dart index 12d9454..ccdbda1 100644 --- a/lib/controller/payment/passenger_wallet_history_controller.dart +++ b/lib/controller/payment/passenger_wallet_history_controller.dart @@ -23,18 +23,19 @@ class PassengerWalletHistoryController extends GetxController { print(archive); isLoading = false; update(); - } else {} - Get.defaultDialog( - barrierDismissible: false, - title: 'No wallet record found'.tr, - titleStyle: AppStyle.title, - middleText: '', - confirm: MyElevatedButton( - title: 'OK'.tr, - onPressed: () { - Get.back(); - Get.back(); - })); + } else { + Get.defaultDialog( + barrierDismissible: false, + title: 'No wallet record found'.tr, + titleStyle: AppStyle.title, + middleText: '', + confirm: MyElevatedButton( + title: 'OK'.tr, + onPressed: () { + Get.back(); + Get.back(); + })); + } } @override diff --git a/lib/controller/payment/payment_controller.dart b/lib/controller/payment/payment_controller.dart index e3abb2a..c5bf497 100644 --- a/lib/controller/payment/payment_controller.dart +++ b/lib/controller/payment/payment_controller.dart @@ -1,5 +1,7 @@ import 'dart:convert'; import 'package:SEFER/constant/api_key.dart'; +import 'package:SEFER/constant/style.dart'; +import 'package:SEFER/views/widgets/elevated_btn.dart'; import 'package:http/http.dart' as http; import 'package:flutter/material.dart'; import 'package:flutter_paypal/flutter_paypal.dart'; @@ -260,7 +262,9 @@ class PaymentController extends GetxController { "amount": { //sb-opsju26682403@personal.example.com "total": '$selectedAmount', - "currency": "USD", + "currency": box.read(BoxName.countryCode) == 'Egypt' + ? 'EGP' + : "JOD", "details": { "subtotal": '$selectedAmount', "shipping": '0', @@ -459,36 +463,125 @@ class PaymentController extends GetxController { } Future payWithPayMob( - BuildContext context, String amount, currency) async { + BuildContext context, String amount, currency, Function method) async { + String newAmount = (double.parse(amount) * 100).toStringAsFixed(2); try { - final PaymobResponse? response = await PaymobPayment.instance.pay( - context: context, - currency: currency, //"EGP", - amountInCents: amount, // 19.00 EGP - onPayment: (PaymobResponse response) { - print('Success: ${response.success}'); - print('Transaction ID: ${response.transactionID}'); - print('Response Code: ${response.responseCode}'); - // print('Message: ${response.message}'); - }, - ); + bool isAvailable = await LocalAuthentication().isDeviceSupported(); + if (isAvailable) { + // Authenticate the user + bool didAuthenticate = await LocalAuthentication().authenticate( + 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 + onPayment: (PaymobResponse response) { + print('Success: ${response.success}'); + print('Transaction ID: ${response.transactionID}'); + print('Response Code: ${response.responseCode}'); + // print('Message: ${response.message}'); + }, + ); - if (response!.responseCode == 'APPROVED') { - Get.defaultDialog( - title: 'Payment Successful', - content: const Text('The payment was approved.'), - ); + 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, + 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 + print('Authentication failed'); + } } else { - Get.defaultDialog( - title: 'Payment Failed', - content: - const Text('The payment was not approved. Please try again.'), + final PaymobResponse? response = await PaymobPayment.instance.pay( + context: context, + currency: currency, //"EGP", + amountInCents: newAmount, // 19.00 EGP + onPayment: (PaymobResponse response) { + // print('Success: ${response.success}'); + // print('Transaction ID: ${response.transactionID}'); + // print('Response Code: ${response.responseCode}'); + // print('Message: ${response.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, + 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( - title: 'Error', - content: const Text('An error occurred during the payment process.'), + title: 'Error'.tr, + content: Text( + 'An error occurred during the payment process.'.tr, + style: AppStyle.title, + ), ); rethrow; } diff --git a/lib/views/home/map_widget.dart/left_main_menu_icons.dart b/lib/views/home/map_widget.dart/left_main_menu_icons.dart index d95434e..a9272e0 100644 --- a/lib/views/home/map_widget.dart/left_main_menu_icons.dart +++ b/lib/views/home/map_widget.dart/left_main_menu_icons.dart @@ -114,8 +114,8 @@ GetBuilder leftMainMenuIcons() { child: IconButton( onPressed: () async { // await PaymobManager().payWithPayMob(100, 'EGP'); - await Get.find() - .payWithPayMob(context, '11', 'EGP'); + // await Get.find() + // .payWithPayMob(context, '1100', 'EGP'); // Initiates a payment with a card using the FlutterPaymob instance // NotificationController() @@ -150,8 +150,8 @@ class PaymobPackage extends StatelessWidget { Widget build(BuildContext context) { return InkWell( onTap: () async { - await Get.find() - .payWithPayMob(context, '11', 'EGP'); + // await Get.find() + // .payWithPayMob(context, '11', 'EGP'); }, child: Container( width: 50, diff --git a/lib/views/home/my_wallet/passenger_wallet_dialoge.dart b/lib/views/home/my_wallet/passenger_wallet_dialoge.dart index 9cb6547..0a92d35 100644 --- a/lib/views/home/my_wallet/passenger_wallet_dialoge.dart +++ b/lib/views/home/my_wallet/passenger_wallet_dialoge.dart @@ -53,14 +53,18 @@ class PassengerWalletDialoge extends StatelessWidget { child: Row( children: [ Radio( - value: 10, + value: box.read(BoxName.countryCode) == 'Egypt' + ? 100 + : 10, groupValue: controller.selectedAmount, onChanged: (value) { controller.updateSelectedAmount(value as int); }, ), Text( - '10\$ and get 3% discount'.tr, + box.read(BoxName.countryCode) == 'Egypt' + ? '100 ${'LE'.tr}'.tr + : '10\$ and get 3% discount', style: AppStyle.title, ), ], @@ -73,7 +77,10 @@ class PassengerWalletDialoge extends StatelessWidget { child: Row( children: [ Radio( - value: 20, + value: + box.read(BoxName.countryCode) == 'Egypt' + ? 200 + : 20, groupValue: controller.selectedAmount, onChanged: (value) { controller @@ -81,7 +88,9 @@ class PassengerWalletDialoge extends StatelessWidget { }, ), Text( - '20\$ and get 4% discount'.tr, + box.read(BoxName.countryCode) == 'Egypt' + ? '200 ${'LE'.tr} '.tr + : '20 ${'JOD'.tr}'.tr, style: AppStyle.title, ), ], @@ -93,7 +102,10 @@ class PassengerWalletDialoge extends StatelessWidget { child: Row( children: [ Radio( - value: 40, + value: + box.read(BoxName.countryCode) == 'Egypt' + ? 400 + : 40, groupValue: controller.selectedAmount, onChanged: (value) { controller @@ -101,7 +113,9 @@ class PassengerWalletDialoge extends StatelessWidget { }, ), Text( - '40\$ and get 6% discount'.tr, + box.read(BoxName.countryCode) == 'Egypt' + ? '400 ${'LE'.tr} '.tr + : '40 ${'JOD'.tr}'.tr, style: AppStyle.title, ), ], @@ -113,7 +127,10 @@ class PassengerWalletDialoge extends StatelessWidget { child: Row( children: [ Radio( - value: 100, + value: + box.read(BoxName.countryCode) == 'Egypt' + ? 1000 + : 50, groupValue: controller.selectedAmount, onChanged: (value) { controller @@ -121,7 +138,9 @@ class PassengerWalletDialoge extends StatelessWidget { }, ), Text( - '100\$ and get 9% discount'.tr, + box.read(BoxName.countryCode) == 'Egypt' + ? '1000 ${'LE'.tr} '.tr + : '50 ${'JOD'.tr}'.tr, style: AppStyle.title, ), ], @@ -141,27 +160,50 @@ class PassengerWalletDialoge extends StatelessWidget { } }, ), - MyElevatedButton( - title: 'Pay with Credit Card'.tr, - onPressed: () { - if (controller.selectedAmount != 0) { - controller.makePaymentStripe( - controller.selectedAmount! - .toDouble(), // Convert int to double - box.read(BoxName.countryCode) != 'Egypt'.tr - ? 'EGP' - : 'USD', () { - controller.addPassengerWallet(); - controller.changePromoSheetDialogue(); - controller.getPassengerWallet(); - }); - } else { - Toast.show( - context, - 'You will choose one of above !'.tr, - AppColor.redColor); - } - }), + box.read(BoxName.countryCode) == 'Egypt' + ? MyElevatedButton( + title: 'Pay with Credit Card'.tr, + onPressed: () { + if (controller.selectedAmount != 0) { + controller.payWithPayMob( + context, + controller.selectedAmount + .toString(), // Convert int to double + box.read(BoxName.countryCode) == 'Egypt' + ? 'EGP' + : 'JOD', () async { + await controller.addPassengerWallet(); + controller.changePromoSheetDialogue(); + await controller.getPassengerWallet(); + }); + } else { + Toast.show( + context, + 'You will choose one of above !'.tr, + AppColor.redColor); + } + }) + : MyElevatedButton( + title: 'Pay with Credit Card'.tr, + onPressed: () { + if (controller.selectedAmount != 0) { + controller.makePaymentStripe( + controller.selectedAmount! + .toDouble(), // Convert int to double + box.read(BoxName.countryCode) != 'Egypt' + ? 'EGP' + : 'USD', () { + controller.addPassengerWallet(); + controller.changePromoSheetDialogue(); + controller.getPassengerWallet(); + }); + } else { + Toast.show( + context, + 'You will choose one of above !'.tr, + AppColor.redColor); + } + }), MyElevatedButton( title: 'Cancel'.tr, kolor: AppColor.redColor, diff --git a/lib/views/home/my_wallet/points_captain.dart b/lib/views/home/my_wallet/points_captain.dart index 7bc5a1d..f78054d 100644 --- a/lib/views/home/my_wallet/points_captain.dart +++ b/lib/views/home/my_wallet/points_captain.dart @@ -27,13 +27,27 @@ class PointsCaptain extends StatelessWidget { Widget build(BuildContext context) { return InkWell( onTap: () async { - await paymentController.makePaymentStripe(pricePoint, - box.read(BoxName.countryCode) == 'Jordan' ? 'jod' : 'egp', - () async { - await captainWalletController.addDriverPayment('visa', pricePoint); - await captainWalletController.addDriverWallet('visa', countPoint); - await captainWalletController.getCaptainWalletFromBuyPoints(); - }); + box.read(BoxName.countryCode) == 'Egypt' + ? await paymentController.payWithPayMob( + context, + pricePoint.toStringAsFixed(2), + box.read(BoxName.countryCode) == 'Egypt' ? 'EGP' : 'JOD', + () async { + await captainWalletController.addDriverPayment( + 'visa', pricePoint); + await captainWalletController.addDriverWallet( + 'visa', countPoint); + await captainWalletController.getCaptainWalletFromBuyPoints(); + }) + : await paymentController.makePaymentStripe(pricePoint, + box.read(BoxName.countryCode) == 'Jordan' ? 'jod' : 'egp', + () async { + await captainWalletController.addDriverPayment( + 'visa', pricePoint); + await captainWalletController.addDriverWallet( + 'visa', countPoint); + await captainWalletController.getCaptainWalletFromBuyPoints(); + }); }, child: Container( width: Get.width * .22, diff --git a/lib/views/home/my_wallet/walet_captain.dart b/lib/views/home/my_wallet/walet_captain.dart index 58b94d8..12070ad 100644 --- a/lib/views/home/my_wallet/walet_captain.dart +++ b/lib/views/home/my_wallet/walet_captain.dart @@ -350,7 +350,7 @@ class WalletCaptain extends StatelessWidget { children: [ MyElevatedButton( title: - 'Create Wallet to recive your money', + 'Create Wallet to receive your money', onPressed: () async { PaymentController paymentController = Get.find();