Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _mise_install_dotnet:
export DOTNET_ROOT="$(mise where dotnet)"

_dotnet_install tpv:
./scripts/dotnet-install.sh --channel {{ tpv }} --install-dir $DOTNET_ROOT
./scripts/dotnet-install.sh --channel {{ tpv }} --install-dir "$(mise where dotnet)"
Copy link
Member Author

Choose a reason for hiding this comment

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

Env isn't shared between recipes, so this doesn't work if you don't have the root set

Copy link
Contributor

Choose a reason for hiding this comment

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

we may want to fail if DOTNET_ROOT isnt set here; iirc a lot of stuff doesnt work right if that env var isn't already set.


_ensure_latest_dotnet:
#!/usr/bin/env bash
Expand Down
8 changes: 8 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,14 @@ 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 or sets the current StripeContext for this requestor.</summary>
/// <value>The current StripeContext.</value>
internal StripeContext CurrentStripeContext
{
get => this.clientOptions.StripeContext;
set => this.clientOptions.StripeContext = value;
}

/// <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
5 changes: 5 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,11 @@ public EventNotification ParseEventNotification(
return EventNotification.FromJson(json, this);
}

public StripeEventRouter Router(string webhookSecret, EventHandler<StripeUnhandledEventNotificationEventArgs> unhandledEventHandler)
{
return new StripeEventRouter(this, webhookSecret, unhandledEventHandler);
}

internal JsonSerializerSettings GetJsonSerializationSettings()
{
return this.jsonSerializerSettings;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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
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
Member 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?

{
this.EventNotification = eventNotification ?? throw new ArgumentNullException(nameof(eventNotification));
Copy link
Contributor

Choose a reason for hiding this comment

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

its a small nit, but can you pull the null check and throw into a separate line/conditional? I find that easier to read

this.Client = client ?? throw new ArgumentNullException(nameof(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; }
}
}
800 changes: 800 additions & 0 deletions src/Stripe.net/Infrastructure/Public/StripeEventRouter.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Stripe
{
using System;

/// <summary>
/// EventArgs for Stripe webhook event notifications.
/// Contains the strongly-typed EventNotification and the StripeClient instance.
/// </summary>
public class StripeUnhandledEventNotificationEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="StripeUnhandledEventNotificationEventArgs"/> class.
/// </summary>
/// <param name="eventNotification">The event notification instance.</param>
/// <param name="client">The StripeClient instance.</param>
/// <param name="details">Details about the unhandled notification.</param>
public StripeUnhandledEventNotificationEventArgs(V2.Core.EventNotification eventNotification, StripeClient client, UnhandledNotificationDetails details)
{
this.EventNotification = eventNotification ?? throw new ArgumentNullException(nameof(eventNotification));
this.Client = client ?? throw new ArgumentNullException(nameof(client));
this.Details = details ?? throw new ArgumentNullException(nameof(details));
}

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

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

/// <summary>
/// Gets details about the unhandled notification.
/// </summary>
public UnhandledNotificationDetails Details { get; }
}
}
22 changes: 22 additions & 0 deletions src/Stripe.net/Infrastructure/UnhandledNotificationDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Stripe
{
/// <summary>
/// EventArgs for Stripe webhook event notifications.
/// Contains the strongly-typed EventNotification and the StripeClient instance.
/// </summary>
public class UnhandledNotificationDetails
{
/// <summary>
/// Initializes a new instance of the <see cref="UnhandledNotificationDetails"/> class.
/// </summary>
public UnhandledNotificationDetails(bool isKnownEventType)
{
this.IsKnownEventType = isKnownEventType;
}

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