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(); Future initPayfort() async { await _payfortService.initPayfortSDK(); } Future 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 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, 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; } } }