Exemplo n.º 1
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       = StoreData.GetStoreBlob();

            if (StoreData.GetDefaultCrypto() != model.DefaultCryptoCurrency)
            {
                needUpdate = true;
                StoreData.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.RequiresRefundEmail = model.RequiresRefundEmail;
            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);
            blob.HtmlTitle           = string.IsNullOrWhiteSpace(model.HtmlTitle) ? null : model.HtmlTitle;
            if (StoreData.SetStoreBlob(blob))
            {
                needUpdate = true;
            }
            if (needUpdate)
            {
                await _Repo.UpdateStore(StoreData);

                StatusMessage = "Store successfully updated";
            }

            return(RedirectToAction(nameof(CheckoutExperience), new
            {
                storeId = StoreData.Id
            }));
        }
Exemplo n.º 2
0
        public IActionResult CheckoutExperience()
        {
            var storeBlob = CurrentStore.GetStoreBlob();
            var vm        = new CheckoutExperienceViewModel();

            SetCryptoCurrencies(vm, CurrentStore);
            vm.PaymentMethodCriteria =
                CurrentStore.GetPaymentMethodCriteria(_NetworkProvider, storeBlob).Select(criteria =>
                                                                                          new PaymentMethodCriteriaViewModel()
            {
                PaymentMethod = criteria.PaymentMethod.ToString(),
                Type          = criteria.Above ? PaymentMethodCriteriaViewModel.CriteriaType.GreaterThan : PaymentMethodCriteriaViewModel.CriteriaType.LessThan,
                Value         = criteria.Value?.ToString() ?? ""
            }).ToList();
            vm.CustomCSS  = storeBlob.CustomCSS;
            vm.CustomLogo = storeBlob.CustomLogo;
            vm.HtmlTitle  = storeBlob.HtmlTitle;
            vm.SetLanguages(_LangService, storeBlob.DefaultLang);
            vm.RequiresRefundEmail        = storeBlob.RequiresRefundEmail;
            vm.ShowRecommendedFee         = storeBlob.ShowRecommendedFee;
            vm.RecommendedFeeBlockTarget  = storeBlob.RecommendedFeeBlockTarget;
            vm.LightningAmountInSatoshi   = storeBlob.LightningAmountInSatoshi;
            vm.LightningPrivateRouteHints = storeBlob.LightningPrivateRouteHints;
            vm.RedirectAutomatically      = storeBlob.RedirectAutomatically;
            return(View(vm));
        }
Exemplo n.º 3
0
        public IActionResult CheckoutExperience()
        {
            var storeBlob = StoreData.GetStoreBlob();
            var vm        = new CheckoutExperienceViewModel();

            vm.SetCryptoCurrencies(_ExplorerProvider, StoreData.GetDefaultCrypto(_NetworkProvider));
            vm.SetLanguages(_LangService, storeBlob.DefaultLang);
            vm.LightningMaxValue   = storeBlob.LightningMaxValue?.ToString() ?? "";
            vm.OnChainMinValue     = storeBlob.OnChainMinValue?.ToString() ?? "";
            vm.RequiresRefundEmail = storeBlob.RequiresRefundEmail;
            vm.CustomCSS           = storeBlob.CustomCSS?.AbsoluteUri;
            vm.CustomLogo          = storeBlob.CustomLogo?.AbsoluteUri;
            vm.HtmlTitle           = storeBlob.HtmlTitle;
            return(View(vm));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CheckoutExperience(string storeId, CheckoutExperienceViewModel model)
        {
            CurrencyValue currencyValue = null;

            if (!string.IsNullOrWhiteSpace(model.LightningMaxValue))
            {
                if (!CurrencyValue.TryParse(model.LightningMaxValue, out currencyValue))
                {
                    ModelState.AddModelError(nameof(model.LightningMaxValue), "Invalid currency 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);
            blob.DefaultLang         = model.DefaultLang;
            blob.AllowCoinConversion = model.AllowCoinConversion;
            blob.LightningMaxValue   = currencyValue;
            blob.CustomLogo          = model.CustomLogo;
            blob.CustomCSS           = model.CustomCSS;
            if (store.SetStoreBlob(blob))
            {
                needUpdate = true;
            }
            if (needUpdate)
            {
                await _Repo.UpdateStore(store);

                StatusMessage = "Store successfully updated";
            }

            return(RedirectToAction(nameof(CheckoutExperience), new
            {
                storeId = storeId
            }));
        }
Exemplo n.º 5
0
        public IActionResult CheckoutExperience()
        {
            var storeBlob = CurrentStore.GetStoreBlob();
            var vm        = new CheckoutExperienceViewModel();

            SetCryptoCurrencies(vm, CurrentStore);
            vm.PaymentMethodCriteria = CurrentStore.GetSupportedPaymentMethods(_NetworkProvider).Select(method =>
            {
                var existing =
                    storeBlob.PaymentMethodCriteria.SingleOrDefault(criteria =>
                                                                    criteria.PaymentMethod == method.PaymentId);
                if (existing is null)
                {
                    return(new PaymentMethodCriteriaViewModel()
                    {
                        PaymentMethod = method.PaymentId.ToString(),
                        Value = ""
                    });
                }
                else
                {
                    return(new PaymentMethodCriteriaViewModel()
                    {
                        PaymentMethod = existing.PaymentMethod.ToString(),
                        Type = existing.Above
                            ? PaymentMethodCriteriaViewModel.CriteriaType.GreaterThan
                            : PaymentMethodCriteriaViewModel.CriteriaType.LessThan,
                        Value = existing.Value?.ToString() ?? ""
                    });
                }
            }).ToList();
            vm.RequiresRefundEmail          = storeBlob.RequiresRefundEmail;
            vm.LightningAmountInSatoshi     = storeBlob.LightningAmountInSatoshi;
            vm.LightningPrivateRouteHints   = storeBlob.LightningPrivateRouteHints;
            vm.OnChainWithLnInvoiceFallback = storeBlob.OnChainWithLnInvoiceFallback;
            vm.LazyPaymentMethods           = storeBlob.LazyPaymentMethods;
            vm.RedirectAutomatically        = storeBlob.RedirectAutomatically;
            vm.ShowRecommendedFee           = storeBlob.ShowRecommendedFee;
            vm.RecommendedFeeBlockTarget    = storeBlob.RecommendedFeeBlockTarget;

            vm.CustomCSS          = storeBlob.CustomCSS;
            vm.CustomLogo         = storeBlob.CustomLogo;
            vm.HtmlTitle          = storeBlob.HtmlTitle;
            vm.AutoDetectLanguage = storeBlob.AutoDetectLanguage;
            vm.SetLanguages(_LangService, storeBlob.DefaultLang);
            return(View(vm));
        }
        public IActionResult CheckoutExperience()
        {
            var storeBlob = StoreData.GetStoreBlob();
            var vm        = new CheckoutExperienceViewModel();

            SetCryptoCurrencies(vm, StoreData);
            vm.CustomCSS  = storeBlob.CustomCSS?.AbsoluteUri;
            vm.CustomLogo = storeBlob.CustomLogo?.AbsoluteUri;
            vm.HtmlTitle  = storeBlob.HtmlTitle;
            vm.SetLanguages(_LangService, storeBlob.DefaultLang);
            vm.RequiresRefundEmail      = storeBlob.RequiresRefundEmail;
            vm.OnChainMinValue          = storeBlob.OnChainMinValue?.ToString() ?? "";
            vm.LightningMaxValue        = storeBlob.LightningMaxValue?.ToString() ?? "";
            vm.LightningAmountInSatoshi = storeBlob.LightningAmountInSatoshi;
            vm.RedirectAutomatically    = storeBlob.RedirectAutomatically;
            return(View(vm));
        }
Exemplo n.º 7
0
        public IActionResult CheckoutExperience()
        {
            var storeBlob = CurrentStore.GetStoreBlob();
            var vm        = new CheckoutExperienceViewModel();

            SetCryptoCurrencies(vm, CurrentStore);
            vm.CustomCSS  = storeBlob.CustomCSS;
            vm.CustomLogo = storeBlob.CustomLogo;
            vm.HtmlTitle  = storeBlob.HtmlTitle;
            vm.SetLanguages(_LangService, storeBlob.DefaultLang);
            vm.RequiresRefundEmail       = storeBlob.RequiresRefundEmail;
            vm.ShowRecommendedFee        = storeBlob.ShowRecommendedFee;
            vm.RecommendedFeeBlockTarget = storeBlob.RecommendedFeeBlockTarget;
            vm.OnChainMinValue           = storeBlob.OnChainMinValue?.ToString() ?? "";
            vm.LightningMaxValue         = storeBlob.LightningMaxValue?.ToString() ?? "";
            vm.LightningAmountInSatoshi  = storeBlob.LightningAmountInSatoshi;
            vm.RedirectAutomatically     = storeBlob.RedirectAutomatically;
            return(View(vm));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> CheckoutExperience(string storeId)
        {
            var store = await _Repo.FindStore(storeId, GetUserId());

            if (store == null)
            {
                return(NotFound());
            }
            var storeBlob = store.GetStoreBlob();
            var vm        = new CheckoutExperienceViewModel();

            vm.SetCryptoCurrencies(_ExplorerProvider, store.GetDefaultCrypto());
            vm.SetLanguages(_LangService, storeBlob.DefaultLang);
            vm.LightningMaxValue   = storeBlob.LightningMaxValue?.ToString() ?? "";
            vm.AllowCoinConversion = storeBlob.AllowCoinConversion;
            vm.CustomCSS           = storeBlob.CustomCSS;
            vm.CustomLogo          = storeBlob.CustomLogo;
            return(View(vm));
        }
Exemplo n.º 9
0
        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
            }));
        }
Exemplo n.º 10
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);
            }
            SetCryptoCurrencies(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.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
            }));
        }
        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), "Valor máximo de rayo no válido");
                }
            }

            CurrencyValue onchainMinValue = null;

            if (!string.IsNullOrWhiteSpace(model.OnChainMinValue))
            {
                if (!CurrencyValue.TryParse(model.OnChainMinValue, out onchainMinValue))
                {
                    ModelState.AddModelError(nameof(model.OnChainMinValue), "Inválido en el valor mínimo de la cadena");
                }
            }
            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 = "Tienda actualizada correctamente";
            }

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