diff --git a/lib/features/immediate_livecare/immediate_livecare_repo.dart b/lib/features/immediate_livecare/immediate_livecare_repo.dart index 6726a09b..e07d6293 100644 --- a/lib/features/immediate_livecare/immediate_livecare_repo.dart +++ b/lib/features/immediate_livecare/immediate_livecare_repo.dart @@ -101,9 +101,7 @@ class ImmediateLiveCareRepoImp implements ImmediateLiveCareRepo { onSuccess: (response, statusCode, {messageStatus, errorMessage}) { try { final respObject = response['GetERAppointmentFeesList']; - final liveCareFeesObj = LiveCareImmediateAppointmentFeesList.fromJson(respObject); - apiResponse = GenericApiModel( messageStatus: messageStatus, statusCode: statusCode, diff --git a/lib/features/payfort/payfort_repo.dart b/lib/features/payfort/payfort_repo.dart index 9262d662..6826478c 100644 --- a/lib/features/payfort/payfort_repo.dart +++ b/lib/features/payfort/payfort_repo.dart @@ -58,7 +58,7 @@ class PayfortRepoImp implements PayfortRepo { try { final list = response; if (list == null || list.isEmpty) { - throw Exception("payfort list is empty"); + throw Exception("No project configuration found."); } final applePayConfigurationResponse = PayfortProjectDetailsRespModel.fromJson(list[0]); diff --git a/lib/features/paytabs/paytabs_view_model.dart b/lib/features/paytabs/paytabs_view_model.dart index 1418cc55..a7894f07 100644 --- a/lib/features/paytabs/paytabs_view_model.dart +++ b/lib/features/paytabs/paytabs_view_model.dart @@ -17,6 +17,7 @@ import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/core/enums.dart'; import 'package:hmg_patient_app_new/core/paytabs_config.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; +import 'package:hmg_patient_app_new/features/payfort/models/payfort_project_details_resp_model.dart'; import 'package:hmg_patient_app_new/features/payfort/payfort_view_model.dart'; import 'package:hmg_patient_app_new/features/paytabs/models/paytabs_transaction_response_model.dart'; import 'package:hmg_patient_app_new/features/payfort/models/payfort_request_insert_model.dart'; @@ -32,19 +33,26 @@ class PayTabsViewModel extends ChangeNotifier { final ErrorHandlerService errorHandlerService; late PaytabsTransactionResponseModel paytabsTransactionResponseModel; + PayfortProjectDetailsRespModel? paytabsProjectDetailsRespModel; + PayTabsViewModel({ required this.appState, required this.payfortRepo, required this.errorHandlerService, }); - setPaymentConfiguration(String paymentDescription, num amount, {bool isAddCard = false}) { + setPaymentConfiguration(String paymentDescription, num amount, int serviceID, int projectID, {bool isAddCard = false}) async { String cartID = DateTime.now().millisecondsSinceEpoch.toString(); + + LoaderBottomSheet.showLoader(); + + await getPayTabsConfigurations(serviceId: serviceID, projectId: projectID); + paymentConfiguration = PaymentSdkConfigurationDetails( - profileId: PaymentSdkDefaultConfig.profileID, - serverKey: PaymentSdkDefaultConfig.serverKey, - clientKey: PaymentSdkDefaultConfig.clientKey, - transactionType: PaymentSdkTransactionType.SALE, + profileId: paytabsProjectDetailsRespModel!.merchantIdentifier, + serverKey: paytabsProjectDetailsRespModel!.accessCode, + clientKey: paytabsProjectDetailsRespModel!.shaResponse, + transactionType: PaymentSdkTransactionType.SALE, cartId: cartID.substring((cartID.length - 5), cartID.length), cartDescription: paymentDescription, merchantName: PaymentSdkDefaultConfig.defaultMerchantName, @@ -112,12 +120,17 @@ class PayTabsViewModel extends ChangeNotifier { notifyListeners(); } - setAlternatePaymentConfiguration(String paymentDescription, num amount, {bool isAddCard = false}) { + setAlternatePaymentConfiguration(String paymentDescription, num amount, int serviceID, int projectID, {bool isAddCard = false}) async { String cartID = DateTime.now().millisecondsSinceEpoch.toString(); + + LoaderBottomSheet.showLoader(); + + await getPayTabsConfigurations(serviceId: serviceID, projectId: projectID); + paymentConfiguration = PaymentSdkConfigurationDetails( - profileId: PaymentSdkDefaultConfig.profileID, - serverKey: PaymentSdkDefaultConfig.serverKey, - clientKey: PaymentSdkDefaultConfig.clientKey, + profileId: paytabsProjectDetailsRespModel!.merchantIdentifier, + serverKey: paytabsProjectDetailsRespModel!.accessCode, + clientKey: paytabsProjectDetailsRespModel!.shaResponse, transactionType: PaymentSdkTransactionType.SALE, cartId: cartID.substring((cartID.length - 5), cartID.length), cartDescription: paymentDescription, @@ -260,7 +273,7 @@ class PayTabsViewModel extends ChangeNotifier { bool _callbackFired = false; // prevent duplicate callback invocations try { - LoaderBottomSheet.showLoader(); + // LoaderBottomSheet.showLoader(); // Create PayfortRequestInsertModel (same as Payfort implementation) PayfortRequestInsertModel payfortRequestInsertModel = PayfortRequestInsertModel(); @@ -382,7 +395,7 @@ class PayTabsViewModel extends ChangeNotifier { required bool isSchedule, Function(PaytabsTransactionResponseModel)? onSuccess, Function(String)? onError}) async { - LoaderBottomSheet.showLoader(); + // LoaderBottomSheet.showLoader(); TamaraRequestModel tamaraRequestModel = TamaraRequestModel(); @@ -448,4 +461,23 @@ class PayTabsViewModel extends ChangeNotifier { } }); } + + Future getPayTabsConfigurations({int? serviceId, int? projectId, int integrationId = 5, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await payfortRepo.getPayfortConfigurations(serviceId: serviceId, projectId: projectId, integrationId: integrationId); + + result.fold( + (failure) async => await errorHandlerService.handleError(failure: failure), + (apiResponse) { + if (apiResponse.messageStatus == 2) { + // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); + } else if (apiResponse.messageStatus == 1) { + paytabsProjectDetailsRespModel = apiResponse.data!; + notifyListeners(); + if (onSuccess != null) { + onSuccess(apiResponse); + } + } + }, + ); + } } diff --git a/lib/presentation/appointments/appointment_payment_page.dart b/lib/presentation/appointments/appointment_payment_page.dart index 6e9bb7b6..bf2c0fcd 100644 --- a/lib/presentation/appointments/appointment_payment_page.dart +++ b/lib/presentation/appointments/appointment_payment_page.dart @@ -150,10 +150,11 @@ class _AppointmentPaymentPageState extends State { widget.patientAppointmentHistoryResponseModel.clinicID, widget.patientAppointmentHistoryResponseModel.appointmentNo, ); - paytabsViewModel.setPaymentConfiguration( - "Appointment Payment", - num.parse(myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString()), - ); + await paytabsViewModel.setPaymentConfiguration( + "Appointment Payment", + num.parse(myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString()), + ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum(), + widget.patientAppointmentHistoryResponseModel.projectID); paytabsViewModel.startCardPayment( paymentOption: selectedPaymentMethod, liveServiceID: "0", @@ -179,7 +180,6 @@ class _AppointmentPaymentPageState extends State { patientID: appState.getAuthenticatedUser()!.patientId.toString(), patientType: appState.getAuthenticatedUser()!.patientType!, onSuccess: (value) async { - print(value); await myAppointmentsViewModel.addAdvanceNumberRequest( advanceNumber: Utils.isVidaPlusProject(widget.patientAppointmentHistoryResponseModel.projectID) ? value.data['OnlineCheckInAppointments'][0]['AdvanceNumber_VP'].toString() @@ -263,7 +263,6 @@ class _AppointmentPaymentPageState extends State { orderDescription: "Appointment Payment", amount: myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString(), onSucceeded: (paymentResult) async { - print("Payment Success Data: ${paymentResult.toString()}"); LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr(context: context)); await myAppointmentsViewModel.createAdvancePayment( paymentMethodName: selectedPaymentMethod, @@ -275,7 +274,6 @@ class _AppointmentPaymentPageState extends State { patientID: appState.getAuthenticatedUser()!.patientId.toString(), patientType: appState.getAuthenticatedUser()!.patientType!, onSuccess: (value) async { - print(value); await myAppointmentsViewModel.addAdvanceNumberRequest( advanceNumber: Utils.isVidaPlusProject(widget.patientAppointmentHistoryResponseModel.projectID) ? value.data['OnlineCheckInAppointments'][0]['AdvanceNumber_VP'].toString() @@ -391,10 +389,11 @@ class _AppointmentPaymentPageState extends State { widget.patientAppointmentHistoryResponseModel.clinicID, widget.patientAppointmentHistoryResponseModel.appointmentNo, ); - paytabsViewModel.setPaymentConfiguration( - "Appointment Payment", - num.parse(myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString()), - ); + await paytabsViewModel.setPaymentConfiguration( + "Appointment Payment", + num.parse(myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString()), + ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum(), + widget.patientAppointmentHistoryResponseModel.projectID); paytabsViewModel.startCardPayment( paymentOption: selectedPaymentMethod, liveServiceID: "0", @@ -420,7 +419,6 @@ class _AppointmentPaymentPageState extends State { patientID: appState.getAuthenticatedUser()!.patientId.toString(), patientType: appState.getAuthenticatedUser()!.patientType!, onSuccess: (value) async { - print(value); await myAppointmentsViewModel.addAdvanceNumberRequest( advanceNumber: Utils.isVidaPlusProject(widget.patientAppointmentHistoryResponseModel.projectID) ? value.data['OnlineCheckInAppointments'][0]['AdvanceNumber_VP'].toString() @@ -504,7 +502,6 @@ class _AppointmentPaymentPageState extends State { amount: myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString(), orderDescription: "Appointment Payment", onSucceeded: (paymentResult) async { - print("Payment Success Data: ${paymentResult.toString()}"); LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr(context: context)); await myAppointmentsViewModel.createAdvancePayment( paymentMethodName: selectedPaymentMethod, @@ -516,7 +513,6 @@ class _AppointmentPaymentPageState extends State { patientID: appState.getAuthenticatedUser()!.patientId.toString(), patientType: appState.getAuthenticatedUser()!.patientType!, onSuccess: (value) async { - print(value); await myAppointmentsViewModel.addAdvanceNumberRequest( advanceNumber: Utils.isVidaPlusProject(widget.patientAppointmentHistoryResponseModel.projectID) ? value.data['OnlineCheckInAppointments'][0]['AdvanceNumber_VP'].toString() @@ -640,7 +636,10 @@ class _AppointmentPaymentPageState extends State { if (appState.isPaytabsEnabled) { paytabsViewModel.setAlternatePaymentConfiguration( - "Appointment Payment", num.parse(myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString())); + "Appointment Payment", + num.parse(myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString()), + ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum(), + widget.patientAppointmentHistoryResponseModel.projectID); paytabsViewModel.startAlternatePayment( liveServiceID: "0", appointmentDate: widget.patientAppointmentHistoryResponseModel.appointmentDate!, @@ -1121,10 +1120,13 @@ class _AppointmentPaymentPageState extends State { ApplePayInsertRequest applePayInsertRequest = ApplePayInsertRequest(); - await payfortViewModel.getPayfortConfigurations( - serviceId: ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum(), - projectId: widget.patientAppointmentHistoryResponseModel.projectID, - integrationId: 2); + if (!appState.isPaytabsEnabled) { + await payfortViewModel.getPayfortConfigurations( + serviceId: ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum(), projectId: widget.patientAppointmentHistoryResponseModel.projectID, integrationId: 2); + } else { + await paytabsViewModel.setPaymentConfiguration("Appointment Payment", num.parse(myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString()), + ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum(), widget.patientAppointmentHistoryResponseModel.projectID); + } applePayInsertRequest.clientRequestID = transID; applePayInsertRequest.clinicID = widget.patientAppointmentHistoryResponseModel.clinicID; @@ -1173,10 +1175,6 @@ class _AppointmentPaymentPageState extends State { if (appState.isPaytabsEnabled) { selectedPaymentMethod = "VISA"; LoaderBottomSheet.hideLoader(); - paytabsViewModel.setPaymentConfiguration( - "Appointment Payment", - num.parse(myAppointmentsViewModel.patientAppointmentShareResponseModel!.patientShareWithTax!.toString()), - ); paytabsViewModel.startApplePayPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr(context: context)); await myAppointmentsViewModel.createAdvancePayment( diff --git a/lib/presentation/book_appointment/livecare/immediate_livecare_payment_page.dart b/lib/presentation/book_appointment/livecare/immediate_livecare_payment_page.dart index 2ab1e303..c51ac120 100644 --- a/lib/presentation/book_appointment/livecare/immediate_livecare_payment_page.dart +++ b/lib/presentation/book_appointment/livecare/immediate_livecare_payment_page.dart @@ -137,10 +137,8 @@ class _ImmediateLiveCarePaymentPageState extends State paytabsViewModel.setPaymentConfiguration( "ER Online Check-In Payment", emergencyServicesViewModel.erOnlineCheckInPaymentDetailsResponse.patientShareWithTax!, - ); + ServiceTypeEnum.erOnlineCheckIn.getIdFromServiceEnum(), emergencyServicesViewModel.selectedHospital!.iD); paytabsViewModel.startCardPayment( paymentOption: selectedPaymentMethod, liveServiceID: "0", @@ -238,7 +238,7 @@ class _ErOnlineCheckinPaymentPageState extends State paytabsViewModel.setPaymentConfiguration( "ER Online Check-In Payment", emergencyServicesViewModel.erOnlineCheckInPaymentDetailsResponse.patientShareWithTax!, - ); + ServiceTypeEnum.erOnlineCheckIn.getIdFromServiceEnum(), emergencyServicesViewModel.selectedHospital!.iD); paytabsViewModel.startCardPayment( paymentOption: selectedPaymentMethod, liveServiceID: "0", @@ -533,7 +533,7 @@ class _ErOnlineCheckinPaymentPageState extends State paytabsViewModel.setPaymentConfiguration( "ER Online Check-In Payment", emergencyServicesViewModel.erOnlineCheckInPaymentDetailsResponse.patientShareWithTax!, - ); + ServiceTypeEnum.erOnlineCheckIn.getIdFromServiceEnum(), emergencyServicesViewModel.selectedHospital!.iD); paytabsViewModel.startApplePayPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr(context: context)); if (emergencyServicesViewModel.isERBookAppointment) { diff --git a/lib/presentation/habib_wallet/wallet_payment_confirm_page.dart b/lib/presentation/habib_wallet/wallet_payment_confirm_page.dart index 1ddaaec9..c407e6ad 100644 --- a/lib/presentation/habib_wallet/wallet_payment_confirm_page.dart +++ b/lib/presentation/habib_wallet/wallet_payment_confirm_page.dart @@ -116,7 +116,8 @@ class _WalletPaymentConfirmPageState extends State { selectedPaymentMethod = "MADA"; if (appState.isPaytabsEnabled) { transID = Utils.getAdvancePaymentTransID(habibWalletVM.selectedHospital!.iD!, int.parse(habibWalletVM.fileNumber)); - paytabsViewModel.setPaymentConfiguration("Advance Payment", habibWalletVM.walletRechargeAmount); + await paytabsViewModel.setPaymentConfiguration( + "Advance Payment", habibWalletVM.walletRechargeAmount, ServiceTypeEnum.advancePayment.getIdFromServiceEnum(), habibWalletVM.selectedHospital!.iD!); paytabsViewModel.startCardPayment( paymentOption: selectedPaymentMethod, liveServiceID: "0", @@ -313,7 +314,8 @@ class _WalletPaymentConfirmPageState extends State { selectedPaymentMethod = "VISA"; if (appState.isPaytabsEnabled) { transID = Utils.getAdvancePaymentTransID(habibWalletVM.selectedHospital!.iD!, int.parse(habibWalletVM.fileNumber)); - paytabsViewModel.setPaymentConfiguration("Advance Payment", habibWalletVM.walletRechargeAmount); + await paytabsViewModel.setPaymentConfiguration( + "Advance Payment", habibWalletVM.walletRechargeAmount, ServiceTypeEnum.advancePayment.getIdFromServiceEnum(), habibWalletVM.selectedHospital!.iD!); paytabsViewModel.startCardPayment( paymentOption: selectedPaymentMethod, liveServiceID: "0", @@ -543,7 +545,11 @@ class _WalletPaymentConfirmPageState extends State { transID = Utils.getAdvancePaymentTransID(habibWalletVM.selectedHospital!.iD!, int.parse(habibWalletVM.fileNumber)); - await payfortViewModel.getPayfortConfigurations(serviceId: ServiceTypeEnum.advancePayment.getIdFromServiceEnum(), projectId: habibWalletVM.selectedHospital!.iD!, integrationId: 2); + if(!appState.isPaytabsEnabled) { + await payfortViewModel.getPayfortConfigurations(serviceId: ServiceTypeEnum.advancePayment.getIdFromServiceEnum(), projectId: habibWalletVM.selectedHospital!.iD!, integrationId: 2); + } else { + await paytabsViewModel.setPaymentConfiguration("Advance Payment", habibWalletVM.walletRechargeAmount, ServiceTypeEnum.advancePayment.getIdFromServiceEnum(), habibWalletVM.selectedHospital!.iD!); + } applePayInsertRequest.clientRequestID = transID; applePayInsertRequest.clinicID = 0; @@ -592,7 +598,6 @@ class _WalletPaymentConfirmPageState extends State { if(appState.isPaytabsEnabled) { selectedPaymentMethod = "VISA"; LoaderBottomSheet.hideLoader(); - paytabsViewModel.setPaymentConfiguration("Advance Payment", habibWalletVM.walletRechargeAmount); paytabsViewModel.startApplePayPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { LoaderBottomSheet.showLoader(); await habibWalletVM.HISCreateAdvancePayment( diff --git a/lib/presentation/todo_section/ancillary_order_payment_page.dart b/lib/presentation/todo_section/ancillary_order_payment_page.dart index e7553df5..365dff2b 100644 --- a/lib/presentation/todo_section/ancillary_order_payment_page.dart +++ b/lib/presentation/todo_section/ancillary_order_payment_page.dart @@ -150,10 +150,7 @@ class _AncillaryOrderPaymentPageState extends State { widget.projectID, appState.getAuthenticatedUser()!.patientId!, ); - paytabsViewModel.setPaymentConfiguration( - "Ancillary Orders Payment", - widget.totalAmount, - ); + await paytabsViewModel.setPaymentConfiguration("Ancillary Orders Payment", widget.totalAmount, ServiceTypeEnum.advancePayment.getIdFromServiceEnum(), widget.projectID); paytabsViewModel.startCardPayment( paymentOption: selectedPaymentMethod, liveServiceID: "0", @@ -289,10 +286,7 @@ class _AncillaryOrderPaymentPageState extends State { widget.projectID, appState.getAuthenticatedUser()!.patientId!, ); - paytabsViewModel.setPaymentConfiguration( - "Ancillary Orders Payment", - widget.totalAmount, - ); + await paytabsViewModel.setPaymentConfiguration("Ancillary Orders Payment", widget.totalAmount, ServiceTypeEnum.advancePayment.getIdFromServiceEnum(), widget.projectID); paytabsViewModel.startCardPayment(paymentOption: selectedPaymentMethod, liveServiceID: "0", isScheduleLiveCare: "false", @@ -721,11 +715,13 @@ class _AncillaryOrderPaymentPageState extends State { transID = Utils.getAdvancePaymentTransID(widget.projectID, user!.patientId!); ApplePayInsertRequest applePayInsertRequest = ApplePayInsertRequest(); - await payfortViewModel.getPayfortConfigurations( - serviceId: ServiceTypeEnum.ancillaryOrder.getIdFromServiceEnum(), - projectId: widget.projectID, - integrationId: 2, - ); + if (!appState.isPaytabsEnabled) { + await payfortViewModel.getPayfortConfigurations( + serviceId: ServiceTypeEnum.ancillaryOrder.getIdFromServiceEnum(), + projectId: widget.projectID, + integrationId: 2, + ); + } applePayInsertRequest.clientRequestID = transID; applePayInsertRequest.clinicID = 0; @@ -770,6 +766,10 @@ class _AncillaryOrderPaymentPageState extends State { applePayInsertRequest.returnURL = ""; try { + if (appState.isPaytabsEnabled) { + await paytabsViewModel.setPaymentConfiguration("Ancillary Orders Payment", widget.totalAmount, ServiceTypeEnum.advancePayment.getIdFromServiceEnum(), widget.projectID); + } + await payfortViewModel.applePayRequestInsert(applePayInsertRequest: applePayInsertRequest); } catch (error) { log("Apple Pay Insert Request Failed: $error"); @@ -787,10 +787,6 @@ class _AncillaryOrderPaymentPageState extends State { if(appState.isPaytabsEnabled) { selectedPaymentMethod = "VISA"; LoaderBottomSheet.hideLoader(); - paytabsViewModel.setPaymentConfiguration( - "Ancillary Orders Payment", - widget.totalAmount, - ); paytabsViewModel.startApplePayPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { final paymentAmount = widget.totalAmount; final fortId = transactionData.transactionReference;