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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4776797593c966ebe1494340934edf45a6764bf2
4776797593c966ebe1494340934edf45a6764bf2
7 changes: 5 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ _default:
# base test command that other, more specific commands use
[no-quiet]
[no-exit-message]
_test no_build framework config:
dotnet test {{no_build}} {{framework}} src/StripeTests/StripeTests.csproj -c {{config}}
_test no_build framework config filter="":
dotnet test {{no_build}} {{framework}} src/StripeTests/StripeTests.csproj -c {{config}} {{ if filter == "" {""} else {"--filter " + filter} }}

# ⭐ run tests in debug mode
test: (_test "" "-f net8.0" "Debug")

# run a test matching a filter
test-one name: (_test "" "-f net8.0" "Debug" name)

# skip build and don't specify the dotnet framework
ci-test: (_test "--no-build" "" "Release")

Expand Down
77 changes: 77 additions & 0 deletions src/Examples/V2/EventNotificationWebhookHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace Examples.V2
{
#pragma warning disable SA1101 // Prefix local calls with this

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Stripe;
using Stripe.Events;
using Stripe.V2;

/// <summary>
/// Receive and process EventNotifications like the v1.billing.meter.error_report_triggered event.
///
/// In this example, we:
/// - use ParseEventNotification to parse the received event notification webhook body
/// - call StripeClient.v2.core.events.retrieve to retrieve the full event object
/// - if it is a V1BillingMeterErrorReportTriggeredEvent event type, call fetchRelatedObject
/// to retrieve the Billing Meter object associated with the event.
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class EventNotificationWebhookHandler : ControllerBase
{
private readonly StripeClient client;
private readonly string webhookSecret;

public EventNotificationWebhookHandler()

Check warning on line 29 in src/Examples/V2/EventNotificationWebhookHandler.cs

View workflow job for this annotation

GitHub Actions / Build and test

Non-nullable field 'webhookSecret' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
var apiKey = Environment.GetEnvironmentVariable("STRIPE_API_KEY");
client = new StripeClient(apiKey);

webhookSecret = Environment.GetEnvironmentVariable("WEBHOOK_SECRET");

Check warning on line 34 in src/Examples/V2/EventNotificationWebhookHandler.cs

View workflow job for this annotation

GitHub Actions / Build and test

Possible null reference assignment.
}

[HttpPost]
public async Task<IActionResult> Index()
{
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
try
{
var eventNotification = client.ParseEventNotification(json, Request.Headers["Stripe-Signature"], webhookSecret);

// match on the type of the class to determine what event you have
if (eventNotification is V1BillingMeterErrorReportTriggeredEventNotification evt)
{
// the related object is correctly typed
var meter = evt.FetchRelatedObject();
Console.WriteLine($"Default aggregation: {meter.DefaultAggregation}");

// can also fetch the full event to get the event data
var eventObj = evt.FetchEvent();
var eventData = eventObj.Data;
Console.WriteLine($"Err summary: {eventData.DeveloperMessageSummary}");
}

// check other types the SDK knows about
// for event types that were released after this SDK was generated, check type
else if (eventNotification is UnknownEventNotification unknownEvt)
{
// fall back to checking type
if (unknownEvt.Type == "some.other.event")
{
// handle the event
}
}

return Ok();
}
catch (StripeException e)
{
return BadRequest(e.Message);
}
}
}
}
63 changes: 0 additions & 63 deletions src/Examples/V2/ThinEventWebhookHandler.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Stripe.net/Entities/V2/Events/Event.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Stripe.V2
using Stripe.Infrastructure;

/// <summary>
/// Manually-maintained convenience methods added to ThinEvent.
/// Manually-maintained convenience methods added to V2 Events.
/// </summary>
[JsonConverter(typeof(V2EventConverter))]
#if NET6_0_OR_GREATER
Expand Down Expand Up @@ -69,7 +69,7 @@ protected virtual Task<T> FetchRelatedObjectAsync<T>(EventRelatedObject relatedO
RequestOptions opts = null;
if (this.Context != null)
{
opts = new RequestOptions { StripeAccount = this.Context };
opts = new RequestOptions { StripeContext = this.Context };
}

return this.Requestor.RequestAsync<T>(
Expand Down
53 changes: 53 additions & 0 deletions src/Stripe.net/Events/V1AccountUpdatedEventNotification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// File generated from our OpenAPI spec
namespace Stripe.Events
{
using System.Threading.Tasks;
using Newtonsoft.Json;
using Stripe.V2;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

/// <summary>
/// Occurs whenever an account status or property has changed.
/// </summary>
public class V1AccountUpdatedEventNotification : V2.EventNotification
{
/// <summary>
/// Object containing the reference to API resource relevant to the event.
/// </summary>
[JsonProperty("related_object")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("related_object")]
#endif

public V2.EventNotificationRelatedObject RelatedObject { get; set; }

/// <summary>
/// Asynchronously retrieves the related object from the API. Make an API request on every
/// call.
/// </summary>
public Task<Account> FetchRelatedObjectAsync()
{
return this.FetchRelatedObjectAsync<Account>(this.RelatedObject);
}

/// <summary>
/// Retrieves the related object from the API. Make an API request on every call.
/// </summary>
public Account FetchRelatedObject()
{
return this.FetchRelatedObject<Account>(this.RelatedObject);
}

public V1AccountUpdatedEvent FetchEvent()
{
return this.FetchEvent<V1AccountUpdatedEvent>();
}

public Task<V1AccountUpdatedEvent> FetchEventAsync()
{
return this.FetchEventAsync<V1AccountUpdatedEvent>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// File generated from our OpenAPI spec
namespace Stripe.Events
{
using System.Threading.Tasks;
using Newtonsoft.Json;
using Stripe.V2;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

/// <summary>
/// Occurs whenever an application fee is created on a charge.
/// </summary>
public class V1ApplicationFeeCreatedEventNotification : V2.EventNotification
{
/// <summary>
/// Object containing the reference to API resource relevant to the event.
/// </summary>
[JsonProperty("related_object")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("related_object")]
#endif

public V2.EventNotificationRelatedObject RelatedObject { get; set; }

/// <summary>
/// Asynchronously retrieves the related object from the API. Make an API request on every
/// call.
/// </summary>
public Task<ApplicationFee> FetchRelatedObjectAsync()
{
return this.FetchRelatedObjectAsync<ApplicationFee>(this.RelatedObject);
}

/// <summary>
/// Retrieves the related object from the API. Make an API request on every call.
/// </summary>
public ApplicationFee FetchRelatedObject()
{
return this.FetchRelatedObject<ApplicationFee>(this.RelatedObject);
}

public V1ApplicationFeeCreatedEvent FetchEvent()
{
return this.FetchEvent<V1ApplicationFeeCreatedEvent>();
}

public Task<V1ApplicationFeeCreatedEvent> FetchEventAsync()
{
return this.FetchEventAsync<V1ApplicationFeeCreatedEvent>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// File generated from our OpenAPI spec
namespace Stripe.Events
{
using System.Threading.Tasks;
using Newtonsoft.Json;
using Stripe.V2;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

/// <summary>
/// Occurs whenever an application fee is refunded, whether from refunding a charge or from
/// <a href="https://stripe.com/docs/api#fee_refunds">refunding the application fee
/// directly</a>. This includes partial refunds.
/// </summary>
public class V1ApplicationFeeRefundedEventNotification : V2.EventNotification
{
/// <summary>
/// Object containing the reference to API resource relevant to the event.
/// </summary>
[JsonProperty("related_object")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("related_object")]
#endif

public V2.EventNotificationRelatedObject RelatedObject { get; set; }

/// <summary>
/// Asynchronously retrieves the related object from the API. Make an API request on every
/// call.
/// </summary>
public Task<ApplicationFee> FetchRelatedObjectAsync()
{
return this.FetchRelatedObjectAsync<ApplicationFee>(this.RelatedObject);
}

/// <summary>
/// Retrieves the related object from the API. Make an API request on every call.
/// </summary>
public ApplicationFee FetchRelatedObject()
{
return this.FetchRelatedObject<ApplicationFee>(this.RelatedObject);
}

public V1ApplicationFeeRefundedEvent FetchEvent()
{
return this.FetchEvent<V1ApplicationFeeRefundedEvent>();
}

public Task<V1ApplicationFeeRefundedEvent> FetchEventAsync()
{
return this.FetchEventAsync<V1ApplicationFeeRefundedEvent>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// File generated from our OpenAPI spec
namespace Stripe.Events
{
using System.Threading.Tasks;
using Newtonsoft.Json;
using Stripe.V2;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

/// <summary>
/// Occurs when a Meter has invalid async usage events.
/// </summary>
public class V1BillingMeterErrorReportTriggeredEventNotification : V2.EventNotification
{
/// <summary>
/// Object containing the reference to API resource relevant to the event.
/// </summary>
[JsonProperty("related_object")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("related_object")]
#endif

public V2.EventNotificationRelatedObject RelatedObject { get; set; }

/// <summary>
/// Asynchronously retrieves the related object from the API. Make an API request on every
/// call.
/// </summary>
public Task<Billing.Meter> FetchRelatedObjectAsync()
{
return this.FetchRelatedObjectAsync<Billing.Meter>(this.RelatedObject);
}

/// <summary>
/// Retrieves the related object from the API. Make an API request on every call.
/// </summary>
public Billing.Meter FetchRelatedObject()
{
return this.FetchRelatedObject<Billing.Meter>(this.RelatedObject);
}

public V1BillingMeterErrorReportTriggeredEvent FetchEvent()
{
return this.FetchEvent<V1BillingMeterErrorReportTriggeredEvent>();
}

public Task<V1BillingMeterErrorReportTriggeredEvent> FetchEventAsync()
{
return this.FetchEventAsync<V1BillingMeterErrorReportTriggeredEvent>();
}
}
}
Loading
Loading