@ -5,17 +5,21 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import ' package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart ' ;
import ' package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart ' ;
import ' package:diplomaticquarterapp/models/Authentication/authenticated_user.dart ' ;
import ' package:diplomaticquarterapp/models/LiveCare/ApplePayInsertRequest.dart ' ;
import ' package:diplomaticquarterapp/services/authentication/auth_provider.dart ' ;
import ' package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart ' ;
import ' package:diplomaticquarterapp/uitl/app_shared_preferences.dart ' ;
import ' package:diplomaticquarterapp/uitl/app_toast.dart ' ;
import ' package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart ' ;
import ' package:flutter/cupertino.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter/widgets.dart ' ;
import ' package:flutter_inappwebview/flutter_inappwebview.dart ' ;
enum _PAYMENT_TYPE { PACKAGES , PHARMACY , PATIENT }
var _InAppBrowserOptions = InAppBrowserClassOptions (
inAppWebViewGroupOptions: InAppWebViewGroupOptions (
crossPlatform: InAppWebViewOptions ( useShouldOverrideUrlLoading: true ) ) ,
inAppWebViewGroupOptions: InAppWebViewGroupOptions ( crossPlatform: InAppWebViewOptions ( useShouldOverrideUrlLoading: true ) ) ,
crossPlatform: InAppBrowserOptions ( hideUrlBar: true ) ,
ios: IOSInAppBrowserOptions (
toolbarBottom: false ,
@ -23,38 +27,28 @@ var _InAppBrowserOptions = InAppBrowserClassOptions(
class MyInAppBrowser extends InAppBrowser {
_PAYMENT_TYPE paymentType ;
/ / static String SERVICE_URL =
/ / ' https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx ' ; / / Payfort Payment Gateway URL UAT
static String SERVICE_URL =
' https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx ' ; / / Payfort Payment Gateway URL LIVE
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
static String PREAUTH_SERVICE_URL = ' https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx ' ; / / Payfort PreAuth Payment Gateway URL Live Store
/ / static String PRESCRIPTION_PAYMENT_WITH_ORDERID =
/ / ' https://uat.hmgwebservices.com/epharmacy/checkout/OpcCompleteRedirectionPaymentClientbyOrder?orderID= ' ;
static String PRESCRIPTION_PAYMENT_WITH_ORDERID =
' https://mdlaboratories.com/exacartapi/checkout/OpcCompleteRedirectionPaymentClientbyOrder?orderID= ' ; / / Live
static String PRESCRIPTION_PAYMENT_WITH_ORDERID = ' https://mdlaboratories.com/exacartapi/checkout/OpcCompleteRedirectionPaymentClientbyOrder?orderID= ' ; / / Live
/ / Packages
static String PACKAGES_REQUEST_PAYMENT_URL =
' $ EXA_CART_API_BASE_URL /checkout/OpcCompleteRedirectionPayment1 ' ;
static String PACKAGES_PAYMENT_SUCCESS_URL =
' $ EXA_CART_API_BASE_URL /Checkout/MobilePaymentSuccess ' ;
static String PACKAGES_PAYMENT_FAIL_URL =
' $ EXA_CART_API_BASE_URL /Checkout/MobilePaymentFailed ' ;
static List < String > successURLS = [
' success ' ,
' PayFortResponse ' ,
' PayFortSucess ' ,
' mobilepaymentcomplete '
] ;
static String PACKAGES_REQUEST_PAYMENT_URL = ' $ EXA_CART_API_BASE_URL /checkout/OpcCompleteRedirectionPayment1 ' ;
static String PACKAGES_PAYMENT_SUCCESS_URL = ' $ EXA_CART_API_BASE_URL /Checkout/MobilePaymentSuccess ' ;
static String PACKAGES_PAYMENT_FAIL_URL = ' $ EXA_CART_API_BASE_URL /Checkout/MobilePaymentFailed ' ;
static List < String > successURLS = [ ' success ' , ' PayFortResponse ' , ' PayFortSucess ' , ' mobilepaymentcomplete ' ] ;
static List < String > errorURLS = [ ' PayfortCancel ' , ' errorpage ' , ' Failed ' ] ;
@ -76,8 +70,7 @@ class MyInAppBrowser extends InAppBrowser {
static bool isPaymentDone = false ;
MyInAppBrowser (
{ this . onExitCallback , this . appo , this . onLoadStartCallback , this . context } ) ;
MyInAppBrowser ( { this . onExitCallback , this . appo , this . onLoadStartCallback , this . context } ) ;
Future onBrowserCreated ( ) async {
print ( " \n \n Browser Created! \n \n " ) ;
@ -99,8 +92,7 @@ class MyInAppBrowser extends InAppBrowser {
}
@ override
void onProgressChanged ( int progress ) {
}
void onProgressChanged ( int progress ) { }
@ override
void onExit ( ) {
@ -109,14 +101,11 @@ class MyInAppBrowser extends InAppBrowser {
}
@ override
Future < ShouldOverrideUrlLoadingAction > shouldOverrideUrlLoading (
ShouldOverrideUrlLoadingRequest shouldOverrideUrlLoadingRequest ) async {
Future < ShouldOverrideUrlLoadingAction > shouldOverrideUrlLoading ( ShouldOverrideUrlLoadingRequest shouldOverrideUrlLoadingRequest ) async {
var url = shouldOverrideUrlLoadingRequest . url ;
debugPrint ( " redirecting/overriding to: $ url " ) ;
if ( paymentType = = _PAYMENT_TYPE . PACKAGES & &
[ PACKAGES_PAYMENT_SUCCESS_URL , PACKAGES_PAYMENT_FAIL_URL ]
. contains ( url ) ) {
if ( paymentType = = _PAYMENT_TYPE . PACKAGES & & [ PACKAGES_PAYMENT_SUCCESS_URL , PACKAGES_PAYMENT_FAIL_URL ] . contains ( url ) ) {
isPaymentDone = ( url = = PACKAGES_PAYMENT_SUCCESS_URL ) ;
close ( ) ;
}
@ -135,86 +124,88 @@ class MyInAppBrowser extends InAppBrowser {
getPatientData ( ) async {
if ( await this . sharedPref . getObject ( USER_PROFILE ) ! = null ) {
var data = AuthenticatedUser . fromJson (
await this . sharedPref . getObject ( USER_PROFILE ) ) ;
var data = AuthenticatedUser . fromJson ( await this . sharedPref . getObject ( USER_PROFILE ) ) ;
authUser = data ;
}
if ( await this . sharedPref . getDouble ( USER_LAT ) ! = null & &
await this . sharedPref . getDouble ( USER_LONG ) ! = null ) {
if ( await this . sharedPref . getDouble ( USER_LAT ) ! = null & & await this . sharedPref . getDouble ( USER_LONG ) ! = null ) {
lat = await this . sharedPref . getDouble ( USER_LAT ) ;
long = await this . sharedPref . getDouble ( USER_LONG ) ;
}
}
openPackagesPaymentBrowser (
{ @ required int customer_id , @ required int order_id } ) {
openPackagesPaymentBrowser ( { @ required int customer_id , @ required int order_id } ) {
paymentType = _PAYMENT_TYPE . PACKAGES ;
var full_url =
' $ PACKAGES_REQUEST_PAYMENT_URL ?customer_id= $ customer_id &order_id= $ order_id ' ;
var full_url = ' $ PACKAGES_REQUEST_PAYMENT_URL ?customer_id= $ customer_id &order_id= $ order_id ' ;
this . openUrl ( url: full_url , options: _InAppBrowserOptions ) ;
}
openPaymentBrowser (
double amount ,
String orderDesc ,
String transactionID ,
String projId ,
String emailId ,
String paymentMethod ,
dynamic patientType ,
String patientName ,
dynamic patientID ,
AuthenticatedUser authenticatedUser ,
InAppBrowser browser ,
bool isLiveCareAppo ,
var servID ,
var LiveServID ,
[ var appoDate ,
var appoNo ,
var clinicID ,
var doctorID ] ) {
openPaymentBrowser ( double amount , String orderDesc , String transactionID , String projId , String emailId , String paymentMethod , dynamic patientType , String patientName , dynamic patientID ,
AuthenticatedUser authenticatedUser , InAppBrowser browser , bool isLiveCareAppo , var servID , var LiveServID ,
[ var appoDate , var appoNo , var clinicID , var doctorID ] ) async {
this . browser = browser ;
getPatientData ( ) ;
generateURL (
amount ,
orderDesc ,
transactionID ,
projId ,
emailId ,
paymentMethod ,
patientType ,
patientName ,
patientID ,
authenticatedUser ,
isLiveCareAppo ,
servID ,
LiveServID ,
appoDate ,
appoNo ,
clinicID ,
doctorID )
. then ( ( value ) {
paymentType = _PAYMENT_TYPE . PATIENT ;
this . browser . openUrl ( url: value , options: _InAppBrowserOptions ) ;
} ) ;
await getPatientData ( ) ;
if ( paymentMethod = = " ApplePay " ) {
MyChromeSafariBrowser safariBrowser = new MyChromeSafariBrowser ( new MyInAppBrowser ( ) , onExitCallback: browser . onExit , onLoadStartCallback: this . browser . onLoadStart , appo: this . appo ) ;
if ( context ! = null ) GifLoaderDialogUtils . showMyDialog ( context ) ;
LiveCareService service = new LiveCareService ( ) ;
ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest ( ) ;
applePayInsertRequest . clientRequestID = transactionID ;
applePayInsertRequest . clinicID = clinicID ! = null ? clinicID : 0 ;
applePayInsertRequest . currency = authenticatedUser . outSA = = 1 ? " AED " : " SAR " ;
applePayInsertRequest . customerEmail = emailId ;
applePayInsertRequest . customerID = authenticatedUser . patientID ;
applePayInsertRequest . customerName = authenticatedUser . firstName ;
applePayInsertRequest . deviceToken = deviceToken ;
applePayInsertRequest . doctorID = doctorID ! = null ? doctorID : 0 ;
applePayInsertRequest . projectID = projId ;
applePayInsertRequest . serviceID = servID ;
applePayInsertRequest . channelID = 3 ;
applePayInsertRequest . patientID = authenticatedUser . patientID ;
applePayInsertRequest . patientTypeID = authenticatedUser . patientType ;
applePayInsertRequest . patientOutSA = authenticatedUser . outSA ;
applePayInsertRequest . appointmentDate = appoDate ! = null ? appoDate : null ;
applePayInsertRequest . appointmentNo = appoNo ! = null ? appoNo : 0 ;
applePayInsertRequest . orderDescription = orderDesc ;
applePayInsertRequest . liveServiceID = LiveServID ;
applePayInsertRequest . latitude = this . lat . toString ( ) ;
applePayInsertRequest . longitude = this . long . toString ( ) ;
applePayInsertRequest . amount = amount . toString ( ) ;
applePayInsertRequest . isSchedule = " 0 " ;
applePayInsertRequest . language = getLanguageID ( ) = = ' ar ' ? ' AR ' : ' EN ' ;
applePayInsertRequest . userName = authenticatedUser . patientID ;
applePayInsertRequest . responseContinueURL = " http://hmg.com/Documents/success.html " ;
applePayInsertRequest . backClickUrl = " http://hmg.com/Documents/success.html " ;
applePayInsertRequest . paymentOption = " ApplePay " ;
service . applePayInsertRequest ( applePayInsertRequest , context ) . then ( ( res ) {
if ( context ! = null ) GifLoaderDialogUtils . hideDialog ( context ) ;
var url = " https://hmgwebservices.com/HMGApplePayLive/applepay/pay?apq= " + res [ ' result ' ] ;
print ( url ) ;
safariBrowser . open ( url: url ) ;
/ / this . browser . openUrl ( url: url , options: _InAppBrowserOptions ) ;
} ) . catchError ( ( err ) {
print ( err ) ;
if ( context ! = null ) GifLoaderDialogUtils . hideDialog ( context ) ;
AppToast . showErrorToast ( message: err ) ;
} ) ;
} else {
generateURL ( amount , orderDesc , transactionID , projId , emailId , paymentMethod , patientType , patientName , patientID , authenticatedUser , isLiveCareAppo , servID , LiveServID , appoDate , appoNo ,
clinicID , doctorID )
. then ( ( value ) {
paymentType = _PAYMENT_TYPE . PATIENT ;
this . browser . openUrl ( url: value , options: _InAppBrowserOptions ) ;
} ) ;
}
}
openPharmacyPaymentBrowser (
OrderDetailModel order ,
double amount ,
String orderDesc ,
String transactionID ,
String emailId ,
String paymentMethod ,
String patientName ,
dynamic patientID ,
AuthenticatedUser authenticatedUser ,
InAppBrowser browser ) {
openPharmacyPaymentBrowser ( OrderDetailModel order , double amount , String orderDesc , String transactionID , String emailId , String paymentMethod , String patientName , dynamic patientID ,
AuthenticatedUser authenticatedUser , InAppBrowser browser ) {
this . browser = browser ;
getPatientData ( ) ;
generatePharmacyURL ( order , amount , orderDesc , transactionID , emailId ,
paymentMethod , patientName , patientID , authenticatedUser )
. then ( ( value ) {
generatePharmacyURL ( order , amount , orderDesc , transactionID , emailId , paymentMethod , patientName , patientID , authenticatedUser ) . then ( ( value ) {
this . browser . openUrl ( url: value ) ;
} ) ;
}
@ -224,25 +215,9 @@ class MyInAppBrowser extends InAppBrowser {
this . browser . openUrl ( url: url , options: _InAppBrowserOptions ) ;
}
Future < String > generateURL (
double amount ,
String orderDesc ,
String transactionID ,
String projId ,
String emailId ,
String paymentMethod ,
dynamic patientType ,
String patientName ,
dynamic patientID ,
AuthenticatedUser authUser ,
bool isLiveCareAppo ,
var servID ,
var LiveServID ,
[ var appoDate ,
var appoNo ,
var clinicID ,
var doctorID ,
var patientData ] ) async {
Future < String > generateURL ( double amount , String orderDesc , String transactionID , String projId , String emailId , String paymentMethod , dynamic patientType , String patientName , dynamic patientID ,
AuthenticatedUser authUser , bool isLiveCareAppo , var servID , var LiveServID ,
[ var appoDate , var appoNo , var clinicID , var doctorID , var patientData ] ) async {
getDeviceToken ( ) ;
String currentLanguageID = getLanguageID ( ) = = ' ar ' ? ' AR ' : ' EN ' ;
String form = isLiveCareAppo ? getLiveCareForm ( ) : getForm ( ) ;
@ -256,19 +231,15 @@ 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 = = 0 ? false . toString ( ) : true . toString ( ) ) ;
form = form . replaceFirst (
' PATIENT_TYPE_ID ' , patientData = = null ? patientType . toString ( ) : " 1 " ) ;
form = form . replaceFirst ( ' PATIENT_OUT_SA ' , authUser . outSA = = 0 ? false . toString ( ) : true . toString ( ) ) ;
form = form . replaceFirst ( ' PATIENT_TYPE_ID ' , patientData = = null ? patientType . toString ( ) : " 1 " ) ;
form = form . replaceFirst (
' DEVICE_TOKEN ' , await sharedPref . getString ( PUSH_TOKEN ) ) ;
form = form . replaceFirst ( ' DEVICE_TOKEN ' , await sharedPref . getString ( PUSH_TOKEN ) ) ;
form = form . replaceFirst ( ' LATITUDE_VALUE ' , this . lat . toString ( ) ) ;
form = form . replaceFirst ( ' LONGITUDE_VALUE ' , this . long . toString ( ) ) ;
if ( servID = = " 4 " )
form = form . replaceFirst (
' SERVICE_URL_VALUE ' , MyInAppBrowser . PREAUTH_SERVICE_URL ) ;
form = form . replaceFirst ( ' SERVICE_URL_VALUE ' , MyInAppBrowser . PREAUTH_SERVICE_URL ) ;
else
form = form . replaceFirst ( ' SERVICE_URL_VALUE ' , MyInAppBrowser . SERVICE_URL ) ;
@ -297,19 +268,8 @@ class MyInAppBrowser extends InAppBrowser {
}
Future < String > generatePharmacyURL (
OrderDetailModel order ,
double amount ,
String orderDesc ,
String transactionID ,
String emailId ,
String paymentMethod ,
String patientName ,
dynamic patientID ,
AuthenticatedUser authUser ) async {
String pharmacyURL = PRESCRIPTION_PAYMENT_WITH_ORDERID +
order . orderGuid +
' &&CustomerId= ' +
" ${ order . customerId } " ;
OrderDetailModel order , double amount , String orderDesc , String transactionID , String emailId , String paymentMethod , String patientName , dynamic patientID , AuthenticatedUser authUser ) async {
String pharmacyURL = PRESCRIPTION_PAYMENT_WITH_ORDERID + order . orderGuid + ' &&CustomerId= ' + " ${ order . customerId } " ;
return pharmacyURL ;
}
@ -380,10 +340,18 @@ class MyInAppBrowser extends InAppBrowser {
' </body> ' +
' </html> ' ;
}
safariCallBack ( ) {
print ( " Safari CallBack!!! " ) ;
}
}
class MyChromeSafariBrowser extends ChromeSafariBrowser {
MyChromeSafariBrowser ( browserFallback ) : super ( bFallback: browserFallback ) ;
final Function onExitCallback ;
final Function onLoadStartCallback ;
AppoitmentAllHistoryResultList appo ;
MyChromeSafariBrowser ( browserFallback , { @ required this . onExitCallback , @ required this . onLoadStartCallback , @ required this . appo } ) : super ( bFallback: browserFallback ) ;
@ override
void onOpened ( ) {
@ -393,10 +361,13 @@ class MyChromeSafariBrowser extends ChromeSafariBrowser {
@ override
void onCompletedInitialLoad ( ) {
print ( " ChromeSafari browser initial load completed " ) ;
onLoadStartCallback ( " ApplePay " ) ;
}
@ override
void onClosed ( ) {
print ( " ChromeSafari browser closed " ) ;
MyInAppBrowser . isPaymentDone = true ;
onExitCallback ( ) ;
}
}