Add ability to add description to pull payment (#3363)

* Add ability to add description to pull payment

close #2625

* Add API support

* Remove 'Model.Description != "<br>"'
This commit is contained in:
Umar Bolatov 2022-02-09 21:54:00 -08:00 committed by GitHub
parent da9a6b835a
commit f06199230c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 66 additions and 11 deletions

View file

@ -8,6 +8,7 @@ namespace BTCPayServer.Client.Models
public class CreatePullPaymentRequest
{
public string Name { get; set; }
public string Description { get; set; }
[JsonProperty(ItemConverterType = typeof(NumericStringJsonConverter))]
public decimal Amount { get; set; }
public string Currency { get; set; }

View file

@ -13,6 +13,7 @@ namespace BTCPayServer.Client.Models
public DateTimeOffset? ExpiresAt { get; set; }
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Currency { get; set; }
[JsonConverter(typeof(NumericStringJsonConverter))]
public decimal Amount { get; set; }

View file

@ -361,6 +361,7 @@ namespace BTCPayServer.Tests
var result = await client.CreatePullPayment(storeId, new Client.Models.CreatePullPaymentRequest()
{
Name = "Test",
Description = "Test description",
Amount = 12.3m,
Currency = "BTC",
PaymentMethods = new[] { "BTC" }
@ -369,6 +370,7 @@ namespace BTCPayServer.Tests
void VerifyResult()
{
Assert.Equal("Test", result.Name);
Assert.Equal("Test description", result.Description);
Assert.Null(result.Period);
// If it contains ? it means that we are resolving an unknown route with the link generator
Assert.DoesNotContain("?", result.ViewLink);

View file

@ -133,6 +133,7 @@ namespace BTCPayServer.Controllers.Greenfield
Period = request.Period,
BOLT11Expiration = request.BOLT11Expiration,
Name = request.Name,
Description = request.Description,
Amount = request.Amount,
Currency = request.Currency,
StoreId = storeId,
@ -152,6 +153,7 @@ namespace BTCPayServer.Controllers.Greenfield
ExpiresAt = pp.EndDate,
Amount = ppBlob.Limit,
Name = ppBlob.Name,
Description = ppBlob.Description,
Currency = ppBlob.Currency,
Period = ppBlob.Period,
Archived = pp.Archived,

View file

@ -129,6 +129,7 @@ namespace BTCPayServer.Controllers
await _pullPaymentService.CreatePullPayment(new HostedServices.CreatePullPayment()
{
Name = model.Name,
Description = model.Description,
Amount = model.Amount,
Currency = model.Currency,
StoreId = storeId,

View file

@ -10,6 +10,7 @@ namespace BTCPayServer.Data
public class PullPaymentBlob
{
public string Name { get; set; }
public string Description { get; set; }
public string Currency { get; set; }
public int Divisibility { get; set; }
[JsonConverter(typeof(NumericStringJsonConverter))]

View file

@ -28,6 +28,7 @@ namespace BTCPayServer.HostedServices
public DateTimeOffset? StartsAt { get; set; }
public string StoreId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Amount { get; set; }
public string Currency { get; set; }
public string CustomCSSLink { get; set; }
@ -103,6 +104,7 @@ namespace BTCPayServer.HostedServices
o.SetBlob(new PullPaymentBlob()
{
Name = create.Name ?? string.Empty,
Description = create.Description ?? string.Empty,
Currency = create.Currency,
Limit = create.Amount,
Period = o.Period is long periodSeconds ? (TimeSpan?)TimeSpan.FromSeconds(periodSeconds) : null,
@ -110,7 +112,7 @@ namespace BTCPayServer.HostedServices
View = new PullPaymentBlob.PullPaymentView()
{
Title = create.Name ?? string.Empty,
Description = string.Empty,
Description = create.Description ?? string.Empty,
CustomCSSLink = create.CustomCSSLink,
Email = null,
EmbeddedCSS = create.EmbeddedCSS,

View file

@ -24,6 +24,7 @@ namespace BTCPayServer.Models
SelectedPaymentMethod = PaymentMethods.First().ToString();
Archived = data.Archived;
Title = blob.View.Title;
Description = blob.View.Description;
Amount = blob.Limit;
Currency = blob.Currency;
Description = blob.View.Description;

View file

@ -35,6 +35,7 @@ namespace BTCPayServer.Models.WalletViewModels
{
[MaxLength(30)]
public string Name { get; set; }
public string Description { get; set; }
[Required]
public decimal Amount
{

View file

@ -119,9 +119,9 @@
<span class="text-nowrap">@Model.ResetIn</span>
</p>
}
@if (!string.IsNullOrEmpty(Model.Description) && Model.Description != "<br>")
@if (!string.IsNullOrEmpty(Model.Description))
{
<div>@Safe.Raw(Model.Description)</div>
<div class="mt-4">@Safe.Raw(Model.Description)</div>
}
</div>
</div>

View file

@ -5,15 +5,25 @@
ViewData.SetActivePage(StoreNavPages.PullPayments, "New pull payment", Context.GetStoreData().Id);
}
@section PageHeadContent {
<bundle name="wwwroot/bundles/pull-payment-admin-bundle.min.css" asp-append-version="true"></bundle>
}
@section PageFootContent {
<partial name="_ValidationScriptsPartial" />
<bundle name="wwwroot/bundles/pull-payment-admin-bundle.min.js" asp-append-version="true"></bundle>
}
<partial name="_StatusMessage" />
<h2 class="mt-1 mb-4">@ViewData["Title"]</h2>
<div class="row">
<div class="col-xl-8 col-xxl-constrain">
<form method="post"
asp-route-walletId="@Context.GetRouteValue("walletId")"
asp-action="NewPullPayment">
<form
method="post"
asp-route-walletId="@Context.GetRouteValue("walletId")"
asp-action="NewPullPayment">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label asp-for="Name" class="form-label"></label>
<input asp-for="Name" class="form-control"/>
@ -44,6 +54,13 @@
}
<span asp-validation-for="PaymentMethods" class="text-danger mt-0"></span>
</div>
</div>
<div class="col-lg-9">
<div class="form-group mb-4">
<label asp-for="Description" class="form-label"></label>
<textarea asp-for="Description" class="form-control richtext"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<h5 class="mt-4 mb-2">Additional Options</h5>
<div class="form-group">
@ -98,6 +115,6 @@
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" id="Create"/>
</div>
</form>
</div>
</div>
</div>
</form>

View file

@ -153,12 +153,26 @@
"wwwroot/payment-request-admin/**/*.js"
]
},
{
"outputFileName": "wwwroot/bundles/pull-payment-admin-bundle.min.js",
"inputFiles": [
"wwwroot/js/summernote-options.js",
"wwwroot/vendor/summernote/summernote-bs5.js",
"wwwroot/pull-payment-admin/**/*.js"
]
},
{
"outputFileName": "wwwroot/bundles/payment-request-admin-bundle.min.css",
"inputFiles": [
"wwwroot/vendor/summernote/summernote-bs5.css"
]
},
{
"outputFileName": "wwwroot/bundles/pull-payment-admin-bundle.min.css",
"inputFiles": [
"wwwroot/vendor/summernote/summernote-bs5.css"
]
},
{
"outputFileName": "wwwroot/bundles/payment-request-bundle.min.js",
"inputFiles": [

View file

@ -0,0 +1,3 @@
document.addEventListener('DOMContentLoaded', () => {
$('.richtext').summernote(window.summernoteOptions())
})

View file

@ -63,6 +63,11 @@
"description": "The name of the pull payment",
"nullable": true
},
"description": {
"type": "string",
"description": "The description of the pull payment",
"nullable": true
},
"amount": {
"type": "string",
"format": "decimal",
@ -645,7 +650,11 @@
},
"name": {
"type": "string",
"description": "Payment method of of the pull payment"
"description": "Name given to pull payment when it was created"
},
"description": {
"type": "string",
"description": "Description given to pull payment when it was created"
},
"currency": {
"type": "string",