diff --git a/BTCPayServer/Controllers/PaymentRequestController.cs b/BTCPayServer/Controllers/PaymentRequestController.cs index 6e34a66ce..8320d04e4 100644 --- a/BTCPayServer/Controllers/PaymentRequestController.cs +++ b/BTCPayServer/Controllers/PaymentRequestController.cs @@ -90,13 +90,6 @@ namespace BTCPayServer.Controllers return NotFound(); } - if (data != null && data.Status != PaymentRequestData.PaymentRequestStatus.Creating) - { - return RedirectToAction("ViewPaymentRequest", new - { - id - }); - } stores = new SelectList(await _StoreRepository.GetStoresByUserId(GetUserId()), nameof(StoreData.Id), nameof(StoreData.StoreName), data?.StoreDataId); if (!stores.Any()) @@ -129,16 +122,6 @@ namespace BTCPayServer.Controllers return NotFound(); } - var oldStatus = data?.Status ?? PaymentRequestData.PaymentRequestStatus.Creating; - - if (data != null && data.Status != PaymentRequestData.PaymentRequestStatus.Creating) - { - return RedirectToAction("ViewPaymentRequest", new - { - id - }); - } - if (!ModelState.IsValid) { viewModel.Stores = new SelectList(await _StoreRepository.GetStoresByUserId(GetUserId()), @@ -167,14 +150,11 @@ namespace BTCPayServer.Controllers blob.AllowCustomPaymentAmounts = viewModel.AllowCustomPaymentAmounts; data.SetBlob(blob); - data.Status = viewModel.Action == "publish" ? PaymentRequestData.PaymentRequestStatus.Pending : PaymentRequestData.PaymentRequestStatus.Creating; data = await _PaymentRequestRepository.CreateOrUpdatePaymentRequest(data); _EventAggregator.Publish(new PaymentRequestUpdated() { Data = data, - PaymentRequestId = data.Id, - Published = oldStatus == PaymentRequestData.PaymentRequestStatus.Creating && - data.Status != PaymentRequestData.PaymentRequestStatus.Creating + PaymentRequestId = data.Id }); return RedirectToAction("EditPaymentRequest", new {id = data.Id, StatusMessage = "Saved"}); @@ -232,13 +212,15 @@ namespace BTCPayServer.Controllers { return NotFound(); } + return View(result); } [HttpGet] [Route("{id}/pay")] [AllowAnonymous] - public async Task PayPaymentRequest(string id, bool redirectToInvoice = true, decimal? amount = null) + public async Task PayPaymentRequest(string id, bool redirectToInvoice = true, + decimal? amount = null) { var result = ((await ViewPaymentRequest(id)) as ViewResult)?.Model as ViewPaymentRequestViewModel; if (result == null) @@ -255,7 +237,7 @@ namespace BTCPayServer.Controllers return BadRequest("Payment Request has already been settled."); } - + if (result.ExpiryDate.HasValue && DateTime.Now >= result.ExpiryDate) { if (redirectToInvoice) @@ -283,11 +265,11 @@ namespace BTCPayServer.Controllers return Ok(validInvoice.Id); } - + if (result.AllowCustomPaymentAmounts && amount != null) { var invoiceAmount = result.AmountDue < amount ? result.AmountDue : amount; - + return await CreateInvoiceForPaymentRequest(id, redirectToInvoice, result, invoiceAmount); } @@ -295,9 +277,9 @@ namespace BTCPayServer.Controllers return await CreateInvoiceForPaymentRequest(id, redirectToInvoice, result); } - private async Task CreateInvoiceForPaymentRequest(string id, - bool redirectToInvoice, - ViewPaymentRequestViewModel result, + private async Task CreateInvoiceForPaymentRequest(string id, + bool redirectToInvoice, + ViewPaymentRequestViewModel result, decimal? amount = null) { var pr = await _PaymentRequestRepository.FindPaymentRequest(id, null); @@ -310,7 +292,7 @@ namespace BTCPayServer.Controllers { OrderId = $"{PaymentRequestRepository.GetOrderIdForPaymentRequest(id)}", Currency = blob.Currency, - Price = amount.GetValueOrDefault(result.AmountDue) , + Price = amount.GetValueOrDefault(result.AmountDue), FullNotifications = true, BuyerEmail = result.Email, RedirectURL = Request.GetDisplayUrl().Replace("/pay", "", StringComparison.InvariantCulture), diff --git a/BTCPayServer/Models/PaymentRequestViewModels/ListPaymentRequestsViewModel.cs b/BTCPayServer/Models/PaymentRequestViewModels/ListPaymentRequestsViewModel.cs index 6742b48ea..a6987f9b3 100644 --- a/BTCPayServer/Models/PaymentRequestViewModels/ListPaymentRequestsViewModel.cs +++ b/BTCPayServer/Models/PaymentRequestViewModels/ListPaymentRequestsViewModel.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using BTCPayServer.Services.Invoices; using BTCPayServer.Services.PaymentRequests; using BTCPayServer.Services.Rates; using Microsoft.AspNetCore.Mvc.Rendering; @@ -20,12 +18,6 @@ namespace BTCPayServer.Models.PaymentRequestViewModels public int Total { get; set; } } - public class RemovePaymentRequestViewModel - { - public string Id { get; set; } - public string Title { get; set; } - } - public class UpdatePaymentRequestViewModel { public UpdatePaymentRequestViewModel() @@ -66,7 +58,6 @@ namespace BTCPayServer.Models.PaymentRequestViewModels [Required] public string Title { get; set; } public string Description { get; set; } public string StatusMessage { get; set; } - public string Action { get; set; } public SelectList Stores { get; set; } [EmailAddress] @@ -80,6 +71,8 @@ namespace BTCPayServer.Models.PaymentRequestViewModels public string EmbeddedCSS { get; set; } [Display(Name = "Allow payee to create invoices in their own denomination")] public bool AllowCustomPaymentAmounts { get; set; } + + public bool Enabled { get; set; } } public class ViewPaymentRequestViewModel @@ -99,18 +92,8 @@ namespace BTCPayServer.Models.PaymentRequestViewModels AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts; switch (data.Status) { - case PaymentRequestData.PaymentRequestStatus.Creating: - Status = "Creating"; - break; case PaymentRequestData.PaymentRequestStatus.Pending: - if (ExpiryDate.HasValue) - { - Status = $"Expires on {ExpiryDate.Value:g}"; - } - else - { - Status = "Pending"; - } + Status = ExpiryDate.HasValue ? $"Expires on {ExpiryDate.Value:g}" : "Pending"; IsPending = true; break; case PaymentRequestData.PaymentRequestStatus.Completed: @@ -124,6 +107,8 @@ namespace BTCPayServer.Models.PaymentRequestViewModels } } + public bool Enabled { get; set; } + public bool AllowCustomPaymentAmounts { get; set; } diff --git a/BTCPayServer/PaymentRequest/PaymentRequestHub.cs b/BTCPayServer/PaymentRequest/PaymentRequestHub.cs index 26d30feef..6a5af97ac 100644 --- a/BTCPayServer/PaymentRequest/PaymentRequestHub.cs +++ b/BTCPayServer/PaymentRequest/PaymentRequestHub.cs @@ -137,11 +137,6 @@ namespace BTCPayServer.PaymentRequest } else if (evt is PaymentRequestUpdated updated) { - if (updated.Published) - { - await _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(updated.Data); - } - await InfoUpdated(updated.PaymentRequestId); var expiry = updated.Data.GetBlob().ExpiryDate; diff --git a/BTCPayServer/PaymentRequest/PaymentRequestService.cs b/BTCPayServer/PaymentRequest/PaymentRequestService.cs index 859a28bdf..ab23dbe1c 100644 --- a/BTCPayServer/PaymentRequest/PaymentRequestService.cs +++ b/BTCPayServer/PaymentRequest/PaymentRequestService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading.Tasks; @@ -36,10 +35,6 @@ namespace BTCPayServer.PaymentRequest public async Task UpdatePaymentRequestStateIfNeeded(string id) { var pr = await _PaymentRequestRepository.FindPaymentRequest(id, null); - if (pr == null || pr.Status == PaymentRequestData.PaymentRequestStatus.Creating) - { - return; - } await UpdatePaymentRequestStateIfNeeded(pr); } @@ -66,7 +61,7 @@ namespace BTCPayServer.PaymentRequest } } - if (pr.Status != PaymentRequestData.PaymentRequestStatus.Creating && currentStatus != pr.Status) + if (currentStatus != pr.Status) { pr.Status = currentStatus; await _PaymentRequestRepository.UpdatePaymentRequestStatus(pr.Id, currentStatus); @@ -81,12 +76,6 @@ namespace BTCPayServer.PaymentRequest return null; } - if (pr.Status == PaymentRequestData.PaymentRequestStatus.Creating && - !await _PaymentRequestRepository.IsPaymentRequestAdmin(id, userId)) - { - return null; - } - var blob = pr.GetBlob(); var rateRules = pr.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider); diff --git a/BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs b/BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs index e584303e4..d4574e3cf 100644 --- a/BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs +++ b/BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs @@ -1,11 +1,9 @@ using System; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Data; using BTCPayServer.Services.Invoices; -using BTCPayServer.Services.Rates; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Internal; using NBitcoin; @@ -179,7 +177,6 @@ namespace BTCPayServer.Services.PaymentRequests { public string PaymentRequestId { get; set; } public PaymentRequestData Data { get; set; } - public bool Published { get; set; } } public class PaymentRequestQuery @@ -239,10 +236,9 @@ namespace BTCPayServer.Services.PaymentRequests public enum PaymentRequestStatus { - Creating = 0, - Pending = 1, - Completed = 2, - Expired = 3 + Pending = 0, + Completed = 1, + Expired = 2 } } } diff --git a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml index b6ffd89c4..4d672fb16 100644 --- a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml @@ -15,7 +15,7 @@ -
- - + @if (!string.IsNullOrEmpty(Model.Id)) { View + Invoices + } Back to list
diff --git a/BTCPayServer/Views/PaymentRequest/GetPaymentRequests.cshtml b/BTCPayServer/Views/PaymentRequest/GetPaymentRequests.cshtml index 20514c393..f83819a13 100644 --- a/BTCPayServer/Views/PaymentRequest/GetPaymentRequests.cshtml +++ b/BTCPayServer/Views/PaymentRequest/GetPaymentRequests.cshtml @@ -46,23 +46,13 @@ @item.Amount @item.Currency @item.Status - @if (item.Status.Equals(nameof(PaymentRequestData.PaymentRequestStatus.Creating), StringComparison.InvariantCultureIgnoreCase)) - { - Edit - - - View - } - else - { - View - - - Invoices - } - @if (item.Status.Equals(nameof(PaymentRequestData.PaymentRequestStatus.Pending), StringComparison.InvariantCultureIgnoreCase)) - { - - - Pay - } + Edit + - + View + - + Invoices + - + Pay - Remove diff --git a/BTCPayServer/Views/PaymentRequest/MinimalPaymentRequest.cshtml b/BTCPayServer/Views/PaymentRequest/MinimalPaymentRequest.cshtml index 0ff7bee3e..4ec3df117 100644 --- a/BTCPayServer/Views/PaymentRequest/MinimalPaymentRequest.cshtml +++ b/BTCPayServer/Views/PaymentRequest/MinimalPaymentRequest.cshtml @@ -3,13 +3,6 @@
- @if (Model.Status == "Creating") - { -
- 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. -
- } -

@Model.Title diff --git a/BTCPayServer/Views/PaymentRequest/ViewPaymentRequest.cshtml b/BTCPayServer/Views/PaymentRequest/ViewPaymentRequest.cshtml index c506b0c90..42c667e70 100644 --- a/BTCPayServer/Views/PaymentRequest/ViewPaymentRequest.cshtml +++ b/BTCPayServer/Views/PaymentRequest/ViewPaymentRequest.cshtml @@ -51,9 +51,6 @@ else
-
- 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. -

{{srvModel.title}}