You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
200 lines
8.2 KiB
Dart
200 lines
8.2 KiB
Dart
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
|
|
import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart';
|
|
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart';
|
|
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
|
|
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
|
|
import 'package:diplomaticquarterapp/widgets/in_app_browser/InAppBrowser.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class PaymentBottomWidget extends StatelessWidget {
|
|
final OrderPreviewViewModel model;
|
|
|
|
BuildContext context;
|
|
MyInAppBrowser browser;
|
|
|
|
PaymentBottomWidget(this.model);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final scaffold = Scaffold.of(context);
|
|
this.context = context;
|
|
OrderPreviewViewModel orderPreviewViewModel = Provider.of(context);
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
|
|
child: orderPreviewViewModel.paymentCheckoutData.cartDataVisible
|
|
? Container(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
Container(
|
|
margin:
|
|
EdgeInsets.symmetric(horizontal: 0, vertical: 4),
|
|
child: Row(
|
|
children: [
|
|
Texts(
|
|
"${TranslationBase.of(context).sar} ${(model.cartResponse.totalAmount).toStringAsFixed(2)}",
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xff929295),
|
|
),
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 4),
|
|
child: Texts(
|
|
"${TranslationBase.of(context).inclusiveVat}",
|
|
fontSize: 8,
|
|
color: Color(0xff929295),
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Texts(
|
|
"${model.cartResponse.quantityCount} ${TranslationBase.of(context).items}",
|
|
fontSize: 10,
|
|
color: Colors.grey,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
],
|
|
),
|
|
Container(
|
|
child: RaisedButton(
|
|
elevation: 0,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
side: BorderSide(
|
|
color: Color(0xff929295),
|
|
width: 1,
|
|
),
|
|
),
|
|
onPressed: (orderPreviewViewModel
|
|
.paymentCheckoutData.address !=
|
|
null &&
|
|
orderPreviewViewModel
|
|
.paymentCheckoutData.paymentOption !=
|
|
null)
|
|
? () async {
|
|
await model.makeOrder();
|
|
if (model.state == ViewState.Idle) {
|
|
AppToast.showSuccessToast(
|
|
message: TranslationBase.of(context).compeleteOrderMsg
|
|
// "Order has been placed successfully!!"
|
|
);
|
|
openPayment(
|
|
model.orderListModel[0], model.authenticatedUserObject.user);
|
|
} else {
|
|
AppToast.showErrorToast(message: model.error);
|
|
}
|
|
Navigator.pop(context);
|
|
Navigator.pop(context);
|
|
}
|
|
: null,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
child: new Text(
|
|
"${TranslationBase.of(context).proceedPay}",
|
|
style: new TextStyle(
|
|
color: (orderPreviewViewModel
|
|
.paymentCheckoutData.address !=
|
|
null &&
|
|
orderPreviewViewModel.paymentCheckoutData
|
|
.paymentOption !=
|
|
null)
|
|
? Colors.white
|
|
: Colors.grey.shade400,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 12),
|
|
),
|
|
),
|
|
color:
|
|
(orderPreviewViewModel.paymentCheckoutData.address !=
|
|
null &&
|
|
orderPreviewViewModel
|
|
.paymentCheckoutData.paymentOption !=
|
|
null)
|
|
? Colors.green
|
|
: Color(0xff929295),
|
|
disabledColor:
|
|
(orderPreviewViewModel.paymentCheckoutData.address !=
|
|
null &&
|
|
orderPreviewViewModel
|
|
.paymentCheckoutData.paymentOption !=
|
|
null)
|
|
? Colors.green
|
|
: Color(0xff929295),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: Container(),
|
|
);
|
|
}
|
|
|
|
openPayment(
|
|
OrderDetailModel order,
|
|
AuthenticatedUser authenticatedUser,
|
|
) {
|
|
browser = new MyInAppBrowser(
|
|
onExitCallback: onBrowserExit, onLoadStartCallback: onBrowserLoadStart);
|
|
|
|
browser.openPharmacyPaymentBrowser(
|
|
order,
|
|
order.orderTotal,
|
|
'ePharmacy Order',
|
|
order.id,
|
|
order.billingAddress.email,
|
|
order.customValuesXml,
|
|
"${authenticatedUser.firstName} ${authenticatedUser.middleName} ${authenticatedUser.lastName}",
|
|
authenticatedUser.patientID,
|
|
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) {
|
|
AppToast.showSuccessToast(
|
|
message: "شكراً\nPayment status for your order is Paid");
|
|
Navigator.pop(context);
|
|
Navigator.pop(context);
|
|
} else {
|
|
AppToast.showErrorToast(
|
|
message:
|
|
"Transaction Failed!\Your transaction is field to some reason please try again or contact to the administration");
|
|
Navigator.pop(context);
|
|
Navigator.pop(context);
|
|
}
|
|
}
|
|
}
|