|
|
|
|
@ -1,9 +1,27 @@
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Clinics/EROnlineCheckInPaymentDetailsResponse.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/LiveCare/ApplePayInsertRequest.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/ToDoList/payment_method_select.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/theme/colors.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/dragable_sheet.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
@ -15,11 +33,18 @@ class EROnlineCheckInPaymentDetails extends StatefulWidget {
|
|
|
|
|
State<EROnlineCheckInPaymentDetails> createState() => _EROnlineCheckInPaymentDetailsState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _EROnlineCheckInPaymentDetailsState extends State<EROnlineCheckInPaymentDetails> {
|
|
|
|
|
class _EROnlineCheckInPaymentDetailsState extends State<EROnlineCheckInPaymentDetails> with SingleTickerProviderStateMixin {
|
|
|
|
|
ProjectViewModel projectViewModel;
|
|
|
|
|
EROnlineCheckInPaymentDetailsResponse erOnlineCheckInPaymentDetailsResponse;
|
|
|
|
|
String selectedPaymentMethod;
|
|
|
|
|
String selectedInstallmentPlan;
|
|
|
|
|
String transID = "";
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
getEROnlineCheckInPaymentDetails();
|
|
|
|
|
});
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -210,54 +235,245 @@ class _EROnlineCheckInPaymentDetailsState extends State<EROnlineCheckInPaymentDe
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
bottomSheet: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10), bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.grey.withOpacity(0.5),
|
|
|
|
|
spreadRadius: 5,
|
|
|
|
|
blurRadius: 7,
|
|
|
|
|
offset: Offset(0, 3), // changes position of shadow
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
padding: EdgeInsets.only(left: 21, right: 21, top: 15, bottom: 15),
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
// color: Colors.white,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(height: 12),
|
|
|
|
|
Text(
|
|
|
|
|
TranslationBase.of(context).YouCanPayByTheFollowingOptions,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 16.0,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: Color(0xff2B353E),
|
|
|
|
|
letterSpacing: -0.64,
|
|
|
|
|
bottomSheet: erOnlineCheckInPaymentDetailsResponse != null
|
|
|
|
|
? Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10), bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.grey.withOpacity(0.5),
|
|
|
|
|
spreadRadius: 5,
|
|
|
|
|
blurRadius: 7,
|
|
|
|
|
offset: Offset(0, 3), // changes position of shadow
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: MediaQuery.of(context).size.width * 0.75,
|
|
|
|
|
child: getPaymentMethods(),
|
|
|
|
|
),
|
|
|
|
|
_amountView(TranslationBase.of(context).patientShareTotalToDo, "51.81" + " " + TranslationBase.of(context).sar, isBold: true, isTotal: true),
|
|
|
|
|
SizedBox(height: 12),
|
|
|
|
|
DefaultButton(
|
|
|
|
|
TranslationBase.of(context).payNow.toUpperCase(),
|
|
|
|
|
() {},
|
|
|
|
|
color: CustomColors.green,
|
|
|
|
|
disabledColor: CustomColors.grey2,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
padding: EdgeInsets.only(left: 21, right: 21, top: 15, bottom: 15),
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
// color: Colors.white,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(height: 12),
|
|
|
|
|
Text(
|
|
|
|
|
TranslationBase.of(context).YouCanPayByTheFollowingOptions,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 16.0,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: Color(0xff2B353E),
|
|
|
|
|
letterSpacing: -0.64,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: MediaQuery.of(context).size.width * 0.75,
|
|
|
|
|
child: getPaymentMethods(),
|
|
|
|
|
),
|
|
|
|
|
_amountView(TranslationBase.of(context).patientShareTotalToDo, erOnlineCheckInPaymentDetailsResponse.patientShareWithTax.toString() + " " + TranslationBase.of(context).sar,
|
|
|
|
|
isBold: true, isTotal: true),
|
|
|
|
|
SizedBox(height: 12),
|
|
|
|
|
DefaultButton(
|
|
|
|
|
TranslationBase.of(context).payNow.toUpperCase(),
|
|
|
|
|
() {
|
|
|
|
|
makePayment();
|
|
|
|
|
},
|
|
|
|
|
color: CustomColors.green,
|
|
|
|
|
disabledColor: CustomColors.grey2,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Container(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
makePayment() {
|
|
|
|
|
showDraggableDialog(
|
|
|
|
|
context,
|
|
|
|
|
PaymentMethod(
|
|
|
|
|
onSelectedMethod: (String method, [String selectedInstallmentPlan]) {
|
|
|
|
|
selectedPaymentMethod = method;
|
|
|
|
|
this.selectedInstallmentPlan = selectedInstallmentPlan;
|
|
|
|
|
if (selectedPaymentMethod == "ApplePay") {
|
|
|
|
|
if (projectViewModel.havePrivilege(103)) {
|
|
|
|
|
startApplePay();
|
|
|
|
|
} else {
|
|
|
|
|
// openPayment(selectedPaymentMethod, projectViewModel.user, erOnlineCheckInPaymentDetailsResponse.patientShareWithTax, null, selectedInstallmentPlan);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// openPayment(selectedPaymentMethod, projectViewModel.user, erOnlineCheckInPaymentDetailsResponse.patientShareWithTax, null, selectedInstallmentPlan);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
patientShare: erOnlineCheckInPaymentDetailsResponse.patientShareWithTax,
|
|
|
|
|
isFromAdvancePayment: false,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startApplePay() async {
|
|
|
|
|
transID = Utils.getAdvancePaymentTransID(15, projectViewModel.user.patientID);
|
|
|
|
|
|
|
|
|
|
print("TransactionID: $transID");
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
|
|
|
|
|
LiveCareService service = new LiveCareService();
|
|
|
|
|
ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest();
|
|
|
|
|
|
|
|
|
|
PayfortProjectDetailsRespModel payfortProjectDetailsRespModel;
|
|
|
|
|
await context.read<PayfortViewModel>().getProjectDetailsForPayfort(projectId: 15, serviceId: ServiceTypeEnum.appointmentPayment.getIdFromServiceEnum()).then((value) {
|
|
|
|
|
payfortProjectDetailsRespModel = value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
applePayInsertRequest.clientRequestID = transID;
|
|
|
|
|
applePayInsertRequest.clinicID = 0;
|
|
|
|
|
applePayInsertRequest.currency = projectViewModel.user.outSA == 1 ? "AED" : "SAR";
|
|
|
|
|
// applePayInsertRequest.customerEmail = projectViewModel.authenticatedUserObject.user.emailAddress;
|
|
|
|
|
applePayInsertRequest.customerEmail = "CustID_${projectViewModel.user.patientID}@HMG.com";
|
|
|
|
|
applePayInsertRequest.customerID = projectViewModel.user.patientID;
|
|
|
|
|
applePayInsertRequest.customerName = projectViewModel.user.firstName + " " + projectViewModel.user.lastName;
|
|
|
|
|
applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN);
|
|
|
|
|
applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN);
|
|
|
|
|
applePayInsertRequest.doctorID = 0;
|
|
|
|
|
applePayInsertRequest.projectID = "15";
|
|
|
|
|
applePayInsertRequest.serviceID = ServiceTypeEnum.advancePayment.getIdFromServiceEnum().toString();
|
|
|
|
|
applePayInsertRequest.channelID = 3;
|
|
|
|
|
applePayInsertRequest.patientID = projectViewModel.user.patientID;
|
|
|
|
|
applePayInsertRequest.patientTypeID = projectViewModel.user.patientType;
|
|
|
|
|
applePayInsertRequest.patientOutSA = projectViewModel.user.outSA;
|
|
|
|
|
applePayInsertRequest.appointmentDate = null;
|
|
|
|
|
applePayInsertRequest.appointmentNo = 0;
|
|
|
|
|
applePayInsertRequest.orderDescription = "Ancillary Order Payment";
|
|
|
|
|
applePayInsertRequest.liveServiceID = "0";
|
|
|
|
|
applePayInsertRequest.latitude = "0.0";
|
|
|
|
|
applePayInsertRequest.longitude = "0.0";
|
|
|
|
|
applePayInsertRequest.amount = erOnlineCheckInPaymentDetailsResponse.patientShareWithTax.toString();
|
|
|
|
|
applePayInsertRequest.isSchedule = "0";
|
|
|
|
|
applePayInsertRequest.language = projectViewModel.isArabic ? 'ar' : 'en';
|
|
|
|
|
applePayInsertRequest.languageID = projectViewModel.isArabic ? 1 : 2;
|
|
|
|
|
applePayInsertRequest.userName = projectViewModel.user.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 = payfortProjectDetailsRespModel.merchantIdentifier;
|
|
|
|
|
applePayInsertRequest.commandType = "PURCHASE";
|
|
|
|
|
applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature;
|
|
|
|
|
applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode;
|
|
|
|
|
applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest;
|
|
|
|
|
applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse;
|
|
|
|
|
applePayInsertRequest.returnURL = "";
|
|
|
|
|
|
|
|
|
|
service.applePayInsertRequest(applePayInsertRequest, context).then((res) async {
|
|
|
|
|
if (res["MessageStatus"] == 1) {
|
|
|
|
|
await context.read<PayfortViewModel>().initiateApplePayWithPayfort(
|
|
|
|
|
customerName: projectViewModel.user.firstName + " " + projectViewModel.user.lastName,
|
|
|
|
|
// customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress,
|
|
|
|
|
customerEmail: "CustID_${projectViewModel.user.patientID}@HMG.com",
|
|
|
|
|
orderDescription: "Ancillary Order Payment",
|
|
|
|
|
orderAmount: erOnlineCheckInPaymentDetailsResponse.patientShareWithTax,
|
|
|
|
|
merchantReference: transID,
|
|
|
|
|
payfortProjectDetailsRespModel: payfortProjectDetailsRespModel,
|
|
|
|
|
currency: projectViewModel.user.outSA == 1 ? "AED" : "SAR",
|
|
|
|
|
onFailed: (failureResult) async {
|
|
|
|
|
log("failureResult: ${failureResult.toString()}");
|
|
|
|
|
AppToast.showErrorToast(message: failureResult.toString());
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (successResult) async {
|
|
|
|
|
log("Payfort: ${successResult.responseMessage}");
|
|
|
|
|
await context.read<PayfortViewModel>().addPayfortApplePayResponse(projectViewModel.user.patientID, result: successResult);
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
checkPaymentStatus(AppoitmentAllHistoryResultList());
|
|
|
|
|
},
|
|
|
|
|
projectId: 15,
|
|
|
|
|
serviceTypeEnum: ServiceTypeEnum.appointmentPayment,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
AppToast.showErrorToast(message: "An error occurred while processing your request");
|
|
|
|
|
}
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
print(err);
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
AppToast.showErrorToast(message: err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkPaymentStatus(AppoitmentAllHistoryResultList appo) {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
DoctorsListService service = new DoctorsListService();
|
|
|
|
|
service.checkPaymentStatus(transID, false, context).then((res) {
|
|
|
|
|
String paymentInfo = res['Response_Message'];
|
|
|
|
|
if (paymentInfo == 'Success') {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
createAdvancePayment(res, appo);
|
|
|
|
|
} else {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
AppToast.showErrorToast(message: res['Response_Message']);
|
|
|
|
|
}
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
AppToast.showErrorToast(message: err);
|
|
|
|
|
print(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createAdvancePayment(paymentRes, AppoitmentAllHistoryResultList appo) {
|
|
|
|
|
DoctorsListService service = new DoctorsListService();
|
|
|
|
|
String paymentReference = paymentRes['Fort_id'].toString();
|
|
|
|
|
service.HIS_createAdvancePayment(appo, "15", paymentRes['Amount'], paymentRes['Fort_id'], paymentRes['PaymentMethod'], projectViewModel.user.patientType,
|
|
|
|
|
projectViewModel.user.firstName + " " + projectViewModel.user.lastName, projectViewModel.user.patientID, context)
|
|
|
|
|
.then((res) {
|
|
|
|
|
addAdvancedNumberRequest(
|
|
|
|
|
Utils.isVidaPlusProject(projectViewModel, 15) ? res['OnlineCheckInAppointments'][0]['AdvanceNumber_VP'].toString() : res['OnlineCheckInAppointments'][0]['AdvanceNumber'].toString(),
|
|
|
|
|
paymentReference,
|
|
|
|
|
0,
|
|
|
|
|
appo,
|
|
|
|
|
paymentRes);
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
AppToast.showErrorToast(message: err);
|
|
|
|
|
print(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addAdvancedNumberRequest(String advanceNumber, String paymentReference, dynamic appointmentID, AppoitmentAllHistoryResultList appo, paymentRes) {
|
|
|
|
|
DoctorsListService service = new DoctorsListService();
|
|
|
|
|
service.addAdvancedNumberRequest(advanceNumber, paymentReference, appointmentID, context).then((res) {
|
|
|
|
|
autoGenerateInvoiceER(paymentRes);
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
AppToast.showErrorToast(message: err.toString());
|
|
|
|
|
print(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
autoGenerateInvoiceER(res) {
|
|
|
|
|
DoctorsListService service = new DoctorsListService();
|
|
|
|
|
service.autoGenerateInvoiceERClinic(15, 4, res['Fort_id'], res['Amount'], res['PaymentMethod'], res['CardNumber'], res['Merchant_Reference'], res['RRN']).then((res) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
AppToast.showErrorToast(message: err);
|
|
|
|
|
print(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getEROnlineCheckInPaymentDetails() {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
ClinicListService ancillaryOrdersService = new ClinicListService();
|
|
|
|
|
ancillaryOrdersService.getEROnlineCheckInPaymentDetails(15, 10).then((response) {
|
|
|
|
|
erOnlineCheckInPaymentDetailsResponse = EROnlineCheckInPaymentDetailsResponse.fromJson(response["ResponsePatientShare"]);
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
setState(() {});
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
AppToast.showErrorToast(message: err.toString());
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_amountView(String title, String value, {bool isBold = false, bool isTotal = false}) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 10, bottom: 10),
|
|
|
|
|
|