protected CheckoutPaymentMethodModel PreparePaymentMethodModel(IList<ShoppingCartItem> 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 && _orderTotalCalculationService.CheckMinimumRewardPointsToUseRequirement(rewardPointsBalance)) { model.DisplayRewardPoints = true; model.RewardPointsAmount = _priceFormatter.FormatPrice(rewardPointsAmount, true, false); model.RewardPointsBalance = rewardPointsBalance; } } var boundPaymentMethods = _paymentService .LoadActivePaymentMethods(_workContext.CurrentCustomer.Id) .Where(pm => pm.PaymentMethodType == PaymentMethodType.Standard || pm.PaymentMethodType == PaymentMethodType.Redirection) .ToList(); foreach (var pm in boundPaymentMethods) { if (cart.IsRecurring() && pm.RecurringPaymentType == RecurringPaymentType.NotSupported) continue; var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel() { Name = pm.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id), PaymentMethodSystemName = pm.PluginDescriptor.SystemName, }; //payment method additional fee decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(cart, pm.PluginDescriptor.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); 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; }
private CheckoutPaymentMethodModel PreparePaymentMethodModel(IList<ShoppingCartItem> 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() .Where(pm => pm.PaymentMethodType == PaymentMethodType.Standard || pm.PaymentMethodType == PaymentMethodType.Redirection) .ToList(); foreach (var pm in boundPaymentMethods) { if (cart.IsRecurring() && pm.RecurringPaymentType == RecurringPaymentType.NotSupported) continue; var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel() { Name = pm.PluginDescriptor.FriendlyName, PaymentMethodSystemName = pm.PluginDescriptor.SystemName, }; //payment method additional fee decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(pm.PluginDescriptor.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); } return model; }