From aa361547643d1487d6f36d0f8dd22bdeca2dbafb Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 1 Feb 2022 15:18:47 +0300 Subject: [PATCH] Updates & fixes --- .../service/parmacyModule/lacum-service.dart | 8 +- .../pharmacyModule/lacum-viewmodel.dart | 22 +-- lib/models/apple_pay_request.dart | 4 +- .../fragments/home_page_fragment2.dart | 4 - .../medical/balance/confirm_payment_page.dart | 128 +++++++++++++----- .../screens/lacum-activitaion-vida-page.dart | 8 +- .../screens/lacum-setting-page.dart | 9 +- .../pharmacies/screens/lakum-main-page.dart | 31 +++-- .../screens/lakum-terms-conditions-page.dart | 21 ++- 9 files changed, 147 insertions(+), 88 deletions(-) diff --git a/lib/core/service/parmacyModule/lacum-service.dart b/lib/core/service/parmacyModule/lacum-service.dart index c7117303..d94632c2 100644 --- a/lib/core/service/parmacyModule/lacum-service.dart +++ b/lib/core/service/parmacyModule/lacum-service.dart @@ -12,12 +12,12 @@ class LacumService extends BaseService{ LacumAccountInformation lacumInformation; LacumAccountInformation lacumGroupInformation; - Future getLacumAccountInformation() async { + Future getLacumAccountInformation(String identificationNo) async { hasError = false; super.error = ""; Map body = Map(); - body['IdentificationNo'] = user.patientIdentificationNo; + body['IdentificationNo'] = identificationNo; try { await baseAppClient.post(GET_LACUM_ACCOUNT_INFORMATION, @@ -32,12 +32,12 @@ class LacumService extends BaseService{ } } - Future getLacumGroupInformation() async { + Future getLacumGroupInformation(String identificationNo) async { hasError = false; super.error = ""; Map body = Map(); - body['IdentificationNo'] = user.patientIdentificationNo; + body['IdentificationNo'] = identificationNo; body['AccountNumber'] = "${lacumInformation.yahalaAccountNo}"; body['IsDetailsRequired'] = true; diff --git a/lib/core/viewModels/pharmacyModule/lacum-viewmodel.dart b/lib/core/viewModels/pharmacyModule/lacum-viewmodel.dart index 1bd0d542..9f624ae5 100644 --- a/lib/core/viewModels/pharmacyModule/lacum-viewmodel.dart +++ b/lib/core/viewModels/pharmacyModule/lacum-viewmodel.dart @@ -22,14 +22,14 @@ class LacumViewModel extends BaseViewModel { String get successMsg => _lacumService.successMsg; - Future getLacumData() async { - await getLacumAccountData(); - getLacumGroupData(); + Future getLacumData(String identificationNo) async { + await getLacumAccountData(identificationNo); + getLacumGroupData(identificationNo); } - Future getLacumAccountData() async { + Future getLacumAccountData(String identificationNo) async { setState(ViewState.Busy); - await _lacumService.getLacumAccountInformation(); + await _lacumService.getLacumAccountInformation(identificationNo); if (_lacumService.hasError) { error = _lacumService.error; setState(ViewState.Error); @@ -38,9 +38,9 @@ class LacumViewModel extends BaseViewModel { } } - Future getLacumGroupData() async { + Future getLacumGroupData(String identificationNo) async { setState(ViewState.Busy); - await _lacumService.getLacumGroupInformation(); + await _lacumService.getLacumGroupInformation(identificationNo); if (_lacumService.hasError) { error = _lacumService.error; setState(ViewState.Error); @@ -49,7 +49,7 @@ class LacumViewModel extends BaseViewModel { } } - Future makeAccountActivate() async { + Future makeAccountActivate(String identificationNo) async { setState(ViewState.Busy); await _lacumService.makeAccountActivate(); if (_lacumService.hasError) { @@ -57,11 +57,11 @@ class LacumViewModel extends BaseViewModel { setState(ViewState.Error); } else { lacumGroupInformation.lakumInquiryInformationObjVersion.accountStatus = "Active"; - getLacumAccountData(); + getLacumAccountData(identificationNo); } } - Future makeAccountDeactivate() async { + Future makeAccountDeactivate(String identificationNo) async { setState(ViewState.Busy); await _lacumService.makeAccountDeactivate(); if (_lacumService.hasError) { @@ -69,7 +69,7 @@ class LacumViewModel extends BaseViewModel { setState(ViewState.Error); } else { lacumGroupInformation.lakumInquiryInformationObjVersion.accountStatus = "Cancelled"; - getLacumAccountData(); + getLacumAccountData(identificationNo); } } diff --git a/lib/models/apple_pay_request.dart b/lib/models/apple_pay_request.dart index 88e16316..4cb6a9e8 100644 --- a/lib/models/apple_pay_request.dart +++ b/lib/models/apple_pay_request.dart @@ -5,8 +5,8 @@ class ApplePayRequest { dynamic customerEmail; String orderdescription; String liveServiceid; - String longitude; - String latitude; + dynamic longitude; + dynamic latitude; String devicetoken; String clientrequestid; String projectid; diff --git a/lib/pages/landing/fragments/home_page_fragment2.dart b/lib/pages/landing/fragments/home_page_fragment2.dart index 87722fac..9b5637c3 100644 --- a/lib/pages/landing/fragments/home_page_fragment2.dart +++ b/lib/pages/landing/fragments/home_page_fragment2.dart @@ -566,10 +566,6 @@ class _HomePageFragment2State extends State { ); } - callPayfortApplePayAPI(ApplePayResponse applePayResponse) { - - } - Widget showFloating(String icon) { return Container( width: MediaQuery.of(context).size.width * 0.06, diff --git a/lib/pages/medical/balance/confirm_payment_page.dart b/lib/pages/medical/balance/confirm_payment_page.dart index 57548633..5f072e57 100644 --- a/lib/pages/medical/balance/confirm_payment_page.dart +++ b/lib/pages/medical/balance/confirm_payment_page.dart @@ -1,10 +1,13 @@ import 'package:diplomaticquarterapp/config/config.dart'; -import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/model/my_balance/AdvanceModel.dart'; import 'package:diplomaticquarterapp/core/model/my_balance/patient_info_and_mobile_number.dart'; import 'package:diplomaticquarterapp/core/viewModels/medical/my_balance_view_model.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; +import 'package:diplomaticquarterapp/models/apple_pay_request.dart'; +import 'package:diplomaticquarterapp/models/apple_pay_response.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; @@ -21,6 +24,7 @@ import 'package:diplomaticquarterapp/widgets/otp/sms-popup.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:pay/pay.dart'; +import 'package:provider/provider.dart'; import 'new_text_Field.dart'; @@ -38,6 +42,7 @@ class ConfirmPaymentPage extends StatefulWidget { class _ConfirmPaymentPageState extends State { MyInAppBrowser browser; + ProjectViewModel projectViewModel; AppSharedPreferences sharedPref = AppSharedPreferences(); @@ -47,14 +52,6 @@ class _ConfirmPaymentPageState extends State { 'applepay.json', ]); - var _paymentItems = [ - PaymentItem( - label: 'Total', - amount: '99.99', - status: PaymentItemStatus.final_price, - ) - ]; - void submit(MyBalanceViewModel model, code) { final activationCode = code; GifLoaderDialogUtils.showMyDialog(AppGlobal.context); @@ -64,26 +61,7 @@ class _ConfirmPaymentPageState extends State { AppoitmentAllHistoryResultList appo = new AppoitmentAllHistoryResultList(); appo.projectID = widget.patientInfoAndMobileNumber.projectID; if (widget.selectedPaymentMethod == "ApplePay") { - - // _payClient.userCanPay(PayProvider.apple_pay).then((value) { - // print(value); - // }); - - // return FutureBuilder( - // builder: (context, snapshot) { - // if (snapshot.connectionState == ConnectionState.done) { - // if (snapshot.data == true) { - // return RawGooglePayButton( - // style: GooglePayButtonStyle.black, - // type: GooglePayButtonType.pay, - // onPressed: onGooglePayPressed); - // } else { - // // userCanPay returned false - // // Consider showing an alternative payment method - // } - // } - // }, - // ); + startApplePay(); } else { openPayment(widget.selectedPaymentMethod, widget.authenticatedUser, double.parse(widget.advanceModel.amount), null); } @@ -92,6 +70,7 @@ class _ConfirmPaymentPageState extends State { @override Widget build(BuildContext context) { + projectViewModel = Provider.of(context); void showSMSDialog(MyBalanceViewModel model) { new SMSOTP( context, @@ -215,14 +194,8 @@ class _ConfirmPaymentPageState extends State { child: DefaultButton( TranslationBase.of(context).confirm.toUpperCase(), () { - _payClient.userCanPay(PayProvider.apple_pay).then((value) async { - print(value); - final result = await _payClient.showPaymentSelector( - provider: PayProvider.apple_pay, - paymentItems: _paymentItems, - ); - print(result); - }); + // if() + startApplePay(); // GifLoaderDialogUtils.showMyDialog(context); // model.sendActivationCodeForAdvancePayment(patientID: int.parse(widget.advanceModel.fileNumber), projectID: widget.advanceModel.hospitalsModel.iD).then((value) { // GifLoaderDialogUtils.hideDialog(context); @@ -236,6 +209,87 @@ class _ConfirmPaymentPageState extends State { ); } + startApplePay() { + GifLoaderDialogUtils.showMyDialog(context); + ApplePayResponse applePayResponse; + var _paymentItems = [ + PaymentItem( + label: 'Total', + amount: widget.advanceModel.amount, + status: PaymentItemStatus.final_price, + ) + ]; + + _payClient.userCanPay(PayProvider.apple_pay).then((value) async { + print(value); + final result = await _payClient.showPaymentSelector( + provider: PayProvider.apple_pay, + paymentItems: _paymentItems, + ); + print(result); + applePayResponse = ApplePayResponse.fromJson(result); + callPayfortApplePayAPI(applePayResponse); + }); + } + + callPayfortApplePayAPI(ApplePayResponse applePayResponse) async { + DoctorsListService service = new DoctorsListService(); + ApplePayRequest applePayRequest = new ApplePayRequest(); + AppleHeader appleHeader = new AppleHeader(); + ApplePaymentMethod applePaymentMethod = new ApplePaymentMethod(); + + applePayRequest.amount = widget.advanceModel.amount; + applePayRequest.currency = "SAR"; + applePayRequest.language = projectViewModel.isArabic ? "ar" : "en"; + applePayRequest.customername = projectViewModel.user.firstName; + applePayRequest.customerEmail = projectViewModel.user.emailAddress; + applePayRequest.orderdescription = "Advance Payment"; + applePayRequest.liveServiceid = ""; + applePayRequest.latitude = await this.sharedPref.getDouble(USER_LAT); + applePayRequest.longitude = await this.sharedPref.getDouble(USER_LONG); + applePayRequest.devicetoken = await sharedPref.getString(PUSH_TOKEN); + applePayRequest.clientrequestid = Utils.getAdvancePaymentTransID(widget.advanceModel.hospitalsModel.iD, int.parse(widget.advanceModel.fileNumber)); + applePayRequest.projectid = widget.advanceModel.hospitalsModel.iD.toString(); + applePayRequest.serviceid = "3"; + applePayRequest.patientid = projectViewModel.user.patientID.toString(); + applePayRequest.appleData = applePayResponse.token.data; + applePayRequest.appleSignature = applePayResponse.token.signature; + + appleHeader.appleEphemeralPublicKey = applePayResponse.token.header.ephemeralPublicKey; + appleHeader.appleTransactionId = applePayResponse.token.header.transactionId; + appleHeader.applePublicKeyHash = applePayResponse.token.header.publicKeyHash; + applePaymentMethod.appleType = getApplePayPaymentType(applePayResponse.paymentMethod.type); + applePaymentMethod.appleNetwork = applePayResponse.paymentMethod.network; + applePaymentMethod.appleDisplayName = applePayResponse.paymentMethod.displayName; + + applePayRequest.appleHeader = appleHeader; + applePayRequest.applePaymentMethod = applePaymentMethod; + + service.callPayfortApplePayAPI(applePayRequest, context).then((res) { + print(res); + GifLoaderDialogUtils.hideDialog(context); + }).catchError((err) { + GifLoaderDialogUtils.hideDialog(context); + print(err); + // _showMyDialog(err, this.context); + }); + } + + String getApplePayPaymentType(dynamic paymentMethod) { + switch (paymentMethod) { + case 1: + return 'debit'; + break; + case 2: + return 'credit'; + break; + case 3: + return 'prepaid'; + break; + } + return 'debit'; + } + String getImagePath(String paymentMethod) { switch (paymentMethod) { case "MADA": diff --git a/lib/pages/pharmacies/screens/lacum-activitaion-vida-page.dart b/lib/pages/pharmacies/screens/lacum-activitaion-vida-page.dart index 4d2c5fbd..bcd367ff 100644 --- a/lib/pages/pharmacies/screens/lacum-activitaion-vida-page.dart +++ b/lib/pages/pharmacies/screens/lacum-activitaion-vida-page.dart @@ -1,5 +1,6 @@ import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/lacum-registration-viewModel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; @@ -7,16 +8,19 @@ import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import 'lacum-registration-page.dart'; class LakumActivationVidaPage extends StatelessWidget { + ProjectViewModel projectViewModel; TextEditingController _identificationNumberController = new TextEditingController(); @override Widget build(BuildContext context) { final mediaQuery = MediaQuery.of(context); + projectViewModel = Provider.of(context); return BaseView( builder: (_, model, wi) => AppScaffold( @@ -72,7 +76,7 @@ class LakumActivationVidaPage extends StatelessWidget { fontSize: 16, hPadding: 8, vPadding: 12, - handler: _identificationNumberController.text != null && + handler: _identificationNumberController.text != null || _identificationNumberController.text != "" ? () { model @@ -89,7 +93,7 @@ class LakumActivationVidaPage extends StatelessWidget { .text))) .then((status) => { if (status == 200) - {Navigator.pop(context, "")} + {model.makeAccountActivate(projectViewModel.user.patientIdentificationNo)} // back to previous page }) } diff --git a/lib/pages/pharmacies/screens/lacum-setting-page.dart b/lib/pages/pharmacies/screens/lacum-setting-page.dart index 7c402402..46dd93f8 100644 --- a/lib/pages/pharmacies/screens/lacum-setting-page.dart +++ b/lib/pages/pharmacies/screens/lacum-setting-page.dart @@ -1,6 +1,7 @@ import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/LacumAccountInformation.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/lacum-viewmodel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/widgets/lacum-banner-widget.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; @@ -10,6 +11,7 @@ import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; class LakumSettingPage extends StatefulWidget { final LacumAccountInformation lacumInformation; @@ -26,6 +28,8 @@ class _LakumSettingPageState extends State { TextEditingController _nameController = new TextEditingController(); TextEditingController _phoneController = new TextEditingController(); + ProjectViewModel projectViewModel; + @override void initState() { _lakumAccountActivated = widget.lacumGroupInformation @@ -39,6 +43,7 @@ class _LakumSettingPageState extends State { @override Widget build(BuildContext context) { final mediaQuery = MediaQuery.of(context); + projectViewModel = Provider.of(context); return BaseView( onModelReady: (model) => model.setLakumData( @@ -126,9 +131,9 @@ class _LakumSettingPageState extends State { value: _lakumAccountActivated, onChanged: (val) { if (_lakumAccountActivated) { - model.makeAccountDeactivate(); + model.makeAccountDeactivate(projectViewModel.user.patientIdentificationNo); } else { - model.makeAccountActivate(); + model.makeAccountActivate(projectViewModel.user.patientIdentificationNo); } setState(() { _lakumAccountActivated = val; diff --git a/lib/pages/pharmacies/screens/lakum-main-page.dart b/lib/pages/pharmacies/screens/lakum-main-page.dart index a6d8aec5..5dc60fda 100644 --- a/lib/pages/pharmacies/screens/lakum-main-page.dart +++ b/lib/pages/pharmacies/screens/lakum-main-page.dart @@ -27,7 +27,7 @@ class LakumMainPage extends StatelessWidget { return BaseView( onModelReady: (model) async { - await model.getLacumData(); + await model.getLacumData(projectViewModel.user.patientIdentificationNo); if (model.lacumInformation.yahalaAccountNo == 0 || model.lacumInformation.yahalaAccountNo == null) { navigateToLakumRegister(context); } else { @@ -73,7 +73,7 @@ class LakumMainPage extends StatelessWidget { SizedBox( height: 12, ), - LakumHomeButtons(mediaQuery, model), + LakumHomeButtons(mediaQuery, model, projectViewModel), SizedBox( height: 12, ), @@ -253,25 +253,26 @@ class LakumMainPage extends StatelessWidget { navigateToLakumRegister(BuildContext context) { Navigator.pushReplacement(context, FadePage(page: LakumRegistrationPage(projectViewModel.user.patientIdentificationNo))); } -} -List _buildAppBarICons(BuildContext context, LacumViewModel model) { - return [ - IconButton( - icon: Icon(Icons.settings), - color: Colors.white, - onPressed: () { - Navigator.push(context, FadePage(page: LakumSettingPage(model.lacumInformation, model.lacumGroupInformation))).then((result) => {model.getLacumGroupData()}); - }, - ), - ]; + List _buildAppBarICons(BuildContext context, LacumViewModel model) { + return [ + IconButton( + icon: Icon(Icons.settings), + color: Colors.white, + onPressed: () { + Navigator.push(context, FadePage(page: LakumSettingPage(model.lacumInformation, model.lacumGroupInformation))).then((result) => {model.getLacumGroupData(projectViewModel.user.patientIdentificationNo)}); + }, + ), + ]; + } } class LakumHomeButtons extends StatelessWidget { final MediaQueryData mediaQuery; final LacumViewModel model; + ProjectViewModel projectViewModel; - LakumHomeButtons(this.mediaQuery, this.model); + LakumHomeButtons(this.mediaQuery, this.model, this.projectViewModel); @override Widget build(BuildContext context) { @@ -328,7 +329,7 @@ class LakumHomeButtons extends StatelessWidget { child: InkWell( onTap: () { Navigator.push(context, FadePage(page: LacumTransferPage(model.lacumInformation, model.lacumGroupInformation))).then((result) { - model.getLacumGroupData(); + model.getLacumGroupData(projectViewModel.user.patientIdentificationNo); }); }, child: Container( diff --git a/lib/pages/pharmacies/screens/lakum-terms-conditions-page.dart b/lib/pages/pharmacies/screens/lakum-terms-conditions-page.dart index 228b0874..ab1a902e 100644 --- a/lib/pages/pharmacies/screens/lakum-terms-conditions-page.dart +++ b/lib/pages/pharmacies/screens/lakum-terms-conditions-page.dart @@ -1,6 +1,7 @@ import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/lacum-registration-viewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; @@ -12,8 +13,7 @@ class LakumTermsConditions extends StatelessWidget { final String firstName, lastName, mobileNo, identificationNo; final int languageId; - LakumTermsConditions(this.identificationNo, this.firstName, this.lastName, - this.mobileNo, this.languageId); + LakumTermsConditions(this.identificationNo, this.firstName, this.lastName, this.mobileNo, this.languageId); @override Widget build(BuildContext context) { @@ -37,13 +37,9 @@ class LakumTermsConditions extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (model.listUserAgreement != null && - model.listUserAgreement.userAgreementLAKUM != - null) + if (model.listUserAgreement != null && model.listUserAgreement.userAgreementLAKUM != null) Html( - data: projectProvider.isArabic - ? model.listUserAgreement.userAgreementLAKUMn - : model.listUserAgreement.userAgreementLAKUM, + data: projectProvider.isArabic ? model.listUserAgreement.userAgreementLAKUMn : model.listUserAgreement.userAgreementLAKUM, ), ], ), @@ -62,9 +58,12 @@ class LakumTermsConditions extends StatelessWidget { vPadding: 12, handler: () { model.createNewLakumAccount("$firstName $lastName", mobileNo, identificationNo, languageId).then((status) => { - if (status == 200) {Navigator.pop(context, "")} - // back to previous page - }); + if (status == 200) {Navigator.pop(context, "")} else { + Navigator.pop(context, ""), + AppToast.showErrorToast(message: model.error) + } + // back to previous page + }); }, ), ),