Payment module implementation contd.
parent
c27ba6ef09
commit
2c45356b07
File diff suppressed because one or more lines are too long
@ -0,0 +1,15 @@
|
||||
class VidaPlusProjectListModel {
|
||||
int? projectID;
|
||||
|
||||
VidaPlusProjectListModel({this.projectID});
|
||||
|
||||
VidaPlusProjectListModel.fromJson(Map<String, dynamic> json) {
|
||||
projectID = json['ProjectID'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['ProjectID'] = this.projectID;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,120 @@
|
||||
class TamaraRequestModel {
|
||||
String? merchantReference;
|
||||
String? merchantIdentifier;
|
||||
String? clientRequestID;
|
||||
num? amount;
|
||||
String? currency;
|
||||
String? language;
|
||||
String? commandType;
|
||||
String? signature;
|
||||
String? customerEmail;
|
||||
String? orderDescription;
|
||||
bool? isInstallment;
|
||||
num? projectID;
|
||||
String? accessCode;
|
||||
String? sHARequestPhase;
|
||||
String? sHAResponsePhase;
|
||||
String? customerName;
|
||||
String? fileNumber;
|
||||
bool? patientOutSA;
|
||||
String? deviceToken;
|
||||
String? longitude;
|
||||
String? latitude;
|
||||
String? appointmentNo;
|
||||
var serviceID;
|
||||
var liveServiceID;
|
||||
String? doctorID;
|
||||
var appointmentDate;
|
||||
bool? isSchedule;
|
||||
|
||||
TamaraRequestModel(
|
||||
{this.merchantReference,
|
||||
this.merchantIdentifier,
|
||||
this.clientRequestID,
|
||||
this.amount,
|
||||
this.currency,
|
||||
this.language,
|
||||
this.commandType,
|
||||
this.signature,
|
||||
this.customerEmail,
|
||||
this.orderDescription,
|
||||
this.isInstallment,
|
||||
this.projectID,
|
||||
this.accessCode,
|
||||
this.sHARequestPhase,
|
||||
this.sHAResponsePhase,
|
||||
this.customerName,
|
||||
this.fileNumber,
|
||||
this.patientOutSA,
|
||||
this.deviceToken,
|
||||
this.longitude,
|
||||
this.latitude,
|
||||
this.appointmentNo,
|
||||
this.serviceID,
|
||||
this.liveServiceID,
|
||||
this.appointmentDate,
|
||||
this.doctorID,
|
||||
this.isSchedule});
|
||||
|
||||
TamaraRequestModel.fromJson(Map<String, dynamic> json) {
|
||||
merchantReference = json['Merchant_Reference'];
|
||||
merchantIdentifier = json['Merchant_Identifier'];
|
||||
clientRequestID = json['ClientRequestID'];
|
||||
amount = json['Amount'];
|
||||
currency = json['Currency'];
|
||||
language = json['Language'];
|
||||
commandType = json['CommandType'];
|
||||
signature = json['Signature'];
|
||||
customerEmail = json['CustomerEmail'];
|
||||
orderDescription = json['OrderDescription'];
|
||||
isInstallment = json['IsInstallment'];
|
||||
projectID = json['ProjectID'];
|
||||
accessCode = json['Access_code'];
|
||||
sHARequestPhase = json['SHA_RequestPhase'];
|
||||
sHAResponsePhase = json['SHA_ResponsePhase'];
|
||||
customerName = json['CustomerName'];
|
||||
fileNumber = json['FileNumber'];
|
||||
patientOutSA = json['PatientOutSA'];
|
||||
deviceToken = json['DeviceToken'];
|
||||
longitude = json['Longitude'];
|
||||
latitude = json['Latitude'];
|
||||
appointmentNo = json['AppointmentNo'];
|
||||
serviceID = json['Service_ID'];
|
||||
liveServiceID = json['Live_ServiceID'];
|
||||
doctorID = json['DoctorID'];
|
||||
appointmentDate = json['AppointmentDate'];
|
||||
isSchedule = json['IsSchedule'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['Merchant_Reference'] = this.merchantReference;
|
||||
data['Merchant_Identifier'] = this.merchantIdentifier;
|
||||
data['ClientRequestID'] = this.clientRequestID;
|
||||
data['Amount'] = this.amount;
|
||||
data['Currency'] = this.currency;
|
||||
data['Language'] = this.language;
|
||||
data['CommandType'] = this.commandType;
|
||||
data['Signature'] = this.signature;
|
||||
data['CustomerEmail'] = this.customerEmail;
|
||||
data['OrderDescription'] = this.orderDescription;
|
||||
data['IsInstallment'] = this.isInstallment;
|
||||
data['ProjectID'] = this.projectID;
|
||||
data['Access_code'] = this.accessCode;
|
||||
data['SHA_RequestPhase'] = this.sHARequestPhase;
|
||||
data['SHA_ResponsePhase'] = this.sHAResponsePhase;
|
||||
data['CustomerName'] = this.customerName;
|
||||
data['FileNumber'] = this.fileNumber;
|
||||
data['PatientOutSA'] = this.patientOutSA;
|
||||
data['DeviceToken'] = this.deviceToken;
|
||||
data['Longitude'] = this.longitude;
|
||||
data['Latitude'] = this.latitude;
|
||||
data['AppointmentNo'] = this.appointmentNo;
|
||||
data['Service_ID'] = this.serviceID;
|
||||
data['Live_ServiceID'] = this.liveServiceID;
|
||||
data['DoctorID'] = this.doctorID;
|
||||
data['AppointmentDate'] = this.appointmentDate;
|
||||
data['IsSchedule'] = this.isSchedule;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,187 @@
|
||||
class ApplePayInsertRequest {
|
||||
String? clientRequestID;
|
||||
int? clinicID;
|
||||
String? currency;
|
||||
String? customerEmail;
|
||||
dynamic customerID;
|
||||
String? customerName;
|
||||
String? deviceToken;
|
||||
String? voipToken;
|
||||
int? doctorID;
|
||||
String? projectID;
|
||||
String? serviceID;
|
||||
int? channelID;
|
||||
dynamic patientID;
|
||||
int? patientTypeID;
|
||||
int? patientOutSA;
|
||||
dynamic appointmentDate;
|
||||
int? appointmentNo;
|
||||
String? orderDescription;
|
||||
String? liveServiceID;
|
||||
String? latitude;
|
||||
String? longitude;
|
||||
String? amount;
|
||||
String? isSchedule;
|
||||
String? language;
|
||||
int? userName;
|
||||
String? responseContinueURL;
|
||||
String? backClickUrl;
|
||||
String? paymentOption;
|
||||
double? versionID;
|
||||
int? channel;
|
||||
int? languageID;
|
||||
String? iPAdress;
|
||||
String? generalid;
|
||||
String? sessionID;
|
||||
bool? isDentalAllowedBackend;
|
||||
int? deviceTypeID;
|
||||
bool? isMobSDK;
|
||||
String? merchantReference;
|
||||
String? merchantIdentifier;
|
||||
String? commandType;
|
||||
String? signature;
|
||||
String? accessCode;
|
||||
String? shaRequestPhrase;
|
||||
String? shaResponsePhrase;
|
||||
String? returnURL;
|
||||
|
||||
ApplePayInsertRequest(
|
||||
{this.clientRequestID,
|
||||
this.clinicID,
|
||||
this.currency,
|
||||
this.customerEmail,
|
||||
this.customerID,
|
||||
this.customerName,
|
||||
this.deviceToken,
|
||||
this.voipToken,
|
||||
this.doctorID,
|
||||
this.projectID,
|
||||
this.serviceID,
|
||||
this.channelID,
|
||||
this.patientID,
|
||||
this.patientTypeID,
|
||||
this.patientOutSA,
|
||||
this.appointmentDate,
|
||||
this.appointmentNo,
|
||||
this.orderDescription,
|
||||
this.liveServiceID,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.amount,
|
||||
this.isSchedule,
|
||||
this.language,
|
||||
this.userName,
|
||||
this.responseContinueURL,
|
||||
this.backClickUrl,
|
||||
this.paymentOption,
|
||||
this.versionID,
|
||||
this.channel,
|
||||
this.languageID,
|
||||
this.iPAdress,
|
||||
this.generalid,
|
||||
this.sessionID,
|
||||
this.isDentalAllowedBackend,
|
||||
this.deviceTypeID,
|
||||
this.isMobSDK,
|
||||
this.merchantReference,
|
||||
this.merchantIdentifier,
|
||||
this.commandType,
|
||||
this.signature,
|
||||
this.accessCode,
|
||||
this.shaRequestPhrase,
|
||||
this.shaResponsePhrase,
|
||||
this.returnURL,
|
||||
});
|
||||
|
||||
ApplePayInsertRequest.fromJson(Map<String, dynamic> json) {
|
||||
clientRequestID = json['ClientRequestID'];
|
||||
clinicID = json['ClinicID'];
|
||||
currency = json['Currency'];
|
||||
customerEmail = json['CustomerEmail'];
|
||||
customerID = json['CustomerID'];
|
||||
customerName = json['CustomerName'];
|
||||
deviceToken = json['DeviceToken'];
|
||||
voipToken = json['VoipToken'];
|
||||
doctorID = json['DoctorID'];
|
||||
projectID = json['ProjectID'];
|
||||
serviceID = json['Service_ID'];
|
||||
channelID = json['Channel_ID'];
|
||||
patientID = json['PatientID'];
|
||||
patientTypeID = json['PatientTypeID'];
|
||||
patientOutSA = json['PatientOutSA'];
|
||||
appointmentDate = json['AppointmentDate'];
|
||||
appointmentNo = json['AppointmentNo'];
|
||||
orderDescription = json['OrderDescription'];
|
||||
liveServiceID = json['Live_ServiceID'];
|
||||
latitude = json['Latitude'];
|
||||
longitude = json['Longitude'];
|
||||
amount = json['Amount'];
|
||||
isSchedule = json['IsSchedule'];
|
||||
language = json['Language'];
|
||||
userName = json['userName'];
|
||||
responseContinueURL = json['ResponseContinueURL'];
|
||||
backClickUrl = json['BackClickUrl'];
|
||||
paymentOption = json['PaymentOption'];
|
||||
versionID = json['VersionID'];
|
||||
channel = json['Channel'];
|
||||
languageID = json['LanguageID'];
|
||||
iPAdress = json['IPAdress'];
|
||||
generalid = json['generalid'];
|
||||
sessionID = json['SessionID'];
|
||||
isDentalAllowedBackend = json['isDentalAllowedBackend'];
|
||||
deviceTypeID = json['DeviceTypeID'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['ClientRequestID'] = this.clientRequestID;
|
||||
data['ClinicID'] = this.clinicID;
|
||||
data['Currency'] = this.currency;
|
||||
data['CustomerEmail'] = this.customerEmail;
|
||||
data['CustomerID'] = this.customerID;
|
||||
data['CustomerName'] = this.customerName;
|
||||
data['DeviceToken'] = this.deviceToken;
|
||||
data['VoipToken'] = this.voipToken;
|
||||
data['DoctorID'] = this.doctorID;
|
||||
data['ProjectID'] = this.projectID;
|
||||
data['Service_ID'] = this.serviceID;
|
||||
data['Channel_ID'] = this.channelID;
|
||||
data['PatientID'] = this.patientID;
|
||||
data['PatientId'] = this.patientID;
|
||||
data['PatientTypeID'] = this.patientTypeID;
|
||||
data['PatientOutSA'] = this.patientOutSA;
|
||||
data['AppointmentDate'] = this.appointmentDate;
|
||||
data['AppointmentNo'] = this.appointmentNo;
|
||||
data['OrderDescription'] = this.orderDescription;
|
||||
data['Live_ServiceID'] = this.liveServiceID;
|
||||
data['Latitude'] = this.latitude;
|
||||
data['Longitude'] = this.longitude;
|
||||
data['Amount'] = this.amount;
|
||||
data['IsSchedule'] = this.isSchedule;
|
||||
data['Language'] = this.language;
|
||||
data['userName'] = this.userName;
|
||||
data['ResponseContinueURL'] = this.responseContinueURL;
|
||||
data['BackClickUrl'] = this.backClickUrl;
|
||||
data['PaymentOption'] = this.paymentOption;
|
||||
data['VersionID'] = this.versionID;
|
||||
data['Channel'] = this.channel;
|
||||
data['LanguageID'] = this.languageID;
|
||||
data['IPAdress'] = this.iPAdress;
|
||||
data['generalid'] = this.generalid;
|
||||
data['SessionID'] = this.sessionID;
|
||||
data['isDentalAllowedBackend'] = this.isDentalAllowedBackend;
|
||||
data['DeviceTypeID'] = this.deviceTypeID;
|
||||
|
||||
data['IsMobSDK'] = this.isMobSDK;
|
||||
data['Merchant_Reference'] = this.merchantReference;
|
||||
data['Merchant_Identifier'] = this.merchantIdentifier;
|
||||
data['CommandType'] = this.commandType;
|
||||
data['Signature'] = this.signature;
|
||||
data['Access_code'] = this.accessCode;
|
||||
data['SHA_RequestPhase'] = this.shaRequestPhrase;
|
||||
data['SHA_ResponsePhase'] = this.shaResponsePhrase;
|
||||
data['ReturnURL'] = this.returnURL;
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
class PayfortCheckPaymentStatusResponseModel {
|
||||
num? amount;
|
||||
String? cardNumber;
|
||||
dynamic clientRequsetID;
|
||||
dynamic errorMessage;
|
||||
String? fortId;
|
||||
String? merchantReference;
|
||||
dynamic orderDescription;
|
||||
dynamic patientFileNumber;
|
||||
String? paymentMethod;
|
||||
dynamic rRN;
|
||||
String? responseMessage;
|
||||
dynamic vidaAdvancedNumber;
|
||||
|
||||
PayfortCheckPaymentStatusResponseModel(
|
||||
{this.amount,
|
||||
this.cardNumber,
|
||||
this.clientRequsetID,
|
||||
this.errorMessage,
|
||||
this.fortId,
|
||||
this.merchantReference,
|
||||
this.orderDescription,
|
||||
this.patientFileNumber,
|
||||
this.paymentMethod,
|
||||
this.rRN,
|
||||
this.responseMessage,
|
||||
this.vidaAdvancedNumber});
|
||||
|
||||
PayfortCheckPaymentStatusResponseModel.fromJson(Map<String, dynamic> json) {
|
||||
amount = json['Amount'];
|
||||
cardNumber = json['CardNumber'];
|
||||
clientRequsetID = json['ClientRequsetID'];
|
||||
errorMessage = json['ErrorMessage'];
|
||||
fortId = json['Fort_id'];
|
||||
merchantReference = json['Merchant_Reference'];
|
||||
orderDescription = json['OrderDescription'];
|
||||
patientFileNumber = json['PatientFileNumber'];
|
||||
paymentMethod = json['PaymentMethod'];
|
||||
rRN = json['RRN'];
|
||||
responseMessage = json['Response_Message'];
|
||||
vidaAdvancedNumber = json['VidaAdvancedNumber'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['Amount'] = this.amount;
|
||||
data['CardNumber'] = this.cardNumber;
|
||||
data['ClientRequsetID'] = this.clientRequsetID;
|
||||
data['ErrorMessage'] = this.errorMessage;
|
||||
data['Fort_id'] = this.fortId;
|
||||
data['Merchant_Reference'] = this.merchantReference;
|
||||
data['OrderDescription'] = this.orderDescription;
|
||||
data['PatientFileNumber'] = this.patientFileNumber;
|
||||
data['PaymentMethod'] = this.paymentMethod;
|
||||
data['RRN'] = this.rRN;
|
||||
data['Response_Message'] = this.responseMessage;
|
||||
data['VidaAdvancedNumber'] = this.vidaAdvancedNumber;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
class PayfortProjectDetailsRespModel {
|
||||
String? accessCode;
|
||||
int? integrationId;
|
||||
String? merchantIdentifier;
|
||||
int? projectID;
|
||||
String? projectName;
|
||||
int? servID;
|
||||
String? shaRequest;
|
||||
String? shaResponse;
|
||||
String? signature;
|
||||
|
||||
PayfortProjectDetailsRespModel({this.accessCode, this.integrationId, this.merchantIdentifier, this.projectID, this.projectName, this.servID, this.shaRequest, this.shaResponse, this.signature});
|
||||
|
||||
PayfortProjectDetailsRespModel.fromJson(Map<String, dynamic> json) {
|
||||
accessCode = json['AccessCode'];
|
||||
integrationId = json['Integration_Id'];
|
||||
merchantIdentifier = json['MerchantIdentifier'];
|
||||
projectID = json['ProjectID'];
|
||||
projectName = json['ProjectName'];
|
||||
servID = json['ServID'];
|
||||
shaRequest = json['Sha_Request'];
|
||||
shaResponse = json['Sha_Response'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['AccessCode'] = this.accessCode;
|
||||
data['Integration_Id'] = this.integrationId;
|
||||
data['MerchantIdentifier'] = this.merchantIdentifier;
|
||||
data['ProjectID'] = this.projectID;
|
||||
data['ProjectName'] = this.projectName;
|
||||
data['ServID'] = this.servID;
|
||||
data['Sha_Request'] = this.shaRequest;
|
||||
data['Sha_Response'] = this.shaResponse;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
class SdkTokenResponse {
|
||||
SdkTokenResponse({
|
||||
this.responseCode,
|
||||
this.deviceId,
|
||||
this.responseMessage,
|
||||
this.serviceCommand,
|
||||
this.sdkToken,
|
||||
this.signature,
|
||||
this.merchantIdentifier,
|
||||
this.accessCode,
|
||||
this.language,
|
||||
this.status,
|
||||
});
|
||||
|
||||
String? responseCode;
|
||||
String? deviceId;
|
||||
String? responseMessage;
|
||||
String? serviceCommand;
|
||||
String? sdkToken;
|
||||
String? signature;
|
||||
String? merchantIdentifier;
|
||||
String? accessCode;
|
||||
String? language;
|
||||
String? status;
|
||||
|
||||
factory SdkTokenResponse.fromMap(Map<String, dynamic> data) {
|
||||
return SdkTokenResponse(
|
||||
responseCode: data['response_code'],
|
||||
deviceId: data['device_id'],
|
||||
responseMessage: data['response_message'],
|
||||
serviceCommand: data['service_command'],
|
||||
sdkToken: data['sdk_token'],
|
||||
signature: data['signature'],
|
||||
merchantIdentifier: data['merchant_identifier'],
|
||||
accessCode: data['access_code'],
|
||||
language: data['language'],
|
||||
status: data['status'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'response_code': responseCode,
|
||||
'device_id': deviceId,
|
||||
'response_message': responseMessage,
|
||||
'service_command': serviceCommand,
|
||||
'sdk_token': sdkToken,
|
||||
'signature': signature,
|
||||
'merchant_identifier': merchantIdentifier,
|
||||
'access_code': accessCode,
|
||||
'language': language,
|
||||
'status': status,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,150 @@
|
||||
import 'package:amazon_payfort/amazon_payfort.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:hmg_patient_app_new/core/api/api_client.dart';
|
||||
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
||||
import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart';
|
||||
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/models/apple_pay_request_insert_model.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/models/payfort_check_payment_status_response_model.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/models/payfort_project_details_resp_model.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/models/sdk_token_response_model.dart';
|
||||
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
||||
|
||||
abstract class PayfortRepo {
|
||||
Future<Either<Failure, GenericApiModel<PayfortProjectDetailsRespModel>>> getPayfortConfigurations({int? serviceId, int? projectId, int integrationId = 2});
|
||||
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> applePayRequestInsert({required ApplePayInsertRequest applePayInsertRequest});
|
||||
|
||||
Future<Either<Failure, GenericApiModel<SdkTokenResponse>>> generateSdkSignatureFromAPI({required SdkTokenRequest tokenRequest});
|
||||
|
||||
Future<Either<Failure, GenericApiModel<PayfortCheckPaymentStatusResponseModel>>> checkPaymentStatus({required String transactionID});
|
||||
}
|
||||
|
||||
class PayfortRepoImp implements PayfortRepo {
|
||||
final ApiClient apiClient;
|
||||
final LoggerService loggerService;
|
||||
|
||||
PayfortRepoImp({required this.loggerService, required this.apiClient});
|
||||
|
||||
@override
|
||||
Future<Either<Failure, GenericApiModel<PayfortProjectDetailsRespModel>>> getPayfortConfigurations({int? serviceId, int? projectId, int integrationId = 2}) async {
|
||||
Map<String, dynamic> body = {"Integration_Id": integrationId, "ServID": serviceId, "ProjectID": projectId};
|
||||
|
||||
try {
|
||||
GenericApiModel<PayfortProjectDetailsRespModel>? apiResponse;
|
||||
Failure? failure;
|
||||
await apiClient.post(getPayFortProjectDetails, body: body, onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
failure = failureType;
|
||||
}, onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
try {
|
||||
final list = response;
|
||||
if (list == null || list.isEmpty) {
|
||||
throw Exception("payfort list is empty");
|
||||
}
|
||||
|
||||
final applePayConfigurationResponse = PayfortProjectDetailsRespModel.fromJson(list[0]);
|
||||
|
||||
apiResponse = GenericApiModel<PayfortProjectDetailsRespModel>(
|
||||
messageStatus: messageStatus,
|
||||
statusCode: statusCode,
|
||||
errorMessage: null,
|
||||
data: applePayConfigurationResponse,
|
||||
);
|
||||
} catch (e) {
|
||||
failure = DataParsingFailure(e.toString());
|
||||
}
|
||||
}, isAllowAny: true);
|
||||
if (failure != null) return Left(failure!);
|
||||
if (apiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||
return Right(apiResponse!);
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, GenericApiModel>> applePayRequestInsert({required ApplePayInsertRequest applePayInsertRequest}) async {
|
||||
try {
|
||||
GenericApiModel<dynamic>? apiResponse;
|
||||
Failure? failure;
|
||||
await apiClient.post(APPLE_PAY_INSERT_REQUEST, body: applePayInsertRequest.toJson(), onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
failure = failureType;
|
||||
}, onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
try {
|
||||
apiResponse = GenericApiModel<dynamic>(
|
||||
messageStatus: messageStatus,
|
||||
statusCode: statusCode,
|
||||
errorMessage: null,
|
||||
data: response["result"],
|
||||
);
|
||||
} catch (e) {
|
||||
failure = DataParsingFailure(e.toString());
|
||||
}
|
||||
}, isAllowAny: true);
|
||||
if (failure != null) return Left(failure!);
|
||||
if (apiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||
return Right(apiResponse!);
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, GenericApiModel<SdkTokenResponse>>> generateSdkSignatureFromAPI({required SdkTokenRequest tokenRequest}) async {
|
||||
try {
|
||||
GenericApiModel<SdkTokenResponse>? apiResponse;
|
||||
Failure? failure;
|
||||
await apiClient.post(ApiConsts.payFortEnvironment.paymentApi, body: tokenRequest.asRequest(), onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
failure = failureType;
|
||||
}, onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
try {
|
||||
final sdkTokenResponse = SdkTokenResponse.fromMap(response);
|
||||
|
||||
apiResponse = GenericApiModel<SdkTokenResponse>(
|
||||
messageStatus: messageStatus,
|
||||
statusCode: statusCode,
|
||||
errorMessage: null,
|
||||
data: sdkTokenResponse,
|
||||
);
|
||||
} catch (e) {
|
||||
failure = DataParsingFailure(e.toString());
|
||||
}
|
||||
}, isAllowAny: true, isExternal: true);
|
||||
if (failure != null) return Left(failure!);
|
||||
if (apiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||
return Right(apiResponse!);
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, GenericApiModel<PayfortCheckPaymentStatusResponseModel>>> checkPaymentStatus({required String transactionID}) async {
|
||||
Map<String, dynamic> body = {"ClientRequestID": transactionID, "IsPharmacy": false};
|
||||
try {
|
||||
GenericApiModel<PayfortCheckPaymentStatusResponseModel>? apiResponse;
|
||||
Failure? failure;
|
||||
await apiClient.post(CHECK_PAYMENT_STATUS, body: body, onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
failure = failureType;
|
||||
}, onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
try {
|
||||
final paymentStatusResponse = PayfortCheckPaymentStatusResponseModel.fromJson(response);
|
||||
|
||||
apiResponse = GenericApiModel<PayfortCheckPaymentStatusResponseModel>(
|
||||
messageStatus: messageStatus,
|
||||
statusCode: statusCode,
|
||||
errorMessage: null,
|
||||
data: paymentStatusResponse,
|
||||
);
|
||||
} catch (e) {
|
||||
failure = DataParsingFailure(e.toString());
|
||||
}
|
||||
}, isAllowAny: true);
|
||||
if (failure != null) return Left(failure!);
|
||||
if (apiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||
return Right(apiResponse!);
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,198 @@
|
||||
import 'package:amazon_payfort/amazon_payfort.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/models/apple_pay_request_insert_model.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/models/payfort_check_payment_status_response_model.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/models/payfort_project_details_resp_model.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/models/sdk_token_response_model.dart';
|
||||
import 'package:hmg_patient_app_new/features/payfort/payfort_repo.dart';
|
||||
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
||||
import 'package:network_info_plus/network_info_plus.dart';
|
||||
|
||||
class PayfortViewModel extends ChangeNotifier {
|
||||
PayfortRepo payfortRepo;
|
||||
ErrorHandlerService errorHandlerService;
|
||||
|
||||
bool isApplePayConfigurationLoading = false;
|
||||
|
||||
PayfortProjectDetailsRespModel? payfortProjectDetailsRespModel;
|
||||
PayfortCheckPaymentStatusResponseModel? payfortCheckPaymentStatusResponseModel;
|
||||
late AmazonPayfort _payfort;
|
||||
final NetworkInfo _info = NetworkInfo();
|
||||
|
||||
PayfortViewModel({required this.payfortRepo, required this.errorHandlerService});
|
||||
|
||||
setIsApplePayConfigurationLoading(bool value) {
|
||||
isApplePayConfigurationLoading = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
initPayfortViewModel() async {
|
||||
_payfort = AmazonPayfort.instance;
|
||||
await AmazonPayfort.initialize(
|
||||
PayFortOptions(environment: ApiConsts.payFortEnvironment),
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> getPayfortConfigurations({int? serviceId, int? projectId, int integrationId = 2, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
||||
final result = await payfortRepo.getPayfortConfigurations(serviceId: serviceId, projectId: projectId, integrationId: integrationId);
|
||||
|
||||
result.fold(
|
||||
(failure) async => await errorHandlerService.handleError(failure: failure),
|
||||
(apiResponse) {
|
||||
if (apiResponse.messageStatus == 2) {
|
||||
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
||||
} else if (apiResponse.messageStatus == 1) {
|
||||
payfortProjectDetailsRespModel = apiResponse.data!;
|
||||
// isApplePayConfigurationLoading = false;
|
||||
notifyListeners();
|
||||
if (onSuccess != null) {
|
||||
onSuccess(apiResponse);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> applePayRequestInsert({required ApplePayInsertRequest applePayInsertRequest, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
||||
final result = await payfortRepo.applePayRequestInsert(applePayInsertRequest: applePayInsertRequest);
|
||||
|
||||
result.fold(
|
||||
(failure) async => await errorHandlerService.handleError(failure: failure),
|
||||
(apiResponse) {
|
||||
if (apiResponse.messageStatus == 2) {
|
||||
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
||||
} else if (apiResponse.messageStatus == 1) {
|
||||
// payfortProjectDetailsRespModel = apiResponse.data!;
|
||||
notifyListeners();
|
||||
if (onSuccess != null) {
|
||||
onSuccess(apiResponse);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> checkPaymentStatus({required String transactionID, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
||||
final result = await payfortRepo.checkPaymentStatus(transactionID: transactionID);
|
||||
|
||||
result.fold(
|
||||
(failure) async => await errorHandlerService.handleError(failure: failure),
|
||||
(apiResponse) {
|
||||
if (apiResponse.messageStatus == 2) {
|
||||
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
||||
} else if (apiResponse.messageStatus == 1) {
|
||||
payfortCheckPaymentStatusResponseModel = apiResponse.data!;
|
||||
notifyListeners();
|
||||
if (onSuccess != null) {
|
||||
onSuccess(apiResponse);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<SdkTokenResponse?> _generateSdkResponse({
|
||||
String? applePayAccessCode,
|
||||
String? merchantIdentifier,
|
||||
String? applePayShaType,
|
||||
String? applePayShaRequestPhrase,
|
||||
}) async {
|
||||
try {
|
||||
String? deviceId = await _payfort.getDeviceId();
|
||||
|
||||
/// Step 2: Generate the Signature
|
||||
SdkTokenRequest tokenRequest = SdkTokenRequest(
|
||||
accessCode: applePayAccessCode!,
|
||||
deviceId: deviceId ?? '',
|
||||
merchantIdentifier: merchantIdentifier!,
|
||||
);
|
||||
|
||||
String? signature = await _payfort.generateSignature(
|
||||
shaType: applePayShaType!,
|
||||
concatenatedString: tokenRequest.toConcatenatedString(applePayShaRequestPhrase!),
|
||||
);
|
||||
|
||||
tokenRequest = tokenRequest.copyWith(signature: signature);
|
||||
|
||||
/// Step 3: Generate the SDK Token
|
||||
final result = await payfortRepo.generateSdkSignatureFromAPI(tokenRequest: tokenRequest);
|
||||
result.fold(
|
||||
(failure) async => await errorHandlerService.handleError(failure: failure),
|
||||
(apiResponse) {
|
||||
if (apiResponse.messageStatus == 2) {
|
||||
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
||||
} else if (apiResponse.messageStatus == 1) {
|
||||
// payfortProjectDetailsRespModel = apiResponse.data!;
|
||||
isApplePayConfigurationLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
print("Error here: ${e.toString()}");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> paymentWithApplePay({
|
||||
SucceededCallback? onSucceeded,
|
||||
FailedCallback? onFailed,
|
||||
String? customerName,
|
||||
String? customerEmail,
|
||||
String? orderDescription,
|
||||
num? orderAmount,
|
||||
String? merchantIdentifier,
|
||||
String? applePayAccessCode,
|
||||
String? applePayShaRequestPhrase,
|
||||
String? merchantReference,
|
||||
String currency = "SAR",
|
||||
String applePayShaType = "SHA-256",
|
||||
String countryIsoCode = "SA",
|
||||
}) async {
|
||||
try {
|
||||
SdkTokenResponse? sdkTokenResponse = await _generateSdkResponse(
|
||||
applePayAccessCode: applePayAccessCode,
|
||||
merchantIdentifier: merchantIdentifier,
|
||||
applePayShaType: applePayShaType,
|
||||
applePayShaRequestPhrase: applePayShaRequestPhrase,
|
||||
);
|
||||
|
||||
if (sdkTokenResponse != null && sdkTokenResponse.sdkToken == null) {
|
||||
onFailed!((sdkTokenResponse.responseMessage ?? '') as PayFortFailureResult);
|
||||
return;
|
||||
}
|
||||
|
||||
/// Step 4: Processing Payment [Don't multiply with 100]
|
||||
/// Amount value send always round ex. [100] not [100.00, 100.21]
|
||||
FortRequest request = FortRequest(
|
||||
command: FortCommand.purchase,
|
||||
amount: orderAmount!,
|
||||
customerName: customerName!,
|
||||
customerEmail: customerEmail!,
|
||||
// orderDescription: orderDescription!,
|
||||
orderDescription: "Dr. Sulaiman Al Habib Hospital",
|
||||
sdkToken: sdkTokenResponse?.sdkToken ?? '',
|
||||
merchantReference: merchantReference!,
|
||||
currency: currency,
|
||||
customerIp: (await _info.getWifiIP() ?? ''),
|
||||
language: 'en');
|
||||
|
||||
isApplePayConfigurationLoading = false;
|
||||
notifyListeners();
|
||||
|
||||
_payfort.callPayFortForApplePay(
|
||||
request: request,
|
||||
countryIsoCode: countryIsoCode,
|
||||
applePayMerchantId: ApiConsts.applePayMerchantId,
|
||||
callback: ApplePayResultCallback(
|
||||
onSucceeded: onSucceeded!,
|
||||
onFailed: onFailed!,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
onFailed!(e.toString() as PayFortFailureResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,489 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
||||
import 'package:hmg_patient_app_new/core/app_state.dart';
|
||||
import 'package:hmg_patient_app_new/core/cache_consts.dart';
|
||||
import 'package:hmg_patient_app_new/core/common_models/tamara_request_model.dart';
|
||||
import 'package:hmg_patient_app_new/core/dependencies.dart';
|
||||
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
|
||||
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
||||
import 'package:hmg_patient_app_new/features/authentication/models/resp_models/authenticated_user_resp_model.dart';
|
||||
|
||||
enum _PAYMENT_TYPE { PACKAGES, PHARMACY, PATIENT }
|
||||
|
||||
var _InAppBrowserOptions = InAppBrowserClassOptions(
|
||||
inAppWebViewGroupOptions: InAppWebViewGroupOptions(
|
||||
crossPlatform: InAppWebViewOptions(useShouldOverrideUrlLoading: true, transparentBackground: false),
|
||||
ios: IOSInAppWebViewOptions(applePayAPIEnabled: true, isFraudulentWebsiteWarningEnabled: false)),
|
||||
crossPlatform: InAppBrowserOptions(hideUrlBar: true, toolbarTopBackgroundColor: Colors.black),
|
||||
android: AndroidInAppBrowserOptions(),
|
||||
ios: IOSInAppBrowserOptions(
|
||||
hideToolbarBottom: true,
|
||||
toolbarBottomBackgroundColor: Colors.white,
|
||||
closeButtonColor: Colors.white,
|
||||
closeButtonCaption: "Close",
|
||||
presentationStyle: IOSUIModalPresentationStyle.OVER_FULL_SCREEN));
|
||||
|
||||
class MyInAppBrowser extends InAppBrowser {
|
||||
_PAYMENT_TYPE? paymentType;
|
||||
|
||||
static String APPLE_PAY_PAYFORT_URL = 'https://hmgwebservices.com/PayFortWebLive/PayFortApi/MakeApplePayRequest'; // Payfort Payment Gateway URL LIVE
|
||||
// static String APPLE_PAY_PAYFORT_URL = 'https://hmgwebservices.com/PayFortWebLive/PayFortApi/MakeApplePayRequest'; // Payfort Payment Gateway URL UAT
|
||||
|
||||
// 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://uat.hmgwebservices.com/payfortforvidaplus/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL UAT VIDA PLUS
|
||||
|
||||
// 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 List<String> successURLS = ['success?', 'PayFortResponse', 'PayFortSucess', 'mobilepaymentcomplete', 'orderdetails', 'redirectToApplePay', 'mdlaboratories.com/?'];
|
||||
|
||||
static List<String> errorURLS = ['PayfortCancel', 'errorpage', 'Failed', 'orderdetails', 'redirectToApplePay', 'mdlaboratories.com/?', 'cancel', 'canceled'];
|
||||
|
||||
final Function onExitCallback;
|
||||
final Function? onLoadStartCallback;
|
||||
final BuildContext? context;
|
||||
|
||||
// AppSharedPreferences sharedPref = AppSharedPreferences();
|
||||
// AuthProvider authProvider = new AuthProvider();
|
||||
InAppBrowser browser = InAppBrowser();
|
||||
|
||||
// AuthenticatedUser authUser;
|
||||
// late AppoitmentAllHistoryResultList? appo;
|
||||
|
||||
String deviceToken = "";
|
||||
|
||||
double lat = 0.0;
|
||||
double long = 0.0;
|
||||
|
||||
static bool isPaymentDone = false;
|
||||
late AppState appState;
|
||||
|
||||
MyInAppBrowser({required this.onExitCallback, this.onLoadStartCallback, this.context});
|
||||
|
||||
Future onBrowserCreated() async {
|
||||
print("\n\nBrowser Created!\n\n");
|
||||
}
|
||||
|
||||
@override
|
||||
Future onLoadStart(Uri? url) async {
|
||||
if (onLoadStartCallback != null) onLoadStartCallback!(url.toString());
|
||||
}
|
||||
|
||||
@override
|
||||
Future onLoadStop(Uri? url) async {
|
||||
print("\n\nStopped $url\n\n");
|
||||
}
|
||||
|
||||
@override
|
||||
void onLoadError(Uri? url, int code, String message) {
|
||||
print("Can't load $url.. Error: $message");
|
||||
}
|
||||
|
||||
@override
|
||||
void onProgressChanged(int progress) {}
|
||||
|
||||
@override
|
||||
void onExit() {
|
||||
print("\n\nBrowser closed before!\n\n");
|
||||
// if (onExitCallback != null) {
|
||||
try {
|
||||
onExitCallback(isPaymentDone);
|
||||
print("\n\nBrowser closed after!\n\n");
|
||||
} catch (err) {
|
||||
print(err.toString());
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
@override
|
||||
Future<NavigationActionPolicy> shouldOverrideUrlLoading(NavigationAction navigationAction) {
|
||||
var url = navigationAction.request.url.toString();
|
||||
debugPrint("redirecting/overriding to: $url");
|
||||
|
||||
// if (paymentType == _PAYMENT_TYPE.PACKAGES && [PACKAGES_PAYMENT_SUCCESS_URL, PACKAGES_PAYMENT_FAIL_URL].contains(url)) {
|
||||
// isPaymentDone = (url == PACKAGES_PAYMENT_SUCCESS_URL);
|
||||
// close();
|
||||
// }
|
||||
|
||||
return Future.value(NavigationActionPolicy.ALLOW);
|
||||
}
|
||||
|
||||
// getLanguageID() async {
|
||||
// return await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
||||
// }
|
||||
|
||||
// getDeviceToken() async {
|
||||
// String deviceToken = await sharedPref.getString(PUSH_TOKEN);
|
||||
// this.deviceToken = deviceToken;
|
||||
// }
|
||||
|
||||
// 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';
|
||||
// this.openUrlRequest(urlRequest: URLRequest(url: WebUri.uri(Uri.parse(full_url))), options: _InAppBrowserOptions);
|
||||
// }
|
||||
|
||||
openPaymentBrowser(num 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, BuildContext context,
|
||||
[var appoDate, var appoNo, var clinicID, var doctorID, var installments]) async {
|
||||
appState = getIt.get<AppState>();
|
||||
this.browser = browser;
|
||||
// await getPatientData();
|
||||
if (paymentMethod == "ApplePay") {
|
||||
MyChromeSafariBrowser safariBrowser = MyChromeSafariBrowser(MyInAppBrowser(onExitCallback: browser.onExit), onExitCallback: browser.onExit, onLoadStartCallback: this.browser.onLoadStart);
|
||||
|
||||
// if (context != null) GifLoaderDialogUtils.showMyDialog(context);
|
||||
|
||||
// LiveCareService service = new LiveCareService();
|
||||
// ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest();
|
||||
|
||||
// applePayInsertRequest.clientRequestID = transactionID;
|
||||
// applePayInsertRequest.clinicID = (clinicID != null && clinicID != "") ? clinicID : 0;
|
||||
// applePayInsertRequest.currency = authenticatedUser.outSA == 1 ? "AED" : "SAR";
|
||||
// applePayInsertRequest.customerEmail = emailId;
|
||||
// applePayInsertRequest.customerID = patientID;
|
||||
// applePayInsertRequest.customerName = patientName;
|
||||
// applePayInsertRequest.deviceToken = await AppSharedPreferences().getString(PUSH_TOKEN);
|
||||
// applePayInsertRequest.voipToken = await AppSharedPreferences().getString(ONESIGNAL_APNS_TOKEN);
|
||||
// applePayInsertRequest.doctorID = (doctorID != null && doctorID != "") ? doctorID : 0;
|
||||
// applePayInsertRequest.projectID = projId;
|
||||
// applePayInsertRequest.serviceID = servID;
|
||||
// applePayInsertRequest.channelID = 3;
|
||||
// applePayInsertRequest.patientID = patientID;
|
||||
// applePayInsertRequest.patientTypeID = authenticatedUser.patientType;
|
||||
// applePayInsertRequest.patientOutSA = authenticatedUser.outSA;
|
||||
// applePayInsertRequest.appointmentDate = (appoDate != null && appoDate != "") ? appoDate : null;
|
||||
// applePayInsertRequest.appointmentNo = (appoNo != null && appoNo != "") ? appoNo : 0;
|
||||
// applePayInsertRequest.orderDescription = orderDesc;
|
||||
// applePayInsertRequest.liveServiceID = LiveServID.toString() == "" ? "0" : LiveServID.toString();
|
||||
// applePayInsertRequest.latitude = this.lat.toString();
|
||||
// applePayInsertRequest.longitude = this.long.toString();
|
||||
// applePayInsertRequest.amount = amount.toString();
|
||||
// applePayInsertRequest.isSchedule = ((appoNo != null && appoNo != "") && (appoDate != null && appoDate != "")) ? "1" : "0";
|
||||
// applePayInsertRequest.language = await 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);
|
||||
// String url = "https://hmgwebservices.com/HMGApplePayLive/applepay/pay?apq=" + res['result']; // Prod
|
||||
// // String url = "https://uat.hmgwebservices.com/HMGApplePayLive/applepay/pay?apq=" + res['result']; // UAT
|
||||
// // safariBrowser.open(url: Uri.parse(url));
|
||||
// this.browser.openUrlRequest(urlRequest: URLRequest(url: WebUri.uri(Uri.parse(url))), options: _InAppBrowserOptions);
|
||||
// }).catchError((err) {
|
||||
// print(err);
|
||||
// if (context != null) GifLoaderDialogUtils.hideDialog(context);
|
||||
// AppToast.showErrorToast(message: err);
|
||||
// });
|
||||
} else if (paymentMethod == "TAMARA") {
|
||||
// LiveCareService service = new LiveCareService();
|
||||
TamaraRequestModel tamaraRequestModel = new TamaraRequestModel();
|
||||
|
||||
// if (context != null) GifLoaderDialogUtils.showMyDialog(context);
|
||||
|
||||
tamaraRequestModel.merchantReference = transactionID;
|
||||
tamaraRequestModel.merchantIdentifier = "Tamara";
|
||||
tamaraRequestModel.clientRequestID = transactionID;
|
||||
tamaraRequestModel.amount = amount;
|
||||
tamaraRequestModel.currency = "SR";
|
||||
tamaraRequestModel.language = appState.isArabic() ? 'AR' : 'EN';
|
||||
tamaraRequestModel.commandType = "PURCHASE";
|
||||
tamaraRequestModel.customerEmail = emailId;
|
||||
tamaraRequestModel.orderDescription = orderDesc;
|
||||
tamaraRequestModel.isInstallment = true;
|
||||
tamaraRequestModel.projectID = num.parse(projId);
|
||||
tamaraRequestModel.accessCode = authenticatedUser.mobileNumber!;
|
||||
tamaraRequestModel.appointmentNo = (appoNo != null && appoNo != "") ? appoNo.toString() : "0";
|
||||
tamaraRequestModel.customerName = patientName;
|
||||
tamaraRequestModel.fileNumber = patientID.toString();
|
||||
tamaraRequestModel.patientOutSA = authenticatedUser.outSA == 1 ? true : false;
|
||||
tamaraRequestModel.deviceToken = await Utils.getStringFromPrefs(CacheConst.pushToken);
|
||||
tamaraRequestModel.latitude = appState.userLat.toString();
|
||||
tamaraRequestModel.longitude = appState.userLong.toString();
|
||||
tamaraRequestModel.serviceID = servID;
|
||||
tamaraRequestModel.liveServiceID = LiveServID;
|
||||
tamaraRequestModel.doctorID = (doctorID.toString() != null && doctorID != "") ? doctorID.toString() : "";
|
||||
tamaraRequestModel.appointmentDate = (appoDate != null && appoDate != "") ? appoDate : null;
|
||||
tamaraRequestModel.isSchedule = ((appoNo != null && appoNo != "") && (appoDate != null && appoDate != "")) ? true : false;
|
||||
|
||||
// service.tamaraInsertRequest(tamaraRequestModel, context).then((res) {
|
||||
// // if (context != null) GifLoaderDialogUtils.hideDialog(context);
|
||||
// generateTamaraURL(amount, orderDesc, transactionID, projId, emailId, paymentMethod, patientType, patientName, patientID, authenticatedUser, isLiveCareAppo, servID, LiveServID, appoDate,
|
||||
// appoNo, clinicID, doctorID, "", installments)
|
||||
// .then((value) {
|
||||
// paymentType = _PAYMENT_TYPE.PATIENT;
|
||||
// this.browser.openUrlRequest(urlRequest: URLRequest(url: WebUri.uri(Uri.parse(value))), 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.openUrlRequest(urlRequest: URLRequest(url: WebUri.uri(Uri.parse(value))), options: _InAppBrowserOptions);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// openPharmacyPaymentBrowser(OrderDetailModel order, double amount, String orderDesc, String transactionID, String emailId, String paymentMethod, String patientName, dynamic patientID,
|
||||
// AuthenticatedUser authenticatedUser, InAppBrowser browser) {
|
||||
// this.browser = browser;
|
||||
// MyChromeSafariBrowser safariBrowser =
|
||||
// new MyChromeSafariBrowser(new MyInAppBrowser(onExitCallback: browser.onExit), onExitCallback: browser.onExit, onLoadStartCallback: this.browser.onLoadStart, appo: this.appo!);
|
||||
// // getPatientData();
|
||||
// generatePharmacyURL(order, amount, orderDesc, transactionID, emailId, paymentMethod, patientName, patientID, authenticatedUser).then((value) {
|
||||
// if (order.customValuesXml!.contains("ApplePay")) {
|
||||
// safariBrowser.open(url: WebUri.uri(Uri.parse(value)));
|
||||
// } else {
|
||||
// this.browser.openUrlRequest(urlRequest: URLRequest(url: WebUri.uri(Uri.parse(value))), options: _InAppBrowserOptions);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
openBrowser(String url) {
|
||||
this.browser = browser;
|
||||
this.browser.openUrlRequest(urlRequest: URLRequest(url: WebUri.uri(Uri.parse(url))), options: _InAppBrowserOptions);
|
||||
}
|
||||
|
||||
Future<String> generateURL(num 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 = appState.isArabic() ? 'AR' : 'EN';
|
||||
String form = isLiveCareAppo ? getLiveCareForm() : getForm();
|
||||
|
||||
form = form.replaceFirst("EMAIL_VALUE", emailId);
|
||||
|
||||
form = form.replaceFirst('AMOUNT_VALUE', amount.toString());
|
||||
form = form.replaceFirst('ORDER_DESCRIPTION_VALUE', orderDesc);
|
||||
form = form.replaceFirst('ORDER_ID_VALUE', transactionID);
|
||||
form = form.replaceFirst('REQUEST_ID_VALUE', transactionID);
|
||||
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");
|
||||
|
||||
Platform.isIOS
|
||||
? form = form.replaceFirst('DEVICE_TOKEN', "${await Utils.getStringFromPrefs(CacheConst.pushToken)},${await Utils.getStringFromPrefs(CacheConst.apnsToken)}")
|
||||
: form = form.replaceFirst('DEVICE_TOKEN', await Utils.getStringFromPrefs(CacheConst.pushToken) ?? "");
|
||||
|
||||
// form = form.replaceFirst('DEVICE_TOKEN', await AppSharedPreferences().getString(PUSH_TOKEN) + "," + await AppSharedPreferences().getString(ONESIGNAL_APNS_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);
|
||||
// else
|
||||
form = form.replaceFirst('SERVICE_URL_VALUE', ApiConsts.SERVICE_URL);
|
||||
|
||||
if (servID != null) {
|
||||
form = form.replaceFirst('SERV_ID', servID);
|
||||
form = form.replaceFirst('LIVE_SERVICE_ID', LiveServID.toString());
|
||||
} else {
|
||||
form = form.replaceFirst('SERV_ID', "2");
|
||||
form = form.replaceFirst('LIVE_SERVICE_ID', "2");
|
||||
}
|
||||
|
||||
form = form.replaceFirst('CUSTNAME_VALUE', patientName);
|
||||
form = form.replaceFirst('CUSTID_VALUE', patientID.toString());
|
||||
|
||||
if (isLiveCareAppo) {
|
||||
form = form.replaceFirst('IS_SCHEDULE_VALUE', "true");
|
||||
form = form.replaceFirst('APPOINTMENT_DATE_VALUE', appoDate);
|
||||
form = form.replaceFirst('APPOINTMENT_NO_VALUE', appoNo.toString());
|
||||
form = form.replaceFirst('DOCTOR_ID_VALUE', doctorID.toString());
|
||||
form = form.replaceFirst('CLINIC_ID_VALUE', clinicID.toString());
|
||||
}
|
||||
|
||||
var bytes = utf8.encode(form);
|
||||
var base64Str = base64.encode(bytes);
|
||||
return 'data:text/html;base64,' + base64Str;
|
||||
}
|
||||
|
||||
Future<String> generateTamaraURL(num 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, var installments]) async {
|
||||
// getDeviceToken();
|
||||
String currentLanguageID = appState.isArabic() ? 'AR' : 'EN';
|
||||
String form = getTamaraForm();
|
||||
|
||||
form = form.replaceFirst("EMAIL_VALUE", emailId);
|
||||
|
||||
form = form.replaceFirst('AMOUNT_VALUE', amount.toString());
|
||||
form = form.replaceFirst('ORDER_DESCRIPTION_VALUE', orderDesc);
|
||||
form = form.replaceFirst('ORDER_ID_VALUE', transactionID);
|
||||
form = form.replaceFirst('REQUEST_ID_VALUE', transactionID);
|
||||
form = form.replaceFirst('PROJECT_ID_VALUE', projId);
|
||||
form = form.replaceFirst('PAYMENT_OPTION_VALUE', paymentMethod);
|
||||
form = form.replaceFirst('LANG_VALUE', currentLanguageID);
|
||||
form = form.replaceFirst('SERVICE_URL_VALUE', "https://mdlaboratories.com/tamaralive/Home/Checkout");
|
||||
|
||||
form = form.replaceFirst('INSTALLMENTS_VALUE', installments);
|
||||
form = form.replaceFirst('CUSTNATIONALID_VALUE', authUser.patientIdentificationNo!);
|
||||
form = form.replaceFirst('CUSTMOBILE_VALUE', authUser.mobileNumber!);
|
||||
form = form.replaceFirst('CUSTDOB_VALUE', DateUtil.getDayMonthYearDateFormatted(authUser.dateofBirthDataTime!));
|
||||
|
||||
form = form.replaceFirst('CURRENCY_VALUE', authUser.outSA == 0 ? "SAR" : "AED");
|
||||
form = form.replaceFirst('COUNTRY_CODE_VALUE', authUser.outSA == 0 ? "966" : "971");
|
||||
form = form.replaceFirst('CUSTNAME_VALUE', patientName);
|
||||
form = form.replaceFirst('CUSTLASTNAME_VALUE', patientName);
|
||||
form = form.replaceFirst('CUSTID_VALUE', patientID.toString());
|
||||
|
||||
var bytes = utf8.encode(form);
|
||||
var base64Str = base64.encode(bytes);
|
||||
return 'data:text/html;base64,' + base64Str;
|
||||
}
|
||||
|
||||
String getForm() {
|
||||
return '<html> ' +
|
||||
'<head></head>' +
|
||||
'<body>' +
|
||||
'<form id="paymentForm" action="SERVICE_URL_VALUE" method="post">' +
|
||||
'<input type="hidden" name="Amount" value="AMOUNT_VALUE">' +
|
||||
'<input type="hidden" name="ProjID" value="PROJECT_ID_VALUE">' +
|
||||
'<input type="hidden" name="Order_Desc" value="ORDER_DESCRIPTION_VALUE">' +
|
||||
'<input type="hidden" name="OrderID" value="ORDER_ID_VALUE">' +
|
||||
'<input type="hidden" name="PaymentOption" value="PAYMENT_OPTION_VALUE">' +
|
||||
'<input type="hidden" name="Email" value="EMAIL_VALUE">' +
|
||||
'<input type="hidden" name="ServID" value="SERV_ID" >' +
|
||||
'<input type="hidden" name="ChannelID" value="2" >' +
|
||||
'<input type="hidden" name="Lang" value="LANG_VALUE" >' +
|
||||
'<input type="hidden" name="ReturnURL" value="" >' +
|
||||
'<input type="hidden" name="CustName" value="CUSTNAME_VALUE" >' +
|
||||
'<input type="hidden" name="PatientOutSA" value="PATIENT_OUT_SA" >' +
|
||||
'<input type="hidden" name="PatientTypeID" value="PATIENT_TYPE_ID" >' +
|
||||
'<input type="hidden" name="DeviceToken" value="DEVICE_TOKEN" >' +
|
||||
'<input type="hidden" name="Longitude" value="LONGITUDE_VALUE" >' +
|
||||
'<input type="hidden" name="Latitude" value="LATITUDE_VALUE" >' +
|
||||
'<input type="hidden" name="Live_ServiceID" value="LIVE_SERVICE_ID" >' +
|
||||
'<input type="hidden" name="CustID" value="CUSTID_VALUE" >' +
|
||||
'<input type="hidden" name="ResponseContinueURL" value="http://hmg.com/Documents/success.html" >' +
|
||||
'<input type="hidden" name="BackClickUrl" value="http://hmg.com/Documents/success.html" >' +
|
||||
'</form>' +
|
||||
'<script type="text/javascript"> document.getElementById("paymentForm").submit(); </script>' +
|
||||
'</body>' +
|
||||
'</html>';
|
||||
}
|
||||
|
||||
String getTamaraForm() {
|
||||
return '<html> ' +
|
||||
'<head></head>' +
|
||||
'<body>' +
|
||||
'<form id="paymentForm" action="SERVICE_URL_VALUE" method="post">' +
|
||||
'<input type="hidden" name="totalAmount" value="AMOUNT_VALUE">' +
|
||||
'<input type="hidden" name="shippingAmount" value="0">' +
|
||||
'<input type="hidden" name="taxAmount" value="0">' +
|
||||
'<input type="hidden" name="discountAmount" value="0">' +
|
||||
'<input type="hidden" name="PaymentType" value="PAY_BY_INSTALMENTS">' +
|
||||
'<input type="hidden" name="Instalments" value="INSTALLMENTS_VALUE">' +
|
||||
'<input type="hidden" name="ProjID" value="PROJECT_ID_VALUE">' +
|
||||
'<input type="hidden" name="description" value="ORDER_DESCRIPTION_VALUE">' +
|
||||
'<input type="hidden" name="OrderID" value="ORDER_ID_VALUE">' +
|
||||
'<input type="hidden" name="Currency" value="CURRENCY_VALUE">' +
|
||||
'<input type="hidden" name="CountryCode" value="COUNTRY_CODE_VALUE">' +
|
||||
'<input type="hidden" name="Consumer.Email" value="EMAIL_VALUE">' +
|
||||
'<input type="hidden" name="Lang" value="LANG_VALUE" >' +
|
||||
'<input type="hidden" name="ReturnURL" value="https://mdlaboratories.com">' +
|
||||
'<input type="hidden" name="Consumer.NationalId" value="CUSTNATIONALID_VALUE" >' +
|
||||
'<input type="hidden" name="Consumer.PhoneNumber" value="CUSTMOBILE_VALUE" >' +
|
||||
'<input type="hidden" name="Consumer.FirstName" value="CUSTNAME_VALUE" >' +
|
||||
'<input type="hidden" name="Consumer.LastName" value="CUSTLASTNAME_VALUE" >' +
|
||||
'<input type="hidden" name="Consumer.DateOfBirth" value="CUSTDOB_VALUE" >' +
|
||||
'<input type="hidden" name="Consumer.IsFirstOrder" value="false" >' +
|
||||
'<input type="hidden" name="address.Line1" value="">' +
|
||||
'<input type="hidden" name="address.Line2" value="">' +
|
||||
'<input type="hidden" name="address.City" value="Riyadh">' +
|
||||
'<input type="hidden" name="address.CountryCode" value="SA">' +
|
||||
'<input type="hidden" name="address.PostalCode" value="12626">' +
|
||||
'<input type="hidden" name="address.Region" value="">'
|
||||
'</form>' +
|
||||
'<script type="text/javascript"> document.getElementById("paymentForm").submit(); </script>' +
|
||||
'</body>' +
|
||||
'</html>';
|
||||
}
|
||||
|
||||
String getLiveCareForm() {
|
||||
return '<html> ' +
|
||||
'<head></head>' +
|
||||
'<body>' +
|
||||
'<form id="paymentForm" action="SERVICE_URL_VALUE" method="post">' +
|
||||
'<input type="hidden" name="Amount" value="AMOUNT_VALUE">' +
|
||||
'<input type="hidden" name="ProjID" value="PROJECT_ID_VALUE">' +
|
||||
'<input type="hidden" name="IsSchedule" value="IS_SCHEDULE_VALUE">' +
|
||||
'<input type="hidden" name="AppointmentDate" value="APPOINTMENT_DATE_VALUE">' +
|
||||
'<input type="hidden" name="AppointmentNo" value="APPOINTMENT_NO_VALUE">' +
|
||||
'<input type="hidden" name="DoctorID" value="DOCTOR_ID_VALUE">' +
|
||||
'<input type="hidden" name="ClinicID" value="CLINIC_ID_VALUE">' +
|
||||
'<input type="hidden" name="Order_Desc" value="ORDER_DESCRIPTION_VALUE">' +
|
||||
'<input type="hidden" name="OrderID" value="ORDER_ID_VALUE">' +
|
||||
'<input type="hidden" name="PaymentOption" value="PAYMENT_OPTION_VALUE">' +
|
||||
'<input type="hidden" name="Email" value="EMAIL_VALUE">' +
|
||||
'<input type="hidden" name="ServID" value="SERV_ID" >' +
|
||||
'<input type="hidden" name="ChannelID" value="2" >' +
|
||||
'<input type="hidden" name="Lang" value="LANG_VALUE" >' +
|
||||
'<input type="hidden" name="ReturnURL" value="" >' +
|
||||
'<input type="hidden" name="CustName" value="CUSTNAME_VALUE" >' +
|
||||
'<input type="hidden" name="PatientOutSA" value="PATIENT_OUT_SA" >' +
|
||||
'<input type="hidden" name="PatientTypeID" value="PATIENT_TYPE_ID" >' +
|
||||
'<input type="hidden" name="DeviceToken" value="DEVICE_TOKEN" >' +
|
||||
'<input type="hidden" name="Longitude" value="LONGITUDE_VALUE" >' +
|
||||
'<input type="hidden" name="Latitude" value="LATITUDE_VALUE" >' +
|
||||
'<input type="hidden" name="Live_ServiceID" value="LIVE_SERVICE_ID" >' +
|
||||
'<input type="hidden" name="CustID" value="CUSTID_VALUE" >' +
|
||||
'<input type="hidden" name="ResponseContinueURL" value="http://hmg.com/Documents/success.html" >' +
|
||||
'<input type="hidden" name="BackClickUrl" value="http://hmg.com/Documents/success.html" >' +
|
||||
'</form>' +
|
||||
'<script type="text/javascript"> document.getElementById("paymentForm").submit(); </script>' +
|
||||
'</body>' +
|
||||
'</html>';
|
||||
}
|
||||
|
||||
safariCallBack() {
|
||||
print("Safari CallBack!!!");
|
||||
}
|
||||
}
|
||||
|
||||
class MyChromeSafariBrowser extends ChromeSafariBrowser {
|
||||
final Function? onExitCallback;
|
||||
final Function? onLoadStartCallback;
|
||||
|
||||
// AppoitmentAllHistoryResultList? appo;
|
||||
|
||||
// MyChromeSafariBrowser(browserFallback, {this.onExitCallback, this.onLoadStartCallback, this.appo});
|
||||
MyChromeSafariBrowser(browserFallback, {this.onExitCallback, this.onLoadStartCallback});
|
||||
|
||||
@override
|
||||
void onOpened() {
|
||||
print("ChromeSafari browser opened");
|
||||
}
|
||||
|
||||
@override
|
||||
void onCompletedInitialLoad(bool? didLoadSuccessfully) {
|
||||
print("ChromeSafari browser initial load completed");
|
||||
onLoadStartCallback!("ApplePay");
|
||||
}
|
||||
|
||||
@override
|
||||
void onClosed() {
|
||||
print("ChromeSafari browser closed");
|
||||
MyInAppBrowser.isPaymentDone = true;
|
||||
onExitCallback!();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue