|
|
|
|
@ -1,20 +1,25 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
|
|
|
|
|
|
|
|
class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
// static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort Payment Gateway URL UAT
|
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
|
static String SERVICE_URL =
|
|
|
|
|
'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL LIVE
|
|
|
|
|
'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort Payment Gateway URL UAT
|
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
|
// static String SERVICE_URL =
|
|
|
|
|
// 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL LIVE
|
|
|
|
|
|
|
|
|
|
// static String PREAUTH_SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort PreAuth Payment Gateway URL UAT
|
|
|
|
|
static String PREAUTH_SERVICE_URL =
|
|
|
|
|
'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort PreAuth Payment Gateway URL Live Store
|
|
|
|
|
'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort PreAuth Payment Gateway URL UAT
|
|
|
|
|
// static String PREAUTH_SERVICE_URL =
|
|
|
|
|
// 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort PreAuth Payment Gateway URL Live Store
|
|
|
|
|
|
|
|
|
|
static List<String> successURLS = [
|
|
|
|
|
'success',
|
|
|
|
|
@ -25,13 +30,18 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
static List<String> errorURLS = ['PayfortCancel'];
|
|
|
|
|
|
|
|
|
|
final Function onExitCallback;
|
|
|
|
|
final Function onLoadStartCallback;
|
|
|
|
|
|
|
|
|
|
AppSharedPreferences sharedPref = AppSharedPreferences();
|
|
|
|
|
AuthProvider authProvider = new AuthProvider();
|
|
|
|
|
InAppBrowser browser = new InAppBrowser();
|
|
|
|
|
|
|
|
|
|
AuthenticatedUser authUser;
|
|
|
|
|
AppoitmentAllHistoryResultList appo;
|
|
|
|
|
|
|
|
|
|
MyInAppBrowser({this.onExitCallback});
|
|
|
|
|
static bool isPaymentDone = false;
|
|
|
|
|
|
|
|
|
|
MyInAppBrowser({this.onExitCallback, this.appo, this.onLoadStartCallback});
|
|
|
|
|
|
|
|
|
|
Future onBrowserCreated() async {
|
|
|
|
|
print("\n\nBrowser Created!\n\n");
|
|
|
|
|
@ -39,7 +49,42 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future onLoadStart(String url) async {
|
|
|
|
|
print("\n\nStarted $url\n\n");
|
|
|
|
|
onLoadStartCallback(url);
|
|
|
|
|
// print("\n\nStarted $url\n\n");
|
|
|
|
|
|
|
|
|
|
// if (successURLS.length != 0) {
|
|
|
|
|
// successURLS.forEach((element) {
|
|
|
|
|
// if (url.contains(element)) {
|
|
|
|
|
// try {
|
|
|
|
|
// if (browser.isOpened()) browser.close();
|
|
|
|
|
// isPaymentDone = true;
|
|
|
|
|
// Utils.hideProgressDialog();
|
|
|
|
|
// return;
|
|
|
|
|
// } on MissingPluginException catch (exception) {
|
|
|
|
|
// Utils.hideProgressDialog();
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// Utils.hideProgressDialog();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (errorURLS.length != 0) {
|
|
|
|
|
// errorURLS.forEach((element) {
|
|
|
|
|
// if (url.contains(element)) {
|
|
|
|
|
// try {
|
|
|
|
|
// if (browser.isOpened()) browser.close();
|
|
|
|
|
// isPaymentDone = false;
|
|
|
|
|
// Utils.hideProgressDialog();
|
|
|
|
|
// return;
|
|
|
|
|
// } on MissingPluginException catch (exception) {
|
|
|
|
|
// Utils.hideProgressDialog();
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// Utils.hideProgressDialog();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -60,7 +105,7 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
@override
|
|
|
|
|
void onExit() {
|
|
|
|
|
print("\n\nBrowser closed!\n\n");
|
|
|
|
|
onExitCallback();
|
|
|
|
|
onExitCallback(appo, isPaymentDone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -70,31 +115,13 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
return ShouldOverrideUrlLoadingAction.ALLOW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onLoadResource(LoadedResource response) {
|
|
|
|
|
print("Started at: " +
|
|
|
|
|
response.startTime.toString() +
|
|
|
|
|
"ms ---> duration: " +
|
|
|
|
|
response.duration.toString() +
|
|
|
|
|
"ms " +
|
|
|
|
|
response.url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onConsoleMessage(ConsoleMessage consoleMessage) {
|
|
|
|
|
print("""
|
|
|
|
|
console output:
|
|
|
|
|
message: ${consoleMessage.message}
|
|
|
|
|
messageLevel: ${consoleMessage.messageLevel.toValue()}
|
|
|
|
|
""");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getLanguageID() async {
|
|
|
|
|
return await sharedPref.getString(APP_LANGUAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDeviceToken() async {
|
|
|
|
|
await sharedPref.getString(PUSH_TOKEN);
|
|
|
|
|
Future<String> getDeviceToken() async {
|
|
|
|
|
String deviceToken = await sharedPref.getString(PUSH_TOKEN);
|
|
|
|
|
return deviceToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPatientData() async {
|
|
|
|
|
@ -105,12 +132,48 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String generateURL(int amount, String orderDesc, String transactionID,
|
|
|
|
|
String projId, String emailId, String paymentMethod,
|
|
|
|
|
[var patientData, var servID, var LiveServID]) {
|
|
|
|
|
openPaymentBrowser(
|
|
|
|
|
double amount,
|
|
|
|
|
String orderDesc,
|
|
|
|
|
String transactionID,
|
|
|
|
|
String projId,
|
|
|
|
|
String emailId,
|
|
|
|
|
String paymentMethod,
|
|
|
|
|
AuthenticatedUser authenticatedUser,
|
|
|
|
|
InAppBrowser browser,
|
|
|
|
|
) {
|
|
|
|
|
this.browser = browser;
|
|
|
|
|
this.browser.openUrl(
|
|
|
|
|
url: generateURL(amount, orderDesc, transactionID, projId, emailId,
|
|
|
|
|
paymentMethod, authenticatedUser));
|
|
|
|
|
|
|
|
|
|
// this.browser.openData(
|
|
|
|
|
// data: generateURL(amount, orderDesc, transactionID, projId, emailId,
|
|
|
|
|
// paymentMethod, authenticatedUser),
|
|
|
|
|
// baseUrl:
|
|
|
|
|
// "https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String generateURL(
|
|
|
|
|
double amount,
|
|
|
|
|
String orderDesc,
|
|
|
|
|
String transactionID,
|
|
|
|
|
String projId,
|
|
|
|
|
String emailId,
|
|
|
|
|
String paymentMethod,
|
|
|
|
|
AuthenticatedUser authUser,
|
|
|
|
|
[var patientData,
|
|
|
|
|
var servID,
|
|
|
|
|
var LiveServID]) {
|
|
|
|
|
getPatientData();
|
|
|
|
|
String currentLanguageID = getLanguageID() == 'ar' ? 'AR' : 'EN';
|
|
|
|
|
String form = getForm();
|
|
|
|
|
String deviceToken;
|
|
|
|
|
|
|
|
|
|
getDeviceToken().then((value) {
|
|
|
|
|
print(value);
|
|
|
|
|
deviceToken = value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (authUser != null) {
|
|
|
|
|
form = form.replaceFirst("EMAIL_VALUE", authUser.emailAddress);
|
|
|
|
|
@ -125,9 +188,13 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
form = form.replaceFirst('PROJECT_ID_VALUE', projId);
|
|
|
|
|
form = form.replaceFirst('PAYMENT_OPTION_VALUE', paymentMethod);
|
|
|
|
|
form = form.replaceFirst('LANG_VALUE', currentLanguageID);
|
|
|
|
|
form = form.replaceFirst('PATIENT_OUT_SA', authUser.outSA.toString());
|
|
|
|
|
form = form.replaceFirst('PATIENT_TYPE_ID',
|
|
|
|
|
patientData == "" ? authUser.patientType : patientData.PatientType);
|
|
|
|
|
form = form.replaceFirst('PATIENT_OUT_SA',
|
|
|
|
|
authUser.outSA == 0 ? false.toString() : true.toString());
|
|
|
|
|
form = form.replaceFirst(
|
|
|
|
|
'PATIENT_TYPE_ID',
|
|
|
|
|
patientData == null
|
|
|
|
|
? authUser.patientType.toString()
|
|
|
|
|
: patientData.PatientType);
|
|
|
|
|
|
|
|
|
|
// form = form.replaceFirst('DEVICE_TOKEN', this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false) + "," + this.cs.sharedService.getSharedData(AuthenticationService.APNS_TOKEN, false));
|
|
|
|
|
// form = form.replaceFirst('LATITUDE_VALUE', this.cs.sharedService.getSharedData('userLat', false));
|
|
|
|
|
@ -135,7 +202,8 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
|
|
|
|
|
form = form.replaceFirst('LATITUDE_VALUE', "24.708488");
|
|
|
|
|
form = form.replaceFirst('LONGITUDE_VALUE', "46.665925");
|
|
|
|
|
form = form.replaceFirst('DEVICE_TOKEN', getDeviceToken());
|
|
|
|
|
form = form.replaceFirst('DEVICE_TOKEN',
|
|
|
|
|
"e8wKxa4EGK8:APA91bGtygxh5E22pSARVKlngyi0iQbyRUvvUWiCIsaAcbE0hiffhUR094WVx22O5bsvwc706LspzIuJthUyK_748jzuaedD-ZwDm9BX_yyYV2K2YnuFBlHQ9pOKy65RfoprtvqyTN1O");
|
|
|
|
|
|
|
|
|
|
if (servID == "4")
|
|
|
|
|
form = form.replaceFirst(
|
|
|
|
|
@ -143,7 +211,7 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
else
|
|
|
|
|
form = form.replaceFirst('SERVICE_URL_VALUE', MyInAppBrowser.SERVICE_URL);
|
|
|
|
|
|
|
|
|
|
if (servID) {
|
|
|
|
|
if (servID != null) {
|
|
|
|
|
form = form.replaceFirst('SERV_ID', servID);
|
|
|
|
|
form = form.replaceFirst('LIVE_SERVICE_ID', LiveServID);
|
|
|
|
|
} else {
|
|
|
|
|
@ -151,7 +219,7 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
form = form.replaceFirst('LIVE_SERVICE_ID', "2");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!patientData) {
|
|
|
|
|
if (patientData == null) {
|
|
|
|
|
form = form.replaceFirst('CUSTNAME_VALUE', authUser.firstName);
|
|
|
|
|
form = form.replaceFirst('CUSTID_VALUE', authUser.patientID.toString());
|
|
|
|
|
} else {
|
|
|
|
|
@ -159,13 +227,11 @@ class MyInAppBrowser extends InAppBrowser {
|
|
|
|
|
form = form.replaceFirst('CUSTID_VALUE', patientData.PatientID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Codec<String, String> stringToBase64Url = utf8.fuse(base64Url);
|
|
|
|
|
String encoded = stringToBase64Url
|
|
|
|
|
.encode('data:text/html;base64,' + form); // dXNlcm5hbWU6cGFzc3dvcmQ=
|
|
|
|
|
String decoded = stringToBase64Url.decode(encoded); // username:password
|
|
|
|
|
var bytes = utf8.encode(form);
|
|
|
|
|
var base64Str = base64.encode(bytes);
|
|
|
|
|
print(form);
|
|
|
|
|
print(encoded);
|
|
|
|
|
return encoded;
|
|
|
|
|
print('data:text/html;base64,' + base64Str);
|
|
|
|
|
return 'data:text/html;base64,' + base64Str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getForm() {
|
|
|
|
|
|