CommunityToolkit.Aspire.Hosting.Stripe 17.0.0

Prefix Reserved
dotnet add package CommunityToolkit.Aspire.Hosting.Stripe --version 17.0.0
                    
NuGet\Install-Package CommunityToolkit.Aspire.Hosting.Stripe -Version 17.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="CommunityToolkit.Aspire.Hosting.Stripe" Version="17.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommunityToolkit.Aspire.Hosting.Stripe" Version="17.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CommunityToolkit.Aspire.Hosting.Stripe" />
                    
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 CommunityToolkit.Aspire.Hosting.Stripe --version 17.0.0
                    
#r "nuget: CommunityToolkit.Aspire.Hosting.Stripe, 17.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 CommunityToolkit.Aspire.Hosting.Stripe@17.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=CommunityToolkit.Aspire.Hosting.Stripe&version=17.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CommunityToolkit.Aspire.Hosting.Stripe&version=17.0.0
                    
Install as a Cake Tool

CommunityToolkit.Aspire.Hosting.Stripe library

Provides extension methods and resource definitions for an Aspire AppHost to configure the Stripe CLI for local webhook forwarding and testing.

Getting Started

Prerequisites

The Stripe CLI must be installed on your machine. You can install it by following the official Stripe CLI installation guide.

Install the package

In your AppHost project, install the package using the following command:

dotnet add package CommunityToolkit.Aspire.Hosting.Stripe

Example usage

Then, in the Program.cs file of your AppHost project, add the Stripe CLI and configure it to forward webhooks to your API:

var builder = DistributedApplication.CreateBuilder(args);

var stripeApiKey = builder.AddParameter("stripe-api-key", "sk_test_default", secret: true); // Override for real keys

var externalEndpoint = builder.AddExternalService("webhook-endpoint", "http://localhost:5082");
var stripe = builder.AddStripe("stripe", stripeApiKey)
    .WithListen(externalEndpoint, webhookPath: "/payments/stripe-webhook");

var api = builder.AddProject<Projects.API>("api")
    .WithReference(stripe);

builder.Build().Run();

This will:

  1. Start the Stripe CLI listening for webhook events
  2. Forward all webhook events to http://localhost:5082/payments/stripe-webhook
  3. Provide the Stripe API key to the container via the STRIPE_API_KEY environment variable
  4. Make the webhook signing secret available to the API project via the STRIPE_WEBHOOK_SECRET environment variable

Forwarding to an Aspire endpoint

You can also construct URLs dynamically using Aspire endpoint references:

var builder = DistributedApplication.CreateBuilder(args);

var api = builder.AddProject<Projects.API>("api")
    .WithHttpEndpoint(port: 5082, name: "http");

var stripeApiKey = builder.AddParameter("stripe-api-key", "sk_test_default", secret: true);

var stripe = builder.AddStripe("stripe", stripeApiKey)
    .WithListen(api, webhookPath: "/payments/stripe-webhook",
                events: ["payment_intent.created", "charge.succeeded"]);

api.WithReference(stripe);

builder.Build().Run();

Note: When constructing URLs with paths, you need to use ReferenceExpression.Create to combine the endpoint URL with your webhook path.

Using a custom environment variable for the webhook secret

By default, the webhook signing secret is exposed as STRIPE_WEBHOOK_SECRET. You can customize this:

var api = builder.AddProject<Projects.API>("api")
    .WithReference(stripe, webhookSigningSecretEnvVarName: "STRIPE_SECRET");

Configuring API key

AddStripe requires an IResourceBuilder<ParameterResource> that supplies your Stripe API key. The value is exposed to the container as the STRIPE_API_KEY environment variable. You can optionally reuse the same parameter to add the --api-key command-line argument:

var apiKey = builder.AddParameter("stripe-api-key", "sk_test_default", secret: true);

var webhookEndpoint = builder.AddExternalService("webhook-endpoint", "http://localhost:5082");
var stripe = builder.AddStripe("stripe", apiKey)
    .WithListen(webhookEndpoint, webhookPath: "/webhooks")
    .WithApiKey(apiKey); // optional: forwards the key to the CLI via --api-key

Filtering events

You can filter which webhook events the Stripe CLI listens for:

var stripeApiKey = builder.AddParameter("stripe-api-key", "sk_test_default", secret: true);
var webhookEndpoint = builder.AddExternalService("webhook-endpoint", "http://localhost:5082");
var stripe = builder.AddStripe("stripe", stripeApiKey)
    .WithListen(webhookEndpoint, webhookPath: "/webhooks",
                events: ["payment_intent.created", "charge.succeeded"]);

How it works

The Stripe CLI integration:

  • Runs stripe listen --forward-to <url> to listen for webhook events from Stripe's test environment
  • Forwards those events to your local application endpoint
  • Exposes the webhook signing secret so your application can verify webhook authenticity
  • Provides a development-friendly way to test webhook integrations without deploying to production

Additional Information

For more information about the Stripe CLI:

https://learn.microsoft.com/dotnet/aspire/community-toolkit/hosting-stripe

Feedback & contributing

https://github.com/CommunityToolkit/Aspire

Product Compatible and additional computed target framework versions.
.NET 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
17.0.0 74 11/20/2026
17.0.0-beta.1090 53 11/20/2026
17.0.0-beta.1088 49 11/20/2026
17.0.0-beta.1080 89 11/20/2026
17.0.0-beta.1078 210 11/19/2026
17.0.0-beta.1077 45 11/19/2026
17.0.0-beta.1076 48 11/19/2026
17.0.0-beta.1075 43 11/19/2026
17.0.0-beta.1052 63 11/16/2026
17.0.0-beta.1051 66 11/12/2026
17.0.0-beta.1033 59 11/10/2026
17.0.0-beta.1022 68 11/8/2026
17.0.0-beta.1018 58 11/6/2026
17.0.0-beta.1009 66 11/5/2026
17.0.0-beta.994 68 11/4/2026
17.0.0-beta.993 69 11/4/2026
13.6.2-beta.959 76 10/27/2026
13.6.1 1,402 10/26/2026
13.6.1-beta.950 68 10/26/2026
13.6.1-beta.938 68 10/24/2026
Loading failed