mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
unarchive endpoint + formatting
This commit is contained in:
@@ -8,17 +8,9 @@ namespace BTCPayServer.Client.Models
|
|||||||
public class CreateInvoiceRequest
|
public class CreateInvoiceRequest
|
||||||
{
|
{
|
||||||
[JsonProperty(ItemConverterType = typeof(DecimalDoubleStringJsonConverter))]
|
[JsonProperty(ItemConverterType = typeof(DecimalDoubleStringJsonConverter))]
|
||||||
public decimal Amount
|
public decimal Amount { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Currency
|
public string Currency { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductInformation Metadata { get; set; }
|
public ProductInformation Metadata { get; set; }
|
||||||
|
|
||||||
@@ -46,67 +38,31 @@ namespace BTCPayServer.Client.Models
|
|||||||
public class BuyerInformation
|
public class BuyerInformation
|
||||||
{
|
{
|
||||||
[JsonProperty(PropertyName = "buyerName")]
|
[JsonProperty(PropertyName = "buyerName")]
|
||||||
public string BuyerName
|
public string BuyerName { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "buyerEmail")]
|
[JsonProperty(PropertyName = "buyerEmail")]
|
||||||
public string BuyerEmail
|
public string BuyerEmail { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "buyerCountry")]
|
[JsonProperty(PropertyName = "buyerCountry")]
|
||||||
public string BuyerCountry
|
public string BuyerCountry { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "buyerZip")]
|
[JsonProperty(PropertyName = "buyerZip")]
|
||||||
public string BuyerZip
|
public string BuyerZip { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "buyerState")]
|
[JsonProperty(PropertyName = "buyerState")]
|
||||||
public string BuyerState
|
public string BuyerState { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "buyerCity")]
|
[JsonProperty(PropertyName = "buyerCity")]
|
||||||
public string BuyerCity
|
public string BuyerCity { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "buyerAddress2")]
|
[JsonProperty(PropertyName = "buyerAddress2")]
|
||||||
public string BuyerAddress2
|
public string BuyerAddress2 { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "buyerAddress1")]
|
[JsonProperty(PropertyName = "buyerAddress1")]
|
||||||
public string BuyerAddress1
|
public string BuyerAddress1 { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "buyerPhone")]
|
[JsonProperty(PropertyName = "buyerPhone")]
|
||||||
public string BuyerPhone
|
public string BuyerPhone { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProductInformation
|
public class ProductInformation
|
||||||
@@ -114,29 +70,13 @@ namespace BTCPayServer.Client.Models
|
|||||||
public string OrderId { get; set; }
|
public string OrderId { get; set; }
|
||||||
public string PosData { get; set; }
|
public string PosData { get; set; }
|
||||||
|
|
||||||
public string ItemDesc
|
public string ItemDesc { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ItemCode
|
public string ItemCode { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Physical
|
public bool Physical { get; set; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public decimal? TaxIncluded
|
public decimal? TaxIncluded { get; set; }
|
||||||
{
|
|
||||||
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.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Client;
|
using BTCPayServer.Client;
|
||||||
|
using BTCPayServer.Client.Models;
|
||||||
using BTCPayServer.Payments;
|
using BTCPayServer.Payments;
|
||||||
using BTCPayServer.Security;
|
using BTCPayServer.Security;
|
||||||
using BTCPayServer.Services.Invoices;
|
using BTCPayServer.Services.Invoices;
|
||||||
@@ -9,7 +10,6 @@ using BTCPayServer.Validation;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
using NBitpayClient;
|
using NBitpayClient;
|
||||||
using CreateInvoiceRequest = BTCPayServer.Client.Models.CreateInvoiceRequest;
|
using CreateInvoiceRequest = BTCPayServer.Client.Models.CreateInvoiceRequest;
|
||||||
@@ -42,7 +42,11 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
return NotFound();
|
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));
|
return Ok(invoices.Select(ToModel));
|
||||||
}
|
}
|
||||||
@@ -79,13 +83,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var invoice = await _invoiceRepository.GetInvoice(invoiceId, true);
|
await _invoiceRepository.ToggleInvoiceArchival(invoiceId, true, storeId);
|
||||||
if (invoice.StoreId != store.Id)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _invoiceRepository.ToggleInvoiceArchival(invoiceId, true);
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +143,21 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
return Ok(ToModel(invoice));
|
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)
|
public InvoiceData ToModel(InvoiceEntity entity)
|
||||||
{
|
{
|
||||||
return new InvoiceData()
|
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())
|
using (var context = _ContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
var invoiceData = await context.FindAsync<InvoiceData>(invoiceId).ConfigureAwait(false);
|
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;
|
return;
|
||||||
invoiceData.Archived = archived;
|
invoiceData.Archived = archived;
|
||||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user