Payment flow implemented in advance payment

find_us
haroon amjad 4 years ago
parent 478917b240
commit a5fd9f53ab

@ -88,6 +88,7 @@ class MyBalanceService extends BaseService {
onSuccess: (response, statusCode) async { onSuccess: (response, statusCode) async {
logInTokenID = response['LogInTokenID']; logInTokenID = response['LogInTokenID'];
verificationCode = response['VerificationCode']; verificationCode = response['VerificationCode'];
print(verificationCode);
}, onFailure: (String error, int statusCode) { }, onFailure: (String error, int statusCode) {
hasError = true; hasError = true;
super.error = error; super.error = error;

@ -1,11 +1,14 @@
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/hospitals/hospitals_model.dart'; import 'package:diplomaticquarterapp/core/model/hospitals/hospitals_model.dart';
import 'package:diplomaticquarterapp/core/model/my_balance/patient_info.dart'; import 'package:diplomaticquarterapp/core/model/my_balance/patient_info.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/my_balance_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/medical/my_balance_view_model.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart'; import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart';
import 'package:diplomaticquarterapp/pages/ToDoList/payment_method_select.dart'; import 'package:diplomaticquarterapp/pages/ToDoList/payment_method_select.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/medical/balance/dialogs/SelectHospitalDialog.dart'; import 'package:diplomaticquarterapp/pages/medical/balance/dialogs/SelectHospitalDialog.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart';
@ -18,11 +21,10 @@ import 'package:flutter/material.dart';
import 'package:smart_progress_bar/smart_progress_bar.dart'; import 'package:smart_progress_bar/smart_progress_bar.dart';
import '../../../core/model/my_balance/AdvanceModel.dart'; import '../../../core/model/my_balance/AdvanceModel.dart';
import 'dialogs/ConfirmSMSDialog.dart'; import 'confirm_payment_page.dart';
import 'dialogs/SelectBeneficiaryDialog.dart'; import 'dialogs/SelectBeneficiaryDialog.dart';
import 'dialogs/SelectPatientFamilyDialog.dart'; import 'dialogs/SelectPatientFamilyDialog.dart';
import 'dialogs/SelectPatientInfoDialog.dart'; import 'dialogs/SelectPatientInfoDialog.dart';
import 'confirm_payment_page.dart';
import 'new_text_Field.dart'; import 'new_text_Field.dart';
enum BeneficiaryType { MyAccount, MyFamilyFiles, OtherAccount, NON } enum BeneficiaryType { MyAccount, MyFamilyFiles, OtherAccount, NON }
@ -40,12 +42,17 @@ class _AdvancePaymentPageState extends State<AdvancePaymentPage> {
String amount = ""; String amount = "";
String email; String email;
PatientInfo _selectedPatientInfo; PatientInfo _selectedPatientInfo;
AuthenticatedUser authenticatedUser;
GetAllSharedRecordsByStatusList selectedPatientFamily; GetAllSharedRecordsByStatusList selectedPatientFamily;
AdvanceModel advanceModel = AdvanceModel(); AdvanceModel advanceModel = AdvanceModel();
AppSharedPreferences sharedPref = AppSharedPreferences();
AuthenticatedUser authUser;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
getAuthUser();
} }
@override @override
@ -253,6 +260,7 @@ class _AdvancePaymentPageState extends State<AdvancePaymentPage> {
selectedPaymentMethod: value, selectedPaymentMethod: value,
patientInfoAndMobileNumber: patientInfoAndMobileNumber:
model.patientInfoAndMobileNumber, model.patientInfoAndMobileNumber,
authenticatedUser: authUser,
), ),
), ),
); );
@ -304,7 +312,6 @@ class _AdvancePaymentPageState extends State<AdvancePaymentPage> {
); );
} }
void confirmSelectPatientDialog(List<PatientInfo> patientInfoList) { void confirmSelectPatientDialog(List<PatientInfo> patientInfoList) {
showDialog( showDialog(
context: context, context: context,
@ -331,7 +338,8 @@ class _AdvancePaymentPageState extends State<AdvancePaymentPage> {
onValueSelected: (value) { onValueSelected: (value) {
setState(() { setState(() {
selectedPatientFamily = value; selectedPatientFamily = value;
_fileTextController.text = selectedPatientFamily.patientID.toString(); _fileTextController.text =
selectedPatientFamily.patientID.toString();
advanceModel.depositorName = value.patientName; advanceModel.depositorName = value.patientName;
}); });
}, },
@ -369,6 +377,16 @@ class _AdvancePaymentPageState extends State<AdvancePaymentPage> {
return TranslationBase.of(context).selectPatientName; return TranslationBase.of(context).selectPatientName;
} }
getAuthUser() async {
if (await this.sharedPref.getObject(USER_PROFILE) != null) {
var data = AuthenticatedUser.fromJson(
await this.sharedPref.getObject(USER_PROFILE));
setState(() {
authUser = data;
});
}
}
String getFamilyMembersName() { String getFamilyMembersName() {
if (selectedPatientFamily != null) if (selectedPatientFamily != null)
return selectedPatientFamily.patientName; return selectedPatientFamily.patientName;

@ -1,28 +1,41 @@
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.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/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/medical/my_balance_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/core/model/my_balance/AdvanceModel.dart'; import 'package:diplomaticquarterapp/routes.dart';
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/in_app_browser/InAppBrowser.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:smart_progress_bar/smart_progress_bar.dart';
import 'dialogs/ConfirmSMSDialog.dart'; import 'dialogs/ConfirmSMSDialog.dart';
import 'new_text_Field.dart'; import 'new_text_Field.dart';
import 'package:smart_progress_bar/smart_progress_bar.dart';
class ConfirmPaymentPage extends StatelessWidget { class ConfirmPaymentPage extends StatelessWidget {
final AdvanceModel advanceModel; final AdvanceModel advanceModel;
final PatientInfoAndMobileNumber patientInfoAndMobileNumber; final PatientInfoAndMobileNumber patientInfoAndMobileNumber;
final String selectedPaymentMethod; final String selectedPaymentMethod;
MyInAppBrowser browser;
AuthenticatedUser authenticatedUser;
AppSharedPreferences sharedPref = AppSharedPreferences();
ConfirmPaymentPage( ConfirmPaymentPage(
{this.advanceModel, {this.advanceModel,
this.patientInfoAndMobileNumber, this.patientInfoAndMobileNumber,
this.selectedPaymentMethod}); this.selectedPaymentMethod,
this.authenticatedUser});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -32,9 +45,18 @@ class ConfirmPaymentPage extends StatelessWidget {
barrierDismissible: false, barrierDismissible: false,
child: ConfirmSMSDialog( child: ConfirmSMSDialog(
phoneNumber: patientInfoAndMobileNumber.mobileNumber, phoneNumber: patientInfoAndMobileNumber.mobileNumber,
), ),
); ).then((value) {
print("dialog dismissed");
print(value);
if (value != null && value) {
AppoitmentAllHistoryResultList appo =
new AppoitmentAllHistoryResultList();
appo.projectID = patientInfoAndMobileNumber.projectID;
openPayment(selectedPaymentMethod, authenticatedUser,
double.parse(advanceModel.amount), appo);
}
});
} }
return BaseView<MyBalanceViewModel>( return BaseView<MyBalanceViewModel>(
@ -139,7 +161,8 @@ class ConfirmPaymentPage extends StatelessWidget {
onTap: () { onTap: () {
model model
.sendActivationCodeForAdvancePayment( .sendActivationCodeForAdvancePayment(
patientID: int.parse(advanceModel.fileNumber),projectID: advanceModel.hospitalsModel.iD) patientID: int.parse(advanceModel.fileNumber),
projectID: advanceModel.hospitalsModel.iD)
.then((value) { .then((value) {
if (model.state != ViewState.ErrorLocal && if (model.state != ViewState.ErrorLocal &&
model.state != ViewState.Error) showSMSDialog(); model.state != ViewState.Error) showSMSDialog();
@ -174,4 +197,110 @@ class ConfirmPaymentPage extends StatelessWidget {
return 'assets/images/new-design/mada.png'; return 'assets/images/new-design/mada.png';
} }
openPayment(String paymentMethod, AuthenticatedUser authenticatedUser,
double amount, AppoitmentAllHistoryResultList appo) {
browser = new MyInAppBrowser(
onExitCallback: onBrowserExit,
appo: appo,
onLoadStartCallback: onBrowserLoadStart);
browser.openPaymentBrowser(
amount,
"Advance Payment",
Utils.getAdvancePaymentTransID(
authenticatedUser.projectID, authenticatedUser.patientID),
appo.projectID.toString(),
authenticatedUser.emailAddress,
paymentMethod,
authenticatedUser,
browser);
}
onBrowserLoadStart(String url) {
print("onBrowserLoadStart");
print(url);
MyInAppBrowser.successURLS.forEach((element) {
if (url.contains(element)) {
if (browser.isOpened()) browser.close();
MyInAppBrowser.isPaymentDone = true;
return;
}
});
MyInAppBrowser.errorURLS.forEach((element) {
if (url.contains(element)) {
if (browser.isOpened()) browser.close();
MyInAppBrowser.isPaymentDone = false;
return;
}
});
}
onBrowserExit(AppoitmentAllHistoryResultList appo, bool isPaymentMade) {
print("onBrowserExit Called!!!!");
if (isPaymentMade) checkPaymentStatus(appo);
}
checkPaymentStatus(AppoitmentAllHistoryResultList appo) {
DoctorsListService service = new DoctorsListService();
service
.checkPaymentStatus(
Utils.getAppointmentTransID(
appo.projectID, appo.clinicID, appo.appointmentNo),
AppGlobal.context)
.then((res) {
print("Printing Payment Status Reponse!!!!");
print(res);
String paymentInfo = res['Response_Message'];
if (paymentInfo == 'Success') {
createAdvancePayment(res, appo);
} else {
AppToast.showErrorToast(message: res['Response_Message']);
}
}).catchError((err) {
print(err);
}).showProgressBar(
text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6));
}
createAdvancePayment(res, AppoitmentAllHistoryResultList appo) {
DoctorsListService service = new DoctorsListService();
String paymentReference = res['Fort_id'].toString();
service
.createAdvancePayment(appo, res['Amount'], res['Fort_id'],
res['PaymentMethod'], AppGlobal.context)
.then((res) {
print(res['OnlineCheckInAppointments'][0]['AdvanceNumber']);
addAdvancedNumberRequest(
res['OnlineCheckInAppointments'][0]['AdvanceNumber'].toString(),
paymentReference,
appo.appointmentNo.toString(),
appo);
}).catchError((err) {
print(err);
}).showProgressBar(
text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6));
}
addAdvancedNumberRequest(String advanceNumber, String paymentReference,
String appointmentID, AppoitmentAllHistoryResultList appo) {
DoctorsListService service = new DoctorsListService();
service
.addAdvancedNumberRequest(
advanceNumber, paymentReference, appointmentID, AppGlobal.context)
.then((res) {
print(res);
navigateToHome(AppGlobal.context);
}).catchError((err) {
print(err);
}).showProgressBar(
text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6));
}
Future navigateToHome(context) async {
Navigator.of(context).pushNamed(HOME);
}
} }

@ -19,7 +19,13 @@ class ConfirmSMSDialog extends StatefulWidget {
final AdvanceModel advanceModel; final AdvanceModel advanceModel;
final PatientInfoAndMobileNumber patientInfoAndMobileNumber; final PatientInfoAndMobileNumber patientInfoAndMobileNumber;
final String selectedPaymentMethod; final String selectedPaymentMethod;
const ConfirmSMSDialog({Key key, this.phoneNumber,this.advanceModel,this.selectedPaymentMethod,this.patientInfoAndMobileNumber})
const ConfirmSMSDialog(
{Key key,
this.phoneNumber,
this.advanceModel,
this.selectedPaymentMethod,
this.patientInfoAndMobileNumber})
: super(key: key); : super(key: key);
@override @override
@ -140,7 +146,8 @@ class _ConfirmSMSDialogState extends State<ConfirmSMSDialog> {
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Texts( child: Texts(
TranslationBase.of(context).pleaseEnterTheVerificationCode+'[${widget.phoneNumber}]', TranslationBase.of(context).pleaseEnterTheVerificationCode +
'[${widget.phoneNumber}]',
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
), ),
@ -277,7 +284,7 @@ class _ConfirmSMSDialogState extends State<ConfirmSMSDialog> {
if (model.state == ViewState.ErrorLocal || if (model.state == ViewState.ErrorLocal ||
model.state == ViewState.Error) model.state == ViewState.Error)
Container( Container(
margin: EdgeInsets.only(left: 8,right: 8), margin: EdgeInsets.only(left: 8, right: 8),
width: double.maxFinite, width: double.maxFinite,
child: Texts( child: Texts(
model.error, model.error,
@ -290,7 +297,9 @@ class _ConfirmSMSDialogState extends State<ConfirmSMSDialog> {
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Texts( child: Texts(
TranslationBase.of(context).theVerificationCodeExpiresIn+' $timerText', TranslationBase.of(context)
.theVerificationCodeExpiresIn +
' $timerText',
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
), ),
@ -301,7 +310,8 @@ class _ConfirmSMSDialogState extends State<ConfirmSMSDialog> {
padding: EdgeInsets.all(12), padding: EdgeInsets.all(12),
child: SecondaryButton( child: SecondaryButton(
textColor: Colors.white, textColor: Colors.white,
label: TranslationBase.of(context).submit.toUpperCase(), label:
TranslationBase.of(context).submit.toUpperCase(),
onTap: () { onTap: () {
submit(model); submit(model);
}, },
@ -322,12 +332,14 @@ class _ConfirmSMSDialogState extends State<ConfirmSMSDialog> {
if (verifyAccountForm.currentState.validate()) { if (verifyAccountForm.currentState.validate()) {
final activationCode = final activationCode =
digit1.text + digit2.text + digit3.text + digit4.text; digit1.text + digit2.text + digit3.text + digit4.text;
model.checkActivationCodeForAdvancePayment( model
activationCode: activationCode).then((value) { .checkActivationCodeForAdvancePayment(activationCode: activationCode)
//TODO complete payment .then((value) {})
}).showProgressBar( .showProgressBar(
text: "Loading", text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6))
backgroundColor: Colors.blue.withOpacity(0.6)); .then((value) {
Navigator.pop(context, true);
});
} }
} }

@ -96,6 +96,14 @@ class Utils {
appoNo.toString(); appoNo.toString();
} }
static String getAdvancePaymentTransID(int projectID, int fileNumber) {
return projectID.toString() +
'-' +
fileNumber.toString() +
'-' +
DateTime.now().millisecondsSinceEpoch.toString();
}
bool validateIDBox(String value, type) { bool validateIDBox(String value, type) {
Pattern pattern = loginIDPattern(type); //r'^\d+(?:\.\d+)?$'; Pattern pattern = loginIDPattern(type); //r'^\d+(?:\.\d+)?$';

Loading…
Cancel
Save