Skip to content
Merged
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
5 changes: 4 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import? '../sdk-codegen/utils.just'
_default:
just --list --unsorted

# ⭐ run format and tests to prepare for CI
prepare: format test

# _supported_dotnet_versions is built from the <TargetFrameworks>...</TargetFrameworks> in the Stripe.net.csproj
_supported_dotnet_versions := `
sed -n 's/.*<TargetFrameworks>\(.*\)<\/TargetFrameworks>.*/\1/p' src/Stripe.net/Stripe.net.csproj \
Expand All @@ -29,7 +32,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)

_ensure_latest_dotnet:
#!/usr/bin/env bash
Expand Down
2 changes: 2 additions & 0 deletions src/Stripe.net/Entities/V2/Core/EventNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ protected async Task<T> FetchEventAsync<T>(CancellationToken cancellationToken =
{
Usage = new List<string> { "fetch_event" },
StripeContext = this.Context,
StripeRequestTrigger = $"event={this.Id}",
},
cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand All @@ -140,6 +141,7 @@ protected virtual async Task<T> FetchRelatedObjectAsync<T>(EventNotificationRela
{
Usage = new List<string> { "fetch_related_object" },
StripeContext = this.Context,
StripeRequestTrigger = $"event={this.Id}",
},
cancellationToken: cancellationToken)
.ConfigureAwait(false);
Expand Down
7 changes: 5 additions & 2 deletions src/Stripe.net/Entities/V2/Core/Events/Event.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ protected virtual Task<T> FetchRelatedObjectAsync<T>(EventRelatedObject relatedO
return null;
}

RequestOptions opts = null;
RequestOptions opts = new RequestOptions
{
StripeRequestTrigger = $"event={this.Id}",
};
if (this.Context != null)
{
opts = new RequestOptions { StripeContext = this.Context };
opts.StripeContext = this.Context;
}

return this.Requestor.RequestAsync<T>(
Expand Down
5 changes: 5 additions & 0 deletions src/Stripe.net/Infrastructure/Public/StripeRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ private static Dictionary<string, string> BuildStripeHeaders(
stripeHeaders.Add("Stripe-Context", requestOptions.StripeContext);
}

if (!string.IsNullOrEmpty(requestOptions?.StripeRequestTrigger))
{
stripeHeaders.Add("Stripe-Request-Trigger", requestOptions.StripeRequestTrigger);
}

if (!string.IsNullOrEmpty(requestOptions?.IdempotencyKey))
{
stripeHeaders.Add("Idempotency-Key", requestOptions.IdempotencyKey);
Expand Down
3 changes: 3 additions & 0 deletions src/Stripe.net/Services/_common/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class RequestOptions
/// <summary>Gets or sets the value or Stripe-Context request header.</summary>
public string StripeContext { get; set; }

/// <summary>Gets or sets the value of the Stripe-Request-Trigger request header.</summary>
public string StripeRequestTrigger { get; set; }

/// <summary>Gets the base URL for the request.</summary>
/// <remarks>
/// This is an internal property. It is set by services or individual request methods when
Expand Down
19 changes: 19 additions & 0 deletions src/StripeTests/Events/V2/EventTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace StripeTests.V2
{
using System;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -383,6 +384,15 @@ public void FetchRelatedObjectFromNotif()

Assert.Equal("meter_123", relatedObject.Id);
Assert.Equal("billing.meter", relatedObject.Object);

this.MockHttpClientFixture.MockHandler.Protected()
.Verify<Task<HttpResponseMessage>>(
"SendAsync",
Times.AtLeastOnce(),
ItExpr.Is<HttpRequestMessage>(m =>
m.Headers.Contains("Stripe-Request-Trigger") &&
m.Headers.GetValues("Stripe-Request-Trigger").First() == "event=evt_234"),
ItExpr.IsAny<CancellationToken>());
}

[Fact]
Expand Down Expand Up @@ -420,6 +430,15 @@ public async void FetchRelatedObjectAsync()
var relatedObject = await stripeEvent.FetchRelatedObjectAsync();
Assert.Equal("meter_123", relatedObject.Id);
Assert.Equal("billing.meter", relatedObject.Object);

this.MockHttpClientFixture.MockHandler.Protected()
.Verify<Task<HttpResponseMessage>>(
"SendAsync",
Times.AtLeastOnce(),
ItExpr.Is<HttpRequestMessage>(m =>
m.Headers.Contains("Stripe-Request-Trigger") &&
m.Headers.GetValues("Stripe-Request-Trigger").First() == "event=evt_234"),
ItExpr.IsAny<CancellationToken>());
}

[Fact]
Expand Down
Loading