Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PatchNotes.Api/PatchNotes.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<!-- The webhook admission predicates sit behind a Stripe API call, so they are
unreachable end-to-end without live network; they are unit-tested directly. -->
<InternalsVisibleTo Include="PatchNotes.Tests" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="1.3.2" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="3.1.2" />
Expand Down
18 changes: 13 additions & 5 deletions PatchNotes.Api/Routes/SubscriptionRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ public static WebApplication MapSubscriptionRoutes(this WebApplication app)
// Determine the base URL for success/cancel redirects
var origin = GetValidatedOrigin(httpContext, configuration);

// One dictionary for both: the session tag and the subscription tag have to agree,
// and building it twice is how they would come to disagree.
var appMetadata = new Dictionary<string, string>
{
{ "stytch_user_id", stytchUserId },
{ "app", "patchnotes" },
};

var sessionOptions = new SessionCreateOptions
{
Mode = "subscription",
Expand All @@ -98,11 +106,11 @@ public static WebApplication MapSubscriptionRoutes(this WebApplication app)
SuccessUrl = $"{origin}/subscription-success?session_id={{CHECKOUT_SESSION_ID}}",
CancelUrl = $"{origin}/subscription-canceled",
CustomerEmail = user.Email,
Metadata = new Dictionary<string, string>
{
{ "stytch_user_id", stytchUserId },
{ "app", "patchnotes" },
},
Metadata = appMetadata,
// Stripe does not copy the session's metadata onto the subscription it creates,
// so the tag is set again here. Without it the subscription and its invoices
// arrive at our webhook carrying nothing that identifies them as ours.
SubscriptionData = new SessionSubscriptionDataOptions { Metadata = appMetadata },
};

// If user already has a Stripe customer ID, use it
Expand Down
Loading