MyFatoorah Payment integration in progress

pull/379/head
haroon amjad 2 weeks ago
parent b78c83a32d
commit d43022bbb4

@ -210,7 +210,7 @@ class ApiClientImp implements ApiClient {
body['TokenID'] = "@dm!n";
}
// body['TokenID'] = "@dm!n";
body['TokenID'] = "@dm!n";
// body['PatientID'] = 1987471;
// body['PatientID'] = 53320;
// body['PatientTypeID'] = 1;

@ -6,7 +6,7 @@ import 'package:myfatoorah_flutter/myfatoorah_flutter.dart';
class ApiConsts {
static const maxSmallScreen = 660;
static AppEnvironmentTypeEnum appEnvironmentType = AppEnvironmentTypeEnum.prod;
static AppEnvironmentTypeEnum appEnvironmentType = AppEnvironmentTypeEnum.uat;
// static String baseUrl = 'https://uat.hmgwebservices.com/'; // HIS API URL UAT

@ -49,6 +49,7 @@ class AppState {
bool isPaytabsEnabled = false;
bool isPayfortHostedPageEnabled = true;
bool isMyFatoorahEnabled = false;
// bool isMyFatoorahEnabled = true;
void setIsPaytabsEnabled(bool value) {
isPaytabsEnabled = value;
@ -56,8 +57,8 @@ class AppState {
}
void setIsMyFatoorahEnabled(bool value) {
isMyFatoorahEnabled = value;
// isMyFatoorahEnabled = true;
// isMyFatoorahEnabled = value;
isMyFatoorahEnabled = true;
}
void setIsPayfortHostedPageEnabled(bool value) {

@ -44,6 +44,7 @@ import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_rep
import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart';
import 'package:hmg_patient_app_new/features/my_invoices/my_invoices_repo.dart';
import 'package:hmg_patient_app_new/features/my_invoices/my_invoices_view_model.dart';
import 'package:hmg_patient_app_new/features/myfatoorah/myfatoorah_view_model.dart';
import 'package:hmg_patient_app_new/features/notifications/notifications_repo.dart';
import 'package:hmg_patient_app_new/features/notifications/notifications_view_model.dart';
import 'package:hmg_patient_app_new/features/offers_and_discounts/offers_and_discounts_repo.dart';
@ -380,6 +381,11 @@ class AppDependencies {
errorHandlerService: getIt(),
));
getIt.registerLazySingleton<MyFatoorahViewModel>(() => MyFatoorahViewModel(
appState: getIt(),
errorHandlerService: getIt(),
));
getIt.registerLazySingleton<ClarityService>(
() => ClarityService(appState: getIt.get<AppState>()),
);

@ -0,0 +1,5 @@
class MyFatoorahConfig {
static const String configAPIKey = "SK_KWT_0auB76h3Frhj7aUBSZa6H5ei792eZoGAPh0bBxKsrgtyjqKgf38MPnZqzGqagErb";
}

@ -1248,6 +1248,7 @@ class AuthenticationViewModel extends ChangeNotifier {
_appState.setUserBloodGroup = activation.patientBlodType ?? "N/A";
_appState.setIsPaytabsEnabled(Utils.havePrivilege(120));
_appState.setIsPayfortHostedPageEnabled(Utils.havePrivilege(121));
_appState.setIsMyFatoorahEnabled(Utils.havePrivilege(123));
// Refresh privileges after user switching to ensure correct privileges are loaded
if (isSwitchUser) {
@ -1796,6 +1797,7 @@ class AuthenticationViewModel extends ChangeNotifier {
_appState.setProjectsDetailList(projectDetailListModel);
_appState.setIsPaytabsEnabled(Utils.havePrivilege(120));
_appState.setIsPayfortHostedPageEnabled(Utils.havePrivilege(121));
_appState.setIsMyFatoorahEnabled(Utils.havePrivilege(123));
}
},
);

@ -1,6 +1,12 @@
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/api_consts.dart';
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/enums.dart';
import 'package:hmg_patient_app_new/core/myFatoorah_config.dart';
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
import 'package:myfatoorah_flutter/myfatoorah_flutter.dart';
class MyFatoorahViewModel extends ChangeNotifier {
final AppState appState;
@ -10,4 +16,40 @@ class MyFatoorahViewModel extends ChangeNotifier {
required this.appState,
required this.errorHandlerService,
});
// Payment Method ID
// 2: Credit/Debit Card
// 6: Mada
initiateCardPayment({
num amount = 10.0,
paymentDescription = "",
String displayCurrencyIso = MFCurrencyISO.KUWAIT_KWD,
Function(MFGetPaymentStatusResponse)? onSuccess,
Function(String)? onError,
}) async {
LoaderBottomSheet.showLoader();
await MFSDK.init(MyFatoorahConfig.configAPIKey, ApiConsts.myFatoorahCountry, ApiConsts.myFatoorahEnvironmentType);
MFSDK.setUpActionBar(toolBarTitle: paymentDescription, toolBarTitleColor: "#ffffff", toolBarBackgroundColor: '#ED1C2B', isShowToolBar: true);
var request = MFExecutePaymentRequest(paymentMethodId: 2, invoiceValue: amount);
request.displayCurrencyIso = displayCurrencyIso;
request.customerName = ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? "Test test" : "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}";
request.customerEmail = "CustID_${appState.getAuthenticatedUser()!.patientId}@HMG.com";
await MFSDK.executePayment(request, appState.isArabic() ? MFLanguage.ARABIC : MFLanguage.ENGLISH, (invoiceId) {
LoaderBottomSheet.hideLoader();
print(invoiceId);
}).then((value) {
if (onSuccess != null) {
onSuccess(value);
}
}).catchError((error) {
if (onError != null) {
onError(error.message);
}
});
}
}

@ -35,6 +35,7 @@ import 'package:hmg_patient_app_new/features/my_appointments/appointment_rating_
import 'package:hmg_patient_app_new/features/my_appointments/appointment_via_region_viewmodel.dart';
import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart';
import 'package:hmg_patient_app_new/features/my_invoices/my_invoices_view_model.dart';
import 'package:hmg_patient_app_new/features/myfatoorah/myfatoorah_view_model.dart';
import 'package:hmg_patient_app_new/features/notifications/notifications_view_model.dart';
import 'package:hmg_patient_app_new/features/offers_and_discounts/offers_and_discounts_view_model.dart';
import 'package:hmg_patient_app_new/features/payfort/payfort_view_model.dart';
@ -303,6 +304,9 @@ void main() async {
ChangeNotifierProvider<PayTabsViewModel>(
create: (_) => getIt.get<PayTabsViewModel>(),
),
ChangeNotifierProvider<MyFatoorahViewModel>(
create: (_) => getIt.get<MyFatoorahViewModel>(),
),
ChangeNotifierProvider<RefundRequestViewModel>(
create: (_) => getIt.get<RefundRequestViewModel>(),
)

@ -13,6 +13,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/utils/date_util.dart';
import 'package:hmg_patient_app_new/features/immediate_livecare/immediate_livecare_view_model.dart';
import 'package:hmg_patient_app_new/features/myfatoorah/myfatoorah_view_model.dart';
import 'package:hmg_patient_app_new/features/payfort/models/apple_pay_request_insert_model.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
@ -33,6 +34,7 @@ import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
import 'package:hmg_patient_app_new/widgets/in_app_browser/InAppBrowser.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart';
import 'package:myfatoorah_flutter/MFEnums.dart';
import 'package:provider/provider.dart';
import 'package:smooth_corner/smooth_corner.dart';
@ -49,6 +51,7 @@ class _ImmediateLiveCarePaymentPageState extends State<ImmediateLiveCarePaymentP
late MyAppointmentsViewModel myAppointmentsViewModel;
late AppState appState;
late PayTabsViewModel paytabsViewModel;
late MyFatoorahViewModel myFatoorahViewModel;
MyInAppBrowser? browser;
String selectedPaymentMethod = "";
@ -85,6 +88,7 @@ class _ImmediateLiveCarePaymentPageState extends State<ImmediateLiveCarePaymentP
immediateLiveCareViewModel = Provider.of<ImmediateLiveCareViewModel>(context, listen: false);
payfortViewModel = Provider.of<PayfortViewModel>(context, listen: false);
paytabsViewModel = Provider.of<PayTabsViewModel>(context, listen: false);
myFatoorahViewModel = Provider.of<MyFatoorahViewModel>(context, listen: false);
return Scaffold(
backgroundColor: AppColors.bgScaffoldColor,
body: Consumer<MyAppointmentsViewModel>(builder: (context, myAppointmentsVM, child) {
@ -298,7 +302,26 @@ class _ImmediateLiveCarePaymentPageState extends State<ImmediateLiveCarePaymentP
).paddingSymmetrical(16.h, 16.h),
).paddingSymmetrical(24.h, 0.h).onPress(() async {
selectedPaymentMethod = "VISA";
if (appState.isPaytabsEnabled) {
if (appState.isMyFatoorahEnabled) {
myFatoorahViewModel.initiateCardPayment(
amount: num.parse(immediateLiveCareViewModel.liveCareImmediateAppointmentFeesList.total ?? "0.0"),
paymentDescription: "LiveCare Payment",
displayCurrencyIso: appState.getAuthenticatedUser()!.outSa == 0
? ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat
? MFCurrencyISO.KUWAIT_KWD
: MFCurrencyISO.SAUDIARABIA_SAR
: MFCurrencyISO.UAE_AED,
onSuccess: (response) {},
onError: (errMessage) {
showCommonBottomSheetWithoutHeight(
context,
child: Utils.getErrorWidget(loadingText: errMessage.toString()),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
});
} else if (appState.isPaytabsEnabled) {
transID = Utils.getAppointmentTransID(
immediateLiveCareViewModel.immediateLiveCareSelectedClinic.serviceID!,
ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? 15 : 12,

Loading…
Cancel
Save