Merge pull request 'haroon_dev' (#379) from haroon_dev into master
Reviewed-on: https://34.17.182.140/Haroon6138/HMG_Patient_App_New/pulls/379pull/381/head
commit
1c30e634aa
@ -0,0 +1,5 @@
|
|||||||
|
class MyFatoorahConfig {
|
||||||
|
|
||||||
|
static const String configAPIKey = "SK_KWT_0auB76h3Frhj7aUBSZa6H5ei792eZoGAPh0bBxKsrgtyjqKgf38MPnZqzGqagErb";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,197 @@
|
|||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
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/cache_consts.dart';
|
||||||
|
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/myFatoorah_config.dart';
|
||||||
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
||||||
|
import 'package:hmg_patient_app_new/features/payfort/models/payfort_request_insert_model.dart';
|
||||||
|
import 'package:hmg_patient_app_new/features/payfort/models/payfort_response_insert_model.dart';
|
||||||
|
import 'package:hmg_patient_app_new/features/payfort/payfort_repo.dart';
|
||||||
|
import 'package:hmg_patient_app_new/generated/codegen_loader.g.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;
|
||||||
|
final ErrorHandlerService errorHandlerService;
|
||||||
|
final PayfortRepo payfortRepo;
|
||||||
|
|
||||||
|
MyFatoorahViewModel({
|
||||||
|
required this.appState,
|
||||||
|
required this.errorHandlerService,
|
||||||
|
required this.payfortRepo,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Payment Method ID
|
||||||
|
// 2: Credit/Debit Card
|
||||||
|
// 6: Mada
|
||||||
|
|
||||||
|
initiateCardPayment({
|
||||||
|
num amount = 10.0,
|
||||||
|
paymentDescription = "",
|
||||||
|
String displayCurrencyIso = MFCurrencyISO.KUWAIT_KWD,
|
||||||
|
required String paymentOption,
|
||||||
|
required String liveServiceID,
|
||||||
|
required String isScheduleLiveCare,
|
||||||
|
required String appointmentDate,
|
||||||
|
required String appointmentNo,
|
||||||
|
required String doctorID,
|
||||||
|
required String fileNumber,
|
||||||
|
required String serviceID,
|
||||||
|
required String projectID,
|
||||||
|
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: paymentOption.toLowerCase() == "mada" ? 6 : 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) async {
|
||||||
|
PayfortRequestInsertModel payfortRequestInsertModel = PayfortRequestInsertModel();
|
||||||
|
|
||||||
|
payfortRequestInsertModel.commandType = "SALE";
|
||||||
|
payfortRequestInsertModel.amount = amount;
|
||||||
|
payfortRequestInsertModel.customerEmail = getIt.get<AppState>().getAuthenticatedUser()!.emailAddress;
|
||||||
|
payfortRequestInsertModel.orderDescription = paymentDescription;
|
||||||
|
payfortRequestInsertModel.serviceID = serviceID;
|
||||||
|
payfortRequestInsertModel.paymentOption = paymentOption;
|
||||||
|
payfortRequestInsertModel.clientRequestID = invoiceId;
|
||||||
|
payfortRequestInsertModel.projectID = projectID;
|
||||||
|
payfortRequestInsertModel.fileNumber = getIt.get<AppState>().getAuthenticatedUser()!.patientId.toString();
|
||||||
|
payfortRequestInsertModel.customerName = "${getIt.get<AppState>().getAuthenticatedUser()!.firstName} ${getIt.get<AppState>().getAuthenticatedUser()!.lastName}";
|
||||||
|
payfortRequestInsertModel.currency = getIt.get<AppState>().getAuthenticatedUser()!.outSa! == 0 ? "SAR" : "AED";
|
||||||
|
payfortRequestInsertModel.liveServiceID = liveServiceID;
|
||||||
|
payfortRequestInsertModel.latitude = getIt.get<AppState>().userLat.toString();
|
||||||
|
payfortRequestInsertModel.longitude = getIt.get<AppState>().userLong.toString();
|
||||||
|
payfortRequestInsertModel.merchantReference = invoiceId;
|
||||||
|
payfortRequestInsertModel.deviceToken = await Utils.getStringFromPrefs(CacheConst.pushToken);
|
||||||
|
payfortRequestInsertModel.language = getIt.get<AppState>().isArabic() ? "ar" : "en";
|
||||||
|
payfortRequestInsertModel.integrationId = "6"; // PayTabs integration ID
|
||||||
|
payfortRequestInsertModel.isSchedule = isScheduleLiveCare;
|
||||||
|
payfortRequestInsertModel.appointmentDate = appointmentDate;
|
||||||
|
payfortRequestInsertModel.appointmentNo = appointmentNo;
|
||||||
|
payfortRequestInsertModel.doctorID = doctorID;
|
||||||
|
|
||||||
|
// Call request insert API before payment
|
||||||
|
await paytabsRequestInsert(payfortRequestInsertModel: payfortRequestInsertModel);
|
||||||
|
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
}).then((value) async {
|
||||||
|
var valJson = value.toString();
|
||||||
|
print(valJson);
|
||||||
|
|
||||||
|
// // Create PayfortResponseInsertModel (same as Payfort implementation)
|
||||||
|
PayfortResponseInsertModel payfortResponseInsertModel = PayfortResponseInsertModel();
|
||||||
|
|
||||||
|
payfortResponseInsertModel.fortId = value.invoiceTransactions!.first.transactionId ?? "";
|
||||||
|
payfortResponseInsertModel.commandType = "SALE";
|
||||||
|
// payfortResponseInsertModel.amount = paytabsTransactionResponseModel.tranTotal ?? 0;
|
||||||
|
payfortResponseInsertModel.amount = amount;
|
||||||
|
payfortResponseInsertModel.sadadOLP = "";
|
||||||
|
payfortResponseInsertModel.paymentOption = value.invoiceTransactions!.first.paymentGateway ?? "";
|
||||||
|
payfortResponseInsertModel.customerIP = "";
|
||||||
|
payfortResponseInsertModel.eCI = "";
|
||||||
|
payfortResponseInsertModel.responseMessage = value.invoiceTransactions!.first.transactionStatus ?? "";
|
||||||
|
payfortResponseInsertModel.cardNumber = value.invoiceTransactions!.first.cardNumber ?? "";
|
||||||
|
payfortResponseInsertModel.cardBin = "";
|
||||||
|
payfortResponseInsertModel.installmentsNumber = 0;
|
||||||
|
payfortResponseInsertModel.status = (value.invoiceStatus ?? "").toLowerCase() == "paid" ? "14" : "00";
|
||||||
|
payfortResponseInsertModel.merchantRef = value.invoiceId.toString();
|
||||||
|
payfortResponseInsertModel.isRefund = false;
|
||||||
|
payfortResponseInsertModel.remmeberMe = true;
|
||||||
|
payfortResponseInsertModel.reconciliationReference = "";
|
||||||
|
|
||||||
|
// Call response insert API after payment
|
||||||
|
await paytabsResponseInsert(payfortResponseInsertModel: payfortResponseInsertModel);
|
||||||
|
|
||||||
|
if ((value.invoiceStatus ?? "").toLowerCase() == "paid") {
|
||||||
|
if (onSuccess != null) {
|
||||||
|
onSuccess(value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (onError != null) {
|
||||||
|
onError(LocaleKeys.paymentFailedPleaseTryAgain.tr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).catchError((error) {
|
||||||
|
if (onError != null) {
|
||||||
|
onError(error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
executeApplePayPayment() {
|
||||||
|
MFApplepay.executeApplePayPayment(onInvoiceCreated: (invoiceID) {
|
||||||
|
log(
|
||||||
|
invoiceID.toString(),
|
||||||
|
);
|
||||||
|
}).then((value) {
|
||||||
|
log(
|
||||||
|
value.toString(),
|
||||||
|
);
|
||||||
|
}).catchError((error) {
|
||||||
|
log(error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
initApplePayPayment(num invoiceValue) async {
|
||||||
|
await MFSDK.init(MyFatoorahConfig.configAPIKey, ApiConsts.myFatoorahCountry, ApiConsts.myFatoorahEnvironmentType);
|
||||||
|
|
||||||
|
await MFSDK.initSession(MFInitiateSessionRequest(), MFLanguage.ENGLISH).then((value) async {
|
||||||
|
var executePaymentRequest = MFExecutePaymentRequest(invoiceValue: invoiceValue, sessionId: value.sessionId, displayCurrencyIso: MFCurrencyISO.SAUDIARABIA_SAR);
|
||||||
|
|
||||||
|
MFApplepay.setupApplePay(value, executePaymentRequest, MFLanguage.ENGLISH, merchantName: "Dr Sulaiman Al Habib");
|
||||||
|
}).catchError((error) {
|
||||||
|
log(error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> paytabsRequestInsert({required PayfortRequestInsertModel payfortRequestInsertModel, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
||||||
|
final result = await payfortRepo.payfortRequestInsert(payfortRequestInsertModel: payfortRequestInsertModel);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
notifyListeners();
|
||||||
|
if (onSuccess != null) {
|
||||||
|
onSuccess(apiResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> paytabsResponseInsert({required PayfortResponseInsertModel payfortResponseInsertModel, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
||||||
|
final result = await payfortRepo.payfortResponseInsert(payfortResponseInsertModel: payfortResponseInsertModel);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
notifyListeners();
|
||||||
|
if (onSuccess != null) {
|
||||||
|
onSuccess(apiResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue