You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PatientApp-KKUMC/lib/services/payfort_services/payfort_view_model.dart

86 lines
3.4 KiB
Dart

import 'package:amazon_payfort/amazon_payfort.dart';
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart';
import 'package:diplomaticquarterapp/services/payfort_services/payfort_service.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:flutter/cupertino.dart';
class PayfortViewModel extends ChangeNotifier {
PayfortService _payfortService = locator<PayfortService>();
Future<void> initPayfort() async {
await _payfortService.initPayfortSDK();
}
Future<PayfortProjectDetailsRespModel?> getProjectDetailsForPayfort({int? serviceId, int? projectId, int? languageID}) async {
PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel();
try {
payfortProjectDetailsRespModel = await _payfortService.getPayfortConfigurations(serviceId: serviceId, projectId: projectId, languageID: languageID);
String signature =
await _payfortService.getPayfortSignature(payfortProjectDetailsRespModel.accessCode!, payfortProjectDetailsRespModel.merchantIdentifier!, payfortProjectDetailsRespModel.shaRequest!);
payfortProjectDetailsRespModel.signature = signature;
return payfortProjectDetailsRespModel;
} on Exception catch (e, s) {
print(s);
return null;
}
}
Future<void> addPayfortApplePayResponse(num patientID, {PayFortResult? result}) async {
try {
await _payfortService.addPayfortApplePayResponse(patientID, result: result);
} on Exception catch (e, s) {
print(s);
return null;
}
}
Future<void> initiateApplePayWithPayfort({
String? customerName,
String? customerEmail,
String? orderDescription,
String? merchantReference,
num? orderAmount,
PayfortProjectDetailsRespModel? payfortProjectDetailsRespModel,
SucceededCallback? onSuccess,
FailedCallback? onFailed,
ServiceTypeEnum? serviceTypeEnum,
int? projectId,
String? currency,
}) async {
// 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(
onSucceeded: onSuccess,
onFailed: onFailed,
customerName: customerName,
customerEmail: customerEmail,
orderDescription: orderDescription,
orderAmount: orderAmount,
merchantReference: merchantReference,
merchantIdentifier: payfortProjectDetailsRespModel!.merchantIdentifier ?? "",
applePayAccessCode: payfortProjectDetailsRespModel!.accessCode ?? "",
applePayShaRequestPhrase: payfortProjectDetailsRespModel.shaRequest ?? "",
currency: currency!,
);
GifLoaderDialogUtils.hideDialog(AppGlobal.context);
} catch (e) {
Utils.showErrorToast(e.toString());
GifLoaderDialogUtils.hideDialog(AppGlobal.context);
throw e;
}
}
}