Synetec.Payment.Gateway 6.0.0

dotnet add package Synetec.Payment.Gateway --version 6.0.0
                    
NuGet\Install-Package Synetec.Payment.Gateway -Version 6.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Synetec.Payment.Gateway" Version="6.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Synetec.Payment.Gateway" Version="6.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Synetec.Payment.Gateway" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Synetec.Payment.Gateway --version 6.0.0
                    
#r "nuget: Synetec.Payment.Gateway, 6.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Synetec.Payment.Gateway@6.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Synetec.Payment.Gateway&version=6.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Synetec.Payment.Gateway&version=6.0.0
                    
Install as a Cake Tool

Synetec.Payment.Gateway

A .NET 8 library for integrating Stripe payment processing into your applications, with support for both hosted and embedded checkout experiences. Optimized for Blazor and ASP.NET Core projects.


✨ Features

  • Stripe Hosted Checkout (redirect-based)
  • Stripe Embedded Checkout (Stripe Elements)
  • Product and price retrieval from Stripe Portal
  • Secure, validated Stripe webhook endpoint

📦 Installation

Add the NuGet package to your project:

dotnet add package Synetec.Payment.Gateway

🚀 Usage

1. Register Endpoints

In your Program.cs (Blazor or ASP.NET Core):

// Register the Payment Gateway context and services
var builder = WebApplication.CreateBuilder(args);
ConfigurationManager configuration = builder.Configuration;
builder.Services.AddPaymentGateway(configuration);

// Register Synetec.Payment.Gateway endpoints depending on your needs
var app = builder.Build();
app.AddStripeProductEndpoints();
app.AddStripeHostedCheckoutEndpoints();
app.AddStripeEmbeddedCheckoutEndpoints();
app.AddStripeWebhook();

app.Run();

2. Configuration

Add your Stripe settings to appsettings.json:

{
  "PaymentGateway": {
    "ConnectionString": "REDACTED",
    "RedirectBaseUrl": "REDACTED",
    "SuccessPath": "REDACTED",
    "CancelPath": "REDACTED",
    "Stripe": {
      "SecretKey": "REDACTED",
      "PublishableKey": "REDACTED",
      "WebhookSecret": "REDACTED",
      "ThrowOnApiVersionMismatch": false
    }
  }
}
ThrowOnApiVersionMismatch (optional, defaults to false)

A Stripe webhook endpoint is pinned to the API version that was current when it was created, and that pin only moves when someone changes it in the Stripe dashboard. It therefore drifts independently of the Stripe.net version this package ships with.

When the two are on different release trains, EventUtility.ConstructEvent throws. Leave this false — the event is processed anyway and the mismatch is logged as a warning. Setting it to true restores Stripe.net's strict behaviour, which rejects the event outright; only do that if you would rather lose the event than risk deserialising a payload shape your handlers were not written against.

Keep the endpoint's API version in the Stripe dashboard aligned with the release train this package expects. Watch for Stripe webhook API version drift warnings — they mean the two have diverged.


3. Endpoints

Get Products
  • GET /api/v{version}/stripe/product
  • Returns a list of Stripe products and prices.
Create Hosted Checkout Session
  • POST /api/v{version}/stripe/checkout
  • Request body: CheckoutRequest
  • Returns a Stripe Checkout session URL.
Create Embedded Payment Intent
  • POST /api/v{version}/stripe/initialize-payment
  • Request body: PaymentIntentRequest
  • Returns a Stripe PaymentIntent client secret.
Stripe Webhook
  • POST /api/v{version}/stripe/webhook
  • Receives Stripe webhook events for payment updates and notifications.

4. Example: Creating a Checkout Session

POST /api/v1/stripe/checkout
Content-Type: application/json

{
  "idempotencyKey": "b1a7c8e2-1234-4c9a-8e2b-1234567890ab",
  "items": [
    { "priceId": "price_1N...", "quantity": 1 }
  ],
  "paymentMethodTypes": ["card"],
  "consumerReference": "user@example.com",
  "additionalMetadata": { "orderId": "12345" }
}

5. Webhook Security

Set your Stripe webhook secret in configuration. The webhook endpoint validates incoming requests using the Stripe-Signature header.


6. Ignored Events

A Stripe account receives webhooks for every payment on it, not only the ones this library created. Events that need no action from us are recorded as ignored rather than failed: they are logged at Information, and written to PaymentWebhookLog with Status = Ignored (4), an IgnoredReason explaining why, and ProcessedAtUtc as the actioned timestamp. Nothing is logged at Error.

An event is ignored when:

  • its PaymentRecordId metadata does not resolve to a payment record in this database — this is how instances sharing one Stripe account avoid claiming each other's payments;
  • it carries neither PaymentRecordId nor ConsumerReference metadata, so nothing identifies it as ours;
  • its ConsumerReference matches no payment record; or
  • no handler is registered for that Stripe event type.

Origin is decided by PaymentRecordId, a GUID this library mints and persists before the client sees anything. Note this is a correlation check, not a security control — the Stripe-Signature validation above remains the security boundary.

Ignored events are kept so they can be reviewed. To pull them for a period — this query uses the IX_PaymentWebhookLog_Status_ProcessedAtUtc index:

SELECT Id, ProcessedAtUtc, ReceivedAtUtc, EventId, EventType, IgnoredReason
FROM PaymentGateway.PaymentWebhookLog
WHERE Status = 4                      -- Ignored
  AND ProcessedAtUtc >= @fromUtc      -- start of day / week / month
  AND ProcessedAtUtc <  @toUtc
ORDER BY ProcessedAtUtc DESC;

Payload holds the raw Stripe event and carries personal data. If you surface these for review, reference Id and IgnoredReason rather than copying payload contents.

Applying the migration that adds these columns is required when upgrading to 4.1.0.

7. Upgrading to 6.0.0

The full list of changes in each version is in CHANGELOG.md. This section covers what you need to do when upgrading.

Breaking changes

  • The library no longer sets the global StripeConfiguration.ApiKey. Code in the host that used the Stripe.net services without a client of its own must now pass one.
  • UpdatePaymentRecordStatus has a third positional parameter, PaymentRecordId. Source that constructs it with two arguments still compiles, but code that deconstructs it into two values must take three, and assemblies built against 5.x must be rebuilt.
  • IPaymentRecordRepository<TPaymentRecord> has new members, GetByIdAsync, GetByProviderIdempotencyKeyAsync and Discard. A host that implements the interface itself must add them.
  • PaymentRecord.PaymentProviderReference is now nullable. It is null while a PaymentIntent attempt is saved but Stripe has not answered yet.

Behaviour changes

  • Repeat declines on one PaymentIntent are processed normally instead of being logged as failed webhooks.
  • Webhook status updates target the record named by the event's PaymentRecordId metadata.
  • A stored PaymentIntent is reused for the same idempotency key only while it can still take a payment. A cancelled or failed one is replaced, and overlapping requests replacing the same one share a single replacement.
  • Each PaymentIntent attempt is saved before Stripe is called. A retry after a crash or a failed save sends the same request under the same Stripe key. If Stripe created a PaymentIntent, it returns the original while it retains the key. Stripe can remove keys once they are at least 24 hours old. A retry after removal can create a second PaymentIntent while the original is still open. Stripe idempotency keys
  • Overlapping requests with the same idempotency key share one attempt. The second gets the first one's PaymentIntent, or fails with PaymentInProgressError while Stripe is still handling the first. The initialize-payment endpoint returns 409 Conflict for that error, so the caller can ask the payer to try again.
  • Reusing an idempotency key with different details, such as another amount, before its PaymentIntent was stored now fails with a clear message instead of a Stripe exception.
  • CreatePaymentIntentRequest.Description sets the PaymentIntent description shown in the Stripe dashboard.

Migration required. Apply Update_PaymentRecord_Reserve_PaymentIntent_Before_Stripe, which makes PaymentProviderReference nullable and adds ProviderIdempotencyKey with a unique filtered index. Rolling it back deletes any attempts Stripe never answered for, since they have no PaymentIntent.


🧩 Getting Started Example

// Example: Minimal API integration
var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<StripeOptions>(builder.Configuration.GetSection("Stripe"));

var app = builder.Build();
app.AddStripeHostedCheckoutEndpoints();
app.Run();

🛠️ Requirements

  • .NET 8.0 or later
  • Stripe account and API keys

🤝 Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Run tests with dotnet test
  4. Submit a pull request

📜 License

© 2025 Synetec Limited. All rights reserved.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 45 11/25/2026
5.0.0 134 9/23/2026
4.1.0 810 8/18/2026
4.0.0 142 8/10/2026
3.0.1 1,035 11/17/2025
3.0.0 350 11/10/2025
2.0.0 251 11/6/2025
1.1.0 255 11/6/2025
1.0.0 331 10/31/2025

Breaking release with a required migration: the library no longer sets the global StripeConfiguration.ApiKey, and PaymentIntent attempts are saved before Stripe is called. Full list of changes: https://dev.azure.com/Synetec/Synetec.Libraries/_git/Synetec.Libraries?path=/Synetec.Payment.Gateway/CHANGELOG.md