mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-21 14:04:12 +01:00
Fix final bugs
This commit is contained in:
parent
ad25a2ed08
commit
f5d366cf7f
8 changed files with 59 additions and 38 deletions
|
@ -34,8 +34,6 @@ namespace BTCPayServer.Controllers
|
|||
private readonly InvoiceController _InvoiceController;
|
||||
private readonly UserManager<ApplicationUser> _UserManager;
|
||||
private readonly StoreRepository _StoreRepository;
|
||||
private readonly RateFetcher _RateFetcher;
|
||||
private readonly BTCPayNetworkProvider _BtcPayNetworkProvider;
|
||||
private readonly PaymentRequestRepository _PaymentRequestRepository;
|
||||
private readonly PaymentRequestService _PaymentRequestService;
|
||||
private readonly EventAggregator _EventAggregator;
|
||||
|
@ -46,8 +44,6 @@ namespace BTCPayServer.Controllers
|
|||
InvoiceController invoiceController,
|
||||
UserManager<ApplicationUser> userManager,
|
||||
StoreRepository storeRepository,
|
||||
RateFetcher rateFetcher,
|
||||
BTCPayNetworkProvider btcPayNetworkProvider,
|
||||
PaymentRequestRepository paymentRequestRepository,
|
||||
PaymentRequestService paymentRequestService,
|
||||
EventAggregator eventAggregator,
|
||||
|
@ -57,8 +53,6 @@ namespace BTCPayServer.Controllers
|
|||
_InvoiceController = invoiceController;
|
||||
_UserManager = userManager;
|
||||
_StoreRepository = storeRepository;
|
||||
_RateFetcher = rateFetcher;
|
||||
_BtcPayNetworkProvider = btcPayNetworkProvider;
|
||||
_PaymentRequestRepository = paymentRequestRepository;
|
||||
_PaymentRequestService = paymentRequestService;
|
||||
_EventAggregator = eventAggregator;
|
||||
|
@ -135,6 +129,8 @@ namespace BTCPayServer.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
var oldStatus = data?.Status ?? PaymentRequestData.PaymentRequestStatus.Creating;
|
||||
|
||||
if (data != null && data.Status != PaymentRequestData.PaymentRequestStatus.Creating)
|
||||
{
|
||||
return RedirectToAction("ViewPaymentRequest", new
|
||||
|
@ -176,8 +172,11 @@ namespace BTCPayServer.Controllers
|
|||
_EventAggregator.Publish(new PaymentRequestUpdated()
|
||||
{
|
||||
Data = data,
|
||||
PaymentRequestId = data.Id
|
||||
PaymentRequestId = data.Id,
|
||||
Published = oldStatus == PaymentRequestData.PaymentRequestStatus.Creating &&
|
||||
data.Status != PaymentRequestData.PaymentRequestStatus.Creating
|
||||
});
|
||||
|
||||
return RedirectToAction("EditPaymentRequest", new {id = data.Id, StatusMessage = "Saved"});
|
||||
}
|
||||
|
||||
|
@ -307,7 +306,7 @@ namespace BTCPayServer.Controllers
|
|||
store.AdditionalClaims.Add(new Claim(Policies.CanCreateInvoice.Key, store.Id));
|
||||
try
|
||||
{
|
||||
var newInvoiceId = (await _InvoiceController.CreateInvoiceCore(new Invoice()
|
||||
var newInvoiceId = (await _InvoiceController.CreateInvoiceCore(new CreateInvoiceRequest()
|
||||
{
|
||||
OrderId = $"{PaymentRequestRepository.GetOrderIdForPaymentRequest(id)}",
|
||||
Currency = blob.Currency,
|
||||
|
|
|
@ -34,6 +34,7 @@ using Microsoft.Extensions.Options;
|
|||
using Microsoft.AspNetCore.Mvc.Cors.Internal;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using System.Net;
|
||||
using BTCPayServer.PaymentRequest;
|
||||
using Meziantou.AspNetCore.BundleTagHelpers;
|
||||
using BTCPayServer.Security;
|
||||
using BTCPayServer.Services.Apps;
|
||||
|
@ -165,6 +166,7 @@ namespace BTCPayServer.Hosting
|
|||
app.UseSignalR(route =>
|
||||
{
|
||||
route.MapHub<AppHub>("/apps/hub");
|
||||
route.MapHub<PaymentRequestHub>("/payment-requests/hub");
|
||||
});
|
||||
app.UseWebSockets();
|
||||
app.UseStatusCodePages();
|
||||
|
|
|
@ -44,7 +44,8 @@ namespace BTCPayServer.PaymentRequest
|
|||
public async Task Pay(decimal? amount = null)
|
||||
{
|
||||
_PaymentRequestController.ControllerContext.HttpContext = Context.GetHttpContext();
|
||||
var result = await _PaymentRequestController.PayPaymentRequest(Context.Items["pr-id"].ToString(), false, amount);
|
||||
var result =
|
||||
await _PaymentRequestController.PayPaymentRequest(Context.Items["pr-id"].ToString(), false, amount);
|
||||
switch (result)
|
||||
{
|
||||
case OkObjectResult okObjectResult:
|
||||
|
@ -60,31 +61,28 @@ namespace BTCPayServer.PaymentRequest
|
|||
}
|
||||
}
|
||||
|
||||
public class PaymentRequestStreamer : EventHostedServiceBase
|
||||
public class PaymentRequestStreamer : EventHostedServiceBase
|
||||
{
|
||||
private readonly IHubContext<PaymentRequestHub> _HubContext;
|
||||
private readonly PaymentRequestRepository _PaymentRequestRepository;
|
||||
private readonly AppService _AppService;
|
||||
private readonly PaymentRequestService _PaymentRequestService;
|
||||
|
||||
|
||||
|
||||
public PaymentRequestStreamer(EventAggregator eventAggregator,
|
||||
IHubContext<PaymentRequestHub> hubContext,
|
||||
PaymentRequestRepository paymentRequestRepository,
|
||||
AppService appService,
|
||||
PaymentRequestService paymentRequestService) : base(eventAggregator)
|
||||
{
|
||||
_HubContext = hubContext;
|
||||
_PaymentRequestRepository = paymentRequestRepository;
|
||||
_AppService = appService;
|
||||
_PaymentRequestService = paymentRequestService;
|
||||
}
|
||||
|
||||
public override async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await base.StartAsync(cancellationToken);
|
||||
_CheckingPendingPayments = CheckingPendingPayments(cancellationToken).ContinueWith(_ => _CheckingPendingPayments = null, TaskScheduler.Default);
|
||||
|
||||
_CheckingPendingPayments = CheckingPendingPayments(cancellationToken)
|
||||
.ContinueWith(_ => _CheckingPendingPayments = null, TaskScheduler.Default);
|
||||
}
|
||||
|
||||
private async Task CheckingPendingPayments(CancellationToken cancellationToken)
|
||||
|
@ -92,19 +90,22 @@ namespace BTCPayServer.PaymentRequest
|
|||
Logs.PayServer.LogInformation("Starting payment request expiration watcher");
|
||||
var (total, items) = await _PaymentRequestRepository.FindPaymentRequests(new PaymentRequestQuery()
|
||||
{
|
||||
Status = new[] { PaymentRequestData.PaymentRequestStatus.Pending }
|
||||
Status = new[] {PaymentRequestData.PaymentRequestStatus.Pending}
|
||||
}, cancellationToken);
|
||||
|
||||
Logs.PayServer.LogInformation($"{total} pending payment requests being checked since last run");
|
||||
await Task.WhenAll(items.Select(i => _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(i)).ToArray());
|
||||
await Task.WhenAll(items.Select(i => _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(i))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
Task _CheckingPendingPayments;
|
||||
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await base.StopAsync(cancellationToken);
|
||||
await (_CheckingPendingPayments ?? Task.CompletedTask);
|
||||
}
|
||||
|
||||
protected override void SubscibeToEvents()
|
||||
{
|
||||
Subscribe<InvoiceEvent>();
|
||||
|
@ -116,7 +117,7 @@ namespace BTCPayServer.PaymentRequest
|
|||
if (evt is InvoiceEvent invoiceEvent)
|
||||
{
|
||||
var paymentRequestId =
|
||||
PaymentRequestRepository.GetPaymentRequestIdFromOrderId(invoiceEvent.Invoice.OrderId);
|
||||
PaymentRequestRepository.GetPaymentRequestIdFromOrderId(invoiceEvent.Invoice.OrderId);
|
||||
|
||||
if (invoiceEvent.Name == InvoiceEvent.ReceivedPayment)
|
||||
{
|
||||
|
@ -131,14 +132,18 @@ namespace BTCPayServer.PaymentRequest
|
|||
invoiceEvent.Payment.GetPaymentMethodId().PaymentType)
|
||||
});
|
||||
}
|
||||
|
||||
await InfoUpdated(paymentRequestId);
|
||||
}
|
||||
else if (evt is PaymentRequestUpdated updated)
|
||||
{
|
||||
if (updated.Data.Status != PaymentRequestData.PaymentRequestStatus.Creating)
|
||||
if (updated.Published)
|
||||
{
|
||||
await InfoUpdated(updated.PaymentRequestId);
|
||||
await _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(updated.Data);
|
||||
}
|
||||
|
||||
await InfoUpdated(updated.PaymentRequestId);
|
||||
|
||||
var expiry = updated.Data.GetBlob().ExpiryDate;
|
||||
if (updated.Data.Status == PaymentRequestData.PaymentRequestStatus.Pending &&
|
||||
expiry.HasValue)
|
||||
|
@ -165,10 +170,10 @@ namespace BTCPayServer.PaymentRequest
|
|||
private async Task InfoUpdated(string paymentRequestId)
|
||||
{
|
||||
var req = await _PaymentRequestService.GetPaymentRequest(paymentRequestId);
|
||||
if(req != null)
|
||||
if (req != null)
|
||||
{
|
||||
await _HubContext.Clients.Group(paymentRequestId)
|
||||
.SendCoreAsync(PaymentRequestHub.InfoUpdated, new object[] { req });
|
||||
.SendCoreAsync(PaymentRequestHub.InfoUpdated, new object[] {req});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,21 +15,18 @@ namespace BTCPayServer.PaymentRequest
|
|||
{
|
||||
public class PaymentRequestService
|
||||
{
|
||||
|
||||
private readonly IHubContext<PaymentRequestHub> _HubContext;
|
||||
private readonly PaymentRequestRepository _PaymentRequestRepository;
|
||||
private readonly BTCPayNetworkProvider _BtcPayNetworkProvider;
|
||||
private readonly AppService _AppService;
|
||||
private readonly CurrencyNameTable _currencies;
|
||||
|
||||
public PaymentRequestService(EventAggregator eventAggregator,
|
||||
public PaymentRequestService(
|
||||
IHubContext<PaymentRequestHub> hubContext,
|
||||
PaymentRequestRepository paymentRequestRepository,
|
||||
BTCPayNetworkProvider btcPayNetworkProvider,
|
||||
AppService appService,
|
||||
CurrencyNameTable currencies)
|
||||
{
|
||||
_HubContext = hubContext;
|
||||
_PaymentRequestRepository = paymentRequestRepository;
|
||||
_BtcPayNetworkProvider = btcPayNetworkProvider;
|
||||
_AppService = appService;
|
||||
|
@ -43,6 +40,7 @@ namespace BTCPayServer.PaymentRequest
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await UpdatePaymentRequestStateIfNeeded(pr);
|
||||
}
|
||||
|
||||
|
@ -55,7 +53,7 @@ namespace BTCPayServer.PaymentRequest
|
|||
if (blob.ExpiryDate.Value <= DateTimeOffset.UtcNow)
|
||||
currentStatus = PaymentRequestData.PaymentRequestStatus.Expired;
|
||||
}
|
||||
else if(pr.Status == PaymentRequestData.PaymentRequestStatus.Pending)
|
||||
else if (pr.Status == PaymentRequestData.PaymentRequestStatus.Pending)
|
||||
{
|
||||
var rateRules = pr.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider);
|
||||
var invoices = await _PaymentRequestRepository.GetInvoicesForPaymentRequest(pr.Id);
|
||||
|
@ -67,6 +65,7 @@ namespace BTCPayServer.PaymentRequest
|
|||
currentStatus = PaymentRequestData.PaymentRequestStatus.Completed;
|
||||
}
|
||||
}
|
||||
|
||||
if (pr.Status != PaymentRequestData.PaymentRequestStatus.Creating && currentStatus != pr.Status)
|
||||
{
|
||||
pr.Status = currentStatus;
|
||||
|
|
|
@ -179,6 +179,7 @@ namespace BTCPayServer.Services.PaymentRequests
|
|||
{
|
||||
public string PaymentRequestId { get; set; }
|
||||
public PaymentRequestData Data { get; set; }
|
||||
public bool Published { get; set; }
|
||||
}
|
||||
|
||||
public class PaymentRequestQuery
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<label asp-for="AllowCustomPaymentAmounts"></label>
|
||||
<input asp-for="AllowCustomPaymentAmounts" type="checkbox" class="form-check"/>
|
||||
<span asp-validation-for="AllowCustomPaymentAmounts" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
||||
<label asp-for="StoreId" class="control-label"></label>
|
||||
|
@ -82,20 +82,25 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="CustomCSSLink" class="control-label"></label>
|
||||
<a href="https://docs.btcpayserver.org/development/theme#bootstrap-themes" target="_blank"><span class="fa fa-question-circle-o" title="More information..."></span></a>
|
||||
<input asp-for="CustomCSSLink" class="form-control" />
|
||||
<a href="https://docs.btcpayserver.org/development/theme#bootstrap-themes" target="_blank">
|
||||
<span class="fa fa-question-circle-o" title="More information..."></span>
|
||||
</a>
|
||||
<input asp-for="CustomCSSLink" class="form-control"/>
|
||||
<span asp-validation-for="CustomCSSLink" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="EmbeddedCSS" class="control-label"></label>
|
||||
<textarea asp-for="EmbeddedCSS" rows="10" cols="40" class="form-control"></textarea>
|
||||
<span asp-validation-for="EmbeddedCSS" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary" name="action" value="draft">Save for later</button>
|
||||
<button type="submit" class="btn btn-primary" name="action" value="publish">Save & Publish</button>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Id))
|
||||
{
|
||||
<a class="btn btn-secondary" target="_blank" asp-action="ViewPaymentRequest" id="@Model.Id">View</a>
|
||||
}
|
||||
<a class="btn btn-secondary" target="_blank" asp-action="GetPaymentRequests">Back to list</a>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
<div class="container">
|
||||
<div class="row w-100 p-0 m-0" style="height: 100vh">
|
||||
<div class="mx-auto my-auto w-100">
|
||||
@if (Model.Status == "Creating")
|
||||
{
|
||||
<div class="w-100 alert alert-danger text-center font-weight-bold d-print-none">
|
||||
This payment request is still in creation mode and can only be viewed by you. Please publish from the settings in order to be able to share it.
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="card">
|
||||
<h1 class="card-header">
|
||||
@Model.Title
|
||||
|
@ -117,7 +124,7 @@
|
|||
class="form-control"
|
||||
type="number"
|
||||
name="amount"
|
||||
|
||||
|
||||
value="@Model.AmountDue"
|
||||
max="@Model.AmountDue"
|
||||
step="any"
|
||||
|
@ -127,7 +134,7 @@
|
|||
<span class='input-group-text'>@Model.Currency.ToUpper()</span>
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
type="submit">
|
||||
type="submit">
|
||||
Pay now
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -51,6 +51,9 @@ else
|
|||
<div class="container" id="app" v-cloak>
|
||||
<div class="row w-100 p-0 m-0" style="height: 100vh">
|
||||
<div class="mx-auto my-auto w-100">
|
||||
<div v-if="srvModel.status === 'Creating'" class="w-100 alert alert-danger text-center font-weight-bold d-print-none">
|
||||
This payment request is still in creation mode and can only be viewed by you. Please publish from the settings in order to be able to share it.
|
||||
</div>
|
||||
<div class="card">
|
||||
<h1 class="card-header">
|
||||
{{srvModel.title}}
|
||||
|
@ -117,7 +120,7 @@ else
|
|||
<div class="table-responsive">
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th class="p-1" style="max-width: 300px">Tx Id</th>
|
||||
<th class="p-1" style="max-width: 300px">Tx Id</th>
|
||||
<th class="p-1">Payment Method</th>
|
||||
<th class="p-1">Amount</th>
|
||||
<th class="p-1">Link</th>
|
||||
|
@ -149,7 +152,7 @@ else
|
|||
<template v-if="srvModel.allowCustomPaymentAmounts && !srvModel.anyPendingInvoice">
|
||||
<form v-on:submit="submitCustomAmountForm">
|
||||
|
||||
<div class="input-group m-auto" style="max-width:250px ">
|
||||
<div class="input-group m-auto" style="max-width: 250px">
|
||||
<input
|
||||
:readonly="!srvModel.allowCustomPaymentAmounts"
|
||||
class="form-control"
|
||||
|
|
Loading…
Add table
Reference in a new issue