|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import 'package:diplomaticquarterapp/config/config.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/config/shared_pref_kay.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';
|
|
|
|
|
@ -6,6 +7,8 @@ import 'package:diplomaticquarterapp/core/viewModels/medical/my_balance_view_mod
|
|
|
|
|
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';
|
|
|
|
|
@ -22,8 +25,8 @@ import 'package:diplomaticquarterapp/widgets/otp/sms-popup.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
|
import 'package:pay/pay.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import 'new_text_Field.dart';
|
|
|
|
|
|
|
|
|
|
class ConfirmPaymentPage extends StatefulWidget {
|
|
|
|
|
@ -40,24 +43,16 @@ class ConfirmPaymentPage extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
|
|
|
|
MyInAppBrowser browser;
|
|
|
|
|
ProjectViewModel projectViewModel;
|
|
|
|
|
|
|
|
|
|
AppSharedPreferences sharedPref = AppSharedPreferences();
|
|
|
|
|
|
|
|
|
|
String transID = "";
|
|
|
|
|
ProjectViewModel projectViewModel;
|
|
|
|
|
|
|
|
|
|
Pay _payClient = Pay.withAssets([
|
|
|
|
|
'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);
|
|
|
|
|
@ -66,15 +61,18 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
|
AppoitmentAllHistoryResultList appo = new AppoitmentAllHistoryResultList();
|
|
|
|
|
appo.projectID = widget.patientInfoAndMobileNumber.projectID;
|
|
|
|
|
|
|
|
|
|
if (widget.selectedPaymentMethod == "ApplePay") {
|
|
|
|
|
startApplePay();
|
|
|
|
|
} else {
|
|
|
|
|
projectViewModel.analytics.advancePayments.payment_otp_confirmation(method: widget.selectedPaymentMethod.toLowerCase(), type: 'wallet');
|
|
|
|
|
openPayment(widget.selectedPaymentMethod, widget.authenticatedUser,
|
|
|
|
|
double.parse(widget.advanceModel.amount), null);
|
|
|
|
|
openPayment(widget.selectedPaymentMethod, widget.authenticatedUser, double.parse(widget.advanceModel.amount), null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
projectViewModel = Provider.of(context);
|
|
|
|
|
void showSMSDialog(MyBalanceViewModel model) {
|
|
|
|
|
new SMSOTP(
|
|
|
|
|
context,
|
|
|
|
|
@ -211,6 +209,8 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
|
|
|
|
if (model.state != ViewState.ErrorLocal &&
|
|
|
|
|
model.state != ViewState.Error) showSMSDialog(model);
|
|
|
|
|
});
|
|
|
|
|
startApplePay();
|
|
|
|
|
// if()
|
|
|
|
|
// GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
// model.sendActivationCodeForAdvancePayment(patientID: int.parse(widget.advanceModel.fileNumber), projectID: widget.advanceModel.hospitalsModel.iD).then((value) {
|
|
|
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
@ -224,6 +224,87 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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":
|
|
|
|
|
|