public async Task <IActionResult> CheckoutExperience(CheckoutExperienceViewModel model)
        {
            bool needUpdate             = false;
            var  blob                   = CurrentStore.GetStoreBlob();
            var  defaultPaymentMethodId = model.DefaultPaymentMethod == null ? null : PaymentMethodId.Parse(model.DefaultPaymentMethod);

            if (CurrentStore.GetDefaultPaymentId(_NetworkProvider) != defaultPaymentMethodId)
            {
                needUpdate = true;
                CurrentStore.SetDefaultPaymentId(defaultPaymentMethodId);
            }
            SetCryptoCurrencies(model, CurrentStore);
            model.SetLanguages(_LangService, model.DefaultLang);
            model.PaymentMethodCriteria ??= new List <PaymentMethodCriteriaViewModel>();
            for (var index = 0; index < model.PaymentMethodCriteria.Count; index++)
            {
                var methodCriterion = model.PaymentMethodCriteria[index];
                if (!string.IsNullOrWhiteSpace(methodCriterion.Value))
                {
                    if (!CurrencyValue.TryParse(methodCriterion.Value, out var value))
                    {
                        model.AddModelError(viewModel => viewModel.PaymentMethodCriteria[index].Value,
                                            $"{methodCriterion.PaymentMethod}: invalid format (1.0 USD)", this);
                    }
                }
            }


            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            blob.PaymentMethodCriteria = model.PaymentMethodCriteria
                                         .Where(viewModel => !string.IsNullOrEmpty(viewModel.Value)).Select(viewModel =>
            {
                CurrencyValue.TryParse(viewModel.Value, out var cv);
                return(new PaymentMethodCriteria()
                {
                    Above = viewModel.Type == PaymentMethodCriteriaViewModel.CriteriaType.GreaterThan, Value = cv, PaymentMethod = PaymentMethodId.Parse(viewModel.PaymentMethod)
                });
            }).ToList();

            blob.RequiresRefundEmail          = model.RequiresRefundEmail;
            blob.LazyPaymentMethods           = model.LazyPaymentMethods;
            blob.LightningAmountInSatoshi     = model.LightningAmountInSatoshi;
            blob.LightningPrivateRouteHints   = model.LightningPrivateRouteHints;
            blob.OnChainWithLnInvoiceFallback = model.OnChainWithLnInvoiceFallback;
            blob.RedirectAutomatically        = model.RedirectAutomatically;
            blob.ShowRecommendedFee           = model.ShowRecommendedFee;
            blob.RecommendedFeeBlockTarget    = model.RecommendedFeeBlockTarget;

            blob.CustomLogo  = model.CustomLogo;
            blob.CustomCSS   = model.CustomCSS;
            blob.HtmlTitle   = string.IsNullOrWhiteSpace(model.HtmlTitle) ? null : model.HtmlTitle;
            blob.DefaultLang = model.DefaultLang;

            if (CurrentStore.SetStoreBlob(blob))
            {
                needUpdate = true;
            }
            if (needUpdate)
            {
                await _Repo.UpdateStore(CurrentStore);

                TempData[WellKnownTempData.SuccessMessage] = "Store successfully updated";
            }

            return(RedirectToAction(nameof(CheckoutExperience), new
            {
                storeId = CurrentStore.Id
            }));
        }
        public async Task <IActionResult> CheckoutExperience(string storeId, CheckoutExperienceViewModel model)
        {
            CurrencyValue lightningMaxValue = null;

            if (!string.IsNullOrWhiteSpace(model.LightningMaxValue))
            {
                if (!CurrencyValue.TryParse(model.LightningMaxValue, out lightningMaxValue))
                {
                    ModelState.AddModelError(nameof(model.LightningMaxValue), "Invalid lightning max value");
                }
            }

            CurrencyValue onchainMinValue = null;

            if (!string.IsNullOrWhiteSpace(model.OnChainMinValue))
            {
                if (!CurrencyValue.TryParse(model.OnChainMinValue, out onchainMinValue))
                {
                    ModelState.AddModelError(nameof(model.OnChainMinValue), "Invalid on chain min value");
                }
            }

            var store = await _Repo.FindStore(storeId, GetUserId());

            if (store == null)
            {
                return(NotFound());
            }
            bool needUpdate = false;
            var  blob       = store.GetStoreBlob();

            if (store.GetDefaultCrypto() != model.DefaultCryptoCurrency)
            {
                needUpdate = true;
                store.SetDefaultCrypto(model.DefaultCryptoCurrency);
            }
            model.SetCryptoCurrencies(_ExplorerProvider, model.DefaultCryptoCurrency);
            model.SetLanguages(_LangService, model.DefaultLang);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            blob.DefaultLang         = model.DefaultLang;
            blob.AllowCoinConversion = model.AllowCoinConversion;
            blob.LightningMaxValue   = lightningMaxValue;
            blob.OnChainMinValue     = onchainMinValue;
            blob.CustomLogo          = string.IsNullOrWhiteSpace(model.CustomLogo) ? null : new Uri(model.CustomLogo, UriKind.Absolute);
            blob.CustomCSS           = string.IsNullOrWhiteSpace(model.CustomCSS) ? null : new Uri(model.CustomCSS, UriKind.Absolute);
            if (store.SetStoreBlob(blob))
            {
                needUpdate = true;
            }
            if (needUpdate)
            {
                await _Repo.UpdateStore(store);

                StatusMessage = "Store successfully updated";
            }

            return(RedirectToAction(nameof(CheckoutExperience), new
            {
                storeId = storeId
            }));
        }
        public async Task <IActionResult> CheckoutExperience(CheckoutExperienceViewModel model)
        {
            CurrencyValue lightningMaxValue = null;

            if (!string.IsNullOrWhiteSpace(model.LightningMaxValue))
            {
                if (!CurrencyValue.TryParse(model.LightningMaxValue, out lightningMaxValue))
                {
                    ModelState.AddModelError(nameof(model.LightningMaxValue), "Invalid lightning max value");
                }
            }

            CurrencyValue onchainMinValue = null;

            if (!string.IsNullOrWhiteSpace(model.OnChainMinValue))
            {
                if (!CurrencyValue.TryParse(model.OnChainMinValue, out onchainMinValue))
                {
                    ModelState.AddModelError(nameof(model.OnChainMinValue), "Invalid on chain min value");
                }
            }
            bool needUpdate             = false;
            var  blob                   = StoreData.GetStoreBlob();
            var  defaultPaymentMethodId = model.DefaultPaymentMethod == null ? null : PaymentMethodId.Parse(model.DefaultPaymentMethod);

            if (StoreData.GetDefaultPaymentId(_NetworkProvider) != defaultPaymentMethodId)
            {
                needUpdate = true;
                StoreData.SetDefaultPaymentId(defaultPaymentMethodId);
            }
            SetCryptoCurrencies(model, StoreData);
            model.SetLanguages(_LangService, model.DefaultLang);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            blob.CustomLogo               = string.IsNullOrWhiteSpace(model.CustomLogo) ? null : new Uri(model.CustomLogo, UriKind.Absolute);
            blob.CustomCSS                = string.IsNullOrWhiteSpace(model.CustomCSS) ? null : new Uri(model.CustomCSS, UriKind.Absolute);
            blob.HtmlTitle                = string.IsNullOrWhiteSpace(model.HtmlTitle) ? null : model.HtmlTitle;
            blob.DefaultLang              = model.DefaultLang;
            blob.RequiresRefundEmail      = model.RequiresRefundEmail;
            blob.OnChainMinValue          = onchainMinValue;
            blob.LightningMaxValue        = lightningMaxValue;
            blob.LightningAmountInSatoshi = model.LightningAmountInSatoshi;
            blob.RedirectAutomatically    = model.RedirectAutomatically;
            if (StoreData.SetStoreBlob(blob))
            {
                needUpdate = true;
            }
            if (needUpdate)
            {
                await _Repo.UpdateStore(StoreData);

                StatusMessage = "Store successfully updated";
            }

            return(RedirectToAction(nameof(CheckoutExperience), new
            {
                storeId = StoreData.Id
            }));
        }
Exemple #4
0
        public async Task <IActionResult> CheckoutExperience(CheckoutExperienceViewModel model)
        {
            CurrencyValue lightningMaxValue = null;

            if (!string.IsNullOrWhiteSpace(model.LightningMaxValue))
            {
                if (!CurrencyValue.TryParse(model.LightningMaxValue, out lightningMaxValue))
                {
                    ModelState.AddModelError(nameof(model.LightningMaxValue), "Invalid lightning max value");
                }
            }

            CurrencyValue onchainMinValue = null;

            if (!string.IsNullOrWhiteSpace(model.OnChainMinValue))
            {
                if (!CurrencyValue.TryParse(model.OnChainMinValue, out onchainMinValue))
                {
                    ModelState.AddModelError(nameof(model.OnChainMinValue), "Invalid on chain min value");
                }
            }
            bool needUpdate             = false;
            var  blob                   = CurrentStore.GetStoreBlob();
            var  defaultPaymentMethodId = model.DefaultPaymentMethod == null ? null : PaymentMethodId.Parse(model.DefaultPaymentMethod);

            if (CurrentStore.GetDefaultPaymentId(_NetworkProvider) != defaultPaymentMethodId)
            {
                needUpdate = true;
                CurrentStore.SetDefaultPaymentId(defaultPaymentMethodId);
            }
            SetbitcoinCurrencies(model, CurrentStore);
            model.SetLanguages(_LangService, model.DefaultLang);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            blob.CustomLogo                 = model.CustomLogo;
            blob.CustomCSS                  = model.CustomCSS;
            blob.HtmlTitle                  = string.IsNullOrWhiteSpace(model.HtmlTitle) ? null : model.HtmlTitle;
            blob.DefaultLang                = model.DefaultLang;
            blob.RequiresRefundEmail        = model.RequiresRefundEmail;
            blob.ShowRecommendedFee         = model.ShowRecommendedFee;
            blob.RecommendedFeeBlockTarget  = model.RecommendedFeeBlockTarget;
            blob.OnChainMinValue            = onchainMinValue;
            blob.LightningMaxValue          = lightningMaxValue;
            blob.LightningAmountInSatoshi   = model.LightningAmountInSatoshi;
            blob.LightningPrivateRouteHints = model.LightningPrivateRouteHints;
            blob.RedirectAutomatically      = model.RedirectAutomatically;
            if (CurrentStore.SetStoreBlob(blob))
            {
                needUpdate = true;
            }
            if (needUpdate)
            {
                await _Repo.UpdateStore(CurrentStore);

                TempData[WellKnownTempData.SuccessMessage] = "Store successfully updated";
            }

            return(RedirectToAction(nameof(CheckoutExperience), new
            {
                storeId = CurrentStore.Id
            }));
        }