remove creating state from payment requests

This commit is contained in:
Kukks 2019-02-24 09:26:37 +01:00 committed by nicolas.dorier
parent f5d366cf7f
commit c134277514
10 changed files with 36 additions and 103 deletions

View file

@ -90,13 +90,6 @@ namespace BTCPayServer.Controllers
return NotFound(); 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), stores = new SelectList(await _StoreRepository.GetStoresByUserId(GetUserId()), nameof(StoreData.Id),
nameof(StoreData.StoreName), data?.StoreDataId); nameof(StoreData.StoreName), data?.StoreDataId);
if (!stores.Any()) if (!stores.Any())
@ -129,16 +122,6 @@ namespace BTCPayServer.Controllers
return NotFound(); 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) if (!ModelState.IsValid)
{ {
viewModel.Stores = new SelectList(await _StoreRepository.GetStoresByUserId(GetUserId()), viewModel.Stores = new SelectList(await _StoreRepository.GetStoresByUserId(GetUserId()),
@ -167,14 +150,11 @@ namespace BTCPayServer.Controllers
blob.AllowCustomPaymentAmounts = viewModel.AllowCustomPaymentAmounts; blob.AllowCustomPaymentAmounts = viewModel.AllowCustomPaymentAmounts;
data.SetBlob(blob); data.SetBlob(blob);
data.Status = viewModel.Action == "publish" ? PaymentRequestData.PaymentRequestStatus.Pending : PaymentRequestData.PaymentRequestStatus.Creating;
data = await _PaymentRequestRepository.CreateOrUpdatePaymentRequest(data); data = await _PaymentRequestRepository.CreateOrUpdatePaymentRequest(data);
_EventAggregator.Publish(new PaymentRequestUpdated() _EventAggregator.Publish(new PaymentRequestUpdated()
{ {
Data = data, 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"}); return RedirectToAction("EditPaymentRequest", new {id = data.Id, StatusMessage = "Saved"});
@ -232,13 +212,15 @@ namespace BTCPayServer.Controllers
{ {
return NotFound(); return NotFound();
} }
return View(result); return View(result);
} }
[HttpGet] [HttpGet]
[Route("{id}/pay")] [Route("{id}/pay")]
[AllowAnonymous] [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; var result = ((await ViewPaymentRequest(id)) as ViewResult)?.Model as ViewPaymentRequestViewModel;
if (result == null) if (result == null)
@ -255,7 +237,7 @@ namespace BTCPayServer.Controllers
return BadRequest("Payment Request has already been settled."); return BadRequest("Payment Request has already been settled.");
} }
if (result.ExpiryDate.HasValue && DateTime.Now >= result.ExpiryDate) if (result.ExpiryDate.HasValue && DateTime.Now >= result.ExpiryDate)
{ {
if (redirectToInvoice) if (redirectToInvoice)
@ -283,11 +265,11 @@ namespace BTCPayServer.Controllers
return Ok(validInvoice.Id); return Ok(validInvoice.Id);
} }
if (result.AllowCustomPaymentAmounts && amount != null) if (result.AllowCustomPaymentAmounts && amount != null)
{ {
var invoiceAmount = result.AmountDue < amount ? result.AmountDue : amount; var invoiceAmount = result.AmountDue < amount ? result.AmountDue : amount;
return await CreateInvoiceForPaymentRequest(id, redirectToInvoice, result, invoiceAmount); return await CreateInvoiceForPaymentRequest(id, redirectToInvoice, result, invoiceAmount);
} }
@ -295,9 +277,9 @@ namespace BTCPayServer.Controllers
return await CreateInvoiceForPaymentRequest(id, redirectToInvoice, result); return await CreateInvoiceForPaymentRequest(id, redirectToInvoice, result);
} }
private async Task<IActionResult> CreateInvoiceForPaymentRequest(string id, private async Task<IActionResult> CreateInvoiceForPaymentRequest(string id,
bool redirectToInvoice, bool redirectToInvoice,
ViewPaymentRequestViewModel result, ViewPaymentRequestViewModel result,
decimal? amount = null) decimal? amount = null)
{ {
var pr = await _PaymentRequestRepository.FindPaymentRequest(id, null); var pr = await _PaymentRequestRepository.FindPaymentRequest(id, null);
@ -310,7 +292,7 @@ namespace BTCPayServer.Controllers
{ {
OrderId = $"{PaymentRequestRepository.GetOrderIdForPaymentRequest(id)}", OrderId = $"{PaymentRequestRepository.GetOrderIdForPaymentRequest(id)}",
Currency = blob.Currency, Currency = blob.Currency,
Price = amount.GetValueOrDefault(result.AmountDue) , Price = amount.GetValueOrDefault(result.AmountDue),
FullNotifications = true, FullNotifications = true,
BuyerEmail = result.Email, BuyerEmail = result.Email,
RedirectURL = Request.GetDisplayUrl().Replace("/pay", "", StringComparison.InvariantCulture), RedirectURL = Request.GetDisplayUrl().Replace("/pay", "", StringComparison.InvariantCulture),

View file

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq;
using BTCPayServer.Services.Invoices;
using BTCPayServer.Services.PaymentRequests; using BTCPayServer.Services.PaymentRequests;
using BTCPayServer.Services.Rates; using BTCPayServer.Services.Rates;
using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.Rendering;
@ -20,12 +18,6 @@ namespace BTCPayServer.Models.PaymentRequestViewModels
public int Total { get; set; } public int Total { get; set; }
} }
public class RemovePaymentRequestViewModel
{
public string Id { get; set; }
public string Title { get; set; }
}
public class UpdatePaymentRequestViewModel public class UpdatePaymentRequestViewModel
{ {
public UpdatePaymentRequestViewModel() public UpdatePaymentRequestViewModel()
@ -66,7 +58,6 @@ namespace BTCPayServer.Models.PaymentRequestViewModels
[Required] public string Title { get; set; } [Required] public string Title { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string StatusMessage { get; set; } public string StatusMessage { get; set; }
public string Action { get; set; }
public SelectList Stores { get; set; } public SelectList Stores { get; set; }
[EmailAddress] [EmailAddress]
@ -80,6 +71,8 @@ namespace BTCPayServer.Models.PaymentRequestViewModels
public string EmbeddedCSS { get; set; } public string EmbeddedCSS { get; set; }
[Display(Name = "Allow payee to create invoices in their own denomination")] [Display(Name = "Allow payee to create invoices in their own denomination")]
public bool AllowCustomPaymentAmounts { get; set; } public bool AllowCustomPaymentAmounts { get; set; }
public bool Enabled { get; set; }
} }
public class ViewPaymentRequestViewModel public class ViewPaymentRequestViewModel
@ -99,18 +92,8 @@ namespace BTCPayServer.Models.PaymentRequestViewModels
AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts; AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts;
switch (data.Status) switch (data.Status)
{ {
case PaymentRequestData.PaymentRequestStatus.Creating:
Status = "Creating";
break;
case PaymentRequestData.PaymentRequestStatus.Pending: case PaymentRequestData.PaymentRequestStatus.Pending:
if (ExpiryDate.HasValue) Status = ExpiryDate.HasValue ? $"Expires on {ExpiryDate.Value:g}" : "Pending";
{
Status = $"Expires on {ExpiryDate.Value:g}";
}
else
{
Status = "Pending";
}
IsPending = true; IsPending = true;
break; break;
case PaymentRequestData.PaymentRequestStatus.Completed: case PaymentRequestData.PaymentRequestStatus.Completed:
@ -124,6 +107,8 @@ namespace BTCPayServer.Models.PaymentRequestViewModels
} }
} }
public bool Enabled { get; set; }
public bool AllowCustomPaymentAmounts { get; set; } public bool AllowCustomPaymentAmounts { get; set; }

View file

@ -137,11 +137,6 @@ namespace BTCPayServer.PaymentRequest
} }
else if (evt is PaymentRequestUpdated updated) else if (evt is PaymentRequestUpdated updated)
{ {
if (updated.Published)
{
await _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(updated.Data);
}
await InfoUpdated(updated.PaymentRequestId); await InfoUpdated(updated.PaymentRequestId);
var expiry = updated.Data.GetBlob().ExpiryDate; var expiry = updated.Data.GetBlob().ExpiryDate;

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -36,10 +35,6 @@ namespace BTCPayServer.PaymentRequest
public async Task UpdatePaymentRequestStateIfNeeded(string id) public async Task UpdatePaymentRequestStateIfNeeded(string id)
{ {
var pr = await _PaymentRequestRepository.FindPaymentRequest(id, null); var pr = await _PaymentRequestRepository.FindPaymentRequest(id, null);
if (pr == null || pr.Status == PaymentRequestData.PaymentRequestStatus.Creating)
{
return;
}
await UpdatePaymentRequestStateIfNeeded(pr); 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; pr.Status = currentStatus;
await _PaymentRequestRepository.UpdatePaymentRequestStatus(pr.Id, currentStatus); await _PaymentRequestRepository.UpdatePaymentRequestStatus(pr.Id, currentStatus);
@ -81,12 +76,6 @@ namespace BTCPayServer.PaymentRequest
return null; return null;
} }
if (pr.Status == PaymentRequestData.PaymentRequestStatus.Creating &&
!await _PaymentRequestRepository.IsPaymentRequestAdmin(id, userId))
{
return null;
}
var blob = pr.GetBlob(); var blob = pr.GetBlob();
var rateRules = pr.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider); var rateRules = pr.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider);

View file

@ -1,11 +1,9 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Invoices;
using BTCPayServer.Services.Rates;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Internal;
using NBitcoin; using NBitcoin;
@ -179,7 +177,6 @@ namespace BTCPayServer.Services.PaymentRequests
{ {
public string PaymentRequestId { get; set; } public string PaymentRequestId { get; set; }
public PaymentRequestData Data { get; set; } public PaymentRequestData Data { get; set; }
public bool Published { get; set; }
} }
public class PaymentRequestQuery public class PaymentRequestQuery
@ -239,10 +236,9 @@ namespace BTCPayServer.Services.PaymentRequests
public enum PaymentRequestStatus public enum PaymentRequestStatus
{ {
Creating = 0, Pending = 0,
Pending = 1, Completed = 1,
Completed = 2, Expired = 2
Expired = 3
} }
} }
} }

View file

@ -15,7 +15,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
</div> </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="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="js-product-save btn btn-primary">Save Changes</button> <button type="button" class="js-product-save btn btn-primary">Save Changes</button>
</div> </div>

View file

@ -1,3 +1,4 @@
@using BTCPayServer.Services.PaymentRequests
@model BTCPayServer.Models.PaymentRequestViewModels.UpdatePaymentRequestViewModel @model BTCPayServer.Models.PaymentRequestViewModels.UpdatePaymentRequestViewModel
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers @addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
@ -95,11 +96,16 @@
</div> </div>
<div class="form-group"> <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">Save</button>
<button type="submit" class="btn btn-primary" name="action" value="publish">Save & Publish</button>
@if (!string.IsNullOrEmpty(Model.Id)) @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="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> <a class="btn btn-secondary" target="_blank" asp-action="GetPaymentRequests">Back to list</a>
</div> </div>

View file

@ -46,23 +46,13 @@
<td class="text-right">@item.Amount @item.Currency</td> <td class="text-right">@item.Amount @item.Currency</td>
<td class="text-right">@item.Status</td> <td class="text-right">@item.Status</td>
<td class="text-right"> <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="EditPaymentRequest" asp-route-id="@item.Id">Edit</a> <a asp-action="ViewPaymentRequest" asp-route-id="@item.Id">View</a>
<span> - </span> <span> - </span>
<a asp-action="ViewPaymentRequest" asp-route-id="@item.Id">View</a> <a target="_blank" asp-action="ListInvoices" asp-controller="Invoice" asp-route-searchterm="@($"orderid:{PaymentRequestRepository.GetOrderIdForPaymentRequest(item.Id)}")">Invoices</a>
} <span> - </span>
else <a target="_blank" asp-action="PayPaymentRequest" asp-route-id="@item.Id">Pay</a>
{
<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>
}
<span> - </span> <span> - </span>
<a asp-action="RemovePaymentRequestPrompt" asp-route-id="@item.Id">Remove</a> <a asp-action="RemovePaymentRequestPrompt" asp-route-id="@item.Id">Remove</a>
</td> </td>

View file

@ -3,13 +3,6 @@
<div class="container"> <div class="container">
<div class="row w-100 p-0 m-0" style="height: 100vh"> <div class="row w-100 p-0 m-0" style="height: 100vh">
<div class="mx-auto my-auto w-100"> <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"> <div class="card">
<h1 class="card-header"> <h1 class="card-header">
@Model.Title @Model.Title

View file

@ -51,9 +51,6 @@ else
<div class="container" id="app" v-cloak> <div class="container" id="app" v-cloak>
<div class="row w-100 p-0 m-0" style="height: 100vh"> <div class="row w-100 p-0 m-0" style="height: 100vh">
<div class="mx-auto my-auto w-100"> <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"> <div class="card">
<h1 class="card-header"> <h1 class="card-header">
{{srvModel.title}} {{srvModel.title}}