|
|
|
|
@ -2,25 +2,35 @@ 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/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/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/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/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';
|
|
|
|
|
import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/theme/colors.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.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';
|
|
|
|
|
|
|
|
|
|
class AncillaryOrderPaymentPage extends StatefulWidget {
|
|
|
|
|
final DateTime? appointmentDate;
|
|
|
|
|
final int appointmentNoVida;
|
|
|
|
|
final int orderNo;
|
|
|
|
|
final int projectID;
|
|
|
|
|
@ -29,6 +39,7 @@ class AncillaryOrderPaymentPage extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
const AncillaryOrderPaymentPage({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.appointmentDate,
|
|
|
|
|
required this.appointmentNoVida,
|
|
|
|
|
required this.orderNo,
|
|
|
|
|
required this.projectID,
|
|
|
|
|
@ -171,7 +182,7 @@ class _AncillaryOrderPaymentPageState extends State<AncillaryOrderPaymentPage> {
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Payment Summary Footer
|
|
|
|
|
todoVM.isProcessingPayment ? SizedBox.shrink() : _buildPaymentSummary(),
|
|
|
|
|
todoVM.isProcessingPayment ? SizedBox.shrink() : _buildPaymentSummary()
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
@ -256,7 +267,7 @@ class _AncillaryOrderPaymentPageState extends State<AncillaryOrderPaymentPage> {
|
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
|
).paddingSymmetrical(24.h, 0.h).onPress(() {
|
|
|
|
|
if (!todoSectionViewModel.isProcessingPayment) {
|
|
|
|
|
_openPaymentURL("ApplePay");
|
|
|
|
|
_startApplePay();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
: SizedBox(height: 12.h),
|
|
|
|
|
@ -474,11 +485,160 @@ class _AncillaryOrderPaymentPageState extends State<AncillaryOrderPaymentPage> {
|
|
|
|
|
|
|
|
|
|
// Show success message and navigate
|
|
|
|
|
Utils.showToast("Payment successful! Invoice #: $invoiceNo");
|
|
|
|
|
|
|
|
|
|
// Navigate back to home after a short delay
|
|
|
|
|
Future.delayed(Duration(seconds: 2), () {
|
|
|
|
|
Navigator.of(context).pop(); // Close payment page
|
|
|
|
|
Navigator.of(context).pop(); // Close details page
|
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
|
|
|
showCommonBottomSheetWithoutHeight(
|
|
|
|
|
context,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
"Here is your invoice #: ".needTranslation.toText14(
|
|
|
|
|
color: AppColors.textColorLight,
|
|
|
|
|
weight: FontWeight.w500,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(width: 4.w),
|
|
|
|
|
("12345").toText16(isBold: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 24.h),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: CustomButton(
|
|
|
|
|
height: 56.h,
|
|
|
|
|
text: LocaleKeys.ok.tr(),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pushAndRemoveUntil(
|
|
|
|
|
context,
|
|
|
|
|
CustomPageRoute(
|
|
|
|
|
page: LandingNavigation(),
|
|
|
|
|
),
|
|
|
|
|
(r) => false);
|
|
|
|
|
},
|
|
|
|
|
backgroundColor: AppColors.secondaryLightRedColor,
|
|
|
|
|
borderColor: AppColors.secondaryLightRedColor,
|
|
|
|
|
textColor: AppColors.primaryRedColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
// title: "Payment Completed Successfully".needTranslation,
|
|
|
|
|
titleWidget: Utils.getSuccessWidget(loadingText: "Payment Completed Successfully".needTranslation),
|
|
|
|
|
isCloseButtonVisible: false,
|
|
|
|
|
isDismissible: false,
|
|
|
|
|
isFullScreen: false,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_startApplePay() async {
|
|
|
|
|
showCommonBottomSheet(
|
|
|
|
|
context,
|
|
|
|
|
child: Utils.getLoadingWidget(),
|
|
|
|
|
callBackFunc: (str) {},
|
|
|
|
|
title: "",
|
|
|
|
|
height: ResponsiveExtension.screenHeight * 0.3,
|
|
|
|
|
isCloseButtonVisible: false,
|
|
|
|
|
isDismissible: false,
|
|
|
|
|
isFullScreen: false,
|
|
|
|
|
);
|
|
|
|
|
final user = appState.getAuthenticatedUser();
|
|
|
|
|
transID = Utils.getAdvancePaymentTransID(widget.projectID, user!.patientId!);
|
|
|
|
|
|
|
|
|
|
ApplePayInsertRequest applePayInsertRequest = ApplePayInsertRequest();
|
|
|
|
|
await payfortViewModel.getPayfortConfigurations(
|
|
|
|
|
serviceId: ServiceTypeEnum.ancillaryOrder.getIdFromServiceEnum(),
|
|
|
|
|
projectId: widget.projectID,
|
|
|
|
|
integrationId: 2,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
applePayInsertRequest.clientRequestID = transID;
|
|
|
|
|
applePayInsertRequest.clinicID = 0;
|
|
|
|
|
|
|
|
|
|
applePayInsertRequest.currency = appState.getAuthenticatedUser()!.outSa! == 0 ? "SAR" : "AED";
|
|
|
|
|
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 = widget.projectID.toString();
|
|
|
|
|
applePayInsertRequest.serviceID = ServiceTypeEnum.ancillaryOrder.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(widget.appointmentDate ?? DateTime.now());
|
|
|
|
|
applePayInsertRequest.appointmentNo = widget.appointmentNoVida;
|
|
|
|
|
applePayInsertRequest.orderDescription = "Ancillary Order Payment";
|
|
|
|
|
applePayInsertRequest.liveServiceID = "0";
|
|
|
|
|
applePayInsertRequest.latitude = "0.0";
|
|
|
|
|
applePayInsertRequest.longitude = "0.0";
|
|
|
|
|
applePayInsertRequest.amount = widget.totalAmount.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 = "";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await payfortViewModel.applePayRequestInsert(applePayInsertRequest: applePayInsertRequest);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
log("Apple Pay Insert Request Failed: $error");
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
showCommonBottomSheetWithoutHeight(
|
|
|
|
|
context,
|
|
|
|
|
child: Utils.getErrorWidget(loadingText: "Failed to initialize Apple Pay. Please try again.".needTranslation),
|
|
|
|
|
callBackFunc: () {},
|
|
|
|
|
isFullScreen: false,
|
|
|
|
|
isCloseButtonVisible: true,
|
|
|
|
|
);
|
|
|
|
|
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()}");
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
showCommonBottomSheetWithoutHeight(
|
|
|
|
|
context,
|
|
|
|
|
child: Utils.getErrorWidget(loadingText: failureResult.message.toString()),
|
|
|
|
|
callBackFunc: () {},
|
|
|
|
|
isFullScreen: false,
|
|
|
|
|
isCloseButtonVisible: true,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
onSucceeded: (successResult) async {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
log("successResult: ${successResult.responseMessage.toString()}");
|
|
|
|
|
selectedPaymentMethod = successResult.paymentOption ?? "VISA";
|
|
|
|
|
_checkPaymentStatus();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|