# StripeExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.Stripe](/reference/api/csharp/communitytoolkit.aspire.hosting.stripe.md)
- Type: [StripeExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.stripe/stripeextensions.md)
- Kind: `Methods`
- Members: `5`

Extension methods for adding Stripe CLI to a `Hosting.IDistributedApplicationBuilder`.

## AddStripe(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>)

- Name: `AddStripe(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StripeResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Stripe/StripeExtensions.cs#L29-L43)

Adds the Stripe CLI to the application model for local webhook forwarding.

```csharp
public static class StripeExtensions
{
    public static IResourceBuilder<StripeResource> AddStripe(
        this IDistributedApplicationBuilder builder,
        string name,
        IResourceBuilder<ParameterResource> apiKey)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder` to add the resource to.
- `name` (`string`)
  The name of the resource.
- `apiKey` (`IResourceBuilder<ParameterResource>`)
  The parameter builder providing the Stripe API key.

## Returns

`IResourceBuilder<StripeResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithApiKey(IResourceBuilder<StripeResource>, IResourceBuilder<ParameterResource>)

- Name: `WithApiKey(IResourceBuilder<StripeResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StripeResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Stripe/StripeExtensions.cs#L148-L155)

Configures the Stripe CLI to use a specific API key from a parameter.

```csharp
public static class StripeExtensions
{
    public static IResourceBuilder<StripeResource> WithApiKey(
        this IResourceBuilder<StripeResource> builder,
        IResourceBuilder<ParameterResource> apiKey)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<StripeResource>`)
  The resource builder.
- `apiKey` (`IResourceBuilder<ParameterResource>`)
  The parameter containing the Stripe API key to use.

## Returns

`IResourceBuilder<StripeResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithListen(IResourceBuilder<StripeResource>, IResourceBuilder<IResourceWithEndpoints>, string, IEnumerable<string>)

- Name: `WithListen(IResourceBuilder<StripeResource>, IResourceBuilder<IResourceWithEndpoints>, string, IEnumerable<string>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StripeResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Stripe/StripeExtensions.cs)

Configures the Stripe CLI to listen for webhooks and forward them to the specified URL expression.

```csharp
public static class StripeExtensions
{
    public static IResourceBuilder<StripeResource> WithListen(
        this IResourceBuilder<StripeResource> builder,
        IResourceBuilder<IResourceWithEndpoints> forwardTo,
        string webhookPath = "/webhooks/stripe",
        IEnumerable<string>? events = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<StripeResource>`)
  The resource builder.
- `forwardTo` (`IResourceBuilder<IResourceWithEndpoints>`)
  The resource to forward webhooks to.
- `webhookPath` (`string`) `optional`
  The path to the webhook endpoint.
- `events` (`IEnumerable<string>`) `optional`
  Optional collection of specific webhook events to listen for (e.g., ["payment_intent.created", "charge.succeeded"]). If not specified, all events are forwarded.

## Returns

`IResourceBuilder<StripeResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithListen(IResourceBuilder<StripeResource>, IResourceBuilder<ExternalServiceResource>, string, IEnumerable<string>)

- Name: `WithListen(IResourceBuilder<StripeResource>, IResourceBuilder<ExternalServiceResource>, string, IEnumerable<string>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StripeResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Stripe/StripeExtensions.cs)

Configures the Stripe CLI to listen for webhooks and forward them to the specified URL expression.

```csharp
public static class StripeExtensions
{
    public static IResourceBuilder<StripeResource> WithListen(
        this IResourceBuilder<StripeResource> builder,
        IResourceBuilder<ExternalServiceResource> forwardTo,
        string webhookPath = "/webhooks/stripe",
        IEnumerable<string>? events = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<StripeResource>`)
  The resource builder.
- `forwardTo` (`IResourceBuilder<ExternalServiceResource>`)
  The resource to forward webhooks to.
- `webhookPath` (`string`) `optional`
  The path to the webhook endpoint.
- `events` (`IEnumerable<string>`) `optional`
  Optional collection of specific webhook events to listen for (e.g., ["payment_intent.created", "charge.succeeded"]). If not specified, all events are forwarded.

## Returns

`IResourceBuilder<StripeResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithReference(IResourceBuilder<TDestination>, IResourceBuilder<StripeResource>, string)

- Name: `WithReference(IResourceBuilder<TDestination>, IResourceBuilder<StripeResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TDestination>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Stripe/StripeExtensions.cs#L172-L184)

Adds a reference to a Stripe CLI resource for accessing its webhook signing secret.

```csharp
public static class StripeExtensions
{
    public static IResourceBuilder<TDestination> WithReference<TDestination>(
        this IResourceBuilder<TDestination> builder,
        IResourceBuilder<StripeResource> source,
        string webhookSigningSecretEnvVarName = "STRIPE_WEBHOOK_SECRET")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<TDestination>`)
  The resource builder.
- `source` (`IResourceBuilder<StripeResource>`)
  The Stripe CLI resource to reference.
- `webhookSigningSecretEnvVarName` (`string`) `optional`
  Optional environment variable name to use for the webhook signing secret. Defaults to "STRIPE_WEBHOOK_SECRET".

## Returns

`IResourceBuilder<TDestination>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
