/// <summary> /// Invoke view component /// </summary> /// <param name="widgetZone">Widget zone name</param> /// <param name="additionalData">Additional data</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the view component result /// </returns> public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData) { var customer = await _workContext.GetCurrentCustomerAsync(); var store = await _storeContext.GetCurrentStoreAsync(); if (!await _paymentPluginManager.IsPluginActiveAsync(PayPalCommerceDefaults.SystemName, customer, store?.Id ?? 0)) { return(Content(string.Empty)); } if (!ServiceManager.IsConfigured(_settings)) { return(Content(string.Empty)); } if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsAddInfo) && !widgetZone.Equals(PublicWidgetZones.OrderSummaryContentAfter)) { return(Content(string.Empty)); } if (widgetZone.Equals(PublicWidgetZones.OrderSummaryContentAfter)) { if (!_settings.DisplayButtonsOnShoppingCart) { return(Content(string.Empty)); } var routeName = HttpContext.GetEndpoint()?.Metadata.GetMetadata <RouteNameMetadata>()?.RouteName; if (routeName != PayPalCommerceDefaults.ShoppingCartRouteName) { return(Content(string.Empty)); } } if (widgetZone.Equals(PublicWidgetZones.ProductDetailsAddInfo) && !_settings.DisplayButtonsOnProductDetails) { return(Content(string.Empty)); } var productId = additionalData is ProductDetailsModel.AddToCartModel model ? model.ProductId : 0; var productCost = "0.00"; if (productId > 0) { var product = await _productServise.GetProductByIdAsync(productId); var finalPrice = (await _priceCalculationService.GetFinalPriceAsync(product, customer)).finalPrice; productCost = finalPrice.ToString("0.00", CultureInfo.InvariantCulture); } return(View("~/Plugins/Payments.PayPalCommerce/Views/Buttons.cshtml", (widgetZone, productId, productCost))); }
/// <summary> /// Invoke view component /// </summary> /// <param name="widgetZone">Widget zone name</param> /// <param name="additionalData">Additional data</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the view component result /// </returns> public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData) { if (!await _paymentPluginManager.IsPluginActiveAsync(Defaults.SystemName, await _workContext.GetCurrentCustomerAsync(), (await _storeContext.GetCurrentStoreAsync()).Id)) { return(Content(string.Empty)); } var script = widgetZone.Equals(PublicWidgetZones.HeaderLinksBefore) && _settings.DisplayLogoInHeaderLinks ? _settings.LogoInHeaderLinks : (widgetZone.Equals(PublicWidgetZones.Footer) && _settings.DisplayLogoInFooter ? _settings.LogoInFooter : null); return(new HtmlContentViewComponentResult(new HtmlString(script ?? string.Empty))); }
/// <summary> /// Invoke view component /// </summary> /// <param name="widgetZone">Widget zone name</param> /// <param name="additionalData">Additional data</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the view component result /// </returns> public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData) { var customer = await _workContext.GetCurrentCustomerAsync(); var store = await _storeContext.GetCurrentStoreAsync(); if (!await _paymentPluginManager.IsPluginActiveAsync(PayPalCommerceDefaults.SystemName, customer, store?.Id ?? 0)) { return(Content(string.Empty)); } if (!ServiceManager.IsConfigured(_settings)) { return(Content(string.Empty)); } if (!widgetZone.Equals(PublicWidgetZones.CheckoutPaymentInfoTop) && !widgetZone.Equals(PublicWidgetZones.OpcContentBefore) && !widgetZone.Equals(PublicWidgetZones.ProductDetailsTop) && !widgetZone.Equals(PublicWidgetZones.OrderSummaryContentBefore)) { return(Content(string.Empty)); } if (widgetZone.Equals(PublicWidgetZones.OrderSummaryContentBefore)) { if (!_settings.DisplayButtonsOnShoppingCart) { return(Content(string.Empty)); } var routeName = HttpContext.GetEndpoint()?.Metadata.GetMetadata <RouteNameMetadata>()?.RouteName; if (routeName != PayPalCommerceDefaults.ShoppingCartRouteName) { return(Content(string.Empty)); } } if (widgetZone.Equals(PublicWidgetZones.ProductDetailsTop) && !_settings.DisplayButtonsOnProductDetails) { return(Content(string.Empty)); } var(script, _) = await _serviceManager.GetScriptAsync(_settings, widgetZone); return(new HtmlContentViewComponentResult(new HtmlString(script ?? string.Empty))); }
/// <summary> /// Invoke view component /// </summary> /// <param name="widgetZone">Widget zone name</param> /// <param name="additionalData">Additional data</param> /// <returns>View component result</returns> public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData) { if (!await _paymentPluginManager.IsPluginActiveAsync(Defaults.SystemName, await _workContext.GetCurrentCustomerAsync(), (await _storeContext.GetCurrentStoreAsync()).Id)) { return(Content(string.Empty)); } if (string.IsNullOrEmpty(_settings.ClientId)) { return(Content(string.Empty)); } if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsAddInfo) && !widgetZone.Equals(PublicWidgetZones.OrderSummaryContentAfter)) { return(Content(string.Empty)); } if (widgetZone.Equals(PublicWidgetZones.OrderSummaryContentAfter)) { if (!_settings.DisplayButtonsOnShoppingCart) { return(Content(string.Empty)); } var routeName = HttpContext.GetEndpoint()?.Metadata.GetMetadata <RouteNameMetadata>()?.RouteName; if (routeName != Defaults.ShoppingCartRouteName) { return(Content(string.Empty)); } } if (widgetZone.Equals(PublicWidgetZones.ProductDetailsAddInfo) && !_settings.DisplayButtonsOnProductDetails) { return(Content(string.Empty)); } var productId = additionalData is ProductDetailsModel.AddToCartModel model ? model.ProductId : 0; return(View("~/Plugins/Payments.PayPalSmartPaymentButtons/Views/Buttons.cshtml", (widgetZone, productId))); }