From 1492efdedbd07a03a3f06d1376653aa96d29a792 Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Tue, 17 Oct 2023 11:27:23 +0300 Subject: [PATCH 01/17] changes to build app --- android/app/build.gradle | 2 +- android/app/gradle/wrapper/gradle-wrapper.properties | 2 +- android/build.gradle | 2 +- lib/widgets/drawer/app_drawer_widget.dart | 10 +++++----- pubspec.yaml | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 965934fd..a1387dd3 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -75,7 +75,7 @@ android { buildTypes { debug { debuggable true - signingConfig signingConfigs.release + signingConfig signingConfigs.debug } release { debuggable false diff --git a/android/app/gradle/wrapper/gradle-wrapper.properties b/android/app/gradle/wrapper/gradle-wrapper.properties index a2c20300..dd658e01 100644 --- a/android/app/gradle/wrapper/gradle-wrapper.properties +++ b/android/app/gradle/wrapper/gradle-wrapper.properties @@ -3,5 +3,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip #distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/android/build.gradle b/android/build.gradle index e723adba..4ee80e4c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.7.20' + ext.kotlin_version = '1.8.20' repositories { google() jcenter() diff --git a/lib/widgets/drawer/app_drawer_widget.dart b/lib/widgets/drawer/app_drawer_widget.dart index e71a4266..dad9e879 100644 --- a/lib/widgets/drawer/app_drawer_widget.dart +++ b/lib/widgets/drawer/app_drawer_widget.dart @@ -50,7 +50,7 @@ import 'package:flutter/services.dart'; // import 'package:flutter_amazonpaymentservices/flutter_amazonpaymentservices.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:in_app_review/in_app_review.dart'; +// import 'package:in_app_review/in_app_review.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -64,7 +64,7 @@ class AppDrawer extends StatefulWidget { } class _AppDrawerState extends State { - final InAppReview _inAppReview = InAppReview.instance; + // final InAppReview _inAppReview = InAppReview.instance; @override void initState() { @@ -737,9 +737,9 @@ class _AppDrawerState extends State { } openAppReviewDialog() async { - if (await _inAppReview.isAvailable()) { - _inAppReview.requestReview(); - } + // if (await _inAppReview.isAvailable()) { + // _inAppReview.requestReview(); + // } } void setUserValues(value) async { diff --git a/pubspec.yaml b/pubspec.yaml index 235254f9..c90a0ebf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -132,7 +132,7 @@ dependencies: carousel_pro: ^1.0.0 #local_notifications - flutter_local_notifications: any + flutter_local_notifications: 10.0.0 #device_calendar device_calendar: ^4.2.0 @@ -187,7 +187,7 @@ dependencies: in_app_update: ^3.0.0 - in_app_review: ^2.0.3 +# in_app_review: ^2.0.6 badges: ^2.0.1 flutter_app_icon_badge: ^2.0.0 From b769959823db5efea6d37a52645a8cede28079ad Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Tue, 19 Dec 2023 10:10:05 +0300 Subject: [PATCH 02/17] Revert "changes to build app" This reverts commit 1492efde --- android/app/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- android/build.gradle | 2 +- lib/widgets/drawer/app_drawer_widget.dart | 10 ++++----- pubspec.yaml | 22 +++++++++---------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index a1387dd3..965934fd 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -75,7 +75,7 @@ android { buildTypes { debug { debuggable true - signingConfig signingConfigs.debug + signingConfig signingConfigs.release } release { debuggable false diff --git a/android/app/gradle/wrapper/gradle-wrapper.properties b/android/app/gradle/wrapper/gradle-wrapper.properties index dd658e01..a2c20300 100644 --- a/android/app/gradle/wrapper/gradle-wrapper.properties +++ b/android/app/gradle/wrapper/gradle-wrapper.properties @@ -3,5 +3,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip #distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/android/build.gradle b/android/build.gradle index 4ee80e4c..e723adba 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.8.20' + ext.kotlin_version = '1.7.20' repositories { google() jcenter() diff --git a/lib/widgets/drawer/app_drawer_widget.dart b/lib/widgets/drawer/app_drawer_widget.dart index dad9e879..e71a4266 100644 --- a/lib/widgets/drawer/app_drawer_widget.dart +++ b/lib/widgets/drawer/app_drawer_widget.dart @@ -50,7 +50,7 @@ import 'package:flutter/services.dart'; // import 'package:flutter_amazonpaymentservices/flutter_amazonpaymentservices.dart'; import 'package:flutter_svg/flutter_svg.dart'; -// import 'package:in_app_review/in_app_review.dart'; +import 'package:in_app_review/in_app_review.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -64,7 +64,7 @@ class AppDrawer extends StatefulWidget { } class _AppDrawerState extends State { - // final InAppReview _inAppReview = InAppReview.instance; + final InAppReview _inAppReview = InAppReview.instance; @override void initState() { @@ -737,9 +737,9 @@ class _AppDrawerState extends State { } openAppReviewDialog() async { - // if (await _inAppReview.isAvailable()) { - // _inAppReview.requestReview(); - // } + if (await _inAppReview.isAvailable()) { + _inAppReview.requestReview(); + } } void setUserValues(value) async { diff --git a/pubspec.yaml b/pubspec.yaml index 2494a580..235254f9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: diplomaticquarterapp description: A new Flutter application. -version: 4.5.73+1 +version: 4.5.028+4050028 environment: sdk: ">=2.7.0 <3.0.0" @@ -57,8 +57,8 @@ dependencies: shared_preferences: ^2.0.0 # flutter_flexible_toast: ^0.1.4 fluttertoast: ^8.0.8 - firebase_messaging: 14.1.0 - firebase_analytics: 10.0.5 + firebase_messaging: ^14.1.0 + firebase_analytics: ^10.0.5 # Progress bar @@ -100,7 +100,7 @@ dependencies: location: ^4.3.0 # Qr code Scanner # barcode_scan_fix: ^1.0.2 - barcode_scan2: 4.2.2 + barcode_scan2: ^4.2.2 # Rating Stars rating_bar: ^0.2.0 @@ -132,17 +132,17 @@ dependencies: carousel_pro: ^1.0.0 #local_notifications - flutter_local_notifications: 10.0.0 + flutter_local_notifications: any #device_calendar device_calendar: ^4.2.0 # TEMPORAL FIX for https://github.com/builttoroam/device_calendar/issues/507 # device_calendar: ^4.3.1 - # device_calendar: - # git: - # url: https://github.com/builttoroam/device_calendar.git - # ref: develop +# device_calendar: +# git: +# url: https://github.com/builttoroam/device_calendar.git +# ref: develop #Handle Geolocation geolocator: ^9.0.2 @@ -178,7 +178,7 @@ dependencies: wifi: ^0.1.5 vibration: ^1.7.3 - flutter_nfc_kit: 3.3.1 + flutter_nfc_kit: ^3.3.1 geofencing: ^0.1.0 @@ -187,7 +187,7 @@ dependencies: in_app_update: ^3.0.0 - in_app_review: 2.0.3 + in_app_review: ^2.0.3 badges: ^2.0.1 flutter_app_icon_badge: ^2.0.0 From ccb9e93d629acf1c3b417c70d768145857c4479e Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Tue, 19 Dec 2023 10:41:28 +0300 Subject: [PATCH 03/17] Added InAppApple Pay with PayFort --- lib/config/config.dart | 9 ++ lib/core/enum/PayfortEnums.dart | 44 ++++++ lib/locator.dart | 4 + lib/main.dart | 8 +- lib/pages/landing/landing_page.dart | 4 + .../medical/balance/confirm_payment_page.dart | 82 +++++++++- .../payfort_project_details_resp_model.dart | 36 +++++ .../payfort_services/payfort_service.dart | 140 ++++++++++++++++++ .../payfort_services/payfort_view_model.dart | 68 +++++++++ .../sdk_token_response_model.dart | 55 +++++++ pubspec.yaml | 2 + 11 files changed, 443 insertions(+), 9 deletions(-) create mode 100644 lib/core/enum/PayfortEnums.dart create mode 100644 lib/services/payfort_services/payfort_project_details_resp_model.dart create mode 100644 lib/services/payfort_services/payfort_service.dart create mode 100644 lib/services/payfort_services/payfort_view_model.dart create mode 100644 lib/services/payfort_services/sdk_token_response_model.dart diff --git a/lib/config/config.dart b/lib/config/config.dart index f0dd61b1..26dda9d2 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:amazon_payfort/amazon_payfort.dart'; import 'package:diplomaticquarterapp/models/Request.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; @@ -620,6 +621,14 @@ var PAYFORT_PROD_URL = 'https://paymentservices.payfort.com/FortAPI/paymentApi'; var CHECK_PATIENT_NPHIES_ELIGIBILITY = 'Services/Doctors.svc/REST/checkPatientInsuranceCompanyValidity'; var CONVERT_PATIENT_TO_CASH = 'Services/Doctors.svc/REST/deActivateInsuranceCompany'; + + +//PAYFORT +var getPayFortProjectDetails = "Services/PayFort_Serv.svc/REST/GetPayFortProjectDetails"; +var payFortEnvironment = FortEnvironment.test; +var applePayMerchantId = "merchant.com.hmgwebservices.uat"; + + class AppGlobal { static var context; diff --git a/lib/core/enum/PayfortEnums.dart b/lib/core/enum/PayfortEnums.dart new file mode 100644 index 00000000..2951eed8 --- /dev/null +++ b/lib/core/enum/PayfortEnums.dart @@ -0,0 +1,44 @@ +enum ServiceTypeEnum { + advancePayment, //3 + ancillaryOrder, //3 + appointmentPayment, //2 + covidPayment, //2 + erOnlineCheckIn, //3 + liveCareAppointment //4 +} + +extension ServiceTypeEnumExt on ServiceTypeEnum { + String value() { + switch (this) { + case ServiceTypeEnum.advancePayment: + return "Advance Payment"; + case ServiceTypeEnum.ancillaryOrder: + return "Ancillary Order"; + case ServiceTypeEnum.appointmentPayment: + return "Appointment Payment"; + case ServiceTypeEnum.covidPayment: + return "Covid Payment"; + case ServiceTypeEnum.erOnlineCheckIn: + return "ER Online Check In"; + case ServiceTypeEnum.liveCareAppointment: + return "LiveCare Appointment"; + } + } + + int getIdFromServiceEnum() { + switch (this) { + case ServiceTypeEnum.advancePayment: + return 3; + case ServiceTypeEnum.ancillaryOrder: + return 3; + case ServiceTypeEnum.appointmentPayment: + return 2; + case ServiceTypeEnum.covidPayment: + return 2; + case ServiceTypeEnum.erOnlineCheckIn: + return 3; + case ServiceTypeEnum.liveCareAppointment: + return 4; + } + } +} diff --git a/lib/locator.dart b/lib/locator.dart index ec696865..61ed983b 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -13,6 +13,8 @@ import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/PharmacyAddr import 'package:diplomaticquarterapp/core/viewModels/product_categories_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/order_model_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/weather/weather_view_model.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_service.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/services/pharmacy_services/cancelOrder_service.dart'; import 'package:diplomaticquarterapp/services/pharmacy_services/order_service.dart'; import 'package:diplomaticquarterapp/services/pharmacy_services/recommendedProduct_service.dart'; @@ -202,6 +204,7 @@ void setupLocator() { locator.registerLazySingleton(() => VaccinationTableService()); locator.registerLazySingleton(() => AncillaryOrdersService()); locator.registerLazySingleton(() => EdOnlineServices()); + locator.registerLazySingleton(() => PayfortService()); //pharmacy // locator.registerLazySingleton(() => PharmacyCategoriseService()); @@ -309,6 +312,7 @@ void setupLocator() { locator.registerFactory(() => BestSellerViewModel()); locator.registerFactory(() => LastVisitedViewModel()); locator.registerFactory(() => MostViewedViewModel()); + locator.registerFactory(() => PayfortViewModel()); // Offer And Packages //---------------------- diff --git a/lib/main.dart b/lib/main.dart index 4f6e43f6..4be8957b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:diplomaticquarterapp/core/viewModels/PharmacyPagesViewModel.dart import 'package:diplomaticquarterapp/core/viewModels/dashboard_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart'; import 'package:diplomaticquarterapp/routes.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart'; import 'package:diplomaticquarterapp/services/robo_search/search_provider.dart'; import 'package:diplomaticquarterapp/theme/theme_notifier.dart'; @@ -118,12 +119,15 @@ class _MyApp extends State { ), ChangeNotifierProvider(create: (context) => CompareList()), ChangeNotifierProvider(create: (context) => OrderPreviewViewModel()), + ChangeNotifierProvider(create: (context) => PayfortViewModel()), ], child: Consumer( builder: (context, projectProvider, child) => MaterialApp( - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget child) { return MediaQuery( - data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0,), //set desired text scale factor here + data: MediaQuery.of(context).copyWith( + textScaleFactor: 1.0, + ), //set desired text scale factor here child: child, ); }, diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index 47dab9ba..6c2b5f6e 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -24,6 +24,7 @@ import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart' import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart'; import 'package:diplomaticquarterapp/services/family_files/family_files_provider.dart' as family; import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/LocalNotification.dart'; @@ -302,6 +303,9 @@ class _LandingPageState extends State with WidgetsBindingObserver { } }); + PayfortViewModel payfortViewModel = context.read(); + payfortViewModel.initPayfort(); + // HMG (Guest/Internet) Wifi Access [Zohaib Kambrani] // for now commented to reduce this call will enable it when needed // HMGNetworkConnectivity(context).start(); diff --git a/lib/pages/medical/balance/confirm_payment_page.dart b/lib/pages/medical/balance/confirm_payment_page.dart index 0697ea75..d60b199c 100644 --- a/lib/pages/medical/balance/confirm_payment_page.dart +++ b/lib/pages/medical/balance/confirm_payment_page.dart @@ -1,5 +1,8 @@ +import 'dart:developer'; + import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/my_balance/AdvanceModel.dart'; import 'package:diplomaticquarterapp/core/model/my_balance/patient_info_and_mobile_number.dart'; @@ -7,11 +10,14 @@ import 'package:diplomaticquarterapp/core/viewModels/medical/my_balance_view_mod import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; +import 'package:diplomaticquarterapp/models/LiveCare/ApplePayInsertRequest.dart'; import 'package:diplomaticquarterapp/models/apple_pay_request.dart'; import 'package:diplomaticquarterapp/models/apple_pay_response.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; +import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; @@ -24,12 +30,10 @@ import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/otp/sms-popup.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; - -// import 'package:pay/pay.dart'; import 'package:provider/provider.dart'; - import 'new_text_Field.dart'; + class ConfirmPaymentPage extends StatefulWidget { final AdvanceModel advanceModel; final PatientInfoAndMobileNumber patientInfoAndMobileNumber; @@ -214,9 +218,73 @@ class _ConfirmPaymentPageState extends State { padding: EdgeInsets.all(20), child: DefaultButton( TranslationBase.of(context).confirm.toUpperCase(), - () { + () async { if (widget.advanceModel.fileNumber == projectViewModel.user.patientID.toString()) { - openPayment(widget.selectedPaymentMethod, widget.authenticatedUser, double.parse(widget.advanceModel.amount), null); + if (widget.selectedPaymentMethod == "ApplePay") { + transID = Utils.getAdvancePaymentTransID(widget.advanceModel.hospitalsModel.iD, int.parse(widget.advanceModel.fileNumber)); + print("TransactionID: $transID"); + GifLoaderDialogUtils.showMyDialog(context); + + LiveCareService service = new LiveCareService(); + ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); + + applePayInsertRequest.clientRequestID = transID; + applePayInsertRequest.clinicID = 0; + applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; + applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; + applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; + applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); + applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); + applePayInsertRequest.doctorID = 0; + applePayInsertRequest.projectID = widget.advanceModel.hospitalsModel.iD.toString(); + applePayInsertRequest.serviceID = ServiceTypeEnum.advancePayment.getIdFromServiceEnum().toString(); + applePayInsertRequest.channelID = 3; + applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; + applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; + applePayInsertRequest.appointmentDate = null; + applePayInsertRequest.appointmentNo = 0; + applePayInsertRequest.orderDescription = "Advance Payment"; + applePayInsertRequest.liveServiceID = "0"; + applePayInsertRequest.latitude = "0.0"; + applePayInsertRequest.longitude = "0.0"; + applePayInsertRequest.amount = widget.advanceModel.amount.toString(); + applePayInsertRequest.isSchedule = "0"; + applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.paymentOption = "ApplePay"; + + service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { + GifLoaderDialogUtils.hideDialog(context); + await context.read().initiateApplePayWithPayfort( + customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, + customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + orderDescription: "Advance Payment", + orderAmount: double.parse(widget.advanceModel.amount), + merchantReference: transID, + onFailed: (failureResult) { + log("failureResult: ${failureResult.toString()}"); + + }, + onSuccess: (successResult) { + log("Payfort: ${successResult.responseMessage}"); + checkPaymentStatus(AppoitmentAllHistoryResultList()); + }, + projectId: widget.advanceModel.hospitalsModel.iD, + // projectId: 95, + serviceTypeEnum: ServiceTypeEnum.advancePayment, + ); + }).catchError((err) { + print(err); + if (context = null) GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: err); + }); + } else { + openPayment(widget.selectedPaymentMethod, widget.authenticatedUser, double.parse(widget.advanceModel.amount), AppoitmentAllHistoryResultList()); + } } else { GifLoaderDialogUtils.showMyDialog(context); model.sendActivationCodeForAdvancePayment(patientID: int.parse(widget.advanceModel.fileNumber), projectID: widget.advanceModel.hospitalsModel.iD).then((value) { @@ -231,7 +299,7 @@ class _ConfirmPaymentPageState extends State { // GifLoaderDialogUtils.showMyDialog(context); // model.sendActivationCodeForAdvancePayment(patientID: int.parse(widget.advanceModel.fileNumber), projectID: widget.advanceModel.hospitalsModel.iD).then((value) { // GifLoaderDialogUtils.hideDialog(context); - // if (model.state != ViewState.ErrorLocal && model.state != ViewState.Error) showSMSDialog(model); + // if (model.state = ViewState.ErrorLocal && model.state = ViewState.Error) showSMSDialog(model); // }); }, ), @@ -410,7 +478,7 @@ class _ConfirmPaymentPageState extends State { } onBrowserExit(AppoitmentAllHistoryResultList appo, bool isPaymentMade) { - print("onBrowserExit Called!!!!"); + print("onBrowserExit Called"); if (widget.selectedPaymentMethod == "TAMARA" && tamaraPaymentStatus != null && tamaraPaymentStatus == "approved") { var res = { "Amount": double.parse(widget.advanceModel.amount), diff --git a/lib/services/payfort_services/payfort_project_details_resp_model.dart b/lib/services/payfort_services/payfort_project_details_resp_model.dart new file mode 100644 index 00000000..18d501ea --- /dev/null +++ b/lib/services/payfort_services/payfort_project_details_resp_model.dart @@ -0,0 +1,36 @@ +class PayfortProjectDetailsRespModel { + String accessCode; + int integrationId; + String merchantIdentifier; + int projectID; + String projectName; + int servID; + String shaRequest; + String shaResponse; + + PayfortProjectDetailsRespModel({this.accessCode, this.integrationId, this.merchantIdentifier, this.projectID, this.projectName, this.servID, this.shaRequest, this.shaResponse}); + + PayfortProjectDetailsRespModel.fromJson(Map json) { + accessCode = json['AccessCode']; + integrationId = json['Integration_Id']; + merchantIdentifier = json['MerchantIdentifier']; + projectID = json['ProjectID']; + projectName = json['ProjectName']; + servID = json['ServID']; + shaRequest = json['Sha_Request']; + shaResponse = json['Sha_Response']; + } + + Map toJson() { + final Map data = new Map(); + data['AccessCode'] = this.accessCode; + data['Integration_Id'] = this.integrationId; + data['MerchantIdentifier'] = this.merchantIdentifier; + data['ProjectID'] = this.projectID; + data['ProjectName'] = this.projectName; + data['ServID'] = this.servID; + data['Sha_Request'] = this.shaRequest; + data['Sha_Response'] = this.shaResponse; + return data; + } +} diff --git a/lib/services/payfort_services/payfort_service.dart b/lib/services/payfort_services/payfort_service.dart new file mode 100644 index 00000000..cb6cb348 --- /dev/null +++ b/lib/services/payfort_services/payfort_service.dart @@ -0,0 +1,140 @@ +import 'dart:convert'; + +import 'package:amazon_payfort/amazon_payfort.dart'; +import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/core/service/base_service.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/sdk_token_response_model.dart'; +import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:http/http.dart'; +import 'package:network_info_plus/network_info_plus.dart'; + +class PayfortService extends BaseService { + final AmazonPayfort _payfort = AmazonPayfort.instance; + + final NetworkInfo _info = NetworkInfo(); + + Future initPayfortSDK() async { + await AmazonPayfort.initialize( + PayFortOptions(environment: payFortEnvironment), + ); + } + + Future getPayfortConfigurations({int serviceId, int projectId, int integrationId = 2}) async { + Map body = {"Integration_Id": integrationId, "ServID": serviceId, "ProjectID": projectId}; + + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel(); + await baseAppClient.post( + getPayFortProjectDetails, + onSuccess: (response, statusCode) async { + payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel.fromJson(response.isNotEmpty ? response.first : response); + }, + onFailure: (String error, int statusCode) { + Utils.showErrorToast(error); + return null; + }, + body: body, + isAllowAny: true, + ); + return payfortProjectDetailsRespModel; + } + + Future generateSdkSignatureFromAPI(SdkTokenRequest request) async { + var response = await post( + Uri.parse(payFortEnvironment.paymentApi), + headers: {'Content-Type': 'application/json'}, + body: jsonEncode(request.asRequest()), + ); + if (response.statusCode == 200) { + var decodedResponse = jsonDecode(response.body); + return SdkTokenResponse.fromMap(decodedResponse); + } + return null; + } + + Future _generateSdkResponse({ + String applePayAccessCode, + String merchantIdentifier, + String applePayShaType, + String applePayShaRequestPhrase, + }) async { + try { + String deviceId = await _payfort.getDeviceId(); + + /// Step 2: Generate the Signature + SdkTokenRequest tokenRequest = SdkTokenRequest( + accessCode: applePayAccessCode, + deviceId: deviceId ?? '', + merchantIdentifier: merchantIdentifier, + ); + + String signature = await _payfort.generateSignature( + shaType: applePayShaType, + concatenatedString: tokenRequest.toConcatenatedString(applePayShaRequestPhrase), + ); + + tokenRequest = tokenRequest.copyWith(signature: signature); + + /// Step 3: Generate the SDK Token + return await generateSdkSignatureFromAPI(tokenRequest); + } catch (e) { + print("Error here: ${e.toString()}"); + } + return null; + } + + Future paymentWithApplePay({ + SucceededCallback onSucceeded, + FailedCallback onFailed, + String customerName, + String customerEmail, + String orderDescription, + double orderAmount, + String merchantIdentifier, + String applePayAccessCode, + String applePayShaRequestPhrase, + String merchantReference, + String currency = "SAR", + String applePayShaType = "SHA-256", + String countryIsoCode = "SA", + }) async { + try { + SdkTokenResponse sdkTokenResponse = await _generateSdkResponse( + applePayAccessCode: applePayAccessCode, + merchantIdentifier: merchantIdentifier, + applePayShaType: applePayShaType, + applePayShaRequestPhrase: applePayShaRequestPhrase, + ); + + if (sdkTokenResponse != null && sdkTokenResponse.sdkToken == null) { + onFailed(sdkTokenResponse.responseMessage ?? ''); + return; + } + + /// Step 4: Processing Payment [Don't multiply with 100] + /// Amount value send always round ex. [100] not [100.00, 100.21] + FortRequest request = FortRequest( + amount: orderAmount, + customerName: customerName, + customerEmail: customerEmail, + orderDescription: orderDescription, + sdkToken: sdkTokenResponse?.sdkToken ?? '', + merchantReference: merchantReference, + currency: currency, + customerIp: (await _info.getWifiIP() ?? ''), + ); + + _payfort.callPayFortForApplePay( + request: request, + countryIsoCode: countryIsoCode, + applePayMerchantId: applePayMerchantId, + callback: ApplePayResultCallback( + onSucceeded: onSucceeded, + onFailed: onFailed, + ), + ); + } catch (e) { + onFailed(e.toString()); + } + } +} diff --git a/lib/services/payfort_services/payfort_view_model.dart b/lib/services/payfort_services/payfort_view_model.dart new file mode 100644 index 00000000..4ad6f8b9 --- /dev/null +++ b/lib/services/payfort_services/payfort_view_model.dart @@ -0,0 +1,68 @@ +import 'package:amazon_payfort/amazon_payfort.dart'; +import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart'; +import 'package:diplomaticquarterapp/locator.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_service.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; +import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:flutter/cupertino.dart'; + +class PayfortViewModel extends ChangeNotifier { + PayfortService _payfortService = locator(); + + Future initPayfort() async { + await _payfortService.initPayfortSDK(); + } + + Future getProjectDetailsForPayfort({ int serviceId, int projectId}) async { + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel(); + try { + payfortProjectDetailsRespModel = await _payfortService.getPayfortConfigurations(serviceId: serviceId, projectId: projectId); + return payfortProjectDetailsRespModel; + } on Exception catch (e, s) { + print(s); + return null; + } + } + + Future initiateApplePayWithPayfort({ + String customerName, + String customerEmail, + String orderDescription, + String merchantReference, + double orderAmount, + SucceededCallback onSuccess, + FailedCallback onFailed, + ServiceTypeEnum serviceTypeEnum, + int projectId, + }) async { + GifLoaderDialogUtils.showMyDialog(AppGlobal.context); + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = await getProjectDetailsForPayfort(projectId: projectId, serviceId: serviceTypeEnum.getIdFromServiceEnum()); + + if (payfortProjectDetailsRespModel == null) { + GifLoaderDialogUtils.hideDialog(AppGlobal.context); + return; + } + + try { + await _payfortService.paymentWithApplePay( + onSucceeded: onSuccess, + onFailed: onFailed, + customerName: customerName, + customerEmail: customerEmail, + orderDescription: orderDescription, + orderAmount: orderAmount, + merchantReference: merchantReference, + merchantIdentifier: payfortProjectDetailsRespModel.merchantIdentifier ?? "", + applePayAccessCode: payfortProjectDetailsRespModel.accessCode ?? "", + applePayShaRequestPhrase: payfortProjectDetailsRespModel.shaRequest ?? "", + ); + GifLoaderDialogUtils.hideDialog(AppGlobal.context); + } catch (e) { + Utils.showErrorToast(e.toString()); + GifLoaderDialogUtils.hideDialog(AppGlobal.context); + throw e; + } + } +} diff --git a/lib/services/payfort_services/sdk_token_response_model.dart b/lib/services/payfort_services/sdk_token_response_model.dart new file mode 100644 index 00000000..75326608 --- /dev/null +++ b/lib/services/payfort_services/sdk_token_response_model.dart @@ -0,0 +1,55 @@ +class SdkTokenResponse { + SdkTokenResponse({ + this.responseCode, + this.deviceId, + this.responseMessage, + this.serviceCommand, + this.sdkToken, + this.signature, + this.merchantIdentifier, + this.accessCode, + this.language, + this.status, + }); + + String responseCode; + String deviceId; + String responseMessage; + String serviceCommand; + String sdkToken; + String signature; + String merchantIdentifier; + String accessCode; + String language; + String status; + + factory SdkTokenResponse.fromMap(Map data) { + return SdkTokenResponse( + responseCode: data['response_code'], + deviceId: data['device_id'], + responseMessage: data['response_message'], + serviceCommand: data['service_command'], + sdkToken: data['sdk_token'], + signature: data['signature'], + merchantIdentifier: data['merchant_identifier'], + accessCode: data['access_code'], + language: data['language'], + status: data['status'], + ); + } + + Map toMap() { + return { + 'response_code': responseCode, + 'device_id': deviceId, + 'response_message': responseMessage, + 'service_command': serviceCommand, + 'sdk_token': sdkToken, + 'signature': signature, + 'merchant_identifier': merchantIdentifier, + 'access_code': accessCode, + 'language': language, + 'status': status, + }; + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 235254f9..b465d1da 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -218,6 +218,8 @@ dependencies: # open_file: ^3.2.1 open_filex: ^4.3.2 path_provider: ^2.0.8 + amazon_payfort: ^1.0.5 + network_info_plus: ^3.0.5 # flutter_callkit_incoming: ^1.0.3+3 # firebase_core: 1.12.0 From 52b3c196d6c9e5e2bcd2c198ad4ac4d191546b89 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 20 Dec 2023 15:37:52 +0300 Subject: [PATCH 04/17] updates --- ios/Runner/Runner.entitlements | 6 + lib/config/config.dart | 5 +- .../LiveCare/ApplePayInsertRequest.dart | 42 +++++- .../medical/balance/confirm_payment_page.dart | 129 ++++++------------ .../payfort_project_details_resp_model.dart | 3 +- .../payfort_services/payfort_service.dart | 58 ++++++++ .../payfort_services/payfort_view_model.dart | 49 ++++--- lib/widgets/in_app_browser/InAppBrowser.dart | 4 +- 8 files changed, 185 insertions(+), 111 deletions(-) diff --git a/ios/Runner/Runner.entitlements b/ios/Runner/Runner.entitlements index 0821ccf0..44ce1b68 100644 --- a/ios/Runner/Runner.entitlements +++ b/ios/Runner/Runner.entitlements @@ -8,6 +8,12 @@ com.apple.developer.healthkit.access + com.apple.developer.in-app-payments + + merchant.com.hmgwebsersives + merchant.com.hmgwebservices.uat + merchant.com.hmgwebservices + com.apple.developer.networking.HotspotConfiguration com.apple.developer.networking.wifi-info diff --git a/lib/config/config.dart b/lib/config/config.dart index 26dda9d2..4831aeb6 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -21,8 +21,8 @@ var PACKAGES_ORDERS = '/api/orders'; var PACKAGES_ORDER_HISTORY = '/api/orders/items'; var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara'; // var BASE_URL = 'http://10.20.200.111:1010/'; - // var BASE_URL = 'https://uat.hmgwebservices.com/'; -var BASE_URL = 'https://hmgwebservices.com/'; + var BASE_URL = 'https://uat.hmgwebservices.com/'; +// var BASE_URL = 'https://hmgwebservices.com/'; // var BASE_URL = 'https://orash.cloudsolutions.com.sa/'; // var BASE_URL = 'https://vidauat.cloudsolutions.com.sa/'; // var BASE_URL = 'https://vidamergeuat.cloudsolutions.com.sa/'; @@ -625,6 +625,7 @@ var CONVERT_PATIENT_TO_CASH = 'Services/Doctors.svc/REST/deActivateInsuranceComp //PAYFORT var getPayFortProjectDetails = "Services/PayFort_Serv.svc/REST/GetPayFortProjectDetails"; +var addPayFortApplePayResponse = "Services/PayFort_Serv.svc/REST/AddResponse"; var payFortEnvironment = FortEnvironment.test; var applePayMerchantId = "merchant.com.hmgwebservices.uat"; diff --git a/lib/models/LiveCare/ApplePayInsertRequest.dart b/lib/models/LiveCare/ApplePayInsertRequest.dart index 2e091f65..aa4e316b 100644 --- a/lib/models/LiveCare/ApplePayInsertRequest.dart +++ b/lib/models/LiveCare/ApplePayInsertRequest.dart @@ -35,6 +35,24 @@ class ApplePayInsertRequest { String sessionID; bool isDentalAllowedBackend; int deviceTypeID; + bool isMobSDK; + String merchantReference; + String merchantIdentifier; + String commandType; + String signature; + String accessCode; + String shaRequestPhrase; + String shaResponsePhrase; + String returnURL; + + // IsMobSDK ==> bool + // Merchant_Reference ==> string + // Merchant_Identifier ==> string + // CommandType ==> string + // Signature ==> string + // Access_code ==> string + // SHA_RequestPhase ==> string + // SHA_ResponsePhase ==> string ApplePayInsertRequest( {this.clientRequestID, @@ -72,7 +90,18 @@ class ApplePayInsertRequest { this.generalid, this.sessionID, this.isDentalAllowedBackend, - this.deviceTypeID}); + this.deviceTypeID, + + this.isMobSDK, + this.merchantReference, + this.merchantIdentifier, + this.commandType, + this.signature, + this.accessCode, + this.shaRequestPhrase, + this.shaResponsePhrase, + this.returnURL, + }); ApplePayInsertRequest.fromJson(Map json) { clientRequestID = json['ClientRequestID']; @@ -151,6 +180,17 @@ class ApplePayInsertRequest { data['SessionID'] = this.sessionID; data['isDentalAllowedBackend'] = this.isDentalAllowedBackend; data['DeviceTypeID'] = this.deviceTypeID; + + data['IsMobSDK'] = this.isMobSDK; + data['Merchant_Reference'] = this.merchantReference; + data['Merchant_Identifier'] = this.merchantIdentifier; + data['CommandType'] = this.commandType; + data['Signature'] = this.signature; + data['Access_code'] = this.accessCode; + data['SHA_RequestPhase'] = this.shaRequestPhrase; + data['SHA_ResponsePhase'] = this.shaResponsePhrase; + data['ReturnURL'] = this.returnURL; + return data; } } diff --git a/lib/pages/medical/balance/confirm_payment_page.dart b/lib/pages/medical/balance/confirm_payment_page.dart index d60b199c..da9f79e1 100644 --- a/lib/pages/medical/balance/confirm_payment_page.dart +++ b/lib/pages/medical/balance/confirm_payment_page.dart @@ -17,6 +17,7 @@ import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart'; import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; @@ -33,7 +34,6 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:provider/provider.dart'; import 'new_text_Field.dart'; - class ConfirmPaymentPage extends StatefulWidget { final AdvanceModel advanceModel; final PatientInfoAndMobileNumber patientInfoAndMobileNumber; @@ -218,7 +218,7 @@ class _ConfirmPaymentPageState extends State { padding: EdgeInsets.all(20), child: DefaultButton( TranslationBase.of(context).confirm.toUpperCase(), - () async { + () async { if (widget.advanceModel.fileNumber == projectViewModel.user.patientID.toString()) { if (widget.selectedPaymentMethod == "ApplePay") { transID = Utils.getAdvancePaymentTransID(widget.advanceModel.hospitalsModel.iD, int.parse(widget.advanceModel.fileNumber)); @@ -228,6 +228,14 @@ class _ConfirmPaymentPageState extends State { LiveCareService service = new LiveCareService(); ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; + await context + .read() + .getProjectDetailsForPayfort(projectId: widget.advanceModel.hospitalsModel.iD, serviceId: ServiceTypeEnum.advancePayment.getIdFromServiceEnum()) + .then((value) { + payfortProjectDetailsRespModel = value; + }); + applePayInsertRequest.clientRequestID = transID; applePayInsertRequest.clinicID = 0; applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; @@ -257,29 +265,39 @@ class _ConfirmPaymentPageState extends State { applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; applePayInsertRequest.paymentOption = "ApplePay"; + applePayInsertRequest.isMobSDK = true; + applePayInsertRequest.merchantReference = transID; + applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; + applePayInsertRequest.commandType = "PURCHASE"; + applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; + applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; + applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; + applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; + applePayInsertRequest.returnURL = ""; + service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { - GifLoaderDialogUtils.hideDialog(context); - await context.read().initiateApplePayWithPayfort( - customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, - customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, - orderDescription: "Advance Payment", - orderAmount: double.parse(widget.advanceModel.amount), - merchantReference: transID, - onFailed: (failureResult) { - log("failureResult: ${failureResult.toString()}"); - - }, - onSuccess: (successResult) { - log("Payfort: ${successResult.responseMessage}"); - checkPaymentStatus(AppoitmentAllHistoryResultList()); - }, - projectId: widget.advanceModel.hospitalsModel.iD, - // projectId: 95, - serviceTypeEnum: ServiceTypeEnum.advancePayment, - ); + // GifLoaderDialogUtils.hideDialog(context); + await context.read().initiateApplePayWithPayfort( + customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, + customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + orderDescription: "Advance Payment", + orderAmount: double.parse(widget.advanceModel.amount), + merchantReference: transID, + payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + onFailed: (failureResult) async { + log("failureResult: ${failureResult.toString()}"); + }, + onSuccess: (successResult) async { + log("Payfort: ${successResult.responseMessage}"); + await context.read().addPayfortApplePayResponse(result: successResult); + checkPaymentStatus(AppoitmentAllHistoryResultList()); + }, + projectId: widget.advanceModel.hospitalsModel.iD, + serviceTypeEnum: ServiceTypeEnum.advancePayment, + ); }).catchError((err) { print(err); - if (context = null) GifLoaderDialogUtils.hideDialog(context); + GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); }); } else { @@ -309,72 +327,7 @@ class _ConfirmPaymentPageState extends State { ); } - // startApplePay() { - // ApplePayResponse applePayResponse; - // var _paymentItems = [ - // PaymentItem( - // label: 'Total', - // amount: widget.advanceModel.amount, - // status: PaymentItemStatus.final_price, - // ) - // ]; - // - // _payClient.userCanPay(PayProvider.apple_pay).then((value) async { - // print(value); - // final result = await _payClient.showPaymentSelector( - // provider: PayProvider.apple_pay, - // paymentItems: _paymentItems, - // ); - // print(result); - // applePayResponse = ApplePayResponse.fromJson(result); - // callPayfortApplePayAPI(applePayResponse); - // }).catchError((err) { - // print(err); - // }); - // } - - callPayfortApplePayAPI(ApplePayResponse applePayResponse) async { - DoctorsListService service = new DoctorsListService(); - ApplePayRequest applePayRequest = new ApplePayRequest(); - AppleHeader appleHeader = new AppleHeader(); - ApplePaymentMethod applePaymentMethod = new ApplePaymentMethod(); - - applePayRequest.amount = widget.advanceModel.amount; - applePayRequest.currency = "SAR"; - applePayRequest.language = projectViewModel.isArabic ? "ar" : "en"; - applePayRequest.customername = projectViewModel.user.firstName; - applePayRequest.customerEmail = projectViewModel.user.emailAddress; - applePayRequest.orderdescription = "Advance Payment"; - applePayRequest.liveServiceid = ""; - applePayRequest.latitude = await this.sharedPref.getDouble(USER_LAT); - applePayRequest.longitude = await this.sharedPref.getDouble(USER_LONG); - applePayRequest.devicetoken = await sharedPref.getString(PUSH_TOKEN); - applePayRequest.clientrequestid = Utils.getAdvancePaymentTransID(widget.advanceModel.hospitalsModel.iD, int.parse(widget.advanceModel.fileNumber)); - applePayRequest.projectid = widget.advanceModel.hospitalsModel.iD.toString(); - applePayRequest.serviceid = "3"; - applePayRequest.patientid = projectViewModel.user.patientID.toString(); - applePayRequest.appleData = applePayResponse.token.data; - applePayRequest.appleSignature = applePayResponse.token.signature; - - appleHeader.appleEphemeralPublicKey = applePayResponse.token.header.ephemeralPublicKey; - appleHeader.appleTransactionId = applePayResponse.token.header.transactionId; - appleHeader.applePublicKeyHash = applePayResponse.token.header.publicKeyHash; - applePaymentMethod.appleType = getApplePayPaymentType(applePayResponse.paymentMethod.type); - applePaymentMethod.appleNetwork = applePayResponse.paymentMethod.network; - applePaymentMethod.appleDisplayName = applePayResponse.paymentMethod.displayName; - - applePayRequest.appleHeader = appleHeader; - applePayRequest.applePaymentMethod = applePaymentMethod; - - service.callPayfortApplePayAPI(applePayRequest, context).then((res) { - print(res); - GifLoaderDialogUtils.hideDialog(context); - }).catchError((err) { - GifLoaderDialogUtils.hideDialog(context); - print(err); - // _showMyDialog(err, this.context); - }); - } + void addPayFortApplePayResponse() {} String getApplePayPaymentType(dynamic paymentMethod) { switch (paymentMethod) { diff --git a/lib/services/payfort_services/payfort_project_details_resp_model.dart b/lib/services/payfort_services/payfort_project_details_resp_model.dart index 18d501ea..2bf9a1e5 100644 --- a/lib/services/payfort_services/payfort_project_details_resp_model.dart +++ b/lib/services/payfort_services/payfort_project_details_resp_model.dart @@ -7,8 +7,9 @@ class PayfortProjectDetailsRespModel { int servID; String shaRequest; String shaResponse; + String signature; - PayfortProjectDetailsRespModel({this.accessCode, this.integrationId, this.merchantIdentifier, this.projectID, this.projectName, this.servID, this.shaRequest, this.shaResponse}); + PayfortProjectDetailsRespModel({this.accessCode, this.integrationId, this.merchantIdentifier, this.projectID, this.projectName, this.servID, this.shaRequest, this.shaResponse, this.signature}); PayfortProjectDetailsRespModel.fromJson(Map json) { accessCode = json['AccessCode']; diff --git a/lib/services/payfort_services/payfort_service.dart b/lib/services/payfort_services/payfort_service.dart index cb6cb348..45e1c2c6 100644 --- a/lib/services/payfort_services/payfort_service.dart +++ b/lib/services/payfort_services/payfort_service.dart @@ -39,6 +39,44 @@ class PayfortService extends BaseService { return payfortProjectDetailsRespModel; } + Future addPayfortApplePayResponse({PayFortResult result}) async { + Map body = { + "Fort_id": result.fortId, + "CommandType": result.command, + "Amount": (num.parse(result.amount) / 100).toString(), + "Payment_Option": result.paymentOption, + "Customer_IP": result.customerIp, + "ECI": result.eci, + "Response_Message": result.responseMessage, + "Card_Number": result.cardNumber, + // "Card_Bin": result.ca, + "Status": result.status, + "Merchant_Ref": result.merchantReference, + // Installments_Number + // plan_code + // issuer_code + "Pat_Token": result.tokenName, + "IsRefund": false, + "RemmeberMe": false, + "Reconciliation_Reference": result.reconcilationReference, + "LanguageID": 1, + }; + + // PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel(); + await baseAppClient.post( + addPayFortApplePayResponse, + onSuccess: (response, statusCode) async { + // payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel.fromJson(response.isNotEmpty ? response.first : response); + }, + onFailure: (String error, int statusCode) { + Utils.showErrorToast(error); + return null; + }, + body: body, + isAllowAny: true, + ); + } + Future generateSdkSignatureFromAPI(SdkTokenRequest request) async { var response = await post( Uri.parse(payFortEnvironment.paymentApi), @@ -83,6 +121,26 @@ class PayfortService extends BaseService { return null; } + Future getPayfortSignature( + String applePayAccessCode, + String merchantIdentifier, + String applePayShaRequestPhrase, + ) async { + String deviceId = await _payfort.getDeviceId(); + SdkTokenRequest tokenRequest = SdkTokenRequest( + accessCode: applePayAccessCode, + deviceId: deviceId ?? '', + merchantIdentifier: merchantIdentifier, + ); + + String signature = await _payfort.generateSignature( + shaType: "SHA-256", + concatenatedString: tokenRequest.toConcatenatedString(applePayShaRequestPhrase), + ); + + return signature; + } + Future paymentWithApplePay({ SucceededCallback onSucceeded, FailedCallback onFailed, diff --git a/lib/services/payfort_services/payfort_view_model.dart b/lib/services/payfort_services/payfort_view_model.dart index 4ad6f8b9..4a9038b0 100644 --- a/lib/services/payfort_services/payfort_view_model.dart +++ b/lib/services/payfort_services/payfort_view_model.dart @@ -15,10 +15,15 @@ class PayfortViewModel extends ChangeNotifier { await _payfortService.initPayfortSDK(); } - Future getProjectDetailsForPayfort({ int serviceId, int projectId}) async { + Future getProjectDetailsForPayfort({int serviceId, int projectId}) async { PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel(); try { payfortProjectDetailsRespModel = await _payfortService.getPayfortConfigurations(serviceId: serviceId, projectId: projectId); + + String signature = + await _payfortService.getPayfortSignature(payfortProjectDetailsRespModel.accessCode, payfortProjectDetailsRespModel.merchantIdentifier, payfortProjectDetailsRespModel.shaRequest); + payfortProjectDetailsRespModel.signature = signature; + return payfortProjectDetailsRespModel; } on Exception catch (e, s) { print(s); @@ -26,24 +31,34 @@ class PayfortViewModel extends ChangeNotifier { } } + Future addPayfortApplePayResponse({PayFortResult result}) async { + try { + await _payfortService.addPayfortApplePayResponse(result: result); + } on Exception catch (e, s) { + print(s); + return null; + } + } + Future initiateApplePayWithPayfort({ - String customerName, - String customerEmail, - String orderDescription, - String merchantReference, - double orderAmount, - SucceededCallback onSuccess, - FailedCallback onFailed, - ServiceTypeEnum serviceTypeEnum, - int projectId, + String customerName, + String customerEmail, + String orderDescription, + String merchantReference, + double orderAmount, + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel, + SucceededCallback onSuccess, + FailedCallback onFailed, + ServiceTypeEnum serviceTypeEnum, + int projectId, }) async { - GifLoaderDialogUtils.showMyDialog(AppGlobal.context); - PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = await getProjectDetailsForPayfort(projectId: projectId, serviceId: serviceTypeEnum.getIdFromServiceEnum()); - - if (payfortProjectDetailsRespModel == null) { - GifLoaderDialogUtils.hideDialog(AppGlobal.context); - return; - } + // GifLoaderDialogUtils.showMyDialog(AppGlobal.context); + // PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = await getProjectDetailsForPayfort(projectId: projectId, serviceId: serviceTypeEnum.getIdFromServiceEnum()); + // + // if (payfortProjectDetailsRespModel == null) { + // GifLoaderDialogUtils.hideDialog(AppGlobal.context); + // return; + // } try { await _payfortService.paymentWithApplePay( diff --git a/lib/widgets/in_app_browser/InAppBrowser.dart b/lib/widgets/in_app_browser/InAppBrowser.dart index c9fecbf9..c71b206b 100644 --- a/lib/widgets/in_app_browser/InAppBrowser.dart +++ b/lib/widgets/in_app_browser/InAppBrowser.dart @@ -40,9 +40,9 @@ class MyInAppBrowser extends InAppBrowser { // static String APPLE_PAY_PAYFORT_URL = 'https://hmgwebservices.com/PayFortWebLive/PayFortApi/MakeApplePayRequest'; // Payfort Payment Gateway URL LIVE static String APPLE_PAY_PAYFORT_URL = 'https://hmgwebservices.com/PayFortWebLive/PayFortApi/MakeApplePayRequest'; // Payfort Payment Gateway URL UAT - // static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort Payment Gateway URL UAT + static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort Payment Gateway URL UAT - static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL LIVE + // static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL LIVE // static String SERVICE_URL = 'https://uat.hmgwebservices.com/payfortforvidaplus/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL UAT VIDA PLUS From e4ce158277426559e7933e3888f7635ffb0068e8 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 20 Dec 2023 22:42:37 +0300 Subject: [PATCH 05/17] updates --- lib/services/payfort_services/payfort_service.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/payfort_services/payfort_service.dart b/lib/services/payfort_services/payfort_service.dart index 45e1c2c6..e684d1bd 100644 --- a/lib/services/payfort_services/payfort_service.dart +++ b/lib/services/payfort_services/payfort_service.dart @@ -43,7 +43,7 @@ class PayfortService extends BaseService { Map body = { "Fort_id": result.fortId, "CommandType": result.command, - "Amount": (num.parse(result.amount) / 100).toString(), + "Amount": (num.parse(result.amount) / 100), "Payment_Option": result.paymentOption, "Customer_IP": result.customerIp, "ECI": result.eci, From cfa341aba5a4e25989af73bcdfdf0864323ca2f6 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Fri, 22 Dec 2023 14:35:59 +0300 Subject: [PATCH 06/17] Apple Pay Updates --- .../LiveCare/ApplePayInsertRequest.dart | 1 + lib/pages/ToDoList/ToDo.dart | 92 +++++++++- .../medical/balance/confirm_payment_page.dart | 169 +++++++++--------- 3 files changed, 173 insertions(+), 89 deletions(-) diff --git a/lib/models/LiveCare/ApplePayInsertRequest.dart b/lib/models/LiveCare/ApplePayInsertRequest.dart index aa4e316b..0272bd9e 100644 --- a/lib/models/LiveCare/ApplePayInsertRequest.dart +++ b/lib/models/LiveCare/ApplePayInsertRequest.dart @@ -157,6 +157,7 @@ class ApplePayInsertRequest { data['Service_ID'] = this.serviceID; data['Channel_ID'] = this.channelID; data['PatientID'] = this.patientID; + data['PatientId'] = this.patientID; data['PatientTypeID'] = this.patientTypeID; data['PatientOutSA'] = this.patientOutSA; data['AppointmentDate'] = this.appointmentDate; diff --git a/lib/pages/ToDoList/ToDo.dart b/lib/pages/ToDoList/ToDo.dart index 30c043e5..2ba88f10 100644 --- a/lib/pages/ToDoList/ToDo.dart +++ b/lib/pages/ToDoList/ToDo.dart @@ -1,7 +1,9 @@ +import 'dart:developer'; import 'dart:io'; import 'package:diplomaticquarterapp/analytics/google-analytics.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart'; import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; @@ -10,6 +12,7 @@ import 'package:diplomaticquarterapp/models/Appointments/OBGyneProcedureListResp import 'package:diplomaticquarterapp/models/Appointments/PatientShareResposne.dart'; import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; +import 'package:diplomaticquarterapp/models/LiveCare/ApplePayInsertRequest.dart'; import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_order_list_model.dart'; import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/QRCode.dart'; @@ -21,6 +24,9 @@ import 'package:diplomaticquarterapp/pages/insurance/insurance_update_screen.dar import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart'; +import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; @@ -1299,12 +1305,96 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { if (value != null) { final appType = appo.isLiveCareAppointment ? 'livecare' : 'regular'; - openPayment(value, projectViewModel.user, double.parse(patientShareResponse.patientShareWithTax.toString()), patientShareResponse, appo); + if (selectedPaymentMethod == "ApplePay") { + startApplePay(appo, patientShareResponse); + } else { + openPayment(value, projectViewModel.user, double.parse(patientShareResponse.patientShareWithTax.toString()), patientShareResponse, appo); + } projectViewModel.analytics.appointment.payment_method(appointment_type: appType, clinic: appo.clinicName, payment_method: value[0], payment_type: 'appointment'); } }); } + void startApplePay(AppoitmentAllHistoryResultList appo, PatientShareResponse patientShareResponse) async { + String transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); + print("TransactionID: $transID"); + GifLoaderDialogUtils.showMyDialog(context); + + LiveCareService service = new LiveCareService(); + ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); + + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; + await context.read().getProjectDetailsForPayfort(projectId: appo.projectID, serviceId: ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum()).then((value) { + payfortProjectDetailsRespModel = value; + }); + + applePayInsertRequest.clientRequestID = transID; + applePayInsertRequest.clinicID = appo.clinicID; + applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; + applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; + applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; + applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); + applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); + applePayInsertRequest.doctorID = appo.doctorID; + applePayInsertRequest.projectID = appo.projectID.toString(); + applePayInsertRequest.serviceID = ServiceTypeEnum.advancePayment.getIdFromServiceEnum().toString(); + applePayInsertRequest.channelID = 3; + applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; + applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; + applePayInsertRequest.appointmentDate = appo.appointmentDate; + applePayInsertRequest.appointmentNo = appo.appointmentNo; + applePayInsertRequest.orderDescription = "Advance Payment"; + applePayInsertRequest.liveServiceID = "0"; + applePayInsertRequest.latitude = "0.0"; + applePayInsertRequest.longitude = "0.0"; + applePayInsertRequest.amount = patientShareResponse.patientShareWithTax.toString(); + applePayInsertRequest.isSchedule = appo.isLiveCareAppointment ? "1" : "0"; + applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.paymentOption = "ApplePay"; + + applePayInsertRequest.isMobSDK = true; + applePayInsertRequest.merchantReference = transID; + applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; + applePayInsertRequest.commandType = "PURCHASE"; + applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; + applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; + applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; + applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; + applePayInsertRequest.returnURL = ""; + + service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { + await context.read().initiateApplePayWithPayfort( + customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, + customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + orderDescription: "Appointment Payment", + orderAmount: double.parse(patientShareResponse.patientShareWithTax.toString()), + merchantReference: transID, + payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + onFailed: (failureResult) async { + log("failureResult: ${failureResult.toString()}"); + // GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: failureResult.toString()); + }, + onSuccess: (successResult) async { + log("Payfort: ${successResult.responseMessage}"); + await context.read().addPayfortApplePayResponse(result: successResult); + checkPaymentStatus(appo); + }, + projectId: appo.projectID, + serviceTypeEnum: ServiceTypeEnum.appointmentPayment, + ); + }).catchError((err) { + print(err); + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: err); + }); + } + confirmAppointment(AppoitmentAllHistoryResultList appo) { GifLoaderDialogUtils.showMyDialog(context); DoctorsListService service = new DoctorsListService(); diff --git a/lib/pages/medical/balance/confirm_payment_page.dart b/lib/pages/medical/balance/confirm_payment_page.dart index da9f79e1..b754b987 100644 --- a/lib/pages/medical/balance/confirm_payment_page.dart +++ b/lib/pages/medical/balance/confirm_payment_page.dart @@ -221,85 +221,7 @@ class _ConfirmPaymentPageState extends State { () async { if (widget.advanceModel.fileNumber == projectViewModel.user.patientID.toString()) { if (widget.selectedPaymentMethod == "ApplePay") { - transID = Utils.getAdvancePaymentTransID(widget.advanceModel.hospitalsModel.iD, int.parse(widget.advanceModel.fileNumber)); - print("TransactionID: $transID"); - GifLoaderDialogUtils.showMyDialog(context); - - LiveCareService service = new LiveCareService(); - ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); - - PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; - await context - .read() - .getProjectDetailsForPayfort(projectId: widget.advanceModel.hospitalsModel.iD, serviceId: ServiceTypeEnum.advancePayment.getIdFromServiceEnum()) - .then((value) { - payfortProjectDetailsRespModel = value; - }); - - applePayInsertRequest.clientRequestID = transID; - applePayInsertRequest.clinicID = 0; - applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; - applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; - applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; - applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; - applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); - applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); - applePayInsertRequest.doctorID = 0; - applePayInsertRequest.projectID = widget.advanceModel.hospitalsModel.iD.toString(); - applePayInsertRequest.serviceID = ServiceTypeEnum.advancePayment.getIdFromServiceEnum().toString(); - applePayInsertRequest.channelID = 3; - applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; - applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; - applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; - applePayInsertRequest.appointmentDate = null; - applePayInsertRequest.appointmentNo = 0; - applePayInsertRequest.orderDescription = "Advance Payment"; - applePayInsertRequest.liveServiceID = "0"; - applePayInsertRequest.latitude = "0.0"; - applePayInsertRequest.longitude = "0.0"; - applePayInsertRequest.amount = widget.advanceModel.amount.toString(); - applePayInsertRequest.isSchedule = "0"; - applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; - applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; - applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; - applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; - applePayInsertRequest.paymentOption = "ApplePay"; - - applePayInsertRequest.isMobSDK = true; - applePayInsertRequest.merchantReference = transID; - applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; - applePayInsertRequest.commandType = "PURCHASE"; - applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; - applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; - applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; - applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; - applePayInsertRequest.returnURL = ""; - - service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { - // GifLoaderDialogUtils.hideDialog(context); - await context.read().initiateApplePayWithPayfort( - customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, - customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, - orderDescription: "Advance Payment", - orderAmount: double.parse(widget.advanceModel.amount), - merchantReference: transID, - payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, - onFailed: (failureResult) async { - log("failureResult: ${failureResult.toString()}"); - }, - onSuccess: (successResult) async { - log("Payfort: ${successResult.responseMessage}"); - await context.read().addPayfortApplePayResponse(result: successResult); - checkPaymentStatus(AppoitmentAllHistoryResultList()); - }, - projectId: widget.advanceModel.hospitalsModel.iD, - serviceTypeEnum: ServiceTypeEnum.advancePayment, - ); - }).catchError((err) { - print(err); - GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: err); - }); + startApplePay(); } else { openPayment(widget.selectedPaymentMethod, widget.authenticatedUser, double.parse(widget.advanceModel.amount), AppoitmentAllHistoryResultList()); } @@ -311,14 +233,6 @@ class _ConfirmPaymentPageState extends State { }); } projectViewModel.analytics.advancePayments.payment_confirm(method: widget.selectedPaymentMethod.toLowerCase(), type: 'wallet'); - - // startApplePay(); - // if() - // GifLoaderDialogUtils.showMyDialog(context); - // model.sendActivationCodeForAdvancePayment(patientID: int.parse(widget.advanceModel.fileNumber), projectID: widget.advanceModel.hospitalsModel.iD).then((value) { - // GifLoaderDialogUtils.hideDialog(context); - // if (model.state = ViewState.ErrorLocal && model.state = ViewState.Error) showSMSDialog(model); - // }); }, ), ), @@ -327,7 +241,86 @@ class _ConfirmPaymentPageState extends State { ); } - void addPayFortApplePayResponse() {} + void startApplePay() async { + transID = Utils.getAdvancePaymentTransID(widget.advanceModel.hospitalsModel.iD, int.parse(widget.advanceModel.fileNumber)); + print("TransactionID: $transID"); + GifLoaderDialogUtils.showMyDialog(context); + + LiveCareService service = new LiveCareService(); + ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); + + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; + await context + .read() + .getProjectDetailsForPayfort(projectId: widget.advanceModel.hospitalsModel.iD, serviceId: ServiceTypeEnum.advancePayment.getIdFromServiceEnum()) + .then((value) { + payfortProjectDetailsRespModel = value; + }); + + applePayInsertRequest.clientRequestID = transID; + applePayInsertRequest.clinicID = 0; + applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; + applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; + applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; + applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); + applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); + applePayInsertRequest.doctorID = 0; + applePayInsertRequest.projectID = widget.advanceModel.hospitalsModel.iD.toString(); + applePayInsertRequest.serviceID = ServiceTypeEnum.advancePayment.getIdFromServiceEnum().toString(); + applePayInsertRequest.channelID = 3; + applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; + applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; + applePayInsertRequest.appointmentDate = null; + applePayInsertRequest.appointmentNo = 0; + applePayInsertRequest.orderDescription = "Advance Payment"; + applePayInsertRequest.liveServiceID = "0"; + applePayInsertRequest.latitude = "0.0"; + applePayInsertRequest.longitude = "0.0"; + applePayInsertRequest.amount = widget.advanceModel.amount.toString(); + applePayInsertRequest.isSchedule = "0"; + applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.paymentOption = "ApplePay"; + + applePayInsertRequest.isMobSDK = true; + applePayInsertRequest.merchantReference = transID; + applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; + applePayInsertRequest.commandType = "PURCHASE"; + applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; + applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; + applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; + applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; + applePayInsertRequest.returnURL = ""; + + service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { + await context.read().initiateApplePayWithPayfort( + customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, + customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + orderDescription: "Advance Payment", + orderAmount: double.parse(widget.advanceModel.amount), + merchantReference: transID, + payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + onFailed: (failureResult) async { + log("failureResult: ${failureResult.toString()}"); + }, + onSuccess: (successResult) async { + log("Payfort: ${successResult.responseMessage}"); + await context.read().addPayfortApplePayResponse(result: successResult); + checkPaymentStatus(AppoitmentAllHistoryResultList()); + }, + projectId: widget.advanceModel.hospitalsModel.iD, + serviceTypeEnum: ServiceTypeEnum.advancePayment, + ); + }).catchError((err) { + print(err); + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: err); + }); + } String getApplePayPaymentType(dynamic paymentMethod) { switch (paymentMethod) { From cd8b76a374dfc3a01eb0a1cce9f19eb8737d47e9 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Thu, 4 Jan 2024 10:57:54 +0300 Subject: [PATCH 07/17] In App Apple Pay implemented --- lib/pages/BookAppointment/BookSuccess.dart | 93 +++++++++++++++++- lib/pages/ToDoList/ToDo.dart | 1 - lib/pages/livecare/widgets/clinic_list.dart | 95 ++++++++++++++++++- .../payfort_services/payfort_service.dart | 4 +- .../payfort_services/payfort_view_model.dart | 4 +- 5 files changed, 189 insertions(+), 8 deletions(-) diff --git a/lib/pages/BookAppointment/BookSuccess.dart b/lib/pages/BookAppointment/BookSuccess.dart index ea0f186b..8e29e908 100644 --- a/lib/pages/BookAppointment/BookSuccess.dart +++ b/lib/pages/BookAppointment/BookSuccess.dart @@ -1,16 +1,22 @@ +import 'dart:developer'; import 'dart:io'; +import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.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/models/LiveCare/ApplePayInsertRequest.dart'; import 'package:diplomaticquarterapp/models/header_model.dart'; import 'package:diplomaticquarterapp/pages/ToDoList/payment_method_select.dart'; import 'package:diplomaticquarterapp/pages/insurance/insurance_update_screen.dart'; import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; +import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; @@ -28,6 +34,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:provider/provider.dart'; +import '../../config/shared_pref_kay.dart'; import 'QRCode.dart'; class BookSuccess extends StatefulWidget { @@ -622,13 +629,97 @@ class _BookSuccessState extends State { }, patientShare: widget.patientShareResponse.patientShareWithTax))) .then((value) { + selectedPaymentMethod = value[0]; if (value != null) { - openPayment(value, projectViewModel.user, double.parse(patientShareResponse.patientShareWithTax.toString()), patientShareResponse, appo); + if (selectedPaymentMethod == "ApplePay") { + startApplePay(appo, patientShareResponse); + } else { + openPayment(value, projectViewModel.user, double.parse(patientShareResponse.patientShareWithTax.toString()), patientShareResponse, appo); + } projectViewModel.analytics.appointment.payment_method(appointment_type: 'regular', clinic: widget.docObject.clinicName, payment_method: value[0], payment_type: 'appointment'); } }); } + void startApplePay(AppoitmentAllHistoryResultList appo, PatientShareResponse patientShareResponse) async { + String transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); + print("TransactionID: $transID"); + GifLoaderDialogUtils.showMyDialog(context); + + LiveCareService service = new LiveCareService(); + ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); + + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; + await context.read().getProjectDetailsForPayfort(projectId: appo.projectID, serviceId: ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum()).then((value) { + payfortProjectDetailsRespModel = value; + }); + + applePayInsertRequest.clientRequestID = transID; + applePayInsertRequest.clinicID = appo.clinicID; + applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; + applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; + applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; + applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); + applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); + applePayInsertRequest.doctorID = appo.doctorID; + applePayInsertRequest.projectID = appo.projectID.toString(); + applePayInsertRequest.serviceID = ServiceTypeEnum.advancePayment.getIdFromServiceEnum().toString(); + applePayInsertRequest.channelID = 3; + applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; + applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; + applePayInsertRequest.appointmentDate = appo.appointmentDate; + applePayInsertRequest.appointmentNo = appo.appointmentNo; + applePayInsertRequest.orderDescription = "Advance Payment"; + applePayInsertRequest.liveServiceID = "0"; + applePayInsertRequest.latitude = "0.0"; + applePayInsertRequest.longitude = "0.0"; + applePayInsertRequest.amount = patientShareResponse.patientShareWithTax.toString(); + applePayInsertRequest.isSchedule = appo.isLiveCareAppointment ? "1" : "0"; + applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.paymentOption = "ApplePay"; + + applePayInsertRequest.isMobSDK = true; + applePayInsertRequest.merchantReference = transID; + applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; + applePayInsertRequest.commandType = "PURCHASE"; + applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; + applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; + applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; + applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; + applePayInsertRequest.returnURL = ""; + + service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { + await context.read().initiateApplePayWithPayfort( + customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, + customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + orderDescription: "Appointment Payment", + orderAmount: double.parse(patientShareResponse.patientShareWithTax.toString()), + merchantReference: transID, + payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + onFailed: (failureResult) async { + log("failureResult: ${failureResult.toString()}"); + AppToast.showErrorToast(message: failureResult.toString()); + }, + onSuccess: (successResult) async { + log("Payfort: ${successResult.responseMessage}"); + await context.read().addPayfortApplePayResponse(result: successResult); + checkPaymentStatus(appo); + }, + projectId: appo.projectID, + serviceTypeEnum: ServiceTypeEnum.appointmentPayment, + ); + }).catchError((err) { + print(err); + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: err); + }); + } + openPayment(List paymentMethod, AuthenticatedUser authenticatedUser, num amount, PatientShareResponse patientShareResponse, AppoitmentAllHistoryResultList appo) async { widget.browser = new MyInAppBrowser(onExitCallback: onBrowserExit, appo: appo, onLoadStartCallback: onBrowserLoadStart, context: context); selectedPaymentMethod = paymentMethod[0]; diff --git a/lib/pages/ToDoList/ToDo.dart b/lib/pages/ToDoList/ToDo.dart index 2ba88f10..d353180a 100644 --- a/lib/pages/ToDoList/ToDo.dart +++ b/lib/pages/ToDoList/ToDo.dart @@ -1377,7 +1377,6 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, onFailed: (failureResult) async { log("failureResult: ${failureResult.toString()}"); - // GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: failureResult.toString()); }, onSuccess: (successResult) async { diff --git a/lib/pages/livecare/widgets/clinic_list.dart b/lib/pages/livecare/widgets/clinic_list.dart index bbf7a159..5a220947 100644 --- a/lib/pages/livecare/widgets/clinic_list.dart +++ b/lib/pages/livecare/widgets/clinic_list.dart @@ -1,10 +1,14 @@ +import 'dart:developer'; import 'dart:io'; +import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; +import 'package:diplomaticquarterapp/models/LiveCare/ApplePayInsertRequest.dart'; import 'package:diplomaticquarterapp/models/LiveCare/ERAppointmentFeesResponse.dart'; import 'package:diplomaticquarterapp/models/LiveCare/LiveCareClinicsListResponse.dart'; import 'package:diplomaticquarterapp/models/LiveCare/LiveCareScheduleClinicsListResponse.dart'; @@ -18,6 +22,8 @@ import 'package:diplomaticquarterapp/pages/livecare/widgets/clinic_card.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/PlatformBridge.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; @@ -296,7 +302,8 @@ class _clinic_listState extends State { appo.clinicID = selectedClinicID; appo.appointmentNo = DateTime.now().millisecondsSinceEpoch; - appo.projectID = 12; + appo.projectID = BASE_URL.contains("uat.") ? 15 : 12; + appo.isLiveCareAppointment = false; if (await this.sharedPref.getObject(USER_PROFILE) != null) { var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE)); @@ -318,16 +325,100 @@ class _clinic_listState extends State { patientShare: num.parse(getERAppointmentFeesList.total), isFromAdvancePayment: widget.isPharmacyLiveCare, ))).then((value) { + selectedPaymentMethod = value[0]; print(value); widget.isPharmacyLiveCare = isPharmacyLiveCare; widget.pharmacyLiveCareQRCode = pharmaLiveCareQRCodeValue; if (value != null) { - openPayment(value, authUser, num.parse(getERAppointmentFeesList.total), appo); + if (selectedPaymentMethod == "ApplePay") { + startApplePay(appo, getERAppointmentFeesList.total); + } else { + openPayment(value, authUser, num.parse(getERAppointmentFeesList.total), appo); + } projectViewModel.analytics.liveCare.payment_method(appointment_type: 'livecare', clinic: selectedClinicName, payment_method: value[0], payment_type: 'appointment'); } }); } + void startApplePay(AppoitmentAllHistoryResultList appo, String amount) async { + String transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); + print("TransactionID: $transID"); + GifLoaderDialogUtils.showMyDialog(context); + + LiveCareService service = new LiveCareService(); + ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); + + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; + await context.read().getProjectDetailsForPayfort(projectId: appo.projectID, serviceId: ServiceTypeEnum.liveCareAppointment.getIdFromServiceEnum(), languageID: projectViewModel.isArabic ? 1 : 2).then((value) { + payfortProjectDetailsRespModel = value; + }); + + applePayInsertRequest.clientRequestID = transID; + applePayInsertRequest.clinicID = appo.clinicID; + applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; + applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; + applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; + applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); + applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); + applePayInsertRequest.doctorID = appo.doctorID; + applePayInsertRequest.projectID = appo.projectID.toString(); + applePayInsertRequest.serviceID = ServiceTypeEnum.liveCareAppointment.getIdFromServiceEnum().toString(); + applePayInsertRequest.channelID = 3; + applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; + applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; + applePayInsertRequest.appointmentDate = appo.appointmentDate; + applePayInsertRequest.appointmentNo = appo.appointmentNo; + applePayInsertRequest.orderDescription = "LiveCare Payment"; + applePayInsertRequest.liveServiceID = "0"; + applePayInsertRequest.latitude = "0.0"; + applePayInsertRequest.longitude = "0.0"; + applePayInsertRequest.amount = amount; + applePayInsertRequest.isSchedule = appo.isLiveCareAppointment ? "1" : "0"; + applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.paymentOption = "ApplePay"; + + applePayInsertRequest.isMobSDK = true; + applePayInsertRequest.merchantReference = transID; + applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; + applePayInsertRequest.commandType = "PURCHASE"; + applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; + applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; + applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; + applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; + applePayInsertRequest.returnURL = ""; + + service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { + await context.read().initiateApplePayWithPayfort( + customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, + customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + orderDescription: "LiveCare Payment", + orderAmount: double.parse(amount), + merchantReference: transID, + payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + onFailed: (failureResult) async { + log("failureResult: ${failureResult.toString()}"); + AppToast.showErrorToast(message: failureResult.toString()); + }, + onSuccess: (successResult) async { + log("Payfort: ${successResult.responseMessage}"); + await context.read().addPayfortApplePayResponse(result: successResult); + checkPaymentStatus(appo); + }, + projectId: appo.projectID, + serviceTypeEnum: ServiceTypeEnum.appointmentPayment, + ); + }).catchError((err) { + print(err); + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: err); + }); + } + openPayment(List paymentMethod, AuthenticatedUser authenticatedUser, num amount, AppoitmentAllHistoryResultList appo) { browser = new MyInAppBrowser(onExitCallback: onBrowserExit, appo: appo, onLoadStartCallback: onBrowserLoadStart, context: context); diff --git a/lib/services/payfort_services/payfort_service.dart b/lib/services/payfort_services/payfort_service.dart index e684d1bd..5a00700c 100644 --- a/lib/services/payfort_services/payfort_service.dart +++ b/lib/services/payfort_services/payfort_service.dart @@ -20,8 +20,8 @@ class PayfortService extends BaseService { ); } - Future getPayfortConfigurations({int serviceId, int projectId, int integrationId = 2}) async { - Map body = {"Integration_Id": integrationId, "ServID": serviceId, "ProjectID": projectId}; + Future getPayfortConfigurations({int serviceId, int projectId, int integrationId = 2, int languageID}) async { + Map body = {"Integration_Id": integrationId, "ServID": serviceId, "ProjectID": projectId, "LanguageID": languageID}; PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel(); await baseAppClient.post( diff --git a/lib/services/payfort_services/payfort_view_model.dart b/lib/services/payfort_services/payfort_view_model.dart index 4a9038b0..f57e936b 100644 --- a/lib/services/payfort_services/payfort_view_model.dart +++ b/lib/services/payfort_services/payfort_view_model.dart @@ -15,10 +15,10 @@ class PayfortViewModel extends ChangeNotifier { await _payfortService.initPayfortSDK(); } - Future getProjectDetailsForPayfort({int serviceId, int projectId}) async { + Future getProjectDetailsForPayfort({int serviceId, int projectId, int languageID}) async { PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel(); try { - payfortProjectDetailsRespModel = await _payfortService.getPayfortConfigurations(serviceId: serviceId, projectId: projectId); + payfortProjectDetailsRespModel = await _payfortService.getPayfortConfigurations(serviceId: serviceId, projectId: projectId, languageID: languageID); String signature = await _payfortService.getPayfortSignature(payfortProjectDetailsRespModel.accessCode, payfortProjectDetailsRespModel.merchantIdentifier, payfortProjectDetailsRespModel.shaRequest); From fe7c2c6873e9b861a939f113c53697ddbb201fbc Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Sun, 14 Jan 2024 10:16:06 +0300 Subject: [PATCH 08/17] CR 6631 --- lib/core/service/er/er_service.dart | 1 + lib/core/service/hospital_service.dart | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/core/service/er/er_service.dart b/lib/core/service/er/er_service.dart index 5b7552bb..445fa6c1 100644 --- a/lib/core/service/er/er_service.dart +++ b/lib/core/service/er/er_service.dart @@ -20,6 +20,7 @@ class ErService extends BaseService { var long = await sharedPref.getDouble(USER_LONG); body['Latitude'] = lat ?? 0; body['Longitude'] = long ?? 0; + body['IsForER'] = true; dynamic localRes; diff --git a/lib/core/service/hospital_service.dart b/lib/core/service/hospital_service.dart index e6dc7727..f07880fe 100644 --- a/lib/core/service/hospital_service.dart +++ b/lib/core/service/hospital_service.dart @@ -59,6 +59,7 @@ class HospitalService extends BaseService { body['IsOnlineCheckIn'] = isResBasedOnLoc; body['IsAdvancePayment'] = isAdvancePayment; body['LanguageID'] = languageID; + body['IsForER'] = true; await baseAppClient.post(GET_PROJECT, onSuccess: (dynamic response, int statusCode) { _hospitals.clear(); From ec0bed04d3e98d5e1250322853d43496b6f798ef Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Sun, 14 Jan 2024 17:01:12 +0300 Subject: [PATCH 09/17] Apple Pay in production implemented & tested --- lib/config/config.dart | 12 ++- .../ancillaryOrdersDetails.dart | 96 ++++++++++++++++++- lib/pages/BookAppointment/BookSuccess.dart | 2 + lib/pages/ToDoList/ToDo.dart | 2 + lib/pages/livecare/widgets/clinic_list.dart | 7 +- .../medical/balance/confirm_payment_page.dart | 3 + .../payfort_services/payfort_view_model.dart | 2 + lib/uitl/utils.dart | 2 +- lib/widgets/in_app_browser/InAppBrowser.dart | 4 +- 9 files changed, 120 insertions(+), 10 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index 4831aeb6..1186bfbd 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -21,8 +21,8 @@ var PACKAGES_ORDERS = '/api/orders'; var PACKAGES_ORDER_HISTORY = '/api/orders/items'; var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara'; // var BASE_URL = 'http://10.20.200.111:1010/'; - var BASE_URL = 'https://uat.hmgwebservices.com/'; -// var BASE_URL = 'https://hmgwebservices.com/'; + // var BASE_URL = 'https://uat.hmgwebservices.com/'; +var BASE_URL = 'https://hmgwebservices.com/'; // var BASE_URL = 'https://orash.cloudsolutions.com.sa/'; // var BASE_URL = 'https://vidauat.cloudsolutions.com.sa/'; // var BASE_URL = 'https://vidamergeuat.cloudsolutions.com.sa/'; @@ -340,7 +340,7 @@ var UPDATE_COVID_QUESTIONNAIRE = 'Services/Doctors.svc/REST/COVID19_Questionnari var CHANNEL = 3; var GENERAL_ID = 'Cs2020@2016\$2958'; var IP_ADDRESS = '10.20.10.20'; -var VERSION_ID = 11.5; +var VERSION_ID = 11.9; var SETUP_ID = '91877'; var LANGUAGE = 2; // var PATIENT_OUT_SA = 0; @@ -626,8 +626,10 @@ var CONVERT_PATIENT_TO_CASH = 'Services/Doctors.svc/REST/deActivateInsuranceComp //PAYFORT var getPayFortProjectDetails = "Services/PayFort_Serv.svc/REST/GetPayFortProjectDetails"; var addPayFortApplePayResponse = "Services/PayFort_Serv.svc/REST/AddResponse"; -var payFortEnvironment = FortEnvironment.test; -var applePayMerchantId = "merchant.com.hmgwebservices.uat"; +var payFortEnvironment = FortEnvironment.production; +// var payFortEnvironment = FortEnvironment.test; +// var applePayMerchantId = "merchant.com.hmgwebservices.uat"; +var applePayMerchantId = "merchant.com.hmgwebservices"; class AppGlobal { diff --git a/lib/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart b/lib/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart index 8e224320..d7d5f983 100644 --- a/lib/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart +++ b/lib/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart @@ -1,18 +1,26 @@ +import 'dart:developer'; import 'dart:io'; import "package:collection/collection.dart"; import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart'; import 'package:diplomaticquarterapp/core/service/ancillary_orders_service.dart'; import 'package:diplomaticquarterapp/core/viewModels/ancillary_orders_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; +import 'package:diplomaticquarterapp/models/LiveCare/ApplePayInsertRequest.dart'; import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_order_proc_model.dart'; import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_orders_proc_list.dart'; import 'package:diplomaticquarterapp/pages/ToDoList/payment_method_select.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; +import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart'; +import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; @@ -507,13 +515,99 @@ class _AnicllaryOrdersState extends State with SingleTic onSelectedMethod: (String method, [String selectedInstallmentPlan]) { selectedPaymentMethod = method; this.selectedInstallmentPlan = selectedInstallmentPlan; - openPayment(selectedPaymentMethod, projectViewModel.user, double.parse(getTotalValue()), null, selectedInstallmentPlan); + if (selectedPaymentMethod == "ApplePay") { + startApplePay(); + } else { + openPayment(selectedPaymentMethod, projectViewModel.user, double.parse(getTotalValue()), null, selectedInstallmentPlan); + } }, patientShare: double.parse(getTotalValue()), isFromAdvancePayment: !projectViewModel.havePrivilege(94), )); } + void startApplePay() async { + transID = Utils.getAdvancePaymentTransID(widget.projectID, projectViewModel.user.patientID); + + print("TransactionID: $transID"); + GifLoaderDialogUtils.showMyDialog(context); + + LiveCareService service = new LiveCareService(); + ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); + + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; + await context.read().getProjectDetailsForPayfort(projectId: widget.projectID, serviceId: ServiceTypeEnum.ancillaryOrder.getIdFromServiceEnum()).then((value) { + payfortProjectDetailsRespModel = value; + }); + + applePayInsertRequest.clientRequestID = transID; + applePayInsertRequest.clinicID = 0; + applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; + applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; + applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; + applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); + applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); + applePayInsertRequest.doctorID = 0; + applePayInsertRequest.projectID = widget.projectID.toString(); + applePayInsertRequest.serviceID = ServiceTypeEnum.advancePayment.getIdFromServiceEnum().toString(); + applePayInsertRequest.channelID = 3; + applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; + applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; + applePayInsertRequest.appointmentDate = null; + applePayInsertRequest.appointmentNo = 0; + applePayInsertRequest.orderDescription = "Advance Payment"; + applePayInsertRequest.liveServiceID = "0"; + applePayInsertRequest.latitude = "0.0"; + applePayInsertRequest.longitude = "0.0"; + applePayInsertRequest.amount = double.parse(getTotalValue()).toString(); + applePayInsertRequest.isSchedule = "0"; + applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.languageID = projectViewModel.isArabic ? 1 : 2; + applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.paymentOption = "ApplePay"; + + applePayInsertRequest.isMobSDK = true; + applePayInsertRequest.merchantReference = transID; + applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; + applePayInsertRequest.commandType = "PURCHASE"; + applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; + applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; + applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; + applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; + applePayInsertRequest.returnURL = ""; + + service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { + await context.read().initiateApplePayWithPayfort( + customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, + customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + orderDescription: "Ancillary Order Payment", + orderAmount: double.parse(getTotalValue()), + merchantReference: transID, + payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + currency: projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR", + onFailed: (failureResult) async { + log("failureResult: ${failureResult.toString()}"); + AppToast.showErrorToast(message: failureResult.toString()); + }, + onSuccess: (successResult) async { + log("Payfort: ${successResult.responseMessage}"); + await context.read().addPayfortApplePayResponse(result: successResult); + checkPaymentStatus(AppoitmentAllHistoryResultList()); + }, + projectId: widget.projectID, + serviceTypeEnum: ServiceTypeEnum.ancillaryOrder, + ); + }).catchError((err) { + print(err); + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: err); + }); + } + openPayment(String paymentMethod, AuthenticatedUser authenticatedUser, num amount, AppoitmentAllHistoryResultList appo, [String selectedInstallmentPlan]) { browser = new MyInAppBrowser(onExitCallback: onBrowserExit, appo: appo, onLoadStartCallback: onBrowserLoadStart); diff --git a/lib/pages/BookAppointment/BookSuccess.dart b/lib/pages/BookAppointment/BookSuccess.dart index 8e29e908..f41d5a84 100644 --- a/lib/pages/BookAppointment/BookSuccess.dart +++ b/lib/pages/BookAppointment/BookSuccess.dart @@ -678,6 +678,7 @@ class _BookSuccessState extends State { applePayInsertRequest.amount = patientShareResponse.patientShareWithTax.toString(); applePayInsertRequest.isSchedule = appo.isLiveCareAppointment ? "1" : "0"; applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.languageID = projectViewModel.isArabic ? 1 : 2; applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; @@ -701,6 +702,7 @@ class _BookSuccessState extends State { orderAmount: double.parse(patientShareResponse.patientShareWithTax.toString()), merchantReference: transID, payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + currency: projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR", onFailed: (failureResult) async { log("failureResult: ${failureResult.toString()}"); AppToast.showErrorToast(message: failureResult.toString()); diff --git a/lib/pages/ToDoList/ToDo.dart b/lib/pages/ToDoList/ToDo.dart index d353180a..488b52a1 100644 --- a/lib/pages/ToDoList/ToDo.dart +++ b/lib/pages/ToDoList/ToDo.dart @@ -1352,6 +1352,7 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { applePayInsertRequest.amount = patientShareResponse.patientShareWithTax.toString(); applePayInsertRequest.isSchedule = appo.isLiveCareAppointment ? "1" : "0"; applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.languageID = projectViewModel.isArabic ? 1 : 2; applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; @@ -1375,6 +1376,7 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { orderAmount: double.parse(patientShareResponse.patientShareWithTax.toString()), merchantReference: transID, payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + currency: projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR", onFailed: (failureResult) async { log("failureResult: ${failureResult.toString()}"); AppToast.showErrorToast(message: failureResult.toString()); diff --git a/lib/pages/livecare/widgets/clinic_list.dart b/lib/pages/livecare/widgets/clinic_list.dart index 5a220947..f8294150 100644 --- a/lib/pages/livecare/widgets/clinic_list.dart +++ b/lib/pages/livecare/widgets/clinic_list.dart @@ -349,7 +349,10 @@ class _clinic_listState extends State { ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; - await context.read().getProjectDetailsForPayfort(projectId: appo.projectID, serviceId: ServiceTypeEnum.liveCareAppointment.getIdFromServiceEnum(), languageID: projectViewModel.isArabic ? 1 : 2).then((value) { + await context + .read() + .getProjectDetailsForPayfort(projectId: appo.projectID, serviceId: ServiceTypeEnum.liveCareAppointment.getIdFromServiceEnum(), languageID: projectViewModel.isArabic ? 1 : 2) + .then((value) { payfortProjectDetailsRespModel = value; }); @@ -377,6 +380,7 @@ class _clinic_listState extends State { applePayInsertRequest.amount = amount; applePayInsertRequest.isSchedule = appo.isLiveCareAppointment ? "1" : "0"; applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.languageID = projectViewModel.isArabic ? 1 : 2; applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; @@ -400,6 +404,7 @@ class _clinic_listState extends State { orderAmount: double.parse(amount), merchantReference: transID, payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + currency: projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR", onFailed: (failureResult) async { log("failureResult: ${failureResult.toString()}"); AppToast.showErrorToast(message: failureResult.toString()); diff --git a/lib/pages/medical/balance/confirm_payment_page.dart b/lib/pages/medical/balance/confirm_payment_page.dart index b754b987..8a70c6f9 100644 --- a/lib/pages/medical/balance/confirm_payment_page.dart +++ b/lib/pages/medical/balance/confirm_payment_page.dart @@ -281,6 +281,7 @@ class _ConfirmPaymentPageState extends State { applePayInsertRequest.amount = widget.advanceModel.amount.toString(); applePayInsertRequest.isSchedule = "0"; applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.languageID = projectViewModel.isArabic ? 1 : 2; applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; @@ -304,8 +305,10 @@ class _ConfirmPaymentPageState extends State { orderAmount: double.parse(widget.advanceModel.amount), merchantReference: transID, payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + currency: projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR", onFailed: (failureResult) async { log("failureResult: ${failureResult.toString()}"); + AppToast.showErrorToast(message: failureResult.toString()); }, onSuccess: (successResult) async { log("Payfort: ${successResult.responseMessage}"); diff --git a/lib/services/payfort_services/payfort_view_model.dart b/lib/services/payfort_services/payfort_view_model.dart index f57e936b..5bef18a8 100644 --- a/lib/services/payfort_services/payfort_view_model.dart +++ b/lib/services/payfort_services/payfort_view_model.dart @@ -51,6 +51,7 @@ class PayfortViewModel extends ChangeNotifier { FailedCallback onFailed, ServiceTypeEnum serviceTypeEnum, int projectId, + String currency, }) async { // GifLoaderDialogUtils.showMyDialog(AppGlobal.context); // PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = await getProjectDetailsForPayfort(projectId: projectId, serviceId: serviceTypeEnum.getIdFromServiceEnum()); @@ -72,6 +73,7 @@ class PayfortViewModel extends ChangeNotifier { merchantIdentifier: payfortProjectDetailsRespModel.merchantIdentifier ?? "", applePayAccessCode: payfortProjectDetailsRespModel.accessCode ?? "", applePayShaRequestPhrase: payfortProjectDetailsRespModel.shaRequest ?? "", + currency: currency, ); GifLoaderDialogUtils.hideDialog(AppGlobal.context); } catch (e) { diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index 77522108..8c48157a 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -154,7 +154,7 @@ class Utils { } static String getAppointmentTransID(int projectID, int clinicID, int appoNo) { - return projectID.toString() + '-' + clinicID.toString() + '-' + appoNo.toString(); + return projectID.toString() + '-' + clinicID.toString() + '-' + appoNo.toString() + '-' + DateTime.now().millisecondsSinceEpoch.toString(); } static String getAdvancePaymentTransID(int projectID, int fileNumber) { diff --git a/lib/widgets/in_app_browser/InAppBrowser.dart b/lib/widgets/in_app_browser/InAppBrowser.dart index c71b206b..c9fecbf9 100644 --- a/lib/widgets/in_app_browser/InAppBrowser.dart +++ b/lib/widgets/in_app_browser/InAppBrowser.dart @@ -40,9 +40,9 @@ class MyInAppBrowser extends InAppBrowser { // static String APPLE_PAY_PAYFORT_URL = 'https://hmgwebservices.com/PayFortWebLive/PayFortApi/MakeApplePayRequest'; // Payfort Payment Gateway URL LIVE static String APPLE_PAY_PAYFORT_URL = 'https://hmgwebservices.com/PayFortWebLive/PayFortApi/MakeApplePayRequest'; // Payfort Payment Gateway URL UAT - static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort Payment Gateway URL UAT + // static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort Payment Gateway URL UAT - // static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL LIVE + static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL LIVE // static String SERVICE_URL = 'https://uat.hmgwebservices.com/payfortforvidaplus/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL UAT VIDA PLUS From 48202ffd120ecccc66da49ffbf3d99341885b850 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 15 Jan 2024 14:02:32 +0300 Subject: [PATCH 10/17] updates --- lib/pages/livecare/widgets/clinic_list.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pages/livecare/widgets/clinic_list.dart b/lib/pages/livecare/widgets/clinic_list.dart index 8a3a2d8f..e19d6105 100644 --- a/lib/pages/livecare/widgets/clinic_list.dart +++ b/lib/pages/livecare/widgets/clinic_list.dart @@ -407,6 +407,7 @@ class _clinic_listState extends State { currency: projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR", onFailed: (failureResult) async { log("failureResult: ${failureResult.toString()}"); + GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: failureResult.toString()); }, onSuccess: (successResult) async { From d3bdcfa9752806223830faa28cc54319a0171543 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 15 Jan 2024 16:52:17 +0300 Subject: [PATCH 11/17] Apple Pay code merged into main branch --- lib/config/config.dart | 8 +- .../ancillaryOrdersDetails.dart | 2 + lib/pages/BookAppointment/BookSuccess.dart | 8 +- lib/pages/ToDoList/ToDo.dart | 9 +- lib/pages/livecare/widgets/clinic_list.dart | 224 +++++++++--------- .../payfort_services/payfort_service.dart | 5 - 6 files changed, 123 insertions(+), 133 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index f63eb699..bc651005 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -21,8 +21,8 @@ var PACKAGES_ORDERS = '/api/orders'; var PACKAGES_ORDER_HISTORY = '/api/orders/items'; var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara'; // var BASE_URL = 'http://10.50.100.198:4422/'; -var BASE_URL = 'https://uat.hmgwebservices.com/'; -// var BASE_URL = 'https://hmgwebservices.com/'; +// var BASE_URL = 'https://uat.hmgwebservices.com/'; +var BASE_URL = 'https://hmgwebservices.com/'; // var BASE_URL = 'http://10.20.200.111:1010/'; // var BASE_URL = 'https://uat.hmgwebservices.com/'; // var BASE_URL = 'https://hmgwebservices.com/'; @@ -343,7 +343,7 @@ var UPDATE_COVID_QUESTIONNAIRE = 'Services/Doctors.svc/REST/COVID19_Questionnari var CHANNEL = 3; var GENERAL_ID = 'Cs2020@2016\$2958'; var IP_ADDRESS = '10.20.10.20'; -var VERSION_ID = 11.9; +var VERSION_ID = 12.0; var SETUP_ID = '91877'; var LANGUAGE = 2; // var PATIENT_OUT_SA = 0; @@ -630,9 +630,9 @@ var CONVERT_PATIENT_TO_CASH = 'Services/Doctors.svc/REST/deActivateInsuranceComp var getPayFortProjectDetails = "Services/PayFort_Serv.svc/REST/GetPayFortProjectDetails"; var addPayFortApplePayResponse = "Services/PayFort_Serv.svc/REST/AddResponse"; var payFortEnvironment = FortEnvironment.production; +var applePayMerchantId = "merchant.com.hmgwebservices"; // var payFortEnvironment = FortEnvironment.test; // var applePayMerchantId = "merchant.com.hmgwebservices.uat"; -var applePayMerchantId = "merchant.com.hmgwebservices"; class AppGlobal { diff --git a/lib/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart b/lib/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart index d7d5f983..701fc269 100644 --- a/lib/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart +++ b/lib/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart @@ -15,6 +15,7 @@ import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_order_pro import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_orders_proc_list.dart'; import 'package:diplomaticquarterapp/pages/ToDoList/payment_method_select.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart'; import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart'; @@ -803,6 +804,7 @@ class _AnicllaryOrdersState extends State with SingleTic okFunction: () { AlertDialogBox.closeAlertDialog(context); Navigator.of(context).pop(); + Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => LandingPage()), (Route r) => false); }).showAlertDialog(context); } diff --git a/lib/pages/BookAppointment/BookSuccess.dart b/lib/pages/BookAppointment/BookSuccess.dart index 7cce4fcf..f6ece784 100644 --- a/lib/pages/BookAppointment/BookSuccess.dart +++ b/lib/pages/BookAppointment/BookSuccess.dart @@ -64,6 +64,7 @@ class _BookSuccessState extends State { String selectedInstallments = ""; String tamaraPaymentStatus; String tamaraOrderID; + String transID; @override initState() { @@ -642,7 +643,7 @@ class _BookSuccessState extends State { } void startApplePay(AppoitmentAllHistoryResultList appo, PatientShareResponse patientShareResponse) async { - String transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); + transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); print("TransactionID: $transID"); GifLoaderDialogUtils.showMyDialog(context); @@ -726,10 +727,11 @@ class _BookSuccessState extends State { widget.browser = new MyInAppBrowser(onExitCallback: onBrowserExit, appo: appo, onLoadStartCallback: onBrowserLoadStart, context: context); selectedPaymentMethod = paymentMethod[0]; selectedInstallments = paymentMethod[1]; + transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); widget.browser.openPaymentBrowser( amount, "Appointment check in", - Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo), + transID, appo.projectID.toString(), authenticatedUser.emailAddress, paymentMethod[0], @@ -884,7 +886,7 @@ class _BookSuccessState extends State { final currency = projectViewModel.user.outSA == 0 ? "sar" : 'aed'; GifLoaderDialogUtils.showMyDialog(context); DoctorsListService service = new DoctorsListService(); - service.checkPaymentStatus(Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo), false, context).then((res) { + service.checkPaymentStatus(transID, false, context).then((res) { String paymentInfo = res['Response_Message']; if (paymentInfo == 'Success') { txn_ref = res['Merchant_Reference']; diff --git a/lib/pages/ToDoList/ToDo.dart b/lib/pages/ToDoList/ToDo.dart index d30ef0fd..771a6557 100644 --- a/lib/pages/ToDoList/ToDo.dart +++ b/lib/pages/ToDoList/ToDo.dart @@ -92,6 +92,7 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { List appoList = []; List ancillaryLists = []; List obGyneAppoList = []; + String transID; @override void initState() { @@ -1061,11 +1062,11 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { openPayment(List paymentMethod, AuthenticatedUser authenticatedUser, num amount, PatientShareResponse patientShareResponse, AppoitmentAllHistoryResultList appo) { browser = new MyInAppBrowser(onExitCallback: onBrowserExit, appo: appo, onLoadStartCallback: onBrowserLoadStart, context: context); - + transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); browser.openPaymentBrowser( amount, "Appointment check in", - Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo), + transID, appo.projectID.toString(), authenticatedUser.emailAddress, paymentMethod[0], @@ -1214,7 +1215,7 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { final currency = projectViewModel.user.outSA == 0 ? "sar" : 'aed'; GifLoaderDialogUtils.showMyDialog(context); DoctorsListService service = new DoctorsListService(); - service.checkPaymentStatus(Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo), false, context).then((res) { + service.checkPaymentStatus(transID, false, context).then((res) { GifLoaderDialogUtils.hideDialog(context); String paymentInfo = res['Response_Message']; if (paymentInfo == 'Success') { @@ -1319,7 +1320,7 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { } void startApplePay(AppoitmentAllHistoryResultList appo, PatientShareResponse patientShareResponse) async { - String transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); + transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); print("TransactionID: $transID"); GifLoaderDialogUtils.showMyDialog(context); diff --git a/lib/pages/livecare/widgets/clinic_list.dart b/lib/pages/livecare/widgets/clinic_list.dart index e19d6105..f0beb79b 100644 --- a/lib/pages/livecare/widgets/clinic_list.dart +++ b/lib/pages/livecare/widgets/clinic_list.dart @@ -89,6 +89,9 @@ class _clinic_listState extends State { String tamaraOrderID; String selectedInstallmentPlan; + String transID; + BuildContext localContext; + @override void initState() { liveCareClinicsListResponse = new LiveCareClinicsListResponse(); @@ -114,6 +117,7 @@ class _clinic_listState extends State { @override Widget build(BuildContext context) { projectViewModel = Provider.of(context); + localContext = context; getLanguageID(); return Container( child: currentSelectedLiveCareType == "immediate" ? getLiveCareImmediateClinicList() : getLiveCareScheduleClinicList(), @@ -325,134 +329,123 @@ class _clinic_listState extends State { patientShare: num.parse(getERAppointmentFeesList.total), isFromAdvancePayment: widget.isPharmacyLiveCare, ))).then((value) { - selectedPaymentMethod = value[0]; - print(value); - widget.isPharmacyLiveCare = isPharmacyLiveCare; - widget.pharmacyLiveCareQRCode = pharmaLiveCareQRCodeValue; if (value != null) { - if (selectedPaymentMethod == "ApplePay") { - startApplePay(appo, getERAppointmentFeesList.total); - } else { - openPayment(value, authUser, num.parse(getERAppointmentFeesList.total), appo); + selectedPaymentMethod = value[0]; + print(value); + widget.isPharmacyLiveCare = isPharmacyLiveCare; + widget.pharmacyLiveCareQRCode = pharmaLiveCareQRCodeValue; + if (value != null) { + if (selectedPaymentMethod == "ApplePay") { + startApplePay(appo, getERAppointmentFeesList.total); + } else { + openPayment(value, authUser, num.parse(getERAppointmentFeesList.total), appo); + } + projectViewModel.analytics.liveCare.payment_method(appointment_type: 'livecare', clinic: selectedClinicName, payment_method: value[0], payment_type: 'appointment'); } - projectViewModel.analytics.liveCare.payment_method(appointment_type: 'livecare', clinic: selectedClinicName, payment_method: value[0], payment_type: 'appointment'); } }); } void startApplePay(AppoitmentAllHistoryResultList appo, String amount) async { - String transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); - print("TransactionID: $transID"); - GifLoaderDialogUtils.showMyDialog(context); - - LiveCareService service = new LiveCareService(); - ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); - - PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; - await context - .read() - .getProjectDetailsForPayfort(projectId: appo.projectID, serviceId: ServiceTypeEnum.liveCareAppointment.getIdFromServiceEnum(), languageID: projectViewModel.isArabic ? 1 : 2) - .then((value) { - payfortProjectDetailsRespModel = value; - }); + try { + transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); + print("TransactionID: $transID"); + GifLoaderDialogUtils.showMyDialog(localContext); + + LiveCareService service = new LiveCareService(); + ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest(); + + PayfortProjectDetailsRespModel payfortProjectDetailsRespModel; + await localContext + .read() + .getProjectDetailsForPayfort(projectId: appo.projectID, serviceId: ServiceTypeEnum.liveCareAppointment.getIdFromServiceEnum(), languageID: projectViewModel.isArabic ? 1 : 2) + .then((value) { + payfortProjectDetailsRespModel = value; + }); - applePayInsertRequest.clientRequestID = transID; - applePayInsertRequest.clinicID = appo.clinicID; - applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; - applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; - applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; - applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; - applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); - applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); - applePayInsertRequest.doctorID = appo.doctorID; - applePayInsertRequest.projectID = appo.projectID.toString(); - applePayInsertRequest.serviceID = ServiceTypeEnum.liveCareAppointment.getIdFromServiceEnum().toString(); - applePayInsertRequest.channelID = 3; - applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; - applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; - applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; - applePayInsertRequest.appointmentDate = appo.appointmentDate; - applePayInsertRequest.appointmentNo = appo.appointmentNo; - applePayInsertRequest.orderDescription = "LiveCare Payment"; - applePayInsertRequest.liveServiceID = "0"; - applePayInsertRequest.latitude = "0.0"; - applePayInsertRequest.longitude = "0.0"; - applePayInsertRequest.amount = amount; - applePayInsertRequest.isSchedule = appo.isLiveCareAppointment ? "1" : "0"; - applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; - applePayInsertRequest.languageID = projectViewModel.isArabic ? 1 : 2; - applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; - applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; - applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; - applePayInsertRequest.paymentOption = "ApplePay"; - - applePayInsertRequest.isMobSDK = true; - applePayInsertRequest.merchantReference = transID; - applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; - applePayInsertRequest.commandType = "PURCHASE"; - applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; - applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; - applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; - applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; - applePayInsertRequest.returnURL = ""; - - service.applePayInsertRequest(applePayInsertRequest, context).then((res) async { - await context.read().initiateApplePayWithPayfort( - customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, - customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, - orderDescription: "LiveCare Payment", - orderAmount: double.parse(amount), - merchantReference: transID, - payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, - currency: projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR", - onFailed: (failureResult) async { - log("failureResult: ${failureResult.toString()}"); - GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: failureResult.toString()); - }, - onSuccess: (successResult) async { - log("Payfort: ${successResult.responseMessage}"); - await context.read().addPayfortApplePayResponse(result: successResult); - checkPaymentStatus(appo); - }, - projectId: appo.projectID, - serviceTypeEnum: ServiceTypeEnum.appointmentPayment, - ); - }).catchError((err) { - print(err); - GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: err); - }); + applePayInsertRequest.clientRequestID = transID; + applePayInsertRequest.clinicID = appo.clinicID; + applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR"; + applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress; + applePayInsertRequest.customerID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.customerName = projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName; + applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN); + applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN); + applePayInsertRequest.doctorID = appo.doctorID; + applePayInsertRequest.projectID = appo.projectID.toString(); + applePayInsertRequest.serviceID = ServiceTypeEnum.liveCareAppointment.getIdFromServiceEnum().toString(); + applePayInsertRequest.channelID = 3; + applePayInsertRequest.patientID = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.patientTypeID = projectViewModel.authenticatedUserObject.user.patientType; + applePayInsertRequest.patientOutSA = projectViewModel.authenticatedUserObject.user.outSA; + applePayInsertRequest.appointmentDate = appo.appointmentDate; + applePayInsertRequest.appointmentNo = appo.appointmentNo; + applePayInsertRequest.orderDescription = "LiveCare Payment"; + applePayInsertRequest.liveServiceID = "0"; + applePayInsertRequest.latitude = "0.0"; + applePayInsertRequest.longitude = "0.0"; + applePayInsertRequest.amount = amount; + applePayInsertRequest.isSchedule = appo.isLiveCareAppointment ? "1" : "0"; + applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en'; + applePayInsertRequest.languageID = projectViewModel.isArabic ? 1 : 2; + applePayInsertRequest.userName = projectViewModel.authenticatedUserObject.user.patientID; + applePayInsertRequest.responseContinueURL = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html"; + applePayInsertRequest.paymentOption = "ApplePay"; + + applePayInsertRequest.isMobSDK = true; + applePayInsertRequest.merchantReference = transID; + applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier; + applePayInsertRequest.commandType = "PURCHASE"; + applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature; + applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode; + applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest; + applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse; + applePayInsertRequest.returnURL = ""; + + service.applePayInsertRequest(applePayInsertRequest, localContext).then((res) async { + await localContext.read().initiateApplePayWithPayfort( + customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName, + customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + orderDescription: "LiveCare Payment", + orderAmount: double.parse(amount), + merchantReference: transID, + payfortProjectDetailsRespModel: payfortProjectDetailsRespModel, + currency: projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR", + onFailed: (failureResult) async { + log("failureResult: ${failureResult.toString()}"); + GifLoaderDialogUtils.hideDialog(localContext); + AppToast.showErrorToast(message: failureResult.toString()); + }, + onSuccess: (successResult) async { + GifLoaderDialogUtils.hideDialog(localContext); + log("Payfort: ${successResult.responseMessage}"); + await localContext.read().addPayfortApplePayResponse(result: successResult); + checkPaymentStatus(appo); + }, + projectId: appo.projectID, + serviceTypeEnum: ServiceTypeEnum.appointmentPayment, + ); + }).catchError((err) { + print(err); + GifLoaderDialogUtils.hideDialog(localContext); + AppToast.showErrorToast(message: err); + }); + } catch (ex) { + print(ex.toString()); + GifLoaderDialogUtils.hideDialog(localContext); + } } openPayment(List paymentMethod, AuthenticatedUser authenticatedUser, num amount, AppoitmentAllHistoryResultList appo) { browser = new MyInAppBrowser(onExitCallback: onBrowserExit, appo: appo, onLoadStartCallback: onBrowserLoadStart, context: context); - + transID = Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo); selectedPaymentMethod = paymentMethod[0]; selectedInstallmentPlan = paymentMethod[1]; this.amount = amount.toString(); - browser.openPaymentBrowser( - amount, - "LiveCare Payment", - widget.isPharmacyLiveCare ? widget.pharmacyLiveCareQRCode : Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo), - "12", - authenticatedUser.emailAddress, - paymentMethod[0], - authenticatedUser.patientType, - authenticatedUser.firstName, - authenticatedUser.patientID, - authenticatedUser, - browser, - false, - "4", - selectedClinicID, - context, - "", - "", - "", - "", - paymentMethod[1]); + browser.openPaymentBrowser(amount, "LiveCare Payment", widget.isPharmacyLiveCare ? widget.pharmacyLiveCareQRCode : transID, "12", authenticatedUser.emailAddress, paymentMethod[0], + authenticatedUser.patientType, authenticatedUser.firstName, authenticatedUser.patientID, authenticatedUser, browser, false, "4", selectedClinicID, context, "", "", "", "", paymentMethod[1]); } onBrowserLoadStart(String url) { @@ -560,10 +553,7 @@ class _clinic_listState extends State { final currency = projectViewModel.user.outSA == 0 ? "sar" : 'aed'; DoctorsListService service = new DoctorsListService(); GifLoaderDialogUtils.showMyDialog(context); - service - .checkPaymentStatus( - widget.isPharmacyLiveCare ? widget.pharmacyLiveCareQRCode : Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo), widget.isPharmacyLiveCare, context) - .then((res) { + service.checkPaymentStatus(widget.isPharmacyLiveCare ? widget.pharmacyLiveCareQRCode : transID, widget.isPharmacyLiveCare, context).then((res) { GifLoaderDialogUtils.hideDialog(context); String paymentInfo = res['Response_Message']; amount = res['Amount'].toString(); @@ -611,7 +601,7 @@ class _clinic_listState extends State { isDataLoaded = false; LiveCareService service = new LiveCareService(); GifLoaderDialogUtils.showMyDialog(context); - service.getLivecareClinics(languageID == 'ar' ? 1: 2, context).then((res) { + service.getLivecareClinics(languageID == 'ar' ? 1 : 2, context).then((res) { GifLoaderDialogUtils.hideDialog(context); print(res['PatientER_GetClinicsList'].length); if (res['MessageStatus'] == 1) { diff --git a/lib/services/payfort_services/payfort_service.dart b/lib/services/payfort_services/payfort_service.dart index 5a00700c..d8cef846 100644 --- a/lib/services/payfort_services/payfort_service.dart +++ b/lib/services/payfort_services/payfort_service.dart @@ -49,12 +49,8 @@ class PayfortService extends BaseService { "ECI": result.eci, "Response_Message": result.responseMessage, "Card_Number": result.cardNumber, - // "Card_Bin": result.ca, "Status": result.status, "Merchant_Ref": result.merchantReference, - // Installments_Number - // plan_code - // issuer_code "Pat_Token": result.tokenName, "IsRefund": false, "RemmeberMe": false, @@ -62,7 +58,6 @@ class PayfortService extends BaseService { "LanguageID": 1, }; - // PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel(); await baseAppClient.post( addPayFortApplePayResponse, onSuccess: (response, statusCode) async { From bbc42bd1e739cdd542e0a587487f06fb31893d18 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 16 Jan 2024 08:44:20 +0300 Subject: [PATCH 12/17] updates --- lib/core/service/client/base_app_client.dart | 4 ++-- lib/services/appointment_services/GetDoctorsList.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index f756ba8e..7b294b28 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -280,7 +280,7 @@ class BaseAppClient { } catch (e) { print(e); onFailure(e.toString(), -1); - _analytics.errorTracking.log(endPoint, error: "api exception: $e"); + _analytics.errorTracking.log(endPoint, error: "api exception: $e - API Path: $url"); } } @@ -450,7 +450,7 @@ class BaseAppClient { } catch (e) { print(e); onFailure(e.toString(), -1); - _analytics.errorTracking.log(endPoint, error: "api exception: $e"); + _analytics.errorTracking.log(endPoint, error: "api exception: $e - API Path: $url"); } } diff --git a/lib/services/appointment_services/GetDoctorsList.dart b/lib/services/appointment_services/GetDoctorsList.dart index 47826a43..bc08fd25 100644 --- a/lib/services/appointment_services/GetDoctorsList.dart +++ b/lib/services/appointment_services/GetDoctorsList.dart @@ -805,7 +805,7 @@ class DoctorsListService extends BaseService { "DeviceTypeID": req.DeviceTypeID, "PatientID": authUser.patientID, "PatientTypeID": authUser.patientType, - "LanguageID": 1, + // "LanguageID": 1, "PatientType": authUser.patientType }; From f1a74749f7868edd193e6dfec916600b08b78093 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 16 Jan 2024 16:18:07 +0300 Subject: [PATCH 13/17] param update --- lib/services/payfort_services/payfort_service.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/payfort_services/payfort_service.dart b/lib/services/payfort_services/payfort_service.dart index d8cef846..308d5818 100644 --- a/lib/services/payfort_services/payfort_service.dart +++ b/lib/services/payfort_services/payfort_service.dart @@ -54,7 +54,7 @@ class PayfortService extends BaseService { "Pat_Token": result.tokenName, "IsRefund": false, "RemmeberMe": false, - "Reconciliation_Reference": result.reconcilationReference, + "Reconciliation_Reference": result.reconciliationReference, "LanguageID": 1, }; From eb1bddf77296cd45fc50829c0d0daa4273f12494 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 17 Jan 2024 13:31:52 +0300 Subject: [PATCH 14/17] updates --- android/app/build.gradle | 4 ++-- lib/config/config.dart | 4 ++-- lib/core/service/client/base_app_client.dart | 4 ++-- lib/pages/BookAppointment/BookConfirm.dart | 2 +- lib/services/appointment_services/GetDoctorsList.dart | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 965934fd..75a9b598 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -41,7 +41,7 @@ configurations.all { } android { - compileSdkVersion 33 + compileSdkVersion 34 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -57,7 +57,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.ejada.hmg" minSdkVersion 21 - targetSdkVersion 33 + targetSdkVersion 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName multiDexEnabled true diff --git a/lib/config/config.dart b/lib/config/config.dart index bc651005..5c5f984c 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -21,8 +21,8 @@ var PACKAGES_ORDERS = '/api/orders'; var PACKAGES_ORDER_HISTORY = '/api/orders/items'; var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara'; // var BASE_URL = 'http://10.50.100.198:4422/'; -// var BASE_URL = 'https://uat.hmgwebservices.com/'; -var BASE_URL = 'https://hmgwebservices.com/'; +var BASE_URL = 'https://uat.hmgwebservices.com/'; +// var BASE_URL = 'https://hmgwebservices.com/'; // var BASE_URL = 'http://10.20.200.111:1010/'; // var BASE_URL = 'https://uat.hmgwebservices.com/'; // var BASE_URL = 'https://hmgwebservices.com/'; diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index 7b294b28..8818d6bb 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -174,8 +174,8 @@ class BaseAppClient { } // body['IdentificationNo'] = 1023854217; - // body['MobileNo'] = "531940021"; - // body['PatientID'] = 1400563; //3844083 + // body['MobileNo'] = "531940021"; //0560717232 + // body['PatientID'] = 1400563; //4609100 // body['TokenID'] = "@dm!n"; // Patient ID: 3027574 diff --git a/lib/pages/BookAppointment/BookConfirm.dart b/lib/pages/BookAppointment/BookConfirm.dart index 63f58910..9f6c5df5 100644 --- a/lib/pages/BookAppointment/BookConfirm.dart +++ b/lib/pages/BookAppointment/BookConfirm.dart @@ -262,7 +262,7 @@ class _BookConfirmState extends State { service.cancelAppointment(appo, context, isReschedule: true).then((res) { GifLoaderDialogUtils.hideDialog(context); if (res['MessageStatus'] == 1) { - Future.delayed(new Duration(milliseconds: 1500), () async { + Future.delayed(new Duration(milliseconds: 500), () async { if (isLiveCareSchedule != null && isLiveCareSchedule) { insertLiveCareScheduledAppointment(context, widget.doctor); } else { diff --git a/lib/services/appointment_services/GetDoctorsList.dart b/lib/services/appointment_services/GetDoctorsList.dart index bc08fd25..d057dcbb 100644 --- a/lib/services/appointment_services/GetDoctorsList.dart +++ b/lib/services/appointment_services/GetDoctorsList.dart @@ -704,7 +704,7 @@ class DoctorsListService extends BaseService { "DeviceTypeID": req.DeviceTypeID, "PatientID": authUser.patientID, "PatientTypeID": authUser.patientType, - "LanguageID": 1, + // "LanguageID": 1, "PatientType": authUser.patientType }; From c29e2c88f0d4d4ff6bb8b94cbc21c97cd1356d13 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 17 Jan 2024 14:01:25 +0300 Subject: [PATCH 15/17] location timeout handled in online check-in via location --- lib/config/localized_values.dart | 1 + lib/uitl/location_util.dart | 30 +++++++++++++++++++++--- lib/uitl/translations_delegate_base.dart | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index cc45dfeb..34251a8f 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -1905,4 +1905,5 @@ const Map localizedValues = { "locationCheckInError": {"en": "Please make sure that you're within the hospital location to perform online check-in.", "ar": "يرجى التأكد من تواجدك داخل موقع المستشفى لإجراء تسجيل الوصول عبر الإنترنت."}, "upcoming": {"en": "Upcoming", "ar": "المواعيد القادمة"}, "noUpcomingAppointment": {"en": "No upcoming appointments", "ar": "لا توجد مواعيد القادمة"}, + "locationTimeoutError": {"en": "Unable to fetch your location, Please try again.", "ar": "غير قادر على جلب موقعك، يرجى المحاولة مرة أخرى."}, }; \ No newline at end of file diff --git a/lib/uitl/location_util.dart b/lib/uitl/location_util.dart index b890882f..a73c48e9 100644 --- a/lib/uitl/location_util.dart +++ b/lib/uitl/location_util.dart @@ -36,9 +36,12 @@ class LocationUtils { if (value) { await Geolocator.checkPermission().then((permission) async { if (permission == LocationPermission.always || permission == LocationPermission.whileInUse) { - Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low, timeLimit: Duration(seconds: 10)).then((value) { + Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best, timeLimit: Duration(seconds: 1)).then((value) { setLocation(value); if (callBack != null) callBack(LatLng(value.latitude, value.longitude)); + }).catchError((err) { + print(err); + if (isShowConfirmDialog) showLocationTimeOutDialog(failureCallBack: failureCallBack); }); } @@ -52,7 +55,7 @@ class LocationUtils { if (callBack != null) callBack(LatLng(value.latitude, value.longitude)); }); } else { - if (isShowConfirmDialog) showErrorLocationDialog(false); + if (isShowConfirmDialog) showErrorLocationDialog(false, failureCallBack: failureCallBack); } }); } else { @@ -60,7 +63,7 @@ class LocationUtils { getCurrentLocation(callBack: callBack); } else { setZeroLocation(); - if (isShowConfirmDialog) showErrorLocationDialog(false); + if (isShowConfirmDialog) showErrorLocationDialog(false, failureCallBack: failureCallBack); } } } @@ -141,6 +144,27 @@ class LocationUtils { } } + showLocationTimeOutDialog({Function() failureCallBack}) { + ConfirmDialog dialog = new ConfirmDialog( + context: context, + confirmMessage: TranslationBase.of(context).locationTimeoutError, + okText: TranslationBase.of(context).ok, + cancelText: TranslationBase.of(context).cancel_nocaps, + okFunction: () { + ConfirmDialog.closeAlertDialog(context); + Navigator.of(context).canPop(); + if (failureCallBack != null) { + failureCallBack(); + } + }, + cancelFunction: () { + if (failureCallBack != null) { + failureCallBack(); + } + }); + return dialog.showAlertDialog(context); + } + showErrorLocationDialog(bool isPermissionError, {Function() failureCallBack}) { ConfirmDialog dialog = new ConfirmDialog( context: context, diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 03a76dc1..150b23c1 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -2914,6 +2914,7 @@ class TranslationBase { String get locationCheckInError => localizedValues["locationCheckInError"][locale.languageCode]; String get upcoming => localizedValues["upcoming"][locale.languageCode]; String get noUpcomingAppointment => localizedValues["noUpcomingAppointment"][locale.languageCode]; + String get locationTimeoutError => localizedValues["locationTimeoutError"][locale.languageCode]; } From 1b0961a08f577b2c7b1c6fecb3cfd508606e3b18 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 17 Jan 2024 14:22:10 +0300 Subject: [PATCH 16/17] location timeout --- lib/uitl/location_util.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uitl/location_util.dart b/lib/uitl/location_util.dart index a73c48e9..2d0424c5 100644 --- a/lib/uitl/location_util.dart +++ b/lib/uitl/location_util.dart @@ -36,7 +36,7 @@ class LocationUtils { if (value) { await Geolocator.checkPermission().then((permission) async { if (permission == LocationPermission.always || permission == LocationPermission.whileInUse) { - Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best, timeLimit: Duration(seconds: 1)).then((value) { + Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best, timeLimit: Duration(seconds: 5)).then((value) { setLocation(value); if (callBack != null) callBack(LatLng(value.latitude, value.longitude)); }).catchError((err) { From 0168f06bb920da3212b04154374c7c3b6d681180 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Thu, 18 Jan 2024 10:53:52 +0300 Subject: [PATCH 17/17] updates --- lib/uitl/gif_loader_dialog_utils.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uitl/gif_loader_dialog_utils.dart b/lib/uitl/gif_loader_dialog_utils.dart index eae84e38..d95307de 100644 --- a/lib/uitl/gif_loader_dialog_utils.dart +++ b/lib/uitl/gif_loader_dialog_utils.dart @@ -11,7 +11,7 @@ class GifLoaderDialogUtils { try { Navigator.of(context).pop(); } catch (error) { - Future.delayed(Duration(milliseconds: 250)).then((value) => Navigator.of(context).pop()); + Future.delayed(Duration(milliseconds: 250)).then((value) => Navigator.of(context).canPop()); } } }