protected CheckoutPaymentMethodModel PreparePaymentMethodModel(IList <OrganizedShoppingCartItem> cart) { var model = new CheckoutPaymentMethodModel(); // was shipping skipped var shippingOptions = _shippingService.GetShippingOptions(cart, _workContext.CurrentCustomer.ShippingAddress, "", _storeContext.CurrentStore.Id).ShippingOptions; if (!cart.RequiresShipping() || (shippingOptions.Count <= 1 && _shippingSettings.SkipShippingIfSingleOption)) { model.SkippedSelectShipping = true; } var paymentTypes = new PaymentMethodType[] { PaymentMethodType.Standard, PaymentMethodType.Redirection, PaymentMethodType.StandardAndRedirection }; var boundPaymentMethods = _paymentService .LoadActivePaymentMethods(_workContext.CurrentCustomer, cart, _storeContext.CurrentStore.Id, paymentTypes) .ToList(); var allPaymentMethods = _paymentService.GetAllPaymentMethods(); foreach (var pm in boundPaymentMethods) { if (cart.IsRecurring() && pm.Value.RecurringPaymentType == RecurringPaymentType.NotSupported) { continue; } var paymentMethod = allPaymentMethods.FirstOrDefault(x => x.PaymentMethodSystemName.IsCaseInsensitiveEqual(pm.Metadata.SystemName)); 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 }; if (paymentMethod != null) { pmModel.FullDescription = paymentMethod.GetLocalized(x => x.FullDescription, _workContext.WorkingLanguage.Id); } 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); }
public virtual async Task <CheckoutPaymentMethodModel> PreparePaymentMethod(IList <ShoppingCartItem> cart, string filterByCountryId) { var model = new CheckoutPaymentMethodModel(); //reward points if (_rewardPointsSettings.Enabled && !cart.IsRecurring()) { int rewardPointsBalance = await _rewardPointsService.GetRewardPointsBalance(_workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id); decimal rewardPointsAmountBase = await _orderTotalCalculationService.ConvertRewardPointsToAmount(rewardPointsBalance); decimal rewardPointsAmount = await _currencyService.ConvertFromPrimaryStoreCurrency(rewardPointsAmountBase, _workContext.WorkingCurrency); if (rewardPointsAmount > decimal.Zero && _orderTotalCalculationService.CheckMinimumRewardPointsToUseRequirement(rewardPointsBalance)) { model.DisplayRewardPoints = true; model.RewardPointsAmount = _priceFormatter.FormatPrice(rewardPointsAmount, true, false); model.RewardPointsBalance = rewardPointsBalance; model.RewardPointsEnoughToPayForOrder = !(await IsPaymentWorkflowRequired(cart, true)); } } //filter by country var paymentMethods = (await _paymentService .LoadActivePaymentMethods(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id, filterByCountryId)) .Where(pm => pm.PaymentMethodType == PaymentMethodType.Standard || pm.PaymentMethodType == PaymentMethodType.Redirection).ToList(); var availablepaymentMethods = new List <IPaymentMethod>(); foreach (var pm in paymentMethods) { if (!await pm.HidePaymentMethod(cart)) { availablepaymentMethods.Add(pm); } } foreach (var pm in availablepaymentMethods) { if (cart.IsRecurring() && pm.RecurringPaymentType == RecurringPaymentType.NotSupported) { continue; } var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel { Name = pm.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id), Description = _paymentSettings.ShowPaymentMethodDescriptions ? await pm.PaymentMethodDescription() : string.Empty, PaymentMethodSystemName = pm.PluginDescriptor.SystemName, LogoUrl = pm.PluginDescriptor.GetLogoUrl(_webHelper) }; //payment method additional fee decimal paymentMethodAdditionalFee = await _paymentService.GetAdditionalHandlingFee(cart, pm.PluginDescriptor.SystemName); decimal rateBase = (await _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, _workContext.CurrentCustomer)).paymentPrice; decimal rate = await _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 = await _workContext.CurrentCustomer.GetAttribute <string>( _genericAttributeService, SystemCustomerAttributeNames.SelectedPaymentMethod, _storeContext.CurrentStore.Id); if (!String.IsNullOrEmpty(selectedPaymentMethodSystemName)) { var paymentMethodToSelect = model.PaymentMethods.ToList() .Find(pm => pm.PaymentMethodSystemName.Equals(selectedPaymentMethodSystemName, StringComparison.OrdinalIgnoreCase)); if (paymentMethodToSelect != null) { paymentMethodToSelect.Selected = true; } } //if no option has been selected, let's do it for the first one if (model.PaymentMethods.FirstOrDefault(so => so.Selected) == null) { var paymentMethodToSelect = model.PaymentMethods.FirstOrDefault(); if (paymentMethodToSelect != null) { paymentMethodToSelect.Selected = true; } } return(model); }
/// <summary> /// Prepare payment method model /// </summary> /// <param name="cart">Cart</param> /// <param name="filterByCountryId">Filter by country identifier</param> /// <returns>Payment method model</returns> public virtual CheckoutPaymentMethodModel PreparePaymentMethodModel(IList <ShoppingCartItem> cart, int filterByCountryId) { var model = new CheckoutPaymentMethodModel(); //reward points if (_rewardPointsSettings.Enabled && !_shoppingCartService.ShoppingCartIsRecurring(cart)) { var rewardPointsBalance = _rewardPointService.GetRewardPointsBalance(_workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id); rewardPointsBalance = _rewardPointService.GetReducedPointsBalance(rewardPointsBalance); var rewardPointsAmountBase = _orderTotalCalculationService.ConvertRewardPointsToAmount(rewardPointsBalance); var rewardPointsAmount = _currencyService.ConvertFromPrimaryStoreCurrency(rewardPointsAmountBase, _workContext.WorkingCurrency); if (rewardPointsAmount > decimal.Zero && _orderTotalCalculationService.CheckMinimumRewardPointsToUseRequirement(rewardPointsBalance)) { model.DisplayRewardPoints = true; model.RewardPointsAmount = _priceFormatter.FormatPrice(rewardPointsAmount, true, false); model.RewardPointsBalance = rewardPointsBalance; //are points enough to pay for entire order? like if this option (to use them) was selected model.RewardPointsEnoughToPayForOrder = !_orderProcessingService.IsPaymentWorkflowRequired(cart, true); } } //filter by country var paymentMethods = _paymentService .LoadActivePaymentMethods(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id, filterByCountryId) .Where(pm => pm.PaymentMethodType == PaymentMethodType.Standard || pm.PaymentMethodType == PaymentMethodType.Redirection) .Where(pm => !pm.HidePaymentMethod(cart)) .ToList(); foreach (var pm in paymentMethods) { if (_shoppingCartService.ShoppingCartIsRecurring(cart) && pm.RecurringPaymentType == RecurringPaymentType.NotSupported) { continue; } var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel { Name = _localizationService.GetLocalizedFriendlyName(pm, _workContext.WorkingLanguage.Id), Description = _paymentSettings.ShowPaymentMethodDescriptions ? pm.PaymentMethodDescription : string.Empty, PaymentMethodSystemName = pm.PluginDescriptor.SystemName, LogoUrl = PluginManager.GetLogoUrl(pm.PluginDescriptor) }; //payment method additional fee var paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(cart, pm.PluginDescriptor.SystemName); var rateBase = _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, _workContext.CurrentCustomer); var 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 = _genericAttributeService.GetAttribute <string>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPaymentMethodAttribute, _storeContext.CurrentStore.Id); if (!string.IsNullOrEmpty(selectedPaymentMethodSystemName)) { var paymentMethodToSelect = model.PaymentMethods.ToList() .Find(pm => pm.PaymentMethodSystemName.Equals(selectedPaymentMethodSystemName, StringComparison.InvariantCultureIgnoreCase)); if (paymentMethodToSelect != null) { paymentMethodToSelect.Selected = true; } } //if no option has been selected, let's do it for the first one if (model.PaymentMethods.FirstOrDefault(so => so.Selected) == null) { var paymentMethodToSelect = model.PaymentMethods.FirstOrDefault(); if (paymentMethodToSelect != null) { paymentMethodToSelect.Selected = true; } } 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; }
public async Task <CheckoutPaymentMethodModel> Handle(GetPaymentMethod request, CancellationToken cancellationToken) { var model = new CheckoutPaymentMethodModel(); //loyalty points if (_loyaltyPointsSettings.Enabled) { int loyaltyPointsBalance = await _loyaltyPointsService.GetLoyaltyPointsBalance(request.Customer.Id, request.Store.Id); double loyaltyPointsAmount = await _currencyService.ConvertFromPrimaryStoreCurrency(await _orderTotalCalculationService.ConvertLoyaltyPointsToAmount(loyaltyPointsBalance), request.Currency); if (loyaltyPointsAmount > 0 && _orderTotalCalculationService.CheckMinimumLoyaltyPointsToUseRequirement(loyaltyPointsBalance)) { model.DisplayLoyaltyPoints = true; model.LoyaltyPointsAmount = _priceFormatter.FormatPrice(loyaltyPointsAmount, false); model.LoyaltyPointsBalance = loyaltyPointsBalance; var shoppingCartTotalBase = (await _orderTotalCalculationService.GetShoppingCartTotal(request.Cart, useLoyaltyPoints: true)).shoppingCartTotal; model.LoyaltyPointsEnoughToPayForOrder = (shoppingCartTotalBase.HasValue && shoppingCartTotalBase.Value == 0); } } //filter by country var paymentMethods = (await _paymentService .LoadActivePaymentMethods(request.Customer, request.Store.Id, request.FilterByCountryId)) .Where(pm => pm.PaymentMethodType == PaymentMethodType.Standard || pm.PaymentMethodType == PaymentMethodType.Redirection).ToList(); var availablepaymentMethods = new List <IPaymentProvider>(); foreach (var pm in paymentMethods) { if (!await pm.HidePaymentMethod(request.Cart)) { availablepaymentMethods.Add(pm); } } foreach (var pm in availablepaymentMethods) { var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel { Name = pm.FriendlyName, Description = _paymentSettings.ShowPaymentDescriptions ? await pm.Description() : string.Empty, PaymentMethodSystemName = pm.SystemName, LogoUrl = pm.LogoURL }; //payment method additional fee double paymentMethodAdditionalFee = await _paymentService.GetAdditionalHandlingFee(request.Cart, pm.SystemName); double rate = (await _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, request.Customer)).paymentPrice; if (rate > 0) { pmModel.Fee = _priceFormatter.FormatPaymentMethodAdditionalFee(rate); } model.PaymentMethods.Add(pmModel); } //find a selected (previously) payment method var selectedPaymentMethodSystemName = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.SelectedPaymentMethod, request.Store.Id); if (!string.IsNullOrEmpty(selectedPaymentMethodSystemName)) { var paymentMethodToSelect = model.PaymentMethods.ToList() .Find(pm => pm.PaymentMethodSystemName.Equals(selectedPaymentMethodSystemName, StringComparison.OrdinalIgnoreCase)); if (paymentMethodToSelect != null) { paymentMethodToSelect.Selected = true; } } //if no option has been selected, do it for the first one if (model.PaymentMethods.FirstOrDefault(so => so.Selected) == null) { var paymentMethodToSelect = model.PaymentMethods.FirstOrDefault(); if (paymentMethodToSelect != null) { paymentMethodToSelect.Selected = true; } } return(model); }