Pinqponq.Billing.RevenueCat 1.0.0

Prefix Reserved
dotnet add package Pinqponq.Billing.RevenueCat --version 1.0.0
                    
NuGet\Install-Package Pinqponq.Billing.RevenueCat -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pinqponq.Billing.RevenueCat" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pinqponq.Billing.RevenueCat" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Pinqponq.Billing.RevenueCat" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pinqponq.Billing.RevenueCat --version 1.0.0
                    
#r "nuget: Pinqponq.Billing.RevenueCat, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pinqponq.Billing.RevenueCat@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pinqponq.Billing.RevenueCat&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Pinqponq.Billing.RevenueCat&version=1.0.0
                    
Install as a Cake Tool

Pinqponq.Billing.RevenueCat

RevenueCat webhook handling for products with subscriptions: the payload model, the Authorization header check and the event dispatch that turns webhook events into subscription state. How a subscription is stored stays with the product — the package asks for it through one interface, IRevenueCatSubscriptionStore.

Install

dotnet add package Pinqponq.Billing.RevenueCat

Requirements

  • .NET 8.0, 9.0, or 10.0
  • A webhook configured in the RevenueCat dashboard with an Authorization header value

Quick start

Implement the store on top of your database:

public sealed class SubscriptionStore(AppDbContext db) : IRevenueCatSubscriptionStore
{
    public bool TryResolveSubscriberId(string? appUserId, out string subscriberId)
    {
        subscriberId = int.TryParse(appUserId, out var id) ? id.ToString() : string.Empty;
        return subscriberId.Length > 0;
    }

    public Task<bool> HasProcessedEvent(string eventId, CancellationToken cancellationToken = default) =>
        db.ProcessedWebhookEvents.AnyAsync(entry => entry.EventId == eventId, cancellationToken);

    public void RecordProcessedEvent(string eventId, string eventType, DateTime processedAtUtc) =>
        db.ProcessedWebhookEvents.Add(new ProcessedWebhookEvent(eventId, eventType, processedAtUtc));

    public async Task<RevenueCatSubscription?> FindSubscription(string subscriberId, CancellationToken cancellationToken = default) =>
        /* load your row and map it to RevenueCatSubscription */;

    public void SaveSubscription(RevenueCatSubscription subscription) =>
        /* add or update your row from the subscription */;

    public Task Commit(CancellationToken cancellationToken = default) => db.SaveChangesAsync(cancellationToken);
}

Register the package and expose the webhook:

builder.Services.AddPinqponqRevenueCat<SubscriptionStore>(options =>
{
    options.WebhookAuthHeader = builder.Configuration["RevenueCat:WebhookAuthHeader"]!;
    options.PremiumEntitlementId = "premium";
});

app.MapPost("/webhooks/revenuecat", async (
    HttpRequest request,
    RevenueCatWebhookPayload payload,
    IRevenueCatWebhookAuthenticator authenticator,
    IRevenueCatEventHandler handler,
    CancellationToken cancellationToken) =>
{
    if (!authenticator.IsAuthorized(request.Headers.Authorization))
    {
        return Results.Unauthorized();
    }

    return await handler.Handle(payload, cancellationToken) ? Results.Ok() : Results.BadRequest();
}).AllowAnonymous();

Configuration

AddPinqponqRevenueCat<TStore>(Action<RevenueCatOptions> configure) registers the handler (scoped), the authenticator (singleton), your store (scoped) and validates the options on startup.

Option Default Notes
WebhookAuthHeader none The Authorization header value set in the RevenueCat dashboard. Required.
PremiumEntitlementId none The entitlement that counts as premium; must match the dashboard and the mobile app. Required.

Main types

  • IRevenueCatEventHandler — Handle(payload) applies one event. Returns false only for an invalid payload (no event, id or type); a duplicate delivery returns true and changes nothing.
  • IRevenueCatWebhookAuthenticator — constant-time check of the Authorization header. An unconfigured secret authorizes nothing.
  • IRevenueCatSubscriptionStore — the product's storage. Everything saved between two Commit calls must be written together, so an event and its effects are stored atomically.
  • IRevenueCatWebhookObserver — optional. Receives a structured record for each noteworthy handler step (named by RevenueCatWebhookLogEvents) next to the ILogger output, so a product can forward them to its own log pipeline. Register your own implementation before or after AddPinqponqRevenueCat; the default ignores them.
  • IRevenueCatEventListener — optional, any number. Runs a product-specific follow-up (a welcome mail on the first purchase, say) after an event has been applied and committed, with a RevenueCatEventContext holding the event, the resolved subscriber id (null if none) and whether it carries the premium entitlement. Not called for duplicates, invalid payloads, TEST events or a failed commit. An exception from a listener propagates out of Handle (the event is already stored, and RevenueCat will redeliver it as a duplicate), so a listener that must not fail the webhook catches its own errors. Register with services.AddScoped<IRevenueCatEventListener, MyListener>().
  • RevenueCatWebhookPayload, RevenueCatEvent, RevenueCatEventType — the webhook body.

Event behavior

Event Effect
INITIAL_PURCHASE, RENEWAL, PRODUCT_CHANGE, UNCANCELLATION, NON_RENEWING_PURCHASE Creates or updates the subscription: active when the event carries the premium entitlement, renewing, product/store/expiry/transaction refreshed.
CANCELLATION Stops renewal; premium stays on until the period ends.
EXPIRATION Deactivates the subscription.
BILLING_ISSUE Marks the grace period; premium stays on.
TRANSFER Deactivates the subscribers in transferred_from, activates those in transferred_to.
SUBSCRIBER_ALIAS, TEST Recorded as processed; no subscription change.
anything else Observed as unhandled and recorded as processed.

CANCELLATION, EXPIRATION and BILLING_ISSUE are skipped when they belong to an older period than the stored one — a different original_transaction_id, or an expiry before the stored one. RevenueCat sends such events right after a resubscribe, and applying them would drop the fresh premium.

Subscribers are found from app_user_id first, then from the aliases, through IRevenueCatSubscriptionStore.TryResolveSubscriberId. Events whose subscriber cannot be resolved are observed and recorded without a subscription change.

Notes

The package has no ASP.NET Core dependency: routing and the HTTP status codes stay in the product, so the same handler serves minimal APIs and controllers.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pinqponq.Billing.RevenueCat:

Package Downloads
Pinqponq.Billing.RevenueCat.Mail

Subscription event mails for Pinqponq.Billing.RevenueCat: maps webhook events to mails, resolves the recipient through the consuming product, renders a branded HTML mail with a plain-text version and sends it through Pinqponq.Mail without ever failing the webhook.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 215 10/17/2026