Skip to content

Commit

Permalink
Payment Request: Warn if there are no email rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisreimann committed Nov 21, 2023
1 parent 8eadec3 commit 5ad41b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 4 additions & 5 deletions BTCPayServer/Controllers/UIPaymentRequestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Abstractions.Extensions;
using BTCPayServer.Abstractions.Form;
using BTCPayServer.Client;
using BTCPayServer.Client.Models;
using BTCPayServer.Data;
using BTCPayServer.Filters;
using BTCPayServer.Forms;
using BTCPayServer.Forms.Models;
using BTCPayServer.Models;
using BTCPayServer.Models.PaymentRequestViewModels;
using BTCPayServer.PaymentRequest;
using BTCPayServer.Services;
Expand All @@ -22,7 +20,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using PaymentRequestData = BTCPayServer.Data.PaymentRequestData;
using StoreData = BTCPayServer.Data.StoreData;

Expand Down Expand Up @@ -113,12 +110,14 @@ public async Task<IActionResult> EditPaymentRequest(string storeId, string payRe
{
return NotFound();
}


var blob = store.GetStoreBlob();
var prInvoices = payReqId is null ? null : (await _PaymentRequestService.GetPaymentRequest(payReqId, GetUserId())).Invoices;
var vm = new UpdatePaymentRequestViewModel(paymentRequest)
{
StoreId = store.Id,
AmountAndCurrencyEditable = payReqId is null || !prInvoices.Any()
AmountAndCurrencyEditable = payReqId is null || !prInvoices.Any(),
HasEmailRules = blob.EmailRules.Any(rule => rule.Trigger.Contains("PaymentRequest", StringComparison.InvariantCultureIgnoreCase))
};

vm.Currency ??= store.GetStoreBlob().DefaultCurrency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public UpdatePaymentRequestViewModel(PaymentRequestData data)

public Dictionary<string, object> FormResponse { get; set; }
public bool AmountAndCurrencyEditable { get; set; } = true;
public bool? HasEmailRules { get; set; }
}

public class ViewPaymentRequestViewModel
Expand Down
10 changes: 8 additions & 2 deletions BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@inject FormDataService FormDataService
@model BTCPayServer.Models.PaymentRequestViewModels.UpdatePaymentRequestViewModel
@{

var checkoutFormOptions = await FormDataService.GetSelect(Model.StoreId, Model.FormId);

ViewData.SetActivePage(PaymentRequestsNavPages.Create, $"{(string.IsNullOrEmpty(Model.Id) ? "Create" : "Edit")} Payment Request", Model.Id);
Expand Down Expand Up @@ -85,7 +84,14 @@
<label asp-for="Email" class="form-label"></label>
<input type="email" asp-for="Email" placeholder="Firstname Lastname <email@example.com>" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
<div id="PaymentRequestEmailHelpBlock" class="form-text">The recipient's email. This will send notification mails to the recipient, as configured by the <a asp-action="StoreEmails" asp-controller="UIStores" asp-route-storeId="@Model.StoreId">email rules</a>, and include the email in the invoice export data.</div>
<div id="PaymentRequestEmailHelpBlock" class="form-text">
This will send notification mails to the recipient, as configured by the
<a asp-action="StoreEmails" asp-controller="UIStores" asp-route-storeId="@Model.StoreId">email rules</a>.
@if (Model.HasEmailRules is not true)
{
<div class="text-warning">No payment request related email rules have been configured for this store.</div>
}
</div>
</div>
<div class="form-group">
<label asp-for="FormId" class="form-label"></label>
Expand Down

0 comments on commit 5ad41b7

Please sign in to comment.