mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
remove creating state from payment requests
This commit is contained in:
parent
f5d366cf7f
commit
c134277514
10 changed files with 36 additions and 103 deletions
|
@ -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<IActionResult> PayPaymentRequest(string id, bool redirectToInvoice = true, decimal? amount = null)
|
||||
public async Task<IActionResult> 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<IActionResult> CreateInvoiceForPaymentRequest(string id,
|
||||
bool redirectToInvoice,
|
||||
ViewPaymentRequestViewModel result,
|
||||
private async Task<IActionResult> 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),
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</div>
|
||||
<div class="modal-body">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="modal-footer">PRS
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="button" class="js-product-save btn btn-primary">Save Changes</button>
|
||||
</div>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
@using BTCPayServer.Services.PaymentRequests
|
||||
@model BTCPayServer.Models.PaymentRequestViewModels.UpdatePaymentRequestViewModel
|
||||
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
|
||||
|
||||
|
@ -95,11 +96,16 @@
|
|||
</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>
|
||||
<button type="submit" class="btn btn-primary">Save</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="ListInvoices"
|
||||
asp-controller="Invoice"
|
||||
asp-route-searchterm="@($"orderid:{PaymentRequestRepository.GetOrderIdForPaymentRequest(Model.Id)}")">Invoices</a>
|
||||
|
||||
}
|
||||
<a class="btn btn-secondary" target="_blank" asp-action="GetPaymentRequests">Back to list</a>
|
||||
</div>
|
||||
|
|
|
@ -46,23 +46,13 @@
|
|||
<td class="text-right">@item.Amount @item.Currency</td>
|
||||
<td class="text-right">@item.Status</td>
|
||||
<td class="text-right">
|
||||
@if (item.Status.Equals(nameof(PaymentRequestData.PaymentRequestStatus.Creating), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
<a asp-action="EditPaymentRequest" asp-route-id="@item.Id">Edit</a>
|
||||
<span> - </span>
|
||||
<a asp-action="ViewPaymentRequest" asp-route-id="@item.Id">View</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a asp-action="ViewPaymentRequest" asp-route-id="@item.Id">View</a>
|
||||
<span> - </span>
|
||||
<a target="_blank" asp-action="ListInvoices" asp-controller="Invoice" asp-route-searchterm="@($"orderid:{PaymentRequestRepository.GetOrderIdForPaymentRequest(item.Id)}")">Invoices</a>
|
||||
}
|
||||
@if (item.Status.Equals(nameof(PaymentRequestData.PaymentRequestStatus.Pending), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
<span> - </span>
|
||||
<a target="_blank" asp-action="PayPaymentRequest" asp-route-id="@item.Id">Pay</a>
|
||||
}
|
||||
<a asp-action="EditPaymentRequest" asp-route-id="@item.Id">Edit</a>
|
||||
<span> - </span>
|
||||
<a asp-action="ViewPaymentRequest" asp-route-id="@item.Id">View</a>
|
||||
<span> - </span>
|
||||
<a target="_blank" asp-action="ListInvoices" asp-controller="Invoice" asp-route-searchterm="@($"orderid:{PaymentRequestRepository.GetOrderIdForPaymentRequest(item.Id)}")">Invoices</a>
|
||||
<span> - </span>
|
||||
<a target="_blank" asp-action="PayPaymentRequest" asp-route-id="@item.Id">Pay</a>
|
||||
<span> - </span>
|
||||
<a asp-action="RemovePaymentRequestPrompt" asp-route-id="@item.Id">Remove</a>
|
||||
</td>
|
||||
|
|
|
@ -3,13 +3,6 @@
|
|||
<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
|
||||
|
|
|
@ -51,9 +51,6 @@ 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}}
|
||||
|
|
Loading…
Add table
Reference in a new issue