From b808aa4971ae02c0ce6b74b74238be75b6cf9737 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Tue, 18 Jun 2019 18:31:20 +0200 Subject: [PATCH 1/2] allow language parameter in pay button endpoint --- BTCPayServer/Controllers/PublicController.cs | 11 ++++++++++- .../Models/StoreViewModels/PayButtonViewModel.cs | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/Controllers/PublicController.cs b/BTCPayServer/Controllers/PublicController.cs index 9faef2565..975e29e18 100644 --- a/BTCPayServer/Controllers/PublicController.cs +++ b/BTCPayServer/Controllers/PublicController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using System.Web; using BTCPayServer.Filters; using BTCPayServer.Models; using BTCPayServer.Models.StoreViewModels; @@ -58,7 +59,15 @@ namespace BTCPayServer.Controllers RedirectURL = model.BrowserRedirect, FullNotifications = true }, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken); - return Redirect(invoice.Data.Url); + if (string.IsNullOrEmpty(model.Language)) + { + return Redirect(invoice.Data.Url); + } + var uriBuilder = new UriBuilder(invoice.Data.Url); + var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query); + paramValues.Add("lang", model.Language); + uriBuilder.Query = paramValues.ToString(); + return Redirect(uriBuilder.Uri.AbsoluteUri); } } } diff --git a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs index dc5c1ea23..122d476d8 100644 --- a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs @@ -30,6 +30,7 @@ namespace BTCPayServer.Models.StoreViewModels public string NotifyEmail { get; set; } public string StoreId { get; set; } + public string Language { get; set; } // Data that influences Pay Button UI, but not invoice creation public string UrlRoot { get; set; } From 11670d0c0f5c021b6640245e276a80eff31315ef Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 25 Jun 2019 21:01:37 +0200 Subject: [PATCH 2/2] make checkout param more generic and add it to pay button generator --- BTCPayServer/Controllers/PublicController.cs | 6 ++++-- .../StoreViewModels/PayButtonViewModel.cs | 2 +- BTCPayServer/Views/Stores/PayButton.cshtml | 20 ++++++++++++++++++- BTCPayServer/wwwroot/paybutton/paybutton.js | 5 ++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Controllers/PublicController.cs b/BTCPayServer/Controllers/PublicController.cs index 975e29e18..2d458f5f5 100644 --- a/BTCPayServer/Controllers/PublicController.cs +++ b/BTCPayServer/Controllers/PublicController.cs @@ -59,13 +59,15 @@ namespace BTCPayServer.Controllers RedirectURL = model.BrowserRedirect, FullNotifications = true }, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken); - if (string.IsNullOrEmpty(model.Language)) + if (string.IsNullOrEmpty(model.CheckoutQueryString)) { return Redirect(invoice.Data.Url); } + + var additionalParamValues = HttpUtility.ParseQueryString(model.CheckoutQueryString); var uriBuilder = new UriBuilder(invoice.Data.Url); var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query); - paramValues.Add("lang", model.Language); + paramValues.Add(additionalParamValues); uriBuilder.Query = paramValues.ToString(); return Redirect(uriBuilder.Uri.AbsoluteUri); } diff --git a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs index 122d476d8..126969d75 100644 --- a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs @@ -30,7 +30,7 @@ namespace BTCPayServer.Models.StoreViewModels public string NotifyEmail { get; set; } public string StoreId { get; set; } - public string Language { get; set; } + public string CheckoutQueryString { get; set; } // Data that influences Pay Button UI, but not invoice creation public string UrlRoot { get; set; } diff --git a/BTCPayServer/Views/Stores/PayButton.cshtml b/BTCPayServer/Views/Stores/PayButton.cshtml index 87c4a9b50..067c732d9 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -1,4 +1,4 @@ -@model PayButtonViewModel +@model PayButtonViewModel @{ Layout = "../Shared/_NavLayout.cshtml"; ViewData.SetActivePageAndTitle(StoreNavPages.PayButton); @@ -140,6 +140,24 @@ Finally Browser Redirect defines where BtcPayServer will redirect customer after puchase is completed. +

Advanced

+
+
+
+
+ + + {{ errors.first('checkoutQueryString') }} +
+
+
+
+ This parameter allows you to specify additional query string paramters that should be appended to the checkout page once the invoice is created. For example, lang=da-DK would load the checkout page in Danishby default. + +
+

Generated code

diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index eda819f62..ccdd0176d 100644 --- a/BTCPayServer/wwwroot/paybutton/paybutton.js +++ b/BTCPayServer/wwwroot/paybutton/paybutton.js @@ -26,7 +26,7 @@ function esc(input) { } Vue.use(VeeValidate); -const dictionary = { +var dictionary = { en: { attributes: { price: 'Price', checkoutDesc: 'Checkout Description', orderId: 'Order Id', @@ -96,6 +96,9 @@ function inputChanges(event, buttonSize) { } if (srvModel.notifyEmail) { html += addinput("notifyEmail", srvModel.notifyEmail); + } + if (srvModel.checkoutQueryString) { + html += addinput("checkoutQueryString", srvModel.checkoutQueryString); } html += '\n