mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Returning whole invoice serialized as JSON on $ajax call
This commit is contained in:
@@ -125,9 +125,18 @@ namespace BTCPayServer.Controllers
|
|||||||
id = invoiceId;
|
id = invoiceId;
|
||||||
////
|
////
|
||||||
|
|
||||||
var invoice = await _InvoiceRepository.GetInvoice(null, invoiceId);
|
var model = await GetInvoiceModel(invoiceId);
|
||||||
if(invoice == null)
|
if (model == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
return View(nameof(Checkout), model);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<PaymentModel> GetInvoiceModel(string invoiceId)
|
||||||
|
{
|
||||||
|
var invoice = await _InvoiceRepository.GetInvoice(null, invoiceId);
|
||||||
|
if (invoice == null)
|
||||||
|
return null;
|
||||||
var store = await _StoreRepository.FindStore(invoice.StoreId);
|
var store = await _StoreRepository.FindStore(invoice.StoreId);
|
||||||
var dto = invoice.EntityToDTO();
|
var dto = invoice.EntityToDTO();
|
||||||
|
|
||||||
@@ -154,11 +163,9 @@ namespace BTCPayServer.Controllers
|
|||||||
status = invoice.Status
|
status = invoice.Status
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var expiration = TimeSpan.FromSeconds(model.expirationSeconds);
|
||||||
|
|
||||||
var expiration = TimeSpan.FromSeconds((double)model.expirationSeconds);
|
|
||||||
model.TimeLeft = PrettyPrint(expiration);
|
model.TimeLeft = PrettyPrint(expiration);
|
||||||
return View(nameof(Checkout), model);
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string PrettyPrint(TimeSpan expiration)
|
private string PrettyPrint(TimeSpan expiration)
|
||||||
@@ -176,10 +183,10 @@ namespace BTCPayServer.Controllers
|
|||||||
[Route("i/{invoiceId}/status")]
|
[Route("i/{invoiceId}/status")]
|
||||||
public async Task<IActionResult> GetStatus(string invoiceId)
|
public async Task<IActionResult> GetStatus(string invoiceId)
|
||||||
{
|
{
|
||||||
var invoice = await _InvoiceRepository.GetInvoice(null, invoiceId);
|
var model = await GetInvoiceModel(invoiceId);
|
||||||
if(invoice == null)
|
if(model == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
return Content(invoice.Status);
|
return Json(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|||||||
@@ -158,7 +158,9 @@ $("#copy-tab").click(function () {
|
|||||||
var oldStat = srvModel.status;
|
var oldStat = srvModel.status;
|
||||||
onDataCallback(srvModel.status);
|
onDataCallback(srvModel.status);
|
||||||
|
|
||||||
function onDataCallback(newStatus) {
|
function onDataCallback(jsonData) {
|
||||||
|
var newStatus = jsonData.status;
|
||||||
|
|
||||||
if (oldStat != newStatus) {
|
if (oldStat != newStatus) {
|
||||||
oldStat = newStatus;
|
oldStat = newStatus;
|
||||||
window.parent.postMessage({ "invoiceId": srvModel.invoiceId, "status": newStatus }, "*");
|
window.parent.postMessage({ "invoiceId": srvModel.invoiceId, "status": newStatus }, "*");
|
||||||
@@ -206,8 +208,7 @@ var watcher = setInterval(function () {
|
|||||||
url: path,
|
url: path,
|
||||||
type: "GET"
|
type: "GET"
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
status = data;
|
onDataCallback(data);
|
||||||
onDataCallback(status);
|
|
||||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user