Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark ServiceNested as Obsolete #2983

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1267
v1268
25 changes: 25 additions & 0 deletions src/Examples/ExampleWebApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>

</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Stripe.net\Stripe.net.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Stylecop.Analyzers" Version="1.1.118">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>..\_stylecop\StyleCopRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

</Project>
29 changes: 29 additions & 0 deletions src/Examples/Examples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>

</PropertyGroup>

<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);V2/StripeWebhookHandler.cs</DefaultItemExcludes>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Stripe.net\Stripe.net.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Stylecop.Analyzers" Version="1.1.118">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>..\_stylecop\StyleCopRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

</Project>
29 changes: 29 additions & 0 deletions src/Examples/NewExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Examples
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Stripe;
using Stripe.V2.Billing;

public class NewExample
{

public static async Task Run()
{
var apiKey = "{{API_KEY}}";

try
{
Console.WriteLine("Hello World");

// var client = new StripeClient(apiKey);
// client.V1...
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
}
22 changes: 22 additions & 0 deletions src/Examples/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Examples
{
using System;
using System.Threading.Tasks;

public class Program
{
public Program()
{
}

public static async Task Main(string[] args)
{
// To create an example, clone NewExample.cs, implement the example
// copy this line and replace the class name with your new class.
// await NewExample.Run();
// e.g.
// await MeterEventExample.Run();
// then build the project and run bin/Debug/net8.0/Examples
}
}
}
70 changes: 70 additions & 0 deletions src/Examples/V2/MeterEventExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
namespace MeterEventExample
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Stripe;
using Stripe.V2.Billing;

public class MeterEventExample
{
private static MeterEventSession? meterEventSession;

public static async Task Run()
{
var apiKey = "{{API_KEY}}";
var customerId = "{{CUSTOMER_ID}}"; // Replace with actual customer ID

try
{
await SendMeterEvent(apiKey, "alpaca_ai_tokens", customerId, "25");
Console.WriteLine("Meter event sent successfully!");
}
catch (Exception ex)
{
Console.WriteLine($"Error sending meter event: {ex.Message}");
}
}

private static async Task RefreshMeterEventSession(string apiKey)
{
// Check if session is null or expired
if (meterEventSession == null || meterEventSession.ExpiresAt <= DateTime.UtcNow)
{
// Create a new meter event session in case the existing session expired
var client = new StripeClient(apiKey);
meterEventSession = await client.V2.Billing.MeterEventSession.CreateAsync(new MeterEventSessionCreateOptions());
}
}

private static async Task SendMeterEvent(string apiKey, string eventName, string stripeCustomerId, string value)
{
// Refresh the meter event session if necessary
await RefreshMeterEventSession(apiKey);

if (meterEventSession == null)
{
throw new Exception("Unable to refresh meter event session");
}

// Create a meter event
var client = new StripeClient(meterEventSession.AuthenticationToken);
var options = new MeterEventStreamCreateOptions
{
Events =
[
new MeterEventStreamCreateEventOptions
{
EventName = eventName,
Payload = new Dictionary<string, string>
{
{ "stripe_customer_id", stripeCustomerId },
{ "value", value },
},
},
],
};
client.V2.Billing.MeterEventStream.Create(options);
}
}
}
52 changes: 52 additions & 0 deletions src/Examples/V2/StripeWebhookHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma warning disable SA1649 // File name should match first type name
#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;

[Route("api/[controller]")]
[ApiController]
public class WebhookController : ControllerBase
{
private readonly StripeClient _client;
private readonly string _webhookSecret;

public WebhookController()
{
var apiKey = Environment.GetEnvironmentVariable("STRIPE_API_KEY");
_client = new StripeClient(apiKey);

_webhookSecret = Environment.GetEnvironmentVariable("WEBHOOK_SECRET");
}

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

// Fetch the event data to understand the failure
var baseEvent = await _client.V2.Core.Events.GetAsync(thinEvent.Id);
if (baseEvent is V1BillingMeterErrorReportTriggeredEvent fullEvent)
{
var meter = await fullEvent.FetchRelatedObjectAsync();
var meterId = meter.Id;

// Record the failures and alert your team
// Add your logic here
}

return Ok();
}
catch (StripeException e)
{
return BadRequest(e.Message);
}
}
}
14 changes: 13 additions & 1 deletion src/Stripe.net.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.4
MinimumVisualStudioVersion = 10.0.40219.1
Expand All @@ -20,6 +20,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stripe.net", "Stripe.net\St
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StripeTests", "StripeTests\StripeTests.csproj", "{75F3AA23-C708-4408-AFD0-D7FA354E031B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{EF1FBE46-76A7-471C-A1EE-229F689A6BB7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleWebApp", "Examples\ExampleWebApp.csproj", "{78BBD781-EDE7-4472-AF01-802442DCB62F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,6 +38,14 @@ Global
{75F3AA23-C708-4408-AFD0-D7FA354E031B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75F3AA23-C708-4408-AFD0-D7FA354E031B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75F3AA23-C708-4408-AFD0-D7FA354E031B}.Release|Any CPU.Build.0 = Release|Any CPU
{EF1FBE46-76A7-471C-A1EE-229F689A6BB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF1FBE46-76A7-471C-A1EE-229F689A6BB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF1FBE46-76A7-471C-A1EE-229F689A6BB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF1FBE46-76A7-471C-A1EE-229F689A6BB7}.Release|Any CPU.Build.0 = Release|Any CPU
{78BBD781-EDE7-4472-AF01-802442DCB62F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78BBD781-EDE7-4472-AF01-802442DCB62F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78BBD781-EDE7-4472-AF01-802442DCB62F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78BBD781-EDE7-4472-AF01-802442DCB62F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/Stripe.net/Constants/ApiVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ namespace Stripe
{
internal class ApiVersion
{
public const string Current = "2024-06-20";
public const string Current = "2024-09-30.acacia";
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// File generated from our OpenAPI spec
namespace Stripe
{
public static class Events
/// <summary>
/// This class used to be called Events.
/// </summary>
public static class EventTypes
{
/// <summary>
/// Occurs whenever a user authorizes an application. Sent to the related application only.
Expand Down
11 changes: 2 additions & 9 deletions src/Stripe.net/Entities/Billing/Alerts/Alert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ public class Alert : StripeEntity<Alert>, IHasId, IHasObject
[JsonProperty("alert_type")]
public string AlertType { get; set; }

/// <summary>
/// Limits the scope of the alert to a specific <a
/// href="https://stripe.com/docs/api/customers">customer</a>.
/// </summary>
[JsonProperty("filter")]
public AlertFilter Filter { get; set; }

/// <summary>
/// Has the value <c>true</c> if the object exists in live mode or the value <c>false</c> if
/// the object exists in test mode.
Expand All @@ -59,7 +52,7 @@ public class Alert : StripeEntity<Alert>, IHasId, IHasObject
/// Encapsulates configuration of the alert to monitor usage on a specific <a
/// href="https://stripe.com/docs/api/billing/meter">Billing Meter</a>.
/// </summary>
[JsonProperty("usage_threshold_config")]
public AlertUsageThresholdConfig UsageThresholdConfig { get; set; }
[JsonProperty("usage_threshold")]
public AlertUsageThreshold UsageThreshold { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
// File generated from our OpenAPI spec
namespace Stripe.Billing
{
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class AlertUsageThresholdConfig : StripeEntity<AlertUsageThresholdConfig>
public class AlertUsageThreshold : StripeEntity<AlertUsageThreshold>
{
/// <summary>
/// The filters allow limiting the scope of this usage alert. You can only specify up to one
/// filter at this time.
/// </summary>
[JsonProperty("filters")]
public List<AlertUsageThresholdFilter> Filters { get; set; }

/// <summary>
/// The value at which this alert will trigger.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Stripe.Billing
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class AlertFilter : StripeEntity<AlertFilter>
public class AlertUsageThresholdFilter : StripeEntity<AlertUsageThresholdFilter>
{
#region Expandable Customer

Expand Down Expand Up @@ -36,5 +36,8 @@ public Customer Customer
[JsonConverter(typeof(ExpandableFieldConverter<Customer>))]
internal ExpandableField<Customer> InternalCustomer { get; set; }
#endregion

[JsonProperty("type")]
public string Type { get; set; }
}
}
Loading
Loading