diff --git a/lib/config/config.dart b/lib/config/config.dart index b2f42ad7..b09dce5b 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -67,6 +67,9 @@ const CHECK_PAYMENT_STATUS = "/PayFort_Serv.svc/REST/GetRequestStatusByRequestID //URL create advance payment const CREATE_ADVANCE_PAYMENT = "/Doctors.svc/REST/CreateAdvancePayment"; + +const ADD_ADVANCE_NUMBER_REQUEST = '/PayFort_Serv.svc/REST/AddAdvancedNumberRequest'; + //URL to get medicine and pharmacies list const CHANNEL = 3; const GENERAL_ID = 'Cs2020@2016\$2958'; diff --git a/lib/pages/BookAppointment/BookSuccess.dart b/lib/pages/BookAppointment/BookSuccess.dart index 42d46956..cdad398f 100644 --- a/lib/pages/BookAppointment/BookSuccess.dart +++ b/lib/pages/BookAppointment/BookSuccess.dart @@ -1,8 +1,16 @@ +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart'; import 'package:diplomaticquarterapp/models/Appointments/PatientShareResposne.dart'; +import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; +import 'package:diplomaticquarterapp/pages/ToDoList/payment_method_select.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:diplomaticquarterapp/widgets/in_app_browser/InAppBrowser.dart'; import 'package:flutter/material.dart'; import 'QRCode.dart'; @@ -11,6 +19,8 @@ class BookSuccess extends StatefulWidget { PatientShareResponse patientShareResponse; DoctorList docObject; + MyInAppBrowser browser; + String appoDateFormatted; String appoTimeFormatted; @@ -25,6 +35,9 @@ class BookSuccess extends StatefulWidget { } class _BookSuccessState extends State { + AppSharedPreferences sharedPref = AppSharedPreferences(); + AuthenticatedUser authUser; + @override void initState() { // TODO: implement initState @@ -34,12 +47,6 @@ class _BookSuccessState extends State { @override Widget build(BuildContext context) { return Scaffold( -// appBar: AppBar( -// title: Text("Book Success"), -// bottomOpacity: 0.0, -// elevation: 0.0, -// backgroundColor: new Color(0xFF20bc44), -// ), body: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -320,12 +327,15 @@ class _BookSuccessState extends State { margin: EdgeInsets.only(top: 20.0, bottom: 0.0), alignment: Alignment.center, child: Text(TranslationBase.of(context).payNowBookSuccess, - style: TextStyle(fontSize: 20.0, letterSpacing: 0.8, fontWeight: FontWeight.bold)), + style: TextStyle( + fontSize: 20.0, + letterSpacing: 0.8, + fontWeight: FontWeight.bold)), ), Container( alignment: Alignment.center, - child: Image.asset("assets/images/new-design/no-wait-queue.png", width: 120.0, - height: 120.0), + child: Image.asset("assets/images/new-design/no-wait-queue.png", + width: 120.0, height: 120.0), ), Flex( direction: Axis.horizontal, @@ -396,7 +406,9 @@ class _BookSuccessState extends State { textColor: Colors.white, disabledTextColor: Colors.white, disabledColor: new Color(0xFFbcc2c4), - onPressed: () {}, + onPressed: () { + startPaymentProcess(); + }, child: Text(TranslationBase.of(context).payNow.toUpperCase(), style: TextStyle(fontSize: 18.0)), ), @@ -427,6 +439,154 @@ class _BookSuccessState extends State { ); } + startPaymentProcess() { + navigateToPaymentMethod(context, widget.patientShareResponse); + } + + Future navigateToPaymentMethod( + context, PatientShareResponse patientShareResponse) async { + if (await this.sharedPref.getObject(USER_PROFILE) != null) { + var data = AuthenticatedUser.fromJson( + await this.sharedPref.getObject(USER_PROFILE)); + setState(() { + authUser = data; + }); + } + + AppoitmentAllHistoryResultList appo = new AppoitmentAllHistoryResultList(); + appo.projectID = widget.patientShareResponse.projectID; + appo.clinicID = widget.patientShareResponse.clinicID; + appo.appointmentNo = widget.patientShareResponse.appointmentNo; + + Navigator.push( + context, MaterialPageRoute(builder: (context) => PaymentMethod())) + .then((value) { + print(value); + if (value != null) { + openPayment( + value, + authUser, + double.parse(patientShareResponse.patientShareWithTax.toString()), + patientShareResponse, + appo); + } + }); + } + + openPayment( + String paymentMethod, + AuthenticatedUser authenticatedUser, + double amount, + PatientShareResponse patientShareResponse, + AppoitmentAllHistoryResultList appo) { + widget.browser = new MyInAppBrowser( + onExitCallback: onBrowserExit, + appo: appo, + onLoadStartCallback: onBrowserLoadStart); + + widget.browser.openPaymentBrowser( + amount, + "Appointment check in", + Utils.getAppointmentTransID( + appo.projectID, appo.clinicID, appo.appointmentNo), + appo.projectID.toString(), + authenticatedUser.emailAddress, + paymentMethod, + authenticatedUser, + widget.browser); + } + + onBrowserLoadStart(String url) { + print("onBrowserLoadStart"); + print(url); + + MyInAppBrowser.successURLS.forEach((element) { + if (url.contains(element)) { + if (widget.browser.isOpened()) widget.browser.close(); + MyInAppBrowser.isPaymentDone = true; + Utils.hideProgressDialog(); + return; + } + }); + + MyInAppBrowser.errorURLS.forEach((element) { + if (url.contains(element)) { + if (widget.browser.isOpened()) widget.browser.close(); + MyInAppBrowser.isPaymentDone = false; + Utils.hideProgressDialog(); + return; + } + }); + } + + onBrowserExit(AppoitmentAllHistoryResultList appo, bool isPaymentMade) { + print("onBrowserExit Called!!!!"); + if (isPaymentMade) checkPaymentStatus(appo); + } + + checkPaymentStatus(AppoitmentAllHistoryResultList appo) { + DoctorsListService service = new DoctorsListService(); + service + .checkPaymentStatus( + Utils.getAppointmentTransID( + appo.projectID, appo.clinicID, appo.appointmentNo), + context) + .then((res) { + print("Printing Payment Status Reponse!!!!"); + print(res); + String paymentInfo = res['Response_Message']; + if (paymentInfo == 'Success') { + createAdvancePayment(res, appo); + } else { + AppToast.showErrorToast(message: res['Response_Message']); + } + }).catchError((err) { + print(err); + }); + } + + createAdvancePayment(res, AppoitmentAllHistoryResultList appo) { + DoctorsListService service = new DoctorsListService(); + String paymentReference = res['Fort_id'].toString(); + service + .createAdvancePayment( + appo, res['Amount'], res['Fort_id'], res['PaymentMethod'], context) + .then((res) { + print(res['OnlineCheckInAppointments'][0]['AdvanceNumber']); + addAdvancedNumberRequest( + res['OnlineCheckInAppointments'][0]['AdvanceNumber'].toString(), + paymentReference, + appo.appointmentNo.toString()); + }).catchError((err) { + print(err); + }); + } +// +// Future navigateToQR( +// context, String appoQR, PatientShareResponse patientShareResponse) async { +// Navigator.push( +// context, +// MaterialPageRoute( +// builder: (context) => QRCode( +// patientShareResponse: patientShareResponse, +// appoQR: appoQR, +// ))).then((value) {}); +// } + + addAdvancedNumberRequest(String advanceNumber, String paymentReference, + String appointmentID) { + DoctorsListService service = new DoctorsListService(); + service + .addAdvancedNumberRequest( + advanceNumber, paymentReference, appointmentID, context) + .then((res) { + print(res); + getAppoQR(context); + }).catchError((err) { + print(err); + }); + } + Widget _getQRAppo() { return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -440,8 +600,8 @@ class _BookSuccessState extends State { ), Container( alignment: Alignment.center, - child: Image.asset("assets/images/new-design/device_icon.png", width: 120.0, - height: 120.0), + child: Image.asset("assets/images/new-design/device_icon.png", + width: 120.0, height: 120.0), ), Flex( direction: Axis.horizontal, diff --git a/lib/pages/MyAppointments/AppointmentDetails.dart b/lib/pages/MyAppointments/AppointmentDetails.dart index fff6d383..281a8aa8 100644 --- a/lib/pages/MyAppointments/AppointmentDetails.dart +++ b/lib/pages/MyAppointments/AppointmentDetails.dart @@ -93,6 +93,7 @@ class _AppointmentDetailsState extends State widget.appo.doctorTitle + " " + widget.appo.doctorNameObj, + textAlign: TextAlign.center, style: TextStyle( fontSize: 20.0, color: Colors.grey[900], diff --git a/lib/pages/MyAppointments/MyAppointments.dart b/lib/pages/MyAppointments/MyAppointments.dart index 122222b2..acd6fba9 100644 --- a/lib/pages/MyAppointments/MyAppointments.dart +++ b/lib/pages/MyAppointments/MyAppointments.dart @@ -127,15 +127,9 @@ class _MyAppointmentsState extends State openAppointmentsTab() { if (widget.bookedAppoList.length != 0) { _tabController.animateTo((_tabController.index + 1) % 1); - return; - } - - if (widget.confirmedAppoList.length != 0) { + } else if (widget.confirmedAppoList.length != 0) { _tabController.animateTo((_tabController.index + 1) % 2); - return; - } - - if (widget.arrivedAppoList.length != 0) { + } else if (widget.arrivedAppoList.length != 0) { _tabController.animateTo((_tabController.index + 1) % 3); return; } diff --git a/lib/pages/MyAppointments/widgets/AppointmentActions.dart b/lib/pages/MyAppointments/widgets/AppointmentActions.dart index f0ff2e6f..1641776d 100644 --- a/lib/pages/MyAppointments/widgets/AppointmentActions.dart +++ b/lib/pages/MyAppointments/widgets/AppointmentActions.dart @@ -95,7 +95,7 @@ class _AppointmentActionsState extends State { Container( alignment: Alignment.bottomRight, margin: - EdgeInsets.fromLTRB(0.0, 10.0, 10.0, 8.0), + EdgeInsets.fromLTRB(0.0, 10.0, 10.0, 7.0), child: Image.asset(e.icon, width: 45.0, height: 45.0), ), @@ -308,6 +308,7 @@ class _AppointmentActionsState extends State { print(res); if (res['MessageStatus'] == 1) { AppToast.showSuccessToast(message: res['ErrorEndUserMessage']); + Navigator.of(context).pop(); } else { AppToast.showErrorToast(message: res['ErrorEndUserMessage']); } diff --git a/lib/pages/MyAppointments/widgets/AppointmentCardView.dart b/lib/pages/MyAppointments/widgets/AppointmentCardView.dart index e038c0af..e2f6f706 100644 --- a/lib/pages/MyAppointments/widgets/AppointmentCardView.dart +++ b/lib/pages/MyAppointments/widgets/AppointmentCardView.dart @@ -42,7 +42,7 @@ class _ApointmentCardState extends State { fit: BoxFit.fill, height: 60.0, width: 60.0), ), Container( - width: MediaQuery.of(context).size.width * 0.666, + width: MediaQuery.of(context).size.width * 0.6, margin: EdgeInsets.fromLTRB(20.0, 10.0, 10.0, 0.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/pages/MyAppointments/widgets/reminder_dialog.dart b/lib/pages/MyAppointments/widgets/reminder_dialog.dart index 238d41d7..13955e5b 100644 --- a/lib/pages/MyAppointments/widgets/reminder_dialog.dart +++ b/lib/pages/MyAppointments/widgets/reminder_dialog.dart @@ -27,7 +27,7 @@ class _ReminderDialogState extends State { shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)), child: Container( - height: MediaQuery.of(context).size.height * 0.55, + height: MediaQuery.of(context).size.height * 0.57, width: 450.0, child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/pages/ToDoList/ToDo.dart b/lib/pages/ToDoList/ToDo.dart index 420ae5e5..a7e06342 100644 --- a/lib/pages/ToDoList/ToDo.dart +++ b/lib/pages/ToDoList/ToDo.dart @@ -597,11 +597,31 @@ class _ToDoState extends State { createAdvancePayment(res, AppoitmentAllHistoryResultList appo) { DoctorsListService service = new DoctorsListService(); + String paymentReference = res['Fort_id'].toString(); service .createAdvancePayment( appo, res['Amount'], res['Fort_id'], res['PaymentMethod'], context) .then((res) { - print(res['OnlineCheckInAppointments']); + print(res['OnlineCheckInAppointments'][0]['AdvanceNumber']); + addAdvancedNumberRequest( + res['OnlineCheckInAppointments'][0]['AdvanceNumber'].toString(), + paymentReference, + appo.appointmentNo.toString(), + appo); + }).catchError((err) { + print(err); + }); + } + + addAdvancedNumberRequest(String advanceNumber, String paymentReference, + String appointmentID, AppoitmentAllHistoryResultList appo) { + DoctorsListService service = new DoctorsListService(); + service + .addAdvancedNumberRequest( + advanceNumber, paymentReference, appointmentID, context) + .then((res) { + print(res); + getAppoQR(context, appo); }).catchError((err) { print(err); }); diff --git a/lib/pages/ToDoList/widgets/paymentDialog.dart b/lib/pages/ToDoList/widgets/paymentDialog.dart index 8bd86b47..d79a1ead 100644 --- a/lib/pages/ToDoList/widgets/paymentDialog.dart +++ b/lib/pages/ToDoList/widgets/paymentDialog.dart @@ -24,7 +24,7 @@ class _PaymentDialogState extends State { shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)), child: Container( - height: MediaQuery.of(context).size.height * 0.62, + height: MediaQuery.of(context).size.height * 0.67, width: 450.0, child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/services/appointment_services/GetDoctorsList.dart b/lib/services/appointment_services/GetDoctorsList.dart index 43590b59..a2991805 100644 --- a/lib/services/appointment_services/GetDoctorsList.dart +++ b/lib/services/appointment_services/GetDoctorsList.dart @@ -613,6 +613,44 @@ class DoctorsListService extends BaseService { return Future.value(localRes); } + Future addAdvancedNumberRequest( + String advanceNumber, String paymentReference, String appointmentID, BuildContext context) async { + Map request; + if (await this.sharedPref.getObject(USER_PROFILE) != null) { + var data = AuthenticatedUser.fromJson( + await this.sharedPref.getObject(USER_PROFILE)); + authUser = data; + } + var languageID = await sharedPref.getString(APP_LANGUAGE); + Request req = appGlobal.getPublicRequest(); + request = { + "AdvanceNumber": advanceNumber, + "PaymentReferenceNumber": paymentReference, + "AppointmentID": appointmentID, + "VersionID": req.VersionID, + "Channel": req.Channel, + "LanguageID": languageID == 'ar' ? 1 : 2, + "IPAdress": req.IPAdress, + "generalid": req.generalid, + "PatientOutSA": authUser.outSA, + "SessionID": "YckwoXhUmWBsnHKEKig", + "isDentalAllowedBackend": false, + "DeviceTypeID": req.DeviceTypeID, + "PatientID": authUser.patientID, + "TokenID": "@dm!n", + "PatientTypeID": authUser.patientType, + "PatientType": authUser.patientType + }; + dynamic localRes; + await baseAppClient.post(ADD_ADVANCE_NUMBER_REQUEST, + onSuccess: (response, statusCode) async { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: request); + return Future.value(localRes); + } + Future createAdvancePayment( AppoitmentAllHistoryResultList appo, double payedAmount,