From 4015f5ba2e2641e7f2c0e97d0651fef4753d17fb Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Thu, 14 May 2026 12:56:17 +0300 Subject: [PATCH] PayTabs Card & Apple Pay Payment integration completed. --- lib/core/app_state.dart | 2 +- .../book_appointments_view_model.dart | 1 + .../habib_wallet/habib_wallet_view_model.dart | 6 +- lib/features/paytabs/paytabs_view_model.dart | 1 + .../waiting_appointment_payment_page.dart | 195 ++++++++++++++--- .../er_online_checkin_payment_page.dart | 197 +++++++++++++++--- .../home/lakum_wallet_details.dart | 16 +- .../home/widgets/lakum_wallet_card.dart | 6 +- .../ancillary_order_payment_page.dart | 134 +++++++++--- 9 files changed, 461 insertions(+), 97 deletions(-) diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index fce61fc7..5eb7a05d 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -44,7 +44,7 @@ class AppState { AuthenticatedUser? _authenticatedRootUser; AuthenticatedUser? _authenticatedChildUser; - bool isPaytabsEnabled = true; + bool isPaytabsEnabled = false; int? _superUserID; bool isChildLoggedIn = false; diff --git a/lib/features/book_appointments/book_appointments_view_model.dart b/lib/features/book_appointments/book_appointments_view_model.dart index c2f35308..e6cfa6c2 100644 --- a/lib/features/book_appointments/book_appointments_view_model.dart +++ b/lib/features/book_appointments/book_appointments_view_model.dart @@ -866,6 +866,7 @@ class BookAppointmentsViewModel extends ChangeNotifier { initialSlotDuration = apiResponse.data["InitialSlotDuration"]; freeSlotsResponse = apiResponse.data['FreeTimeSlots']; isWaitingAppointmentAvailable = apiResponse.data["IsAllowToBookWaitingAppointment"]; + // isWaitingAppointmentAvailable = true; freeSlotsResponse.forEach((element) { diff --git a/lib/features/habib_wallet/habib_wallet_view_model.dart b/lib/features/habib_wallet/habib_wallet_view_model.dart index 94570a08..21139c80 100644 --- a/lib/features/habib_wallet/habib_wallet_view_model.dart +++ b/lib/features/habib_wallet/habib_wallet_view_model.dart @@ -48,18 +48,18 @@ class HabibWalletViewModel extends ChangeNotifier { String yahalaAccountNumber = ''; bool isLakumAccountInfoLoading = false; - late LakumInquiryInformationResponseModel lakumAccountInfo; + LakumInquiryInformationResponseModel? lakumAccountInfo; // Get all flattened transactions sorted by date descending List getAllLakumTransactions() { - if (lakumAccountInfo.gainedPointsAmountPerYear == null) { + if (lakumAccountInfo?.gainedPointsAmountPerYear == null) { return []; } List allTransactions = []; // Flatten the nested structure - for (var yearData in lakumAccountInfo.gainedPointsAmountPerYear!) { + for (var yearData in lakumAccountInfo!.gainedPointsAmountPerYear!) { if (yearData.pointsAmountPerMonth != null) { for (var monthData in yearData.pointsAmountPerMonth!) { if (monthData.pointsAmountPerday != null) { diff --git a/lib/features/paytabs/paytabs_view_model.dart b/lib/features/paytabs/paytabs_view_model.dart index b5b37e8d..c922c752 100644 --- a/lib/features/paytabs/paytabs_view_model.dart +++ b/lib/features/paytabs/paytabs_view_model.dart @@ -35,6 +35,7 @@ class PayTabsViewModel extends ChangeNotifier { locale: appState.isArabic() ? PaymentSdkLocale.AR : PaymentSdkLocale.EN, merchantApplePayIndentifier: ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? PaymentSdkDefaultConfig.defaultMerchantAppleBundleIDUAT : PaymentSdkDefaultConfig.defaultMerchantAppleBundleID, + // merchantApplePayIndentifier: PaymentSdkDefaultConfig.defaultMerchantAppleBundleIDUAT, screentTitle: paymentDescription, amount: amount.toDouble(), showBillingInfo: false, diff --git a/lib/presentation/book_appointment/waiting_appointment/waiting_appointment_payment_page.dart b/lib/presentation/book_appointment/waiting_appointment/waiting_appointment_payment_page.dart index 4d136cdd..63e6aa72 100644 --- a/lib/presentation/book_appointment/waiting_appointment/waiting_appointment_payment_page.dart +++ b/lib/presentation/book_appointment/waiting_appointment/waiting_appointment_payment_page.dart @@ -19,6 +19,8 @@ import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/ import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart'; import 'package:hmg_patient_app_new/features/payfort/models/apple_pay_request_insert_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/paytabs/paytabs_view_model.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart'; import 'package:hmg_patient_app_new/presentation/insurance/insurance_home_page.dart'; @@ -45,6 +47,7 @@ class _WaitingAppointmentPaymentPageState extends State(context); myAppointmentsViewModel = Provider.of(context); payfortViewModel = Provider.of(context); + paytabsViewModel = Provider.of(context, listen: false); return Scaffold( backgroundColor: AppColors.bgScaffoldColor, body: Consumer(builder: (context, bookAppointmentsVM, child) { @@ -133,7 +137,50 @@ class _WaitingAppointmentPaymentPageState extends State { late PayfortViewModel payfortViewModel; late EmergencyServicesViewModel emergencyServicesViewModel; + late PayTabsViewModel paytabsViewModel; late AppState appState; @@ -75,6 +78,7 @@ class _ErOnlineCheckinPaymentPageState extends State appState = getIt.get(); payfortViewModel = Provider.of(context, listen: false); emergencyServicesViewModel = Provider.of(context, listen: false); + paytabsViewModel = Provider.of(context, listen: false); return Scaffold( backgroundColor: AppColors.bgScaffoldColor, body: Column( @@ -119,7 +123,54 @@ class _ErOnlineCheckinPaymentPageState extends State ).paddingSymmetrical(16.h, 16.h), ).paddingSymmetrical(24.h, 0.h).onPress(() { selectedPaymentMethod = "MADA"; - openPaymentURL("mada"); + if (appState.isPaytabsEnabled) { + paytabsViewModel.setPaymentConfiguration( + "ER Online Check-In Payment", + emergencyServicesViewModel.erOnlineCheckInPaymentDetailsResponse.patientShareWithTax!, + ); + paytabsViewModel.startCardPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { + if (emergencyServicesViewModel.isERBookAppointment) { + await emergencyServicesViewModel.ER_CreateAdvancePayment( + paymentMethodName: selectedPaymentMethod, + paymentReference: transactionData.transactionReference!, + onSuccess: (value) async { + await emergencyServicesViewModel.addAdvanceNumberRequest( + advanceNumber: value, + paymentReference: transactionData.transactionReference!, + appointmentNo: "0", + onSuccess: (val) { + LoaderBottomSheet.hideLoader(); + if (emergencyServicesViewModel.isERBookAppointment) { + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getSuccessWidget(loadingText: LocaleKeys.erAppointmentBookedSuccess.tr(context: context)), + callBackFunc: () { + Navigator.pushAndRemoveUntil( + context, + CustomPageRoute( + page: LandingNavigation(), + ), + (r) => false); + }, + isFullScreen: false, + isCloseButtonVisible: true, + ); + } else {} + }); + }); + } else {} + }, onError: (errMsg) { + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getErrorWidget(loadingText: errMsg.toString()), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + }); + } else { + openPaymentURL("mada"); + } }), SizedBox(height: 16.h), Container( @@ -161,7 +212,54 @@ class _ErOnlineCheckinPaymentPageState extends State ).paddingSymmetrical(16.h, 16.h), ).paddingSymmetrical(24.h, 0.h).onPress(() { selectedPaymentMethod = "VISA"; - openPaymentURL("visa"); + if (appState.isPaytabsEnabled) { + paytabsViewModel.setPaymentConfiguration( + "ER Online Check-In Payment", + emergencyServicesViewModel.erOnlineCheckInPaymentDetailsResponse.patientShareWithTax!, + ); + paytabsViewModel.startCardPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { + if (emergencyServicesViewModel.isERBookAppointment) { + await emergencyServicesViewModel.ER_CreateAdvancePayment( + paymentMethodName: selectedPaymentMethod, + paymentReference: transactionData.transactionReference!, + onSuccess: (value) async { + await emergencyServicesViewModel.addAdvanceNumberRequest( + advanceNumber: value, + paymentReference: transactionData.transactionReference!, + appointmentNo: "0", + onSuccess: (val) { + LoaderBottomSheet.hideLoader(); + if (emergencyServicesViewModel.isERBookAppointment) { + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getSuccessWidget(loadingText: LocaleKeys.erAppointmentBookedSuccess.tr(context: context)), + callBackFunc: () { + Navigator.pushAndRemoveUntil( + context, + CustomPageRoute( + page: LandingNavigation(), + ), + (r) => false); + }, + isFullScreen: false, + isCloseButtonVisible: true, + ); + } else {} + }); + }); + } else {} + }, onError: (errMsg) { + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getErrorWidget(loadingText: errMsg.toString()), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + }); + } else { + openPaymentURL("visa"); + } }), SizedBox(height: 16.h), isShowTamara @@ -393,35 +491,84 @@ class _ErOnlineCheckinPaymentPageState extends State //TODO: Need to pass dynamic params to the Apple Pay instead of static values await payfortViewModel.applePayRequestInsert(applePayInsertRequest: applePayInsertRequest).then((value) { - payfortViewModel.paymentWithApplePay( - customerName: "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}", - // customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, - customerEmail: "CustID_${appState.getAuthenticatedUser()!.patientId.toString()}@HMG.com", - orderDescription: "Appointment Payment", - orderAmount: double.parse(emergencyServicesViewModel.erOnlineCheckInPaymentDetailsResponse.patientShareWithTax!.toString()), - merchantReference: transID, - merchantIdentifier: payfortViewModel.payfortProjectDetailsRespModel!.merchantIdentifier, - applePayAccessCode: payfortViewModel.payfortProjectDetailsRespModel!.accessCode, - applePayShaRequestPhrase: payfortViewModel.payfortProjectDetailsRespModel!.shaRequest, - currency: appState.getAuthenticatedUser()!.outSa! == 0 ? "SAR" : "AED", - onFailed: (failureResult) async { - LoaderBottomSheet.hideLoader(); - log("failureResult: ${failureResult.message.toString()}"); + if (appState.isPaytabsEnabled) { + LoaderBottomSheet.hideLoader(); + paytabsViewModel.setPaymentConfiguration( + "ER Online Check-In Payment", + emergencyServicesViewModel.erOnlineCheckInPaymentDetailsResponse.patientShareWithTax!, + ); + paytabsViewModel.startApplePayPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { + LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr(context: context)); + if (emergencyServicesViewModel.isERBookAppointment) { + await emergencyServicesViewModel.ER_CreateAdvancePayment( + paymentMethodName: selectedPaymentMethod, + paymentReference: transactionData.transactionReference!, + onSuccess: (value) async { + await emergencyServicesViewModel.addAdvanceNumberRequest( + advanceNumber: value, + paymentReference: transactionData.transactionReference!, + appointmentNo: "0", + onSuccess: (val) { + LoaderBottomSheet.hideLoader(); + if (emergencyServicesViewModel.isERBookAppointment) { + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getSuccessWidget(loadingText: LocaleKeys.erAppointmentBookedSuccess.tr(context: context)), + callBackFunc: () { + Navigator.pushAndRemoveUntil( + context, + CustomPageRoute( + page: LandingNavigation(), + ), + (r) => false); + }, + isFullScreen: false, + isCloseButtonVisible: true, + ); + } else {} + }); + }); + } else {} + }, onError: (err) { showCommonBottomSheetWithoutHeight( context, - child: Utils.getErrorWidget(loadingText: failureResult.message.toString()), + child: Utils.getErrorWidget(loadingText: err.toString()), callBackFunc: () {}, isFullScreen: false, isCloseButtonVisible: true, ); - }, - onSucceeded: (successResult) async { - LoaderBottomSheet.hideLoader(); - log("successResult: ${successResult.responseMessage.toString()}"); - selectedPaymentMethod = successResult.paymentOption ?? "VISA"; - checkPaymentStatus(); - }, - ); + }); + } else { + payfortViewModel.paymentWithApplePay( + customerName: "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}", + // customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress, + customerEmail: "CustID_${appState.getAuthenticatedUser()!.patientId.toString()}@HMG.com", + orderDescription: "ER Online Check-In Payment", + orderAmount: double.parse(emergencyServicesViewModel.erOnlineCheckInPaymentDetailsResponse.patientShareWithTax!.toString()), + merchantReference: transID, + merchantIdentifier: payfortViewModel.payfortProjectDetailsRespModel!.merchantIdentifier, + applePayAccessCode: payfortViewModel.payfortProjectDetailsRespModel!.accessCode, + applePayShaRequestPhrase: payfortViewModel.payfortProjectDetailsRespModel!.shaRequest, + currency: appState.getAuthenticatedUser()!.outSa! == 0 ? "SAR" : "AED", + onFailed: (failureResult) async { + LoaderBottomSheet.hideLoader(); + log("failureResult: ${failureResult.message.toString()}"); + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getErrorWidget(loadingText: failureResult.message.toString()), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + }, + onSucceeded: (successResult) async { + LoaderBottomSheet.hideLoader(); + log("successResult: ${successResult.responseMessage.toString()}"); + selectedPaymentMethod = successResult.paymentOption ?? "VISA"; + checkPaymentStatus(); + }, + ); + } }); } diff --git a/lib/presentation/home/lakum_wallet_details.dart b/lib/presentation/home/lakum_wallet_details.dart index 5b044952..79b71ec0 100644 --- a/lib/presentation/home/lakum_wallet_details.dart +++ b/lib/presentation/home/lakum_wallet_details.dart @@ -95,7 +95,7 @@ class LakumWalletDetails extends StatelessWidget { ); } - Widget _buildLakumMainCard(LakumInquiryInformationResponseModel accountInfo, AppState appState) { + Widget _buildLakumMainCard(LakumInquiryInformationResponseModel? accountInfo, AppState appState) { return Container( decoration: BoxDecoration( gradient: LinearGradient( @@ -134,7 +134,7 @@ class LakumWalletDetails extends StatelessWidget { color: Colors.white, ), SizedBox(height: 4.h), - (accountInfo.accountNumber ?? 0).toString().toText14( + (accountInfo?.accountNumber ?? 0).toString().toText14( color: Colors.white.withAlpha(230), ), ], @@ -155,7 +155,7 @@ class LakumWalletDetails extends StatelessWidget { Row( crossAxisAlignment: CrossAxisAlignment.end, children: [ - (accountInfo.pointsBalance?.toString() ?? "0").toText44( + (accountInfo?.pointsBalance?.toString() ?? "0").toText44( isBold: true, color: Colors.white, ), @@ -172,7 +172,7 @@ class LakumWalletDetails extends StatelessWidget { SizedBox(height: 4.h), // Balance Amount in SAR - "≈ ${accountInfo.pointsBalanceAmount?.toStringAsFixed(2) ?? "0.00"} SAR".toText18( + "≈ ${accountInfo?.pointsBalanceAmount?.toStringAsFixed(2) ?? "0.00"} SAR".toText18( color: Colors.white.withAlpha(204), ), SizedBox(height: 20.h), @@ -183,7 +183,7 @@ class LakumWalletDetails extends StatelessWidget { Expanded( child: _buildStatChip( LocaleKeys.gained.tr(), - accountInfo.gainedPoints?.toString() ?? "0", + accountInfo?.gainedPoints?.toString() ?? "0", Icons.arrow_circle_up, ), ), @@ -191,16 +191,14 @@ class LakumWalletDetails extends StatelessWidget { Expanded( child: _buildStatChip( LocaleKeys.consumed.tr(), - accountInfo.consumedPoints?.toString() ?? "0", + accountInfo?.consumedPoints?.toString() ?? "0", Icons.arrow_circle_down, ), ), SizedBox(width: 8.w), Expanded( child: _buildStatChip( - LocaleKeys.expired.tr(), - accountInfo.expiredPoints?.toString() ?? "0", - Icons.calendar_month, + LocaleKeys.expired.tr(), accountInfo?.expiredPoints?.toString() ?? "0", Icons.calendar_month, isSvg: true ), ), diff --git a/lib/presentation/home/widgets/lakum_wallet_card.dart b/lib/presentation/home/widgets/lakum_wallet_card.dart index 0a3bf8c0..3645a2d3 100644 --- a/lib/presentation/home/widgets/lakum_wallet_card.dart +++ b/lib/presentation/home/widgets/lakum_wallet_card.dart @@ -99,7 +99,11 @@ class LakumWalletCard extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.end, children: [ NumberFormat.decimalPattern() - .format(habibWalletVM.isLakumAccountInfoLoading ? 123 : habibWalletVM.yahalaAccountNumber == "0" ? 0 : habibWalletVM.lakumAccountInfo.pointsBalance) + .format(habibWalletVM.isLakumAccountInfoLoading + ? 123 + : habibWalletVM.yahalaAccountNumber == "0" + ? 0 + : (habibWalletVM.lakumAccountInfo?.pointsBalance ?? 0)) .toString() .toText32(isBold: true, isEnglishOnly: true) .toShimmer2(isShow: habibWalletVM.isLakumAccountInfoLoading, radius: 12.h, width: 80.h, height: 40.h), diff --git a/lib/presentation/todo_section/ancillary_order_payment_page.dart b/lib/presentation/todo_section/ancillary_order_payment_page.dart index a8de2708..24ed9fc5 100644 --- a/lib/presentation/todo_section/ancillary_order_payment_page.dart +++ b/lib/presentation/todo_section/ancillary_order_payment_page.dart @@ -16,6 +16,8 @@ import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/features/payfort/models/apple_pay_request_insert_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/paytabs/paytabs_view_model.dart'; import 'package:hmg_patient_app_new/features/todo_section/models/resp_models/ancillary_order_procedures_detail_response_model.dart'; import 'package:hmg_patient_app_new/features/todo_section/todo_section_view_model.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; @@ -55,6 +57,7 @@ class _AncillaryOrderPaymentPageState extends State { late PayfortViewModel payfortViewModel; late AppState appState; late TodoSectionViewModel todoSectionViewModel; + late PayTabsViewModel paytabsViewModel; MyInAppBrowser? browser; String selectedPaymentMethod = ""; @@ -74,6 +77,7 @@ class _AncillaryOrderPaymentPageState extends State { appState = getIt.get(); todoSectionViewModel = Provider.of(context); payfortViewModel = Provider.of(context); + paytabsViewModel = Provider.of(context, listen: false); return Scaffold( backgroundColor: AppColors.bgScaffoldColor, @@ -125,7 +129,34 @@ class _AncillaryOrderPaymentPageState extends State { ).paddingSymmetrical(24.h, 0.h).onPress(() { if (!todoVM.isProcessingPayment) { selectedPaymentMethod = "MADA"; - _openPaymentURL("mada"); + if (appState.isPaytabsEnabled) { + paytabsViewModel.setPaymentConfiguration( + "Ancillary Orders Payment", + widget.totalAmount, + ); + paytabsViewModel.startCardPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { + final paymentAmount = widget.totalAmount; + final fortId = transactionData.transactionReference; + final paymentMethod = selectedPaymentMethod; + + // Call createAdvancePayment with the payment details + _createAdvancePayment( + paymentAmount: paymentAmount.toDouble(), + paymentReference: fortId!, + paymentMethod: paymentMethod, + ); + }, onError: (err) { + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getErrorWidget(loadingText: err.toString()), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + }); + } else { + _openPaymentURL("mada"); + } } }), @@ -172,7 +203,34 @@ class _AncillaryOrderPaymentPageState extends State { ).paddingSymmetrical(24.h, 0.h).onPress(() { if (!todoVM.isProcessingPayment) { selectedPaymentMethod = "VISA"; - _openPaymentURL("visa"); + if (appState.isPaytabsEnabled) { + paytabsViewModel.setPaymentConfiguration( + "Ancillary Orders Payment", + widget.totalAmount, + ); + paytabsViewModel.startCardPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { + final paymentAmount = widget.totalAmount; + final fortId = transactionData.transactionReference; + final paymentMethod = selectedPaymentMethod; + + // Call createAdvancePayment with the payment details + _createAdvancePayment( + paymentAmount: paymentAmount.toDouble(), + paymentReference: fortId!, + paymentMethod: paymentMethod, + ); + }, onError: (err) { + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getErrorWidget(loadingText: err.toString()), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + }); + } else { + _openPaymentURL("visa"); + } } }), ], @@ -573,33 +631,61 @@ class _AncillaryOrderPaymentPageState extends State { return; } // Only proceed with Apple Pay if insert was successful - payfortViewModel.paymentWithApplePay( - customerName: "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}", - customerEmail: "CustID_${appState.getAuthenticatedUser()!.patientId.toString()}@HMG.com", - orderDescription: "Ancillary Order Payment", - orderAmount: widget.totalAmount, - merchantReference: transID, - merchantIdentifier: payfortViewModel.payfortProjectDetailsRespModel!.merchantIdentifier, - applePayAccessCode: payfortViewModel.payfortProjectDetailsRespModel!.accessCode, - applePayShaRequestPhrase: payfortViewModel.payfortProjectDetailsRespModel!.shaRequest, - currency: appState.getAuthenticatedUser()!.outSa! == 0 ? "SAR" : "AED", - onFailed: (failureResult) async { - log("failureResult: ${failureResult.message.toString()}"); - LoaderBottomSheet.hideLoader(); + if(appState.isPaytabsEnabled) { + LoaderBottomSheet.hideLoader(); + paytabsViewModel.setPaymentConfiguration( + "Ancillary Orders Payment", + widget.totalAmount, + ); + paytabsViewModel.startApplePayPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async { + final paymentAmount = widget.totalAmount; + final fortId = transactionData.transactionReference; + final paymentMethod = selectedPaymentMethod; + + // Call createAdvancePayment with the payment details + _createAdvancePayment( + paymentAmount: paymentAmount.toDouble(), + paymentReference: fortId!, + paymentMethod: paymentMethod, + ); + }, onError: (err) { showCommonBottomSheetWithoutHeight( context, - child: Utils.getErrorWidget(loadingText: failureResult.message.toString()), + child: Utils.getErrorWidget(loadingText: err.toString()), callBackFunc: () {}, isFullScreen: false, isCloseButtonVisible: true, ); - }, - onSucceeded: (successResult) async { - LoaderBottomSheet.hideLoader(); - log("successResult: ${successResult.responseMessage.toString()}"); - selectedPaymentMethod = successResult.paymentOption ?? "VISA"; - _checkPaymentStatus(); - }, - ); + }); + } else { + payfortViewModel.paymentWithApplePay( + customerName: "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}", + customerEmail: "CustID_${appState.getAuthenticatedUser()!.patientId.toString()}@HMG.com", + orderDescription: "Ancillary Order Payment", + orderAmount: widget.totalAmount, + merchantReference: transID, + merchantIdentifier: payfortViewModel.payfortProjectDetailsRespModel!.merchantIdentifier, + applePayAccessCode: payfortViewModel.payfortProjectDetailsRespModel!.accessCode, + applePayShaRequestPhrase: payfortViewModel.payfortProjectDetailsRespModel!.shaRequest, + currency: appState.getAuthenticatedUser()!.outSa! == 0 ? "SAR" : "AED", + onFailed: (failureResult) async { + log("failureResult: ${failureResult.message.toString()}"); + LoaderBottomSheet.hideLoader(); + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getErrorWidget(loadingText: failureResult.message.toString()), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + }, + onSucceeded: (successResult) async { + LoaderBottomSheet.hideLoader(); + log("successResult: ${successResult.responseMessage.toString()}"); + selectedPaymentMethod = successResult.paymentOption ?? "VISA"; + _checkPaymentStatus(); + }, + ); + } } }