Add PendingInvoice inside CreateInvoice

This commit is contained in:
nicolas.dorier 2017-11-12 23:51:14 +09:00
parent a29a8f7ed9
commit 479fc50d9a
4 changed files with 6 additions and 19 deletions

View file

@ -23,11 +23,11 @@ namespace BTCPayServer.Controllers
[HttpPost]
[Route("invoices/{invoiceId}")]
public async Task<IActionResult> Invoice(string invoiceId, string command)
public IActionResult Invoice(string invoiceId, string command)
{
if (command == "refresh")
{
await _Watcher.WatchAsync(invoiceId, true);
_Watcher.Watch(invoiceId);
}
StatusMessage = "Invoice is state is being refreshed, please refresh the page soon...";
return RedirectToAction(nameof(Invoice), new

View file

@ -118,9 +118,8 @@ namespace BTCPayServer.Controllers
entity.Rate = (double)await getRate;
entity.PosData = invoice.PosData;
entity.DepositAddress = await getAddress;
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity);
await _Watcher.WatchAsync(entity.Id);
_Watcher.Watch(entity.Id);
var resp = entity.EntityToDTO();
return new DataWrapper<InvoiceResponse>(resp) { Facade = "pos/invoice" };
}

View file

@ -56,15 +56,6 @@ namespace BTCPayServer.Services.Invoices
_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)
{
using (var ctx = _ContextFactory.CreateContext())
@ -119,7 +110,7 @@ namespace BTCPayServer.Services.Invoices
invoice.StoreId = storeId;
using (var context = _ContextFactory.CreateContext())
{
context.Add(new InvoiceData()
context.Invoices.Add(new InvoiceData()
{
StoreDataId = storeId,
Id = invoice.Id,
@ -130,20 +121,19 @@ namespace BTCPayServer.Services.Invoices
ItemCode = invoice.ProductInformation.ItemCode,
CustomerEmail = invoice.RefundMail
});
context.AddressInvoices.Add(new AddressInvoiceData()
{
Address = invoice.DepositAddress.ScriptPubKey.Hash.ToString(),
InvoiceDataId = invoice.Id,
CreatedTime = DateTimeOffset.UtcNow,
});
context.HistoricalAddressInvoices.Add(new HistoricalAddressInvoiceData()
{
InvoiceDataId = invoice.Id,
Address = invoice.DepositAddress.ToString(),
Assigned = DateTimeOffset.UtcNow
});
context.PendingInvoices.Add(new PendingInvoiceData() { Id = invoice.Id });
await context.SaveChangesAsync().ConfigureAwait(false);
}

View file

@ -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)
throw new ArgumentNullException(nameof(invoiceId));
if (!singleShot)
await _InvoiceRepository.AddPendingInvoice(invoiceId).ConfigureAwait(false);
_WatchRequests.Add(invoiceId);
}