private PayPalPlusCheckoutModel.ThirdPartyPaymentMethod GetThirdPartyPaymentMethodModel( Provider <IPaymentMethod> provider, PayPalPlusPaymentSettings settings, Store store) { var model = new PayPalPlusCheckoutModel.ThirdPartyPaymentMethod(); model.MethodName = GetPaymentMethodName(provider); model.RedirectUrl = Url.Action("CheckoutReturn", "PayPalPlus", new { area = Plugin.SystemName, systemName = provider.Metadata.SystemName }, store.SslEnabled ? "https" : "http"); try { if (settings.DisplayPaymentMethodDescription) { // not the short description, the full description is intended for frontend var paymentMethod = _paymentService.GetPaymentMethodBySystemName(provider.Metadata.SystemName); if (paymentMethod != null) { string description = paymentMethod.GetLocalized(x => x.FullDescription); if (description.HasValue()) { description = HtmlUtils.ConvertHtmlToPlainText(description); description = HtmlUtils.StripTags(HttpUtility.HtmlDecode(description)); if (description.HasValue()) { model.Description = description.EncodeJsString(); } } } } } catch { } try { if (settings.DisplayPaymentMethodLogo && provider.Metadata.PluginDescriptor != null && store.SslEnabled) { var brandImageUrl = _pluginMediator.GetBrandImageUrl(provider.Metadata); if (brandImageUrl.HasValue()) { if (brandImageUrl.StartsWith("~")) { brandImageUrl = brandImageUrl.Substring(1); } var uri = new UriBuilder(Uri.UriSchemeHttps, Request.Url.Host, -1, brandImageUrl); model.ImageUrl = uri.ToString(); } } } catch { } return(model); }
protected CheckoutShippingMethodModel PrepareShippingMethodModel(IList <OrganizedShoppingCartItem> cart) { var model = new CheckoutShippingMethodModel(); var getShippingOptionResponse = _shippingService.GetShippingOptions(cart, _workContext.CurrentCustomer.ShippingAddress, "", _storeContext.CurrentStore.Id); if (getShippingOptionResponse.Success) { //performance optimization. cache returned shipping options. //we'll use them later (after a customer has selected an option). _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer, SystemCustomerAttributeNames.OfferedShippingOptions, getShippingOptionResponse.ShippingOptions, _storeContext.CurrentStore.Id); var shippingMethods = _shippingService.GetAllShippingMethods(); foreach (var shippingOption in getShippingOptionResponse.ShippingOptions) { var soModel = new CheckoutShippingMethodModel.ShippingMethodModel() { ShippingMethodId = shippingOption.ShippingMethodId, Name = shippingOption.Name, Description = shippingOption.Description, ShippingRateComputationMethodSystemName = shippingOption.ShippingRateComputationMethodSystemName, }; var srcmProvider = _shippingService.LoadShippingRateComputationMethodBySystemName(shippingOption.ShippingRateComputationMethodSystemName); if (srcmProvider != null) { soModel.BrandUrl = _pluginMediator.GetBrandImageUrl(srcmProvider.Metadata); } //adjust rate Discount appliedDiscount = null; var shippingTotal = _orderTotalCalculationService.AdjustShippingRate( shippingOption.Rate, cart, shippingOption.Name, shippingMethods, out appliedDiscount); decimal rateBase = _taxService.GetShippingPrice(shippingTotal, _workContext.CurrentCustomer); decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency); soModel.FeeRaw = rate; soModel.Fee = _priceFormatter.FormatShippingPrice(rate, true); model.ShippingMethods.Add(soModel); } //find a selected (previously) shipping method var selectedShippingOption = _workContext.CurrentCustomer.GetAttribute <ShippingOption>(SystemCustomerAttributeNames.SelectedShippingOption, _storeContext.CurrentStore.Id); if (selectedShippingOption != null) { var shippingOptionToSelect = model.ShippingMethods.ToList() .Find(so => !String.IsNullOrEmpty(so.Name) && so.Name.Equals(selectedShippingOption.Name, StringComparison.InvariantCultureIgnoreCase) && !String.IsNullOrEmpty(so.ShippingRateComputationMethodSystemName) && so.ShippingRateComputationMethodSystemName.Equals(selectedShippingOption.ShippingRateComputationMethodSystemName, StringComparison.InvariantCultureIgnoreCase)); if (shippingOptionToSelect != null) { shippingOptionToSelect.Selected = true; } } //if no option has been selected, let's do it for the first one if (model.ShippingMethods.Where(so => so.Selected).FirstOrDefault() == null) { var shippingOptionToSelect = model.ShippingMethods.FirstOrDefault(); if (shippingOptionToSelect != null) { shippingOptionToSelect.Selected = true; } } } else { foreach (var error in getShippingOptionResponse.Errors) { model.Warnings.Add(error); } } return(model); }
private PayPalPlusCheckoutModel.ThirdPartyPaymentMethod GetThirdPartyPaymentMethodModel( Provider <IPaymentMethod> provider, PayPalPlusPaymentSettings settings, Store store) { var model = new PayPalPlusCheckoutModel.ThirdPartyPaymentMethod(); try { model.RedirectUrl = Url.Action("CheckoutReturn", "PayPalPlus", new { area = Plugin.SystemName, systemName = provider.Metadata.SystemName }, store.SslEnabled ? "https" : "http"); if (provider.Metadata.SystemName == PayPalInstalmentsProvider.SystemName) { // "The methodName contains up to 25 characters. All additional characters are truncated." // https://developer.paypal.com/docs/paypal-plus/germany/how-to/integrate-third-party-payments/ model.MethodName = T("Plugins.Payments.PayPalInstalments.ShortMethodName"); } else { model.MethodName = _pluginMediator.GetLocalizedFriendlyName(provider.Metadata).NullEmpty() ?? provider.Metadata.FriendlyName.NullEmpty() ?? provider.Metadata.SystemName; } model.MethodName = model.MethodName.EmptyNull(); if (settings.DisplayPaymentMethodDescription) { // Not the short description, the full description is intended for frontend. var paymentMethod = _paymentService.GetPaymentMethodBySystemName(provider.Metadata.SystemName); if (paymentMethod != null) { string description = paymentMethod.GetLocalized(x => x.FullDescription); if (description.HasValue()) { description = HtmlUtils.ConvertHtmlToPlainText(description); description = HtmlUtils.StripTags(HttpUtility.HtmlDecode(description)); if (description.HasValue()) { model.Description = description.EncodeJsString(); } } } } } catch { } try { if (settings.DisplayPaymentMethodLogo && provider.Metadata.PluginDescriptor != null && store.SslEnabled) { // Special case PayPal instalments. if (provider.Metadata.SystemName == PayPalInstalmentsProvider.SystemName && model.ImageUrl.IsEmpty()) { var uri = new UriBuilder(Uri.UriSchemeHttps, Request.Url.Host, -1, "Plugins/SmartStore.PayPal/Content/instalments-sm.png"); model.ImageUrl = uri.ToString(); } else { var brandImageUrl = _pluginMediator.GetBrandImageUrl(provider.Metadata); if (brandImageUrl.HasValue()) { if (brandImageUrl.StartsWith("~")) { brandImageUrl = brandImageUrl.Substring(1); } var uri = new UriBuilder(Uri.UriSchemeHttps, Request.Url.Host, -1, brandImageUrl); model.ImageUrl = uri.ToString(); } } } } catch { } return(model); }
protected CheckoutPaymentMethodModel PreparePaymentMethodModel(IList<OrganizedShoppingCartItem> cart) { var model = new CheckoutPaymentMethodModel(); //reward points if (_rewardPointsSettings.Enabled && !cart.IsRecurring()) { int rewardPointsBalance = _workContext.CurrentCustomer.GetRewardPointsBalance(); decimal rewardPointsAmountBase = _orderTotalCalculationService.ConvertRewardPointsToAmount(rewardPointsBalance); decimal rewardPointsAmount = _currencyService.ConvertFromPrimaryStoreCurrency(rewardPointsAmountBase, _workContext.WorkingCurrency); if (rewardPointsAmount > decimal.Zero) { model.DisplayRewardPoints = true; model.RewardPointsAmount = _priceFormatter.FormatPrice(rewardPointsAmount, true, false); model.RewardPointsBalance = rewardPointsBalance; } } var boundPaymentMethods = _paymentService .LoadActivePaymentMethods(_workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id) .Where(pm => pm.Value.PaymentMethodType == PaymentMethodType.Standard || pm.Value.PaymentMethodType == PaymentMethodType.Redirection || pm.Value.PaymentMethodType == PaymentMethodType.StandardAndRedirection) .ToList(); foreach (var pm in boundPaymentMethods) { if (cart.IsRecurring() && pm.Value.RecurringPaymentType == RecurringPaymentType.NotSupported) continue; var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel() { Name = _pluginMediator.GetLocalizedFriendlyName(pm.Metadata), Description = _pluginMediator.GetLocalizedDescription(pm.Metadata), PaymentMethodSystemName = pm.Metadata.SystemName, PaymentInfoRoute = pm.Value.GetPaymentInfoRoute(), RequiresInteraction = pm.Value.RequiresInteraction }; pmModel.BrandUrl = _pluginMediator.GetBrandImageUrl(pm.Metadata); // payment method additional fee decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(cart, pm.Metadata.SystemName); decimal rateBase = _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, _workContext.CurrentCustomer); decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency); if (rate != decimal.Zero) pmModel.Fee = _priceFormatter.FormatPaymentMethodAdditionalFee(rate, true); model.PaymentMethods.Add(pmModel); } // find a selected (previously) payment method var selectedPaymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute<string>( SystemCustomerAttributeNames.SelectedPaymentMethod, _genericAttributeService, _storeContext.CurrentStore.Id); bool selected = false; if (selectedPaymentMethodSystemName.HasValue()) { var paymentMethodToSelect = model.PaymentMethods.Find(pm => pm.PaymentMethodSystemName.IsCaseInsensitiveEqual(selectedPaymentMethodSystemName)); if (paymentMethodToSelect != null) { paymentMethodToSelect.Selected = true; selected = true; } } // if no option has been selected, let's do it for the first one if (!selected) { var paymentMethodToSelect = model.PaymentMethods.FirstOrDefault(); if (paymentMethodToSelect != null) paymentMethodToSelect.Selected = true; } return model; }