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 class CreatePullPaymentRequest
{ {
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; }
[JsonProperty(ItemConverterType = typeof(NumericStringJsonConverter))] [JsonProperty(ItemConverterType = typeof(NumericStringJsonConverter))]
public decimal Amount { get; set; } public decimal Amount { get; set; }
public string Currency { get; set; } public string Currency { get; set; }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -119,9 +119,9 @@
<span class="text-nowrap">@Model.ResetIn</span> <span class="text-nowrap">@Model.ResetIn</span>
</p> </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>
</div> </div>

View file

@ -5,15 +5,25 @@
ViewData.SetActivePage(StoreNavPages.PullPayments, "New pull payment", Context.GetStoreData().Id); 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" /> <partial name="_StatusMessage" />
<h2 class="mt-1 mb-4">@ViewData["Title"]</h2> <h2 class="mt-1 mb-4">@ViewData["Title"]</h2>
<div class="row"> <form
<div class="col-xl-8 col-xxl-constrain"> method="post"
<form method="post" asp-route-walletId="@Context.GetRouteValue("walletId")"
asp-route-walletId="@Context.GetRouteValue("walletId")" asp-action="NewPullPayment">
asp-action="NewPullPayment"> <div class="row">
<div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label asp-for="Name" class="form-label"></label> <label asp-for="Name" class="form-label"></label>
<input asp-for="Name" class="form-control"/> <input asp-for="Name" class="form-control"/>
@ -44,6 +54,13 @@
} }
<span asp-validation-for="PaymentMethods" class="text-danger mt-0"></span> <span asp-validation-for="PaymentMethods" class="text-danger mt-0"></span>
</div> </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> <h5 class="mt-4 mb-2">Additional Options</h5>
<div class="form-group"> <div class="form-group">
@ -98,6 +115,6 @@
<div class="form-group"> <div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" id="Create"/> <input type="submit" value="Create" class="btn btn-primary" id="Create"/>
</div> </div>
</form> </div>
</div> </div>
</div> </form>

View file

@ -153,12 +153,26 @@
"wwwroot/payment-request-admin/**/*.js" "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", "outputFileName": "wwwroot/bundles/payment-request-admin-bundle.min.css",
"inputFiles": [ "inputFiles": [
"wwwroot/vendor/summernote/summernote-bs5.css" "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", "outputFileName": "wwwroot/bundles/payment-request-bundle.min.js",
"inputFiles": [ "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", "description": "The name of the pull payment",
"nullable": true "nullable": true
}, },
"description": {
"type": "string",
"description": "The description of the pull payment",
"nullable": true
},
"amount": { "amount": {
"type": "string", "type": "string",
"format": "decimal", "format": "decimal",
@ -645,7 +650,11 @@
}, },
"name": { "name": {
"type": "string", "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": { "currency": {
"type": "string", "type": "string",