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}) async { PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel(); try { payfortProjectDetailsRespModel = await _payfortService.getPayfortConfigurations(serviceId: serviceId, projectId: projectId); return payfortProjectDetailsRespModel; } 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, }) 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 ?? "", ); GifLoaderDialogUtils.hideDialog(AppGlobal.context); } catch (e) { Utils.showErrorToast(e.toString()); GifLoaderDialogUtils.hideDialog(AppGlobal.context); throw e; } } }