Skip to content

Commit

Permalink
Greenfield: Add CSS and logo URL to store settings API
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisreimann committed May 7, 2024
1 parent d367ad0 commit adec6a8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions BTCPayServer.Client/Models/StoreBaseData.cs
Expand Up @@ -17,6 +17,8 @@ public abstract class StoreBaseData
public string Website { get; set; }

public string BrandColor { get; set; }
public string LogoUrl { get; set; }
public string CssUrl { get; set; }

public string SupportUrl { get; set; }

Expand Down
15 changes: 15 additions & 0 deletions BTCPayServer.Tests/GreenfieldAPITests.cs
Expand Up @@ -1365,13 +1365,25 @@ public async Task StoresControllerTests()
//create store
var newStore = await client.CreateStore(new CreateStoreRequest { Name = "A" });
Assert.Equal("A", newStore.Name);

// validate
await AssertValidationError(["CssUrl", "LogoUrl", "BrandColor"], async () =>
await client.UpdateStore(newStore.Id, new UpdateStoreRequest
{
CssUrl = "style.css",
LogoUrl = "logo.svg",
BrandColor = "invalid"
}));

//update store
Assert.Empty(newStore.PaymentMethodCriteria);
await client.GenerateOnChainWallet(newStore.Id, "BTC", new GenerateOnChainWalletRequest());
var updatedStore = await client.UpdateStore(newStore.Id, new UpdateStoreRequest
{
Name = "B",
CssUrl = "https://example.org/style.css",
LogoUrl = "https://example.org/logo.svg",
BrandColor = "#003366",
PaymentMethodCriteria = new List<PaymentMethodCriteriaData>
{
new()
Expand All @@ -1384,6 +1396,9 @@ public async Task StoresControllerTests()
}
});
Assert.Equal("B", updatedStore.Name);
Assert.Equal("https://example.org/style.css", updatedStore.CssUrl);
Assert.Equal("https://example.org/logo.svg", updatedStore.LogoUrl);
Assert.Equal("#003366", updatedStore.BrandColor);
var s = (await client.GetStore(newStore.Id));
Assert.Equal("B", s.Name);
var pmc = Assert.Single(s.PaymentMethodCriteria);
Expand Down
12 changes: 12 additions & 0 deletions BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs
Expand Up @@ -117,6 +117,8 @@ internal static Client.Models.StoreData FromModel(StoreData data)
Website = data.StoreWebsite,
Archived = data.Archived,
BrandColor = storeBlob.BrandColor,
CssUrl = storeBlob.CssUrl,
LogoUrl = storeBlob.LogoUrl,
SupportUrl = storeBlob.StoreSupportUrl,
SpeedPolicy = data.SpeedPolicy,
DefaultPaymentMethod = data.GetDefaultPaymentId()?.ToString(),
Expand Down Expand Up @@ -194,6 +196,8 @@ private void ToModel(StoreBaseData restModel, StoreData model, PaymentMethodId d
blob.PaymentTolerance = restModel.PaymentTolerance;
blob.PayJoinEnabled = restModel.PayJoinEnabled;
blob.BrandColor = restModel.BrandColor;
blob.LogoUrl = restModel.LogoUrl;
blob.CssUrl = restModel.CssUrl;
if (restModel.AutoDetectLanguage.HasValue)
blob.AutoDetectLanguage = restModel.AutoDetectLanguage.Value;
if (restModel.ShowPayInWalletButton.HasValue)
Expand Down Expand Up @@ -239,6 +243,14 @@ private IActionResult Validate(StoreBaseData request)
{
ModelState.AddModelError(nameof(request.Website), "Website is not a valid url");
}
if (!string.IsNullOrEmpty(request.LogoUrl) && !Uri.TryCreate(request.LogoUrl, UriKind.Absolute, out _))
{
ModelState.AddModelError(nameof(request.LogoUrl), "Logo is not a valid url");
}
if (!string.IsNullOrEmpty(request.CssUrl) && !Uri.TryCreate(request.CssUrl, UriKind.Absolute, out _))
{
ModelState.AddModelError(nameof(request.CssUrl), "CSS is not a valid url");
}
if (!string.IsNullOrEmpty(request.BrandColor) && !ColorPalette.IsValid(request.BrandColor))
{
ModelState.AddModelError(nameof(request.BrandColor), "Brand color is not a valid HEX Color (e.g. #F7931A)");
Expand Down
1 change: 0 additions & 1 deletion BTCPayServer/Data/StoreBlob.cs
Expand Up @@ -215,7 +215,6 @@ public RateRules GetDefaultRateRules(BTCPayNetworkProvider networkProvider)

public List<UIStoresController.StoreEmailRule> EmailRules { get; set; }
public string BrandColor { get; set; }

public string LogoUrl { get; set; }
public string CssUrl { get; set; }

Expand Down
12 changes: 12 additions & 0 deletions BTCPayServer/wwwroot/swagger/v1/swagger.template.stores.json
Expand Up @@ -411,6 +411,18 @@
"description": "The support URI of the store, can contain the placeholders `{OrderId}` and `{InvoiceId}`. Can be any valid URI, such as a website, email, and nostr.",
"format": "uri"
},
"logoUrl": {
"type": "string",
"nullable": true,
"description": "Absolute URL to a logo file",
"format": "uri"
},
"cssUrl": {
"type": "string",
"nullable": true,
"description": "Absolute URL to CSS file to customize the public/customer-facing pages of the store. (Invoice, Payment Request, Pull Payment, etc.)",
"format": "uri"
},
"brandColor": {
"type": "string",
"description": "The brand color of the store in HEX format",
Expand Down

0 comments on commit adec6a8

Please sign in to comment.