Skip to content

Commit

Permalink
add StripeClient to context
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilphillip committed Jun 2, 2024
1 parent c60a2e6 commit adbf22a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static IEndpointRouteBuilder MapStripeWebhookHandler<T>(this IEndpointRou
endpointRouteBuilder.MapPost(pattern, async context =>
{
var handlerFactory = ActivatorUtilities.CreateFactory(typeof(T), [typeof(StripeWebhookContext)]);
context.RequestServices.GetKeyedService<IStripeClient>(namedConfiguration);
var stripeClient = context.RequestServices.GetRequiredKeyedService<IStripeClient>(namedConfiguration);
var options = context.RequestServices.GetRequiredService<IOptionsSnapshot<StripeOptions>>()
.Get(namedConfiguration);

Expand All @@ -42,7 +42,7 @@ public static IEndpointRouteBuilder MapStripeWebhookHandler<T>(this IEndpointRou
$"Stripe services for {namedConfiguration} were not registered. Please call services.AddStripe()");
}

var stripeWebhookContext = new StripeWebhookContext(context, options);
var stripeWebhookContext = new StripeWebhookContext(context, options, stripeClient);
var handler = (T)handlerFactory(context.RequestServices, [stripeWebhookContext]);
await handler.ExecuteAsync();
});
Expand Down
13 changes: 4 additions & 9 deletions src/Stripe.Extensions.AspNetCore/StripeWebhookContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

namespace Stripe.Extensions.AspNetCore;

public class StripeWebhookContext
public class StripeWebhookContext(HttpContext httpContext, StripeOptions stripeOptions, IStripeClient stripeClient)
{
public HttpContext HttpContext { get; }
public StripeOptions StripeOptions { get; }

public StripeWebhookContext(HttpContext httpContext, StripeOptions stripeOptions)
{
HttpContext = httpContext;
StripeOptions = stripeOptions;
}
public HttpContext HttpContext { get; } = httpContext;
public StripeOptions StripeOptions { get; } = stripeOptions;
public IStripeClient? Client { get; } = stripeClient;
}

0 comments on commit adbf22a

Please sign in to comment.