mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-13 11:35:51 +01:00
unarchive endpoint + formatting
This commit is contained in:
parent
34e76494e3
commit
cb5601c68b
4 changed files with 48 additions and 86 deletions
|
@ -8,17 +8,9 @@ namespace BTCPayServer.Client.Models
|
|||
public class CreateInvoiceRequest
|
||||
{
|
||||
[JsonProperty(ItemConverterType = typeof(DecimalDoubleStringJsonConverter))]
|
||||
public decimal Amount
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
public string Currency
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string Currency { get; set; }
|
||||
|
||||
public ProductInformation Metadata { get; set; }
|
||||
|
||||
|
@ -46,67 +38,31 @@ namespace BTCPayServer.Client.Models
|
|||
public class BuyerInformation
|
||||
{
|
||||
[JsonProperty(PropertyName = "buyerName")]
|
||||
public string BuyerName
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerName { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "buyerEmail")]
|
||||
public string BuyerEmail
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerEmail { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "buyerCountry")]
|
||||
public string BuyerCountry
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerCountry { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "buyerZip")]
|
||||
public string BuyerZip
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerZip { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "buyerState")]
|
||||
public string BuyerState
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerState { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "buyerCity")]
|
||||
public string BuyerCity
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerCity { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "buyerAddress2")]
|
||||
public string BuyerAddress2
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerAddress2 { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "buyerAddress1")]
|
||||
public string BuyerAddress1
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerAddress1 { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "buyerPhone")]
|
||||
public string BuyerPhone
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string BuyerPhone { get; set; }
|
||||
}
|
||||
|
||||
public class ProductInformation
|
||||
|
@ -114,29 +70,13 @@ namespace BTCPayServer.Client.Models
|
|||
public string OrderId { get; set; }
|
||||
public string PosData { get; set; }
|
||||
|
||||
public string ItemDesc
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string ItemDesc { get; set; }
|
||||
|
||||
public string ItemCode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string ItemCode { get; set; }
|
||||
|
||||
public bool Physical
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public bool Physical { get; set; }
|
||||
|
||||
public decimal? TaxIncluded
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public decimal? TaxIncluded { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
7
BTCPayServer.Client/Models/UpdateInvoiceRequest.cs
Normal file
7
BTCPayServer.Client/Models/UpdateInvoiceRequest.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace BTCPayServer.Client.Models
|
||||
{
|
||||
public class UpdateInvoiceRequest
|
||||
{
|
||||
public bool Archived { get; set; }
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Client;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Payments;
|
||||
using BTCPayServer.Security;
|
||||
using BTCPayServer.Services.Invoices;
|
||||
|
@ -9,7 +10,6 @@ using BTCPayServer.Validation;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using NBitcoin;
|
||||
using NBitpayClient;
|
||||
using CreateInvoiceRequest = BTCPayServer.Client.Models.CreateInvoiceRequest;
|
||||
|
@ -42,7 +42,11 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
var invoices = await _invoiceRepository.GetInvoices(new InvoiceQuery() {StoreId = new[] {store.Id}});
|
||||
var invoices =
|
||||
await _invoiceRepository.GetInvoices(new InvoiceQuery()
|
||||
{
|
||||
StoreId = new[] {store.Id}, IncludeArchived = false
|
||||
});
|
||||
|
||||
return Ok(invoices.Select(ToModel));
|
||||
}
|
||||
|
@ -79,13 +83,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
var invoice = await _invoiceRepository.GetInvoice(invoiceId, true);
|
||||
if (invoice.StoreId != store.Id)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
await _invoiceRepository.ToggleInvoiceArchival(invoiceId, true);
|
||||
await _invoiceRepository.ToggleInvoiceArchival(invoiceId, true, storeId);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
@ -145,6 +143,21 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
return Ok(ToModel(invoice));
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings,
|
||||
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpPost("~/api/v1/stores/{storeId}/invoices/{invoiceId}")]
|
||||
public async Task<IActionResult> UpdateInvoice(string storeId, string invoiceId, UpdateInvoiceRequest request)
|
||||
{
|
||||
var store = HttpContext.GetStoreData();
|
||||
if (store == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
await _invoiceRepository.ToggleInvoiceArchival(invoiceId, request.Archived, storeId);
|
||||
return await GetInvoice(storeId, invoiceId);
|
||||
}
|
||||
|
||||
public InvoiceData ToModel(InvoiceEntity entity)
|
||||
{
|
||||
return new InvoiceData()
|
||||
|
|
|
@ -428,12 +428,14 @@ retry:
|
|||
}
|
||||
}
|
||||
|
||||
public async Task ToggleInvoiceArchival(string invoiceId, bool archived)
|
||||
public async Task ToggleInvoiceArchival(string invoiceId, bool archived, string storeId = null)
|
||||
{
|
||||
using (var context = _ContextFactory.CreateContext())
|
||||
{
|
||||
var invoiceData = await context.FindAsync<InvoiceData>(invoiceId).ConfigureAwait(false);
|
||||
if (invoiceData == null || invoiceData.Archived == archived)
|
||||
if (invoiceData == null || invoiceData.Archived == archived ||
|
||||
(storeId != null &&
|
||||
invoiceData.StoreDataId.Equals(storeId, StringComparison.InvariantCultureIgnoreCase)))
|
||||
return;
|
||||
invoiceData.Archived = archived;
|
||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||
|
|
Loading…
Add table
Reference in a new issue