mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 05:54:26 +01:00
Add a 'Pending invoice' pill in portal subscription when invoice processing
This commit is contained in:
@@ -56,6 +56,9 @@ public class SubscriberData : BaseEntityData
|
||||
public decimal MissingCredit()
|
||||
=> Math.Max(0m, NextPlan.Price - GetCredit(NextPlan.Currency));
|
||||
|
||||
[Column("processing_invoice_id")]
|
||||
public string? ProcessingInvoiceId { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("phase")]
|
||||
public PhaseTypes Phase { get; set; } = PhaseTypes.Expired;
|
||||
|
||||
@@ -200,6 +200,7 @@ namespace BTCPayServer.Migrations
|
||||
plan_id = table.Column<string>(type: "text", nullable: false),
|
||||
new_plan_id = table.Column<string>(type: "text", nullable: true),
|
||||
paid_amount = table.Column<decimal>(type: "numeric", nullable: true),
|
||||
processing_invoice_id = table.Column<string>(type: "text", nullable: true),
|
||||
phase = table.Column<string>(type: "text", nullable: false, defaultValueSql: "'Expired'::TEXT"),
|
||||
plan_started = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
||||
period_end = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
|
||||
@@ -1567,6 +1567,10 @@ namespace BTCPayServer.Migrations
|
||||
.HasColumnName("plan_started")
|
||||
.HasDefaultValueSql("now()");
|
||||
|
||||
b.Property<string>("ProcessingInvoiceId")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("processing_invoice_id");
|
||||
|
||||
b.Property<string>("SuspensionReason")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("suspension_reason");
|
||||
|
||||
@@ -375,7 +375,6 @@ public class SubscriptionHostedService(
|
||||
var checkout = await ctx.PlanCheckouts.GetCheckout(checkoutId);
|
||||
var plan = checkout?.Plan;
|
||||
if (checkout is null || plan is null ||
|
||||
(invoice.Status == InvoiceStatus.Processing && !plan.OptimisticActivation) ||
|
||||
checkout.Plan.Offering.App.StoreDataId != invoice.StoreId)
|
||||
return;
|
||||
|
||||
@@ -384,6 +383,16 @@ public class SubscriptionHostedService(
|
||||
throw new InvalidOperationException("Bug: Subscriber is null and not a new subscriber");
|
||||
|
||||
var sub = checkout.Subscriber;
|
||||
var processingInvoiceId = invoice.Status == InvoiceStatus.Processing ? invoice.Id : null;
|
||||
if (sub is not null &&
|
||||
sub.ProcessingInvoiceId != processingInvoiceId)
|
||||
{
|
||||
sub.ProcessingInvoiceId = processingInvoiceId;
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
if (invoice.Status == InvoiceStatus.Processing && !plan.OptimisticActivation)
|
||||
return;
|
||||
|
||||
if (invoice.Status is InvoiceStatus.Settled or InvoiceStatus.Processing)
|
||||
{
|
||||
|
||||
@@ -280,6 +280,10 @@
|
||||
{
|
||||
<span class="badge badge-translucent rounded-pill text-bg-warning">Grace</span>
|
||||
}
|
||||
@if (Model.Data.Subscriber is { ProcessingInvoiceId: {} pendingInvoiceId, OptimisticActivation: false })
|
||||
{
|
||||
<span class="badge badge-translucent rounded-pill text-bg-warning" title="@pendingInvoiceId">Pending invoice</span>
|
||||
}
|
||||
</h5>
|
||||
@if (Model.Subscriber.Plan.Description is not null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user