Add buyerEmail to invoice metadata created by suscribers

This commit is contained in:
Nicolas Dorier
2025-11-19 13:55:53 +09:00
parent 414c71ec09
commit 0e649a68bf
3 changed files with 20 additions and 5 deletions

View File

@@ -323,7 +323,7 @@ namespace BTCPayServer.Tests
await GoToUrl("/login");
}
public async Task Logout()
{
{
await Page.Locator("#menu-item-Account").ClickAsync();
await Page.Locator("#Nav-Logout").ClickAsync();
}
@@ -827,5 +827,8 @@ namespace BTCPayServer.Tests
Assert.Contains("- Denied</h", content);
}
}
public Task FastReloadAsync()
=> Page.ReloadAsync(new() { WaitUntil = WaitUntilState.Commit });
}
}

View File

@@ -363,8 +363,11 @@ public class SubscriptionTests(ITestOutputHelper testOutputHelper) : UnitTestBas
await edit.Save();
// basic2@example.com is a basic plan subscriber (optimistic activation), so he is imediatly activated
await offering.NewSubscriber("Basic Plan", "basic2@example.com", false);
await s.Server.WaitForEvent<SubscriptionEvent.NewSubscriber>(async () => {
await offering.NewSubscriber("Basic Plan", "basic2@example.com", false);
});
await s.FastReloadAsync();
await offering.AssertHasSubscriber("enterprise@example.com", new()
{
Phase = SubscriberData.PhaseTypes.Trial,
@@ -381,7 +384,9 @@ public class SubscriptionTests(ITestOutputHelper testOutputHelper) : UnitTestBas
// Mark the invoice of basic2 invalid, so he should go from active to inactive
var api = await s.AsTestAccount().CreateClient();
var invoiceId = (await api.GetInvoices(storeId)).First().Id;
var invoice = (await api.GetInvoices(storeId)).First();
var invoiceId = invoice.Id;
Assert.Equal("basic2@example.com", invoice.Metadata["buyerEmail"]?.ToString());
var waiting = offering.WaitEvent<SubscriptionEvent.SubscriberEvent.SubscriberDisabled>();
await api.MarkInvoiceStatus(storeId, invoiceId, new()
@@ -392,7 +397,7 @@ public class SubscriptionTests(ITestOutputHelper testOutputHelper) : UnitTestBas
Assert.True(disabled.Subscriber.IsSuspended);
Assert.Equal("The plan has been started by an invoice which later became invalid.", disabled.Subscriber.SuspensionReason);
await s.Page.ReloadAsync(new() { WaitUntil = WaitUntilState.Commit });
await s.FastReloadAsync();
await offering.AssertHasSubscriber("basic2@example.com",
new()
@@ -411,7 +416,7 @@ public class SubscriptionTests(ITestOutputHelper testOutputHelper) : UnitTestBas
var activated = await activating;
Assert.Equal("basic@example.com", activated.Subscriber.Customer.GetPrimaryIdentity());
await s.Page.ReloadAsync(new() { WaitUntil = WaitUntilState.Commit });
await s.FastReloadAsync();
// Payment confirmed, this one should be active now
await offering.AssertHasSubscriber("basic@example.com",

View File

@@ -152,6 +152,8 @@ public class SubscriptionHostedService(
invoiceMetadata["planId"] = checkout.PlanId;
invoiceMetadata["offeringId"] = checkout.Plan.OfferingId;
}
if (GetBuyerEmail(checkout, customerSelector) is string email)
invoiceMetadata["buyerEmail"] = email;
var plan = checkout.Plan;
var existingCredit = checkout.Subscriber?.GetCredit() ?? 0m;
@@ -194,6 +196,11 @@ public class SubscriptionHostedService(
}
}
private static string? GetBuyerEmail(PlanCheckoutData checkout, CustomerSelector customerSelector)
=> customerSelector is CustomerSelector.Identity { Type: "Email", Value: { } email }
? email
: checkout.Subscriber?.Customer.Email.Get();
class MembershipServerSettings
{
public MembershipServerSettings()