Offers And Discounts Apis
parent
1d9783a5b3
commit
369a566006
@ -0,0 +1,691 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
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_assets.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/utils/date_util.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/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';
|
||||||
|
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/my_appointments/my_appointments_view_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/widgets/appbar/collapsing_list_view.dart';
|
||||||
|
import 'package:hmg_patient_app_new/theme/colors.dart';
|
||||||
|
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
|
||||||
|
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:provider/provider.dart';
|
||||||
|
import 'package:smooth_corner/smooth_corner.dart';
|
||||||
|
|
||||||
|
class OffersAndDiscountPaymentPage extends StatefulWidget {
|
||||||
|
OffersAndDiscountPaymentPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<OffersAndDiscountPaymentPage> createState() => _OffersAndDiscountPaymentPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _OffersAndDiscountPaymentPageState extends State<OffersAndDiscountPaymentPage> {
|
||||||
|
late PayfortViewModel payfortViewModel;
|
||||||
|
late OffersAndDiscountsViewModel offersAndDiscountsViewModel;
|
||||||
|
late MyAppointmentsViewModel myAppointmentsViewModel;
|
||||||
|
late AppState appState;
|
||||||
|
late PayTabsViewModel paytabsViewModel;
|
||||||
|
|
||||||
|
|
||||||
|
MyInAppBrowser? browser;
|
||||||
|
String selectedPaymentMethod = "";
|
||||||
|
|
||||||
|
String transID = "";
|
||||||
|
|
||||||
|
bool isShowTamara = false;
|
||||||
|
String tamaraPaymentStatus = "";
|
||||||
|
String tamaraOrderID = "";
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
scheduleMicrotask(() {
|
||||||
|
payfortViewModel.initPayfortViewModel();
|
||||||
|
});
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
appState = getIt.get<AppState>();
|
||||||
|
myAppointmentsViewModel = Provider.of<MyAppointmentsViewModel>(context, listen: false);
|
||||||
|
offersAndDiscountsViewModel = Provider.of<OffersAndDiscountsViewModel>(context, listen: false);
|
||||||
|
payfortViewModel = Provider.of<PayfortViewModel>(context, listen: false);
|
||||||
|
paytabsViewModel = Provider.of<PayTabsViewModel>(context, listen: false);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: AppColors.bgScaffoldColor,
|
||||||
|
body: Consumer<OffersAndDiscountsViewModel>(builder: (context, offersVM, child) {
|
||||||
|
final selectedOffer = offersVM.selectedOffer;
|
||||||
|
|
||||||
|
if (selectedOffer == null) {
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.error_outline, size: 64.h, color: AppColors.errorColor),
|
||||||
|
SizedBox(height: 16.h),
|
||||||
|
LocaleKeys.noDataAvailable.tr(context: context).toText16(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: CollapsingListView(
|
||||||
|
title: "${LocaleKeys.offers.tr(context: context)} ${LocaleKeys.payment.tr(context: context)}",
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
SizedBox(height: 24.h),
|
||||||
|
// Offer Summary Card
|
||||||
|
Container(
|
||||||
|
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
|
||||||
|
color: AppColors.whiteColor,
|
||||||
|
borderRadius: 20.h,
|
||||||
|
hasShadow: false,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
(appState.getLanguageID() == 1 ? selectedOffer.nameAr : selectedOffer.name).toText18(isBold: true),
|
||||||
|
SizedBox(height: 8.h),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
LocaleKeys.price.tr(context: context).toText14(color: AppColors.greyTextColor),
|
||||||
|
"${selectedOffer.listPrice} ${selectedOffer.currency}".toText16(isBold: true, color: AppColors.primaryRedColor),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).paddingSymmetrical(16.h, 16.h),
|
||||||
|
).paddingSymmetrical(24.h, 0.h),
|
||||||
|
SizedBox(height: 24.h),
|
||||||
|
LocaleKeys.selectPaymentMethod.tr(context: context).toText18(isBold: true).paddingSymmetrical(24.h, 0.h),
|
||||||
|
SizedBox(height: 16.h),
|
||||||
|
Container(
|
||||||
|
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
|
||||||
|
color: AppColors.whiteColor,
|
||||||
|
borderRadius: 20.h,
|
||||||
|
hasShadow: false,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Utils.buildImgWithAssets(icon: AppAssets.mada, width: 72.h, height: 25.h, fit: BoxFit.contain),
|
||||||
|
SizedBox(height: 16.h),
|
||||||
|
LocaleKeys.mada.tr(context: context).toText16(isBold: true),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(width: 8.h),
|
||||||
|
const Spacer(),
|
||||||
|
Transform.flip(
|
||||||
|
flipX: appState.isArabic(),
|
||||||
|
child: Utils.buildSvgWithAssets(
|
||||||
|
icon: AppAssets.forward_arrow_icon,
|
||||||
|
iconColor: AppColors.blackColor,
|
||||||
|
width: 40.h,
|
||||||
|
height: 40.h,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).paddingSymmetrical(16.h, 16.h),
|
||||||
|
).paddingSymmetrical(24.h, 0.h).onPress(() async {
|
||||||
|
selectedPaymentMethod = "MADA";
|
||||||
|
if (appState.isPaytabsEnabled) {
|
||||||
|
paytabsViewModel.setPaymentConfiguration(
|
||||||
|
"Offer Payment",
|
||||||
|
selectedOffer.listPrice,
|
||||||
|
);
|
||||||
|
paytabsViewModel.startCardPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async {
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr());
|
||||||
|
// TODO: Call API to complete offer purchase
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getSuccessWidget(loadingText: LocaleKeys.paymentSuccessful.tr(context: context)),
|
||||||
|
callBackFunc: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
}, onError: (err) {
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getErrorWidget(loadingText: err.toString()),
|
||||||
|
callBackFunc: () {},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (appState.isPayfortHostedPageEnabled) {
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.fetchingPaymentInformation.tr(context: context));
|
||||||
|
transID = Utils.getAppointmentTransID(
|
||||||
|
selectedOffer.id,
|
||||||
|
ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? 15 : 12,
|
||||||
|
DateTime.now().millisecondsSinceEpoch,
|
||||||
|
);
|
||||||
|
await payfortViewModel.getPayfortConfigurations(
|
||||||
|
serviceId: ServiceTypeEnum.offerPayment.getIdFromServiceEnum(),
|
||||||
|
projectId: ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? 15 : 12,
|
||||||
|
integrationId: 1);
|
||||||
|
|
||||||
|
payfortViewModel.initiatePaymentWithCard(
|
||||||
|
transactionID: transID,
|
||||||
|
fileNumber: appState.getAuthenticatedUser()!.patientId.toString(),
|
||||||
|
amount: selectedOffer.listPrice.toString(),
|
||||||
|
onSucceeded: (paymentResult) async {
|
||||||
|
print("Payment Success Data: ${paymentResult.toString()}");
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr(context: context));
|
||||||
|
// TODO: Call API to complete offer purchase
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getSuccessWidget(loadingText: LocaleKeys.paymentSuccessful.tr(context: context)),
|
||||||
|
callBackFunc: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onFailed: (err) {
|
||||||
|
print("Payment Failed Data: ${err.toString()}");
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getErrorWidget(loadingText: LocaleKeys.paymentFailedPleaseTryAgain.tr(context: context)),
|
||||||
|
callBackFunc: () {},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
openPaymentURL("mada", selectedOffer.listPrice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
SizedBox(height: 16.h),
|
||||||
|
Container(
|
||||||
|
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
|
||||||
|
color: AppColors.whiteColor,
|
||||||
|
borderRadius: 20.h,
|
||||||
|
hasShadow: false,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Utils.buildImgWithAssets(icon: AppAssets.visa, width: 50.h, height: 50.h),
|
||||||
|
SizedBox(width: 8.h),
|
||||||
|
Utils.buildImgWithAssets(icon: AppAssets.mastercard, width: 40.h, height: 40.h, fit: BoxFit.contain),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.h),
|
||||||
|
LocaleKeys.visaOrMastercard.tr(context: context).toText16(isBold: true),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(width: 8.h),
|
||||||
|
const Spacer(),
|
||||||
|
Transform.flip(
|
||||||
|
flipX: appState.isArabic(),
|
||||||
|
child: Utils.buildSvgWithAssets(
|
||||||
|
icon: AppAssets.forward_arrow_icon,
|
||||||
|
iconColor: AppColors.blackColor,
|
||||||
|
width: 40.h,
|
||||||
|
height: 40.h,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).paddingSymmetrical(16.h, 16.h),
|
||||||
|
).paddingSymmetrical(24.h, 0.h).onPress(() async {
|
||||||
|
selectedPaymentMethod = "VISA";
|
||||||
|
if (appState.isPaytabsEnabled) {
|
||||||
|
paytabsViewModel.setPaymentConfiguration(
|
||||||
|
"Offer Payment",
|
||||||
|
selectedOffer.listPrice,
|
||||||
|
);
|
||||||
|
paytabsViewModel.startCardPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async {
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr());
|
||||||
|
// TODO: Call API to complete offer purchase
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getSuccessWidget(loadingText: LocaleKeys.paymentSuccessful.tr(context: context)),
|
||||||
|
callBackFunc: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
}, onError: (err) {
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getErrorWidget(loadingText: err.toString()),
|
||||||
|
callBackFunc: () {},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (appState.isPayfortHostedPageEnabled) {
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.fetchingPaymentInformation.tr(context: context));
|
||||||
|
transID = Utils.getAppointmentTransID(
|
||||||
|
selectedOffer.id,
|
||||||
|
ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? 15 : 12,
|
||||||
|
DateTime.now().millisecondsSinceEpoch,
|
||||||
|
);
|
||||||
|
await payfortViewModel.getPayfortConfigurations(
|
||||||
|
serviceId: ServiceTypeEnum.offerPayment.getIdFromServiceEnum(),
|
||||||
|
projectId: ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? 15 : 12,
|
||||||
|
integrationId: 1);
|
||||||
|
|
||||||
|
payfortViewModel.initiatePaymentWithCard(
|
||||||
|
transactionID: transID,
|
||||||
|
fileNumber: appState.getAuthenticatedUser()!.patientId.toString(),
|
||||||
|
amount: selectedOffer.listPrice.toString(),
|
||||||
|
onSucceeded: (paymentResult) async {
|
||||||
|
print("Payment Success Data: ${paymentResult.toString()}");
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr(context: context));
|
||||||
|
// TODO: Call API to complete offer purchase
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getSuccessWidget(loadingText: LocaleKeys.paymentSuccessful.tr(context: context)),
|
||||||
|
callBackFunc: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onFailed: (err) {
|
||||||
|
print("Payment Failed Data: ${err.toString()}");
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getErrorWidget(loadingText: LocaleKeys.paymentFailedPleaseTryAgain.tr(context: context)),
|
||||||
|
callBackFunc: () {},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
openPaymentURL("visa", selectedOffer.listPrice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
|
||||||
|
color: AppColors.whiteColor,
|
||||||
|
borderRadius: 24.h,
|
||||||
|
hasShadow: false,
|
||||||
|
),
|
||||||
|
child: Consumer<PayfortViewModel>(builder: (context, payfortVM, child) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
SizedBox(height: 24.h),
|
||||||
|
LocaleKeys.totalAmountToPay.tr().toText18(isBold: true).paddingSymmetrical(24.h, 0.h),
|
||||||
|
SizedBox(height: 17.h),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
LocaleKeys.amountBeforeTax.tr().toText14(isBold: true),
|
||||||
|
Utils.getPaymentAmountWithSymbol(selectedOffer.vatExclusivePrice.toString().toText16(isBold: true), AppColors.blackColor, 13,
|
||||||
|
isSaudiCurrency: selectedOffer.currency == "SAR"),
|
||||||
|
],
|
||||||
|
).paddingSymmetrical(24.h, 0.h),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
LocaleKeys.vat15.tr().toText14(isBold: true, color: AppColors.greyTextColor),
|
||||||
|
Utils.getPaymentAmountWithSymbol(
|
||||||
|
(selectedOffer.vatInclusivePrice - selectedOffer.vatExclusivePrice).toStringAsFixed(2).toText14(isBold: true, color: AppColors.greyTextColor), AppColors.greyTextColor, 13,
|
||||||
|
isSaudiCurrency: selectedOffer.currency == "SAR"),
|
||||||
|
],
|
||||||
|
).paddingSymmetrical(24.h, 0.h),
|
||||||
|
SizedBox(height: 17.h),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
"".toText14(isBold: true),
|
||||||
|
Utils.getPaymentAmountWithSymbol(selectedOffer.listPrice.toString().toText24(isBold: true), AppColors.blackColor, 17,
|
||||||
|
isSaudiCurrency: selectedOffer.currency == "SAR"),
|
||||||
|
],
|
||||||
|
).paddingSymmetrical(24.h, 0.h),
|
||||||
|
Platform.isIOS
|
||||||
|
? Utils.buildSvgWithAssets(
|
||||||
|
icon: AppAssets.apple_pay_button,
|
||||||
|
width: 200.h,
|
||||||
|
height: 80.h,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
applyThemeColor: false
|
||||||
|
).paddingSymmetrical(24.h, 0.h).onPress(() {
|
||||||
|
if (Utils.havePrivilege(103)) {
|
||||||
|
startApplePay(selectedOffer.listPrice);
|
||||||
|
} else {
|
||||||
|
openPaymentURL("ApplePay", selectedOffer.listPrice);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
: SizedBox(height: 12.h),
|
||||||
|
SizedBox(height: 12.h),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
onBrowserLoadStart(String url) {
|
||||||
|
print("onBrowserLoadStart");
|
||||||
|
print(url);
|
||||||
|
|
||||||
|
if (selectedPaymentMethod == "TAMARA") {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
Uri uri = new Uri.dataFromString(url);
|
||||||
|
tamaraPaymentStatus = uri.queryParameters['status']!;
|
||||||
|
tamaraOrderID = uri.queryParameters['AuthorizePaymentId']!;
|
||||||
|
} else {
|
||||||
|
Uri uri = new Uri.dataFromString(url);
|
||||||
|
tamaraPaymentStatus = uri.queryParameters['paymentStatus']!;
|
||||||
|
tamaraOrderID = uri.queryParameters['orderId']!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if(selectedPaymentMethod != "TAMARA") {
|
||||||
|
MyInAppBrowser.successURLS.forEach((element) {
|
||||||
|
if (url.contains(element)) {
|
||||||
|
browser?.close();
|
||||||
|
MyInAppBrowser.isPaymentDone = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if(selectedPaymentMethod != "TAMARA") {
|
||||||
|
MyInAppBrowser.errorURLS.forEach((element) {
|
||||||
|
if (url.contains(element)) {
|
||||||
|
browser?.close();
|
||||||
|
MyInAppBrowser.isPaymentDone = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
onBrowserExit(bool isPaymentMade) async {
|
||||||
|
debugPrint("onBrowserExit Called!!!!");
|
||||||
|
checkPaymentStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkPaymentStatus() async {
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr());
|
||||||
|
if (selectedPaymentMethod == "TAMARA") {
|
||||||
|
await payfortViewModel.checkTamaraPaymentStatus(
|
||||||
|
transactionID: transID,
|
||||||
|
onSuccess: (apiResponse) async {
|
||||||
|
if (apiResponse.data["status"].toString().toLowerCase() == "success") {
|
||||||
|
tamaraOrderID = apiResponse.data["tamara_order_id"].toString();
|
||||||
|
await payfortViewModel.updateTamaraRequestStatus(responseMessage: "success", status: "14", clientRequestID: transID, tamaraOrderID: tamaraOrderID);
|
||||||
|
// TODO: Call API to complete offer purchase
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getSuccessWidget(loadingText: LocaleKeys.paymentSuccessful.tr(context: context)),
|
||||||
|
callBackFunc: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await payfortViewModel.updateTamaraRequestStatus(responseMessage: "Failed", status: "00", clientRequestID: transID, tamaraOrderID: tamaraOrderID);
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getErrorWidget(loadingText: LocaleKeys.paymentFailedPleaseTryAgain.tr()),
|
||||||
|
callBackFunc: () {},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (err) {
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getErrorWidget(loadingText: err),
|
||||||
|
callBackFunc: () {},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await payfortViewModel.checkPaymentStatus(
|
||||||
|
transactionID: transID,
|
||||||
|
onSuccess: (apiResponse) async {
|
||||||
|
debugPrint(apiResponse.data.toString());
|
||||||
|
if (payfortViewModel.payfortCheckPaymentStatusResponseModel!.responseMessage!.toLowerCase() == "success") {
|
||||||
|
// TODO: Call API to complete offer purchase
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getSuccessWidget(loadingText: LocaleKeys.paymentSuccessful.tr(context: context)),
|
||||||
|
callBackFunc: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getErrorWidget(loadingText: LocaleKeys.paymentFailedPleaseTryAgain.tr()),
|
||||||
|
callBackFunc: () {},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
openPaymentURL(String paymentMethod, double amount) {
|
||||||
|
browser = MyInAppBrowser(onExitCallback: onBrowserExit, onLoadStartCallback: onBrowserLoadStart, context: context);
|
||||||
|
final selectedOffer = offersAndDiscountsViewModel.selectedOffer;
|
||||||
|
|
||||||
|
if (selectedOffer == null) return;
|
||||||
|
|
||||||
|
transID = Utils.getAppointmentTransID(
|
||||||
|
selectedOffer.id,
|
||||||
|
ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? 15 : 12,
|
||||||
|
DateTime.now().millisecondsSinceEpoch,
|
||||||
|
);
|
||||||
|
|
||||||
|
browser?.openPaymentBrowser(
|
||||||
|
amount,
|
||||||
|
"Offer Payment",
|
||||||
|
transID,
|
||||||
|
"12",
|
||||||
|
"CustID_${appState.getAuthenticatedUser()!.patientId.toString()}@HMG.com",
|
||||||
|
selectedPaymentMethod,
|
||||||
|
appState.getAuthenticatedUser()!.patientType.toString(),
|
||||||
|
"${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}",
|
||||||
|
appState.getAuthenticatedUser()!.patientId.toString(),
|
||||||
|
appState.getAuthenticatedUser()!,
|
||||||
|
browser!,
|
||||||
|
false,
|
||||||
|
"4",
|
||||||
|
selectedOffer.id.toString(),
|
||||||
|
context,
|
||||||
|
"3");
|
||||||
|
}
|
||||||
|
|
||||||
|
startApplePay(double amount) async {
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.fetchingApplePayDetails.tr());
|
||||||
|
final selectedOffer = offersAndDiscountsViewModel.selectedOffer;
|
||||||
|
|
||||||
|
if (selectedOffer == null) {
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
transID = Utils.getAppointmentTransID(
|
||||||
|
selectedOffer.id,
|
||||||
|
ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? 15 : 12,
|
||||||
|
DateTime.now().millisecondsSinceEpoch,
|
||||||
|
);
|
||||||
|
|
||||||
|
ApplePayInsertRequest applePayInsertRequest = ApplePayInsertRequest();
|
||||||
|
|
||||||
|
await payfortViewModel.getPayfortConfigurations(
|
||||||
|
serviceId: ServiceTypeEnum.offerPayment.getIdFromServiceEnum(),
|
||||||
|
projectId: ApiConsts.appEnvironmentType == AppEnvironmentTypeEnum.uat ? 15 : 12,
|
||||||
|
integrationId: 2);
|
||||||
|
|
||||||
|
applePayInsertRequest.clientRequestID = transID;
|
||||||
|
applePayInsertRequest.clinicID = selectedOffer.id;
|
||||||
|
|
||||||
|
applePayInsertRequest.currency = selectedOffer.currency;
|
||||||
|
applePayInsertRequest.customerEmail = "CustID_${appState.getAuthenticatedUser()!.patientId.toString()}@HMG.com";
|
||||||
|
applePayInsertRequest.customerID = appState.getAuthenticatedUser()!.patientId.toString();
|
||||||
|
applePayInsertRequest.customerName = "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}";
|
||||||
|
|
||||||
|
applePayInsertRequest.deviceToken = await Utils.getStringFromPrefs(CacheConst.pushToken);
|
||||||
|
applePayInsertRequest.voipToken = await Utils.getStringFromPrefs(CacheConst.voipToken);
|
||||||
|
applePayInsertRequest.doctorID = 0;
|
||||||
|
applePayInsertRequest.projectID = "12";
|
||||||
|
applePayInsertRequest.serviceID = ServiceTypeEnum.offerPayment.getIdFromServiceEnum().toString();
|
||||||
|
applePayInsertRequest.channelID = 3;
|
||||||
|
applePayInsertRequest.patientID = appState.getAuthenticatedUser()!.patientId.toString();
|
||||||
|
applePayInsertRequest.patientTypeID = appState.getAuthenticatedUser()!.patientType;
|
||||||
|
applePayInsertRequest.patientOutSA = appState.getAuthenticatedUser()!.outSa;
|
||||||
|
applePayInsertRequest.appointmentDate = DateUtil.convertDateToString(DateTime.now());
|
||||||
|
applePayInsertRequest.appointmentNo = 0;
|
||||||
|
applePayInsertRequest.orderDescription = "Offer Payment";
|
||||||
|
applePayInsertRequest.liveServiceID = selectedOffer.id.toString();
|
||||||
|
applePayInsertRequest.latitude = "0.0";
|
||||||
|
applePayInsertRequest.longitude = "0.0";
|
||||||
|
applePayInsertRequest.amount = amount.toString();
|
||||||
|
applePayInsertRequest.isSchedule = "0";
|
||||||
|
applePayInsertRequest.language = appState.isArabic() ? 'ar' : 'en';
|
||||||
|
applePayInsertRequest.languageID = appState.isArabic() ? 1 : 2;
|
||||||
|
applePayInsertRequest.userName = appState.getAuthenticatedUser()!.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 = payfortViewModel.payfortProjectDetailsRespModel!.merchantIdentifier;
|
||||||
|
applePayInsertRequest.commandType = "PURCHASE";
|
||||||
|
applePayInsertRequest.signature = payfortViewModel.payfortProjectDetailsRespModel!.signature;
|
||||||
|
applePayInsertRequest.accessCode = payfortViewModel.payfortProjectDetailsRespModel!.accessCode;
|
||||||
|
applePayInsertRequest.shaRequestPhrase = payfortViewModel.payfortProjectDetailsRespModel!.shaRequest;
|
||||||
|
applePayInsertRequest.shaResponsePhrase = payfortViewModel.payfortProjectDetailsRespModel!.shaResponse;
|
||||||
|
applePayInsertRequest.returnURL = "";
|
||||||
|
|
||||||
|
await payfortViewModel.applePayRequestInsert(applePayInsertRequest: applePayInsertRequest).then((value) {
|
||||||
|
if (appState.isPaytabsEnabled) {
|
||||||
|
selectedPaymentMethod = "VISA";
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
paytabsViewModel.setPaymentConfiguration("Offer Payment", amount);
|
||||||
|
paytabsViewModel.startApplePayPayment(onSuccess: (PaytabsTransactionResponseModel transactionData) async {
|
||||||
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.checkingPaymentStatusPleaseWait.tr());
|
||||||
|
// TODO: Call API to complete offer purchase
|
||||||
|
LoaderBottomSheet.hideLoader();
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getSuccessWidget(loadingText: LocaleKeys.paymentSuccessful.tr(context: context)),
|
||||||
|
callBackFunc: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
}, onError: (err) {
|
||||||
|
showCommonBottomSheetWithoutHeight(
|
||||||
|
context,
|
||||||
|
child: Utils.getErrorWidget(loadingText: err.toString()),
|
||||||
|
callBackFunc: () {},
|
||||||
|
isFullScreen: false,
|
||||||
|
isCloseButtonVisible: true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
payfortViewModel.paymentWithApplePay(
|
||||||
|
customerName: "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}",
|
||||||
|
customerEmail: "CustID_${appState.getAuthenticatedUser()!.patientId.toString()}@HMG.com",
|
||||||
|
orderDescription: "Offer Payment",
|
||||||
|
orderAmount: amount,
|
||||||
|
merchantReference: transID,
|
||||||
|
merchantIdentifier: payfortViewModel.payfortProjectDetailsRespModel!.merchantIdentifier,
|
||||||
|
applePayAccessCode: payfortViewModel.payfortProjectDetailsRespModel!.accessCode,
|
||||||
|
applePayShaRequestPhrase: payfortViewModel.payfortProjectDetailsRespModel!.shaRequest,
|
||||||
|
currency: selectedOffer.currency,
|
||||||
|
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();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue