Skip to content
Merged
7 changes: 7 additions & 0 deletions src/Stripe.net/Infrastructure/Public/LiveApiRequestor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public LiveApiRequestor(StripeClientOptions options, List<string> defaultUsage =
/// <value>The <see cref="IHttpClient"/> used to send HTTP requests.</value>
public override IHttpClient HttpClient { get; }

/// <summary>Gets the current StripeContext for this requestor; Used in unit tests.</summary>
/// <value>The current StripeContext.</value>
internal StripeContext CurrentStripeContext
{
get => this.clientOptions.StripeContext;
}

/// <summary>Sends a request to Stripe's API as an asynchronous operation.</summary>
/// <typeparam name="T">Type of the Stripe entity returned by the API.</typeparam>
/// <param name="baseAddress">The base address of the request.</param>
Expand Down
11 changes: 11 additions & 0 deletions src/Stripe.net/Infrastructure/Public/StripeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ public EventNotification ParseEventNotification(
return EventNotification.FromJson(json, this);
}

/// <summary>
/// Create a new StripeEventNotificationHandler bound to this StripeClient.
/// </summary>
/// <param name="webhookSecret">The secret for this event destination, e.g. "wh_sec_...".</param>
/// <param name="fallbackCallback">The function to call when handing an event for whom there's no callback registered.</param>
/// <returns></returns>
public StripeEventNotificationHandler NotificationHandler(string webhookSecret, Action<object, StripeUnhandledEventNotificationEventArgs> fallbackCallback)
{
return new StripeEventNotificationHandler(this, webhookSecret, fallbackCallback);
}

internal JsonSerializerSettings GetJsonSerializationSettings()
{
return this.jsonSerializerSettings;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace Stripe
{
using System;

/// <summary>
/// EventArgs for Stripe webhook event notifications.
/// Contains the strongly-typed EventNotification and the StripeClient instance.
/// </summary>
/// <typeparam name="TEventNotification">The type of EventNotification.</typeparam>
public class StripeEventNotificationEventArgs<TEventNotification> : EventArgs
where TEventNotification : V2.Core.EventNotification
{
/// <summary>
/// Initializes a new instance of the <see cref="StripeEventNotificationEventArgs{TEventNotification}"/> class.
/// </summary>
/// <param name="eventNotification">The event notification instance.</param>
/// <param name="client">The StripeClient instance.</param>
public StripeEventNotificationEventArgs(TEventNotification eventNotification, StripeClient client)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this ever get constructed outside of our SDK code? If not, I would consider changing this constructor to be internal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't users need it for tests? Like, if they write their function and want to test it in isolation, that function takes these args and they'd nee to be able to construct it?

{
if (eventNotification == null)
{
throw new ArgumentNullException(nameof(eventNotification));
}

this.EventNotification = eventNotification;

if (client == null)
{
throw new ArgumentNullException(nameof(client));
}

this.Client = client;
}

/// <summary>
/// Gets the event notification instance.
/// </summary>
public TEventNotification EventNotification { get; }

/// <summary>
/// Gets the StripeClient instance that can be used to make API requests.
/// </summary>
public StripeClient Client { get; }
}
}
Loading
Loading