From 56728cefda0db3cd300e465517dbf93fc0ca93f5 Mon Sep 17 00:00:00 2001 From: Kyle McCullen Date: Fri, 17 Oct 2025 12:49:46 -0400 Subject: [PATCH 1/5] release 0.4.0 --- BTCPayServer.Plugins.Branta/BTCPayServer.Plugins.Branta.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer.Plugins.Branta/BTCPayServer.Plugins.Branta.csproj b/BTCPayServer.Plugins.Branta/BTCPayServer.Plugins.Branta.csproj index 7c2d428..270c1ff 100644 --- a/BTCPayServer.Plugins.Branta/BTCPayServer.Plugins.Branta.csproj +++ b/BTCPayServer.Plugins.Branta/BTCPayServer.Plugins.Branta.csproj @@ -7,7 +7,7 @@ Branta Easily verify payments, checkouts, and invoices. - 0.3.0 + 0.4.0 From 37943606e76f75f2b521b83ec8e674e6923c1c3a Mon Sep 17 00:00:00 2001 From: Kyle McCullen Date: Fri, 24 Oct 2025 11:48:06 -0400 Subject: [PATCH 2/5] update to payments api v2 with zero knowledge option --- .../Classes/BrantaClient.cs | 31 +++++++++++++------ BTCPayServer.Plugins.Branta/Classes/Helper.cs | 2 +- .../Services/BrantaService.cs | 30 ++++++++++-------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/BTCPayServer.Plugins.Branta/Classes/BrantaClient.cs b/BTCPayServer.Plugins.Branta/Classes/BrantaClient.cs index 42bd577..3b3a5f2 100644 --- a/BTCPayServer.Plugins.Branta/Classes/BrantaClient.cs +++ b/BTCPayServer.Plugins.Branta/Classes/BrantaClient.cs @@ -1,6 +1,8 @@ using BTCPayServer.Plugins.Branta.Models; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using System; +using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Text; @@ -10,11 +12,17 @@ namespace BTCPayServer.Plugins.Branta.Classes; public class BrantaClient(IHttpClientFactory httpClientFactory) { - public static readonly string PaymentVersion = "v1"; + public static readonly string PaymentVersion = "v2"; + + private JsonSerializerSettings _jsonSettings = new() + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; public async Task PostPaymentAsync(PaymentRequest paymentRequest, BrantaSettings brantaSettings) { - var json = JsonConvert.SerializeObject(paymentRequest); + + var json = JsonConvert.SerializeObject(paymentRequest, _jsonSettings); var content = new StringContent(json, Encoding.UTF8, "application/json"); using var request = new HttpRequestMessage(HttpMethod.Post, $"{PaymentVersion}/payments") @@ -38,15 +46,18 @@ public async Task PostPaymentAsync(PaymentRequest paymentRequest, BrantaSettings public class PaymentRequest { - public Payment payment { get; set; } + public List Destinations { get; set; } + + public string Description { get; set; } + + public string Ttl { get; set; } + + public string BtcPayServerPluginVersion { get; set; } } -public class Payment +public class Destination { - public string description { get; set; } - public string payment { get; set; } - public string[] alt_payments { get; set; } - public string ttl { get; set; } - public string btcPayServerPluginVersion { get; set; } - public bool zk { get; set; } + public string Value { get; set; } + + public bool Zk { get; set; } } diff --git a/BTCPayServer.Plugins.Branta/Classes/Helper.cs b/BTCPayServer.Plugins.Branta/Classes/Helper.cs index fab96cb..1c64058 100644 --- a/BTCPayServer.Plugins.Branta/Classes/Helper.cs +++ b/BTCPayServer.Plugins.Branta/Classes/Helper.cs @@ -14,7 +14,7 @@ public static string GetVersion() public static void SetZeroKnowledgeParams(this CheckoutModel model, string payment, string secret) { - if (payment == null || secret == null) + if (payment == null || secret == null || model.PaymentMethodId != "BTC-CHAIN") { return; } diff --git a/BTCPayServer.Plugins.Branta/Services/BrantaService.cs b/BTCPayServer.Plugins.Branta/Services/BrantaService.cs index a03a9c2..7e082f1 100644 --- a/BTCPayServer.Plugins.Branta/Services/BrantaService.cs +++ b/BTCPayServer.Plugins.Branta/Services/BrantaService.cs @@ -115,8 +115,16 @@ private async Task CreateInvoiceAsync(InvoiceEntity btcPayInvoice, return 3; }) - .Select(pp => pp.Destination) - .Select(d => brantaSettings.EnableZeroKnowledge ? Helper.Encrypt(d, secret.ToString()) : d) + .Select(pp => + { + var isZk = brantaSettings.EnableZeroKnowledge && pp.PaymentMethodId == PaymentMethodId.TryParse("BTC"); + + return new Destination() + { + Value = isZk ? Helper.Encrypt(pp.Destination, secret.ToString()) : pp.Destination, + Zk = isZk + }; + }) .ToList(); var invoiceData = new InvoiceData() @@ -124,8 +132,9 @@ private async Task CreateInvoiceAsync(InvoiceEntity btcPayInvoice, DateCreated = now, InvoiceId = btcPayInvoice.Id, PaymentId = payments - .OrderBy(p => p.Length) - .First(), + .OrderBy(p => p.Value.Length) + .First() + .Value, Environment = brantaSettings.StagingEnabled ? Enums.ServerEnvironment.Staging : Enums.ServerEnvironment.Production, StoreId = btcPayInvoice.StoreId, ZeroKnowledgeSecret = secret @@ -148,15 +157,10 @@ private async Task CreateInvoiceAsync(InvoiceEntity btcPayInvoice, var paymentRequest = new Classes.PaymentRequest() { - payment = new Payment - { - description = brantaSettings.PostDescriptionEnabled ? GetDescription(btcPayInvoice) : null, - payment = payments.First(), - alt_payments = [.. payments.Skip(1)], - ttl = ttl.ToString(), - btcPayServerPluginVersion = Helper.GetVersion(), - zk = brantaSettings.EnableZeroKnowledge - } + Destinations = payments, + Description = brantaSettings.PostDescriptionEnabled ? GetDescription(btcPayInvoice) : null, + Ttl = ttl.ToString(), + BtcPayServerPluginVersion = Helper.GetVersion() }; await brantaClient.PostPaymentAsync(paymentRequest, brantaSettings); From fa5b4a7ca38ff0611d9d295d001bef4c19ff47cd Mon Sep 17 00:00:00 2001 From: Kyle McCullen Date: Fri, 24 Oct 2025 14:21:46 -0400 Subject: [PATCH 3/5] update test --- .../Services/BrantaServiceTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BTCPayServer.Plugins.Branta.Tests/Services/BrantaServiceTests.cs b/BTCPayServer.Plugins.Branta.Tests/Services/BrantaServiceTests.cs index 66954fe..ca09b32 100644 --- a/BTCPayServer.Plugins.Branta.Tests/Services/BrantaServiceTests.cs +++ b/BTCPayServer.Plugins.Branta.Tests/Services/BrantaServiceTests.cs @@ -178,7 +178,7 @@ public async Task CreateInvoiceIfNotExists_CreatesZeroKnowledgeInvoice() } [Fact] - public async Task CreateInvoiceIfNotExists_ProperlyAddsQueryParamsForLightningOnly() + public async Task CreateInvoiceIfNotExists_DoesNotAddZeroParamsLightningOnly() { var invoice = CreateInvoice("BTC-Lightning"); var checkoutModel = CreateCheckoutModel(invoice); @@ -187,8 +187,8 @@ public async Task CreateInvoiceIfNotExists_ProperlyAddsQueryParamsForLightningOn await _brantaService.CreateInvoiceIfNotExistsAsync(checkoutModel); - Assert.Contains("?branta_id", checkoutModel.InvoiceBitcoinUrlQR); - Assert.Contains("&branta_secret", checkoutModel.InvoiceBitcoinUrlQR); + Assert.DoesNotContain("?branta_id", checkoutModel.InvoiceBitcoinUrlQR); + Assert.DoesNotContain("&branta_secret", checkoutModel.InvoiceBitcoinUrlQR); } [Fact] From f54b4f5c887f110ffc2642d4030baaf1336a29b7 Mon Sep 17 00:00:00 2001 From: Kyle McCullen Date: Fri, 24 Oct 2025 14:23:41 -0400 Subject: [PATCH 4/5] test on merge into release branches --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe2dac7..891180a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build & Test on: pull_request: - branches: [main, develop] + branches: [main, develop, release/**] jobs: build-and-test: From 2e9d8db3c6c235ed16403386cc863be9f344b76c Mon Sep 17 00:00:00 2001 From: Kyle McCullen Date: Fri, 24 Oct 2025 14:32:51 -0400 Subject: [PATCH 5/5] update wording --- .../Services/BrantaServiceTests.cs | 3 +-- BTCPayServer.Plugins.Branta/Views/UIBranta/EditBranta.cshtml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/BTCPayServer.Plugins.Branta.Tests/Services/BrantaServiceTests.cs b/BTCPayServer.Plugins.Branta.Tests/Services/BrantaServiceTests.cs index ca09b32..a8477d1 100644 --- a/BTCPayServer.Plugins.Branta.Tests/Services/BrantaServiceTests.cs +++ b/BTCPayServer.Plugins.Branta.Tests/Services/BrantaServiceTests.cs @@ -178,7 +178,7 @@ public async Task CreateInvoiceIfNotExists_CreatesZeroKnowledgeInvoice() } [Fact] - public async Task CreateInvoiceIfNotExists_DoesNotAddZeroParamsLightningOnly() + public async Task CreateInvoiceIfNotExists_DoesNotAddZeroKnowledgeParamsBolt11() { var invoice = CreateInvoice("BTC-Lightning"); var checkoutModel = CreateCheckoutModel(invoice); @@ -205,7 +205,6 @@ public async Task CreateInvoiceIfNotExists_ShouldNotSetZeroKnowledgeIfRequestUns Assert.DoesNotContain("&branta_secret", checkoutModel.InvoiceBitcoinUrlQR); } - private InvoiceData GetSavedInvoiceData() { return _invoiceServiceMock.Invocations diff --git a/BTCPayServer.Plugins.Branta/Views/UIBranta/EditBranta.cshtml b/BTCPayServer.Plugins.Branta/Views/UIBranta/EditBranta.cshtml index a91dfbe..3491251 100644 --- a/BTCPayServer.Plugins.Branta/Views/UIBranta/EditBranta.cshtml +++ b/BTCPayServer.Plugins.Branta/Views/UIBranta/EditBranta.cshtml @@ -142,7 +142,7 @@ else
- +