Merge pull request #891 from Kukks/pay-button-language

Allow language parameter in pay button endpoint
This commit is contained in:
Nicolas Dorier 2019-06-26 13:27:52 +09:00 committed by GitHub
commit 9e354d7703
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3 deletions

View file

@ -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,17 @@ namespace BTCPayServer.Controllers
RedirectURL = model.BrowserRedirect,
FullNotifications = true
}, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken);
return Redirect(invoice.Data.Url);
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(additionalParamValues);
uriBuilder.Query = paramValues.ToString();
return Redirect(uriBuilder.Uri.AbsoluteUri);
}
}
}

View file

@ -30,6 +30,7 @@ namespace BTCPayServer.Models.StoreViewModels
public string NotifyEmail { get; set; }
public string StoreId { get; set; }
public string CheckoutQueryString { get; set; }
// Data that influences Pay Button UI, but not invoice creation
public string UrlRoot { get; set; }

View file

@ -1,4 +1,4 @@
@model PayButtonViewModel
@model PayButtonViewModel
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewData.SetActivePageAndTitle(StoreNavPages.PayButton);
@ -140,6 +140,24 @@
Finally <i>Browser Redirect</i> defines where BtcPayServer will redirect customer after puchase is completed.
</div>
</div>
<h3>Advanced</h3>
<br />
<div class="row">
<div class="col-lg-7">
<div class="form-group">
<label>Checkout Additional Query String</label>
<input name="checkoutQueryString" type="text" class="form-control" placeholder="(optional)"
v-model="srvModel.checkoutQueryString" v-on:change="inputChanges"
:class="{'is-invalid': errors.has('checkoutQueryString') }">
<small class="text-danger">{{ errors.first('checkoutQueryString') }}</small>
</div>
</div>
<div class="col-lg-5">
<br />
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, <kbd>lang=da-DK</kbd> would load the checkout page in Danishby default.
</div>
</div>
<hr />
<h3>Generated code</h3>
<div class="row" v-show="!errors.any()">

View file

@ -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 <input type="image" src="' + esc(srvModel.payButtonImageUrl) + '" name="submit" style="width:' + width +