Exemple #1
0
        private IActionResult Validate(StoreBaseData request)
        {
            if (request is null)
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(request.Name))
            {
                ModelState.AddModelError(nameof(request.Name), "Name is missing");
            }
            else if (request.Name.Length < 1 || request.Name.Length > 50)
            {
                ModelState.AddModelError(nameof(request.Name), "Name can only be between 1 and 50 characters");
            }
            if (!string.IsNullOrEmpty(request.Website) && !Uri.TryCreate(request.Website, UriKind.Absolute, out _))
            {
                ModelState.AddModelError(nameof(request.Website), "Website is not a valid url");
            }
            if (request.InvoiceExpiration < TimeSpan.FromMinutes(1) && request.InvoiceExpiration > TimeSpan.FromMinutes(60 * 24 * 24))
            {
                ModelState.AddModelError(nameof(request.InvoiceExpiration), "InvoiceExpiration can only be between 1 and 34560 mins");
            }
            if (request.MonitoringExpiration < TimeSpan.FromMinutes(10) && request.MonitoringExpiration > TimeSpan.FromMinutes(60 * 24 * 24))
            {
                ModelState.AddModelError(nameof(request.MonitoringExpiration), "InvoiceExpiration can only be between 10 and 34560 mins");
            }
            if (request.PaymentTolerance < 0 && request.PaymentTolerance > 100)
            {
                ModelState.AddModelError(nameof(request.PaymentTolerance), "PaymentTolerance can only be between 0 and 100 percent");
            }

            return(!ModelState.IsValid ? this.CreateValidationError(ModelState) : null);
        }
Exemple #2
0
        private static void ToModel(StoreBaseData restModel, Data.StoreData model)
        {
            var blob = model.GetStoreBlob();

            model.StoreName    = restModel.Name;
            model.StoreName    = restModel.Name;
            model.StoreWebsite = restModel.Website;
            model.SpeedPolicy  = restModel.SpeedPolicy;
            //we do not include the default payment method in this model and instead opt to set it in the stores/storeid/payment-methods endpoints
            //blob
            //we do not include DefaultCurrencyPairs;Spread; PreferredExchange; RateScripting; RateScript  in this model and instead opt to set it in stores/storeid/rates endpoints
            //we do not include CoinSwitchSettings in this model and instead opt to set it in stores/storeid/coinswitch endpoints
            //we do not include ExcludedPaymentMethods in this model and instead opt to set it in stores/storeid/payment-methods endpoints
            //we do not include EmailSettings in this model and instead opt to set it in stores/storeid/email endpoints
            //we do not include OnChainMinValue and LightningMaxValue because moving the CurrencyValueJsonConverter to the Client csproj is hard and requires a refactor (#1571 & #1572)
            blob.NetworkFeeMode            = restModel.NetworkFeeMode;
            blob.RequiresRefundEmail       = restModel.RequiresRefundEmail;
            blob.ShowRecommendedFee        = restModel.ShowRecommendedFee;
            blob.RecommendedFeeBlockTarget = restModel.RecommendedFeeBlockTarget;
            blob.DefaultLang              = restModel.DefaultLang;
            blob.MonitoringExpiration     = restModel.MonitoringExpiration;
            blob.InvoiceExpiration        = restModel.InvoiceExpiration;
            blob.LightningAmountInSatoshi = restModel.LightningAmountInSatoshi;
            blob.CustomLogo                   = restModel.CustomLogo;
            blob.CustomCSS                    = restModel.CustomCSS;
            blob.HtmlTitle                    = restModel.HtmlTitle;
            blob.AnyoneCanInvoice             = restModel.AnyoneCanCreateInvoice;
            blob.LightningDescriptionTemplate = restModel.LightningDescriptionTemplate;
            blob.PaymentTolerance             = restModel.PaymentTolerance;
            blob.RedirectAutomatically        = restModel.RedirectAutomatically;
            blob.PayJoinEnabled               = restModel.PayJoinEnabled;
            blob.LightningPrivateRouteHints   = restModel.LightningPrivateRouteHints;
            blob.Webhooks = restModel.Webhooks;
            model.SetStoreBlob(blob);
        }
 private IActionResult Validate(StoreBaseData request)
 {
     if (request?.Name is null)
     {
         ModelState.AddModelError(nameof(request.Name), "Name is missing");
     }
     return(!ModelState.IsValid ? BadRequest(new ValidationProblemDetails(ModelState)) : null);
 }
 private static void ToModel(StoreBaseData restModel, Data.StoreData model)
 {
     model.StoreName = restModel.Name;
 }