mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Add PendingInvoice inside CreateInvoice
This commit is contained in:
@@ -23,11 +23,11 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("invoices/{invoiceId}")]
|
[Route("invoices/{invoiceId}")]
|
||||||
public async Task<IActionResult> Invoice(string invoiceId, string command)
|
public IActionResult Invoice(string invoiceId, string command)
|
||||||
{
|
{
|
||||||
if (command == "refresh")
|
if (command == "refresh")
|
||||||
{
|
{
|
||||||
await _Watcher.WatchAsync(invoiceId, true);
|
_Watcher.Watch(invoiceId);
|
||||||
}
|
}
|
||||||
StatusMessage = "Invoice is state is being refreshed, please refresh the page soon...";
|
StatusMessage = "Invoice is state is being refreshed, please refresh the page soon...";
|
||||||
return RedirectToAction(nameof(Invoice), new
|
return RedirectToAction(nameof(Invoice), new
|
||||||
|
|||||||
@@ -118,9 +118,8 @@ namespace BTCPayServer.Controllers
|
|||||||
entity.Rate = (double)await getRate;
|
entity.Rate = (double)await getRate;
|
||||||
entity.PosData = invoice.PosData;
|
entity.PosData = invoice.PosData;
|
||||||
entity.DepositAddress = await getAddress;
|
entity.DepositAddress = await getAddress;
|
||||||
|
|
||||||
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity);
|
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity);
|
||||||
await _Watcher.WatchAsync(entity.Id);
|
_Watcher.Watch(entity.Id);
|
||||||
var resp = entity.EntityToDTO();
|
var resp = entity.EntityToDTO();
|
||||||
return new DataWrapper<InvoiceResponse>(resp) { Facade = "pos/invoice" };
|
return new DataWrapper<InvoiceResponse>(resp) { Facade = "pos/invoice" };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,15 +56,6 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
_ContextFactory = contextFactory;
|
_ContextFactory = contextFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddPendingInvoice(string invoiceId)
|
|
||||||
{
|
|
||||||
using (var ctx = _ContextFactory.CreateContext())
|
|
||||||
{
|
|
||||||
ctx.PendingInvoices.Add(new PendingInvoiceData() { Id = invoiceId });
|
|
||||||
await ctx.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> RemovePendingInvoice(string invoiceId)
|
public async Task<bool> RemovePendingInvoice(string invoiceId)
|
||||||
{
|
{
|
||||||
using (var ctx = _ContextFactory.CreateContext())
|
using (var ctx = _ContextFactory.CreateContext())
|
||||||
@@ -119,7 +110,7 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
invoice.StoreId = storeId;
|
invoice.StoreId = storeId;
|
||||||
using (var context = _ContextFactory.CreateContext())
|
using (var context = _ContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
context.Add(new InvoiceData()
|
context.Invoices.Add(new InvoiceData()
|
||||||
{
|
{
|
||||||
StoreDataId = storeId,
|
StoreDataId = storeId,
|
||||||
Id = invoice.Id,
|
Id = invoice.Id,
|
||||||
@@ -130,20 +121,19 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
ItemCode = invoice.ProductInformation.ItemCode,
|
ItemCode = invoice.ProductInformation.ItemCode,
|
||||||
CustomerEmail = invoice.RefundMail
|
CustomerEmail = invoice.RefundMail
|
||||||
});
|
});
|
||||||
|
|
||||||
context.AddressInvoices.Add(new AddressInvoiceData()
|
context.AddressInvoices.Add(new AddressInvoiceData()
|
||||||
{
|
{
|
||||||
Address = invoice.DepositAddress.ScriptPubKey.Hash.ToString(),
|
Address = invoice.DepositAddress.ScriptPubKey.Hash.ToString(),
|
||||||
InvoiceDataId = invoice.Id,
|
InvoiceDataId = invoice.Id,
|
||||||
CreatedTime = DateTimeOffset.UtcNow,
|
CreatedTime = DateTimeOffset.UtcNow,
|
||||||
});
|
});
|
||||||
|
|
||||||
context.HistoricalAddressInvoices.Add(new HistoricalAddressInvoiceData()
|
context.HistoricalAddressInvoices.Add(new HistoricalAddressInvoiceData()
|
||||||
{
|
{
|
||||||
InvoiceDataId = invoice.Id,
|
InvoiceDataId = invoice.Id,
|
||||||
Address = invoice.DepositAddress.ToString(),
|
Address = invoice.DepositAddress.ToString(),
|
||||||
Assigned = DateTimeOffset.UtcNow
|
Assigned = DateTimeOffset.UtcNow
|
||||||
});
|
});
|
||||||
|
context.PendingInvoices.Add(new PendingInvoiceData() { Id = invoice.Id });
|
||||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -302,12 +302,10 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WatchAsync(string invoiceId, bool singleShot = false)
|
public void Watch(string invoiceId)
|
||||||
{
|
{
|
||||||
if (invoiceId == null)
|
if (invoiceId == null)
|
||||||
throw new ArgumentNullException(nameof(invoiceId));
|
throw new ArgumentNullException(nameof(invoiceId));
|
||||||
if (!singleShot)
|
|
||||||
await _InvoiceRepository.AddPendingInvoice(invoiceId).ConfigureAwait(false);
|
|
||||||
_WatchRequests.Add(invoiceId);
|
_WatchRequests.Add(invoiceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user