diff --git a/ios/Runner/Runner.entitlements b/ios/Runner/Runner.entitlements
index 0821ccf0..44ce1b68 100644
--- a/ios/Runner/Runner.entitlements
+++ b/ios/Runner/Runner.entitlements
@@ -8,6 +8,12 @@
com.apple.developer.healthkit.access
+ com.apple.developer.in-app-payments
+
+ merchant.com.hmgwebsersives
+ merchant.com.hmgwebservices.uat
+ merchant.com.hmgwebservices
+
com.apple.developer.networking.HotspotConfiguration
com.apple.developer.networking.wifi-info
diff --git a/lib/config/config.dart b/lib/config/config.dart
index 26dda9d2..4831aeb6 100644
--- a/lib/config/config.dart
+++ b/lib/config/config.dart
@@ -21,8 +21,8 @@ var PACKAGES_ORDERS = '/api/orders';
var PACKAGES_ORDER_HISTORY = '/api/orders/items';
var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara';
// var BASE_URL = 'http://10.20.200.111:1010/';
- // var BASE_URL = 'https://uat.hmgwebservices.com/';
-var BASE_URL = 'https://hmgwebservices.com/';
+ var BASE_URL = 'https://uat.hmgwebservices.com/';
+// var BASE_URL = 'https://hmgwebservices.com/';
// var BASE_URL = 'https://orash.cloudsolutions.com.sa/';
// var BASE_URL = 'https://vidauat.cloudsolutions.com.sa/';
// var BASE_URL = 'https://vidamergeuat.cloudsolutions.com.sa/';
@@ -625,6 +625,7 @@ var CONVERT_PATIENT_TO_CASH = 'Services/Doctors.svc/REST/deActivateInsuranceComp
//PAYFORT
var getPayFortProjectDetails = "Services/PayFort_Serv.svc/REST/GetPayFortProjectDetails";
+var addPayFortApplePayResponse = "Services/PayFort_Serv.svc/REST/AddResponse";
var payFortEnvironment = FortEnvironment.test;
var applePayMerchantId = "merchant.com.hmgwebservices.uat";
diff --git a/lib/models/LiveCare/ApplePayInsertRequest.dart b/lib/models/LiveCare/ApplePayInsertRequest.dart
index 2e091f65..aa4e316b 100644
--- a/lib/models/LiveCare/ApplePayInsertRequest.dart
+++ b/lib/models/LiveCare/ApplePayInsertRequest.dart
@@ -35,6 +35,24 @@ class ApplePayInsertRequest {
String sessionID;
bool isDentalAllowedBackend;
int deviceTypeID;
+ bool isMobSDK;
+ String merchantReference;
+ String merchantIdentifier;
+ String commandType;
+ String signature;
+ String accessCode;
+ String shaRequestPhrase;
+ String shaResponsePhrase;
+ String returnURL;
+
+ // IsMobSDK ==> bool
+ // Merchant_Reference ==> string
+ // Merchant_Identifier ==> string
+ // CommandType ==> string
+ // Signature ==> string
+ // Access_code ==> string
+ // SHA_RequestPhase ==> string
+ // SHA_ResponsePhase ==> string
ApplePayInsertRequest(
{this.clientRequestID,
@@ -72,7 +90,18 @@ class ApplePayInsertRequest {
this.generalid,
this.sessionID,
this.isDentalAllowedBackend,
- this.deviceTypeID});
+ this.deviceTypeID,
+
+ this.isMobSDK,
+ this.merchantReference,
+ this.merchantIdentifier,
+ this.commandType,
+ this.signature,
+ this.accessCode,
+ this.shaRequestPhrase,
+ this.shaResponsePhrase,
+ this.returnURL,
+ });
ApplePayInsertRequest.fromJson(Map json) {
clientRequestID = json['ClientRequestID'];
@@ -151,6 +180,17 @@ class ApplePayInsertRequest {
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;
}
}
diff --git a/lib/pages/medical/balance/confirm_payment_page.dart b/lib/pages/medical/balance/confirm_payment_page.dart
index d60b199c..da9f79e1 100644
--- a/lib/pages/medical/balance/confirm_payment_page.dart
+++ b/lib/pages/medical/balance/confirm_payment_page.dart
@@ -17,6 +17,7 @@ import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/routes.dart';
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart';
+import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart';
import 'package:diplomaticquarterapp/services/payfort_services/payfort_view_model.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
@@ -33,7 +34,6 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';
import 'new_text_Field.dart';
-
class ConfirmPaymentPage extends StatefulWidget {
final AdvanceModel advanceModel;
final PatientInfoAndMobileNumber patientInfoAndMobileNumber;
@@ -218,7 +218,7 @@ class _ConfirmPaymentPageState extends State {
padding: EdgeInsets.all(20),
child: DefaultButton(
TranslationBase.of(context).confirm.toUpperCase(),
- () async {
+ () async {
if (widget.advanceModel.fileNumber == projectViewModel.user.patientID.toString()) {
if (widget.selectedPaymentMethod == "ApplePay") {
transID = Utils.getAdvancePaymentTransID(widget.advanceModel.hospitalsModel.iD, int.parse(widget.advanceModel.fileNumber));
@@ -228,6 +228,14 @@ class _ConfirmPaymentPageState extends State {
LiveCareService service = new LiveCareService();
ApplePayInsertRequest applePayInsertRequest = new ApplePayInsertRequest();
+ PayfortProjectDetailsRespModel payfortProjectDetailsRespModel;
+ await context
+ .read()
+ .getProjectDetailsForPayfort(projectId: widget.advanceModel.hospitalsModel.iD, serviceId: ServiceTypeEnum.advancePayment.getIdFromServiceEnum())
+ .then((value) {
+ payfortProjectDetailsRespModel = value;
+ });
+
applePayInsertRequest.clientRequestID = transID;
applePayInsertRequest.clinicID = 0;
applePayInsertRequest.currency = projectViewModel.authenticatedUserObject.user.outSA == 1 ? "AED" : "SAR";
@@ -257,29 +265,39 @@ class _ConfirmPaymentPageState extends State {
applePayInsertRequest.backClickUrl = "http://hmg.com/Documents/success.html";
applePayInsertRequest.paymentOption = "ApplePay";
+ applePayInsertRequest.isMobSDK = true;
+ applePayInsertRequest.merchantReference = transID;
+ applePayInsertRequest.merchantIdentifier = payfortProjectDetailsRespModel.merchantIdentifier;
+ applePayInsertRequest.commandType = "PURCHASE";
+ applePayInsertRequest.signature = payfortProjectDetailsRespModel.signature;
+ applePayInsertRequest.accessCode = payfortProjectDetailsRespModel.accessCode;
+ applePayInsertRequest.shaRequestPhrase = payfortProjectDetailsRespModel.shaRequest;
+ applePayInsertRequest.shaResponsePhrase = payfortProjectDetailsRespModel.shaResponse;
+ applePayInsertRequest.returnURL = "";
+
service.applePayInsertRequest(applePayInsertRequest, context).then((res) async {
- GifLoaderDialogUtils.hideDialog(context);
- await context.read().initiateApplePayWithPayfort(
- customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName,
- customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress,
- orderDescription: "Advance Payment",
- orderAmount: double.parse(widget.advanceModel.amount),
- merchantReference: transID,
- onFailed: (failureResult) {
- log("failureResult: ${failureResult.toString()}");
-
- },
- onSuccess: (successResult) {
- log("Payfort: ${successResult.responseMessage}");
- checkPaymentStatus(AppoitmentAllHistoryResultList());
- },
- projectId: widget.advanceModel.hospitalsModel.iD,
- // projectId: 95,
- serviceTypeEnum: ServiceTypeEnum.advancePayment,
- );
+ // GifLoaderDialogUtils.hideDialog(context);
+ await context.read().initiateApplePayWithPayfort(
+ customerName: projectViewModel.authenticatedUserObject.user.firstName + " " + projectViewModel.authenticatedUserObject.user.lastName,
+ customerEmail: projectViewModel.authenticatedUserObject.user.emailAddress,
+ orderDescription: "Advance Payment",
+ orderAmount: double.parse(widget.advanceModel.amount),
+ merchantReference: transID,
+ payfortProjectDetailsRespModel: payfortProjectDetailsRespModel,
+ onFailed: (failureResult) async {
+ log("failureResult: ${failureResult.toString()}");
+ },
+ onSuccess: (successResult) async {
+ log("Payfort: ${successResult.responseMessage}");
+ await context.read().addPayfortApplePayResponse(result: successResult);
+ checkPaymentStatus(AppoitmentAllHistoryResultList());
+ },
+ projectId: widget.advanceModel.hospitalsModel.iD,
+ serviceTypeEnum: ServiceTypeEnum.advancePayment,
+ );
}).catchError((err) {
print(err);
- if (context = null) GifLoaderDialogUtils.hideDialog(context);
+ GifLoaderDialogUtils.hideDialog(context);
AppToast.showErrorToast(message: err);
});
} else {
@@ -309,72 +327,7 @@ class _ConfirmPaymentPageState extends State {
);
}
- // startApplePay() {
- // 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);
- // }).catchError((err) {
- // print(err);
- // });
- // }
-
- 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);
- });
- }
+ void addPayFortApplePayResponse() {}
String getApplePayPaymentType(dynamic paymentMethod) {
switch (paymentMethod) {
diff --git a/lib/services/payfort_services/payfort_project_details_resp_model.dart b/lib/services/payfort_services/payfort_project_details_resp_model.dart
index 18d501ea..2bf9a1e5 100644
--- a/lib/services/payfort_services/payfort_project_details_resp_model.dart
+++ b/lib/services/payfort_services/payfort_project_details_resp_model.dart
@@ -7,8 +7,9 @@ class PayfortProjectDetailsRespModel {
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});
+ PayfortProjectDetailsRespModel({this.accessCode, this.integrationId, this.merchantIdentifier, this.projectID, this.projectName, this.servID, this.shaRequest, this.shaResponse, this.signature});
PayfortProjectDetailsRespModel.fromJson(Map json) {
accessCode = json['AccessCode'];
diff --git a/lib/services/payfort_services/payfort_service.dart b/lib/services/payfort_services/payfort_service.dart
index cb6cb348..45e1c2c6 100644
--- a/lib/services/payfort_services/payfort_service.dart
+++ b/lib/services/payfort_services/payfort_service.dart
@@ -39,6 +39,44 @@ class PayfortService extends BaseService {
return payfortProjectDetailsRespModel;
}
+ Future addPayfortApplePayResponse({PayFortResult result}) async {
+ Map body = {
+ "Fort_id": result.fortId,
+ "CommandType": result.command,
+ "Amount": (num.parse(result.amount) / 100).toString(),
+ "Payment_Option": result.paymentOption,
+ "Customer_IP": result.customerIp,
+ "ECI": result.eci,
+ "Response_Message": result.responseMessage,
+ "Card_Number": result.cardNumber,
+ // "Card_Bin": result.ca,
+ "Status": result.status,
+ "Merchant_Ref": result.merchantReference,
+ // Installments_Number
+ // plan_code
+ // issuer_code
+ "Pat_Token": result.tokenName,
+ "IsRefund": false,
+ "RemmeberMe": false,
+ "Reconciliation_Reference": result.reconcilationReference,
+ "LanguageID": 1,
+ };
+
+ // PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel();
+ await baseAppClient.post(
+ addPayFortApplePayResponse,
+ onSuccess: (response, statusCode) async {
+ // payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel.fromJson(response.isNotEmpty ? response.first : response);
+ },
+ onFailure: (String error, int statusCode) {
+ Utils.showErrorToast(error);
+ return null;
+ },
+ body: body,
+ isAllowAny: true,
+ );
+ }
+
Future generateSdkSignatureFromAPI(SdkTokenRequest request) async {
var response = await post(
Uri.parse(payFortEnvironment.paymentApi),
@@ -83,6 +121,26 @@ class PayfortService extends BaseService {
return null;
}
+ Future getPayfortSignature(
+ String applePayAccessCode,
+ String merchantIdentifier,
+ String applePayShaRequestPhrase,
+ ) async {
+ String deviceId = await _payfort.getDeviceId();
+ SdkTokenRequest tokenRequest = SdkTokenRequest(
+ accessCode: applePayAccessCode,
+ deviceId: deviceId ?? '',
+ merchantIdentifier: merchantIdentifier,
+ );
+
+ String signature = await _payfort.generateSignature(
+ shaType: "SHA-256",
+ concatenatedString: tokenRequest.toConcatenatedString(applePayShaRequestPhrase),
+ );
+
+ return signature;
+ }
+
Future paymentWithApplePay({
SucceededCallback onSucceeded,
FailedCallback onFailed,
diff --git a/lib/services/payfort_services/payfort_view_model.dart b/lib/services/payfort_services/payfort_view_model.dart
index 4ad6f8b9..4a9038b0 100644
--- a/lib/services/payfort_services/payfort_view_model.dart
+++ b/lib/services/payfort_services/payfort_view_model.dart
@@ -15,10 +15,15 @@ class PayfortViewModel extends ChangeNotifier {
await _payfortService.initPayfortSDK();
}
- Future getProjectDetailsForPayfort({ int serviceId, int projectId}) async {
+ Future getProjectDetailsForPayfort({int serviceId, int projectId}) async {
PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel();
try {
payfortProjectDetailsRespModel = await _payfortService.getPayfortConfigurations(serviceId: serviceId, projectId: projectId);
+
+ String signature =
+ await _payfortService.getPayfortSignature(payfortProjectDetailsRespModel.accessCode, payfortProjectDetailsRespModel.merchantIdentifier, payfortProjectDetailsRespModel.shaRequest);
+ payfortProjectDetailsRespModel.signature = signature;
+
return payfortProjectDetailsRespModel;
} on Exception catch (e, s) {
print(s);
@@ -26,24 +31,34 @@ class PayfortViewModel extends ChangeNotifier {
}
}
+ Future addPayfortApplePayResponse({PayFortResult result}) async {
+ try {
+ await _payfortService.addPayfortApplePayResponse(result: result);
+ } on Exception catch (e, s) {
+ print(s);
+ return null;
+ }
+ }
+
Future initiateApplePayWithPayfort({
- String customerName,
- String customerEmail,
- String orderDescription,
- String merchantReference,
- double orderAmount,
- SucceededCallback onSuccess,
- FailedCallback onFailed,
- ServiceTypeEnum serviceTypeEnum,
- int projectId,
+ String customerName,
+ String customerEmail,
+ String orderDescription,
+ String merchantReference,
+ double orderAmount,
+ PayfortProjectDetailsRespModel payfortProjectDetailsRespModel,
+ SucceededCallback onSuccess,
+ FailedCallback onFailed,
+ ServiceTypeEnum serviceTypeEnum,
+ int projectId,
}) async {
- GifLoaderDialogUtils.showMyDialog(AppGlobal.context);
- PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = await getProjectDetailsForPayfort(projectId: projectId, serviceId: serviceTypeEnum.getIdFromServiceEnum());
-
- if (payfortProjectDetailsRespModel == null) {
- GifLoaderDialogUtils.hideDialog(AppGlobal.context);
- return;
- }
+ // GifLoaderDialogUtils.showMyDialog(AppGlobal.context);
+ // PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = await getProjectDetailsForPayfort(projectId: projectId, serviceId: serviceTypeEnum.getIdFromServiceEnum());
+ //
+ // if (payfortProjectDetailsRespModel == null) {
+ // GifLoaderDialogUtils.hideDialog(AppGlobal.context);
+ // return;
+ // }
try {
await _payfortService.paymentWithApplePay(
diff --git a/lib/widgets/in_app_browser/InAppBrowser.dart b/lib/widgets/in_app_browser/InAppBrowser.dart
index c9fecbf9..c71b206b 100644
--- a/lib/widgets/in_app_browser/InAppBrowser.dart
+++ b/lib/widgets/in_app_browser/InAppBrowser.dart
@@ -40,9 +40,9 @@ class MyInAppBrowser extends InAppBrowser {
// 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/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 SERVICE_URL = 'https://uat.hmgwebservices.com/payfortforvidaplus/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL UAT VIDA PLUS