CommunityToolkit.Aspire.Hosting.Stripe 13.6.1

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package CommunityToolkit.Aspire.Hosting.Stripe --version 13.6.1
                    
NuGet\Install-Package CommunityToolkit.Aspire.Hosting.Stripe -Version 13.6.1
                    
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="13.6.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommunityToolkit.Aspire.Hosting.Stripe" Version="13.6.1" />
                    
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 13.6.1
                    
#r "nuget: CommunityToolkit.Aspire.Hosting.Stripe, 13.6.1"
                    
#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@13.6.1
                    
#: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=13.6.1
                    
Install as a Cake Addin
#tool nuget:?package=CommunityToolkit.Aspire.Hosting.Stripe&version=13.6.1
                    
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 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

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
13.6.2-beta.959 38 10/27/2026
13.6.1 84 10/26/2026
13.6.1-beta.950 50 10/26/2026
13.6.1-beta.938 49 10/24/2026
13.6.1-beta.935 131 10/15/2026
13.6.1-beta.933 56 10/13/2026
13.6.1-beta.930 55 10/11/2026
13.6.0 700 10/1/2026
13.6.0-beta.914 61 10/1/2026
13.6.0-beta.910 68 9/30/2026
13.5.1-beta.895 68 9/29/2026
13.5.1-beta.806 60 9/28/2026
13.5.1-beta.803 63 9/28/2026
13.5.1-beta.781 62 9/28/2026
13.5.1-beta.779 60 9/28/2026
13.5.1-beta.777 63 9/28/2026
13.5.1-beta.776 73 9/28/2026
13.5.1-beta.775 63 9/27/2026
13.5.1-beta.770 67 9/25/2026
13.5.1-beta.767 65 9/22/2026
Loading failed