Omnia.PaymentStripe
1.3.3
dotnet add package Omnia.PaymentStripe --version 1.3.3
NuGet\Install-Package Omnia.PaymentStripe -Version 1.3.3
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="Omnia.PaymentStripe" Version="1.3.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Omnia.PaymentStripe" Version="1.3.3" />
<PackageReference Include="Omnia.PaymentStripe" />
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 Omnia.PaymentStripe --version 1.3.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Omnia.PaymentStripe, 1.3.3"
#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 Omnia.PaymentStripe@1.3.3
#: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=Omnia.PaymentStripe&version=1.3.3
#tool nuget:?package=Omnia.PaymentStripe&version=1.3.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Omnia.PaymentStripe
Libreria ASP.NET Core per integrazione completa con Stripe: pagamenti, clienti, webhook, subscriptions.
Installazione
dotnet add package Omnia.PaymentStripe
Setup rapido
1. Configurazione appsettings.json
{
"Stripe": {
"SecretKey": "sk_test_...",
"PublishableKey": "pk_test_...",
"WebhookSecret": "whsec_...",
"DefaultCurrency": "usd"
}
}
2. Implementa IStripeSettings
public class StripeConfiguration : IStripeSettings
{
private readonly IConfiguration _config;
public StripeConfiguration(IConfiguration config) => _config = config;
public string GetSecretKey() => _config["Stripe:SecretKey"]!;
public string GetPublishableKey() => _config["Stripe:PublishableKey"]!;
public string GetWebhookSecret() => _config["Stripe:WebhookSecret"]!;
public string GetDefaultCurrency() => _config["Stripe:DefaultCurrency"] ?? "usd";
public string GetSuccessUrl() => _config["Stripe:SuccessUrl"] ?? "/success";
public string GetCancelUrl() => _config["Stripe:CancelUrl"] ?? "/cancel";
public string GetWebhookEndpoint() => _config["Stripe:WebhookEndpoint"] ?? "/api/stripwebhook/hook";
}
3. Registra i servizi in Program.cs
builder.Services.AddSingleton<IStripeSettings, StripeConfiguration>();
builder.Services.AddScoped<IPaymentRepository, StripePaymentRepository>();
builder.Services.AddScoped<ICustomerRepository, StripeCustomerRepository>();
builder.Services.AddScoped<IStripeEventHandler, StripeEventHandler>();
// Opzionale: hook Before/After per logica personalizzata
builder.Services.AddScoped<CustomerControllerBefore>();
builder.Services.AddScoped<CustomerControllerAfter>();
builder.Services.AddScoped<PaymentControllerBefore>();
builder.Services.AddScoped<PaymentControllerAfter>();
builder.Services.AddControllers();
Controller inclusi
La libreria fornisce controller REST pronti all'uso:
PaymentController - /api/payment
POST /create- Crea un PaymentIntentPOST /confirm/{id}- Conferma un pagamentoPOST /cancel/{id}- Annulla un pagamentoGET /{id}- Recupera dettagli pagamentoPUT /{id}- Aggiorna un pagamentoGET /{id}/status- Verifica stato pagamentoGET /customer/{customerId}- Lista pagamenti cliente
CustomerController - /api/customer
POST /create- Crea un cliente StripePUT /{id}- Aggiorna un clienteDELETE /{id}- Cancella un clienteGET /{id}- Recupera dettagli clienteGET /list- Elenca clienti (paginato)
StripeWebhookController - /api/stripwebhook
POST /hook- Gestisce webhook Stripe
Uso diretto delle interfacce
Gestione pagamenti
public class MyService
{
private readonly IPaymentRepository _paymentHandler;
public async Task<PaymentIntent> CreatePayment(decimal amount)
{
return await _paymentHandler.InitiatePaymentAsync(
amount: (long)(amount * 100), // converti in centesimi
currency: "eur",
customerId: "cus_xxx",
description: "Ordine #123",
metadata: new Dictionary<string, string> { ["orderId"] = "123" }
);
}
}
Gestione clienti
public class MyService
{
private readonly ICustomerRepository _customerHandler;
public Customer CreateCustomer(string email, string name)
{
return _customerHandler.CreateCustomer(
email: email,
name: name,
metadata: new Dictionary<string, string> { ["source"] = "web" }
);
}
}
Hook Before/After
Personalizza la logica prima e dopo ogni operazione estendendo le classi base:
public class MyPaymentHooks : PaymentControllerBefore
{
public override void BeforeCreatePayment(CreatePaymentRequest request)
{
// Validazione custom, logging, ecc.
Console.WriteLine($"Creating payment for {request.Amount}");
}
}
public class MyPaymentAfterHooks : PaymentControllerAfter
{
public override void AfterCreatePayment(CreatePaymentRequest request, PaymentIntent paymentIntent)
{
// Salva in database, invia notifica, ecc.
Console.WriteLine($"Payment created: {paymentIntent.Id}");
}
}
// Registra in Program.cs
builder.Services.AddScoped<PaymentControllerBefore, MyPaymentHooks>();
builder.Services.AddScoped<PaymentControllerAfter, MyPaymentAfterHooks>();
Gestione eventi webhook
Estendi StripeEventHandler per gestire eventi Stripe:
public class MyEventHandler : StripeEventHandler
{
public override void SuccessfulPayment(PaymentIntent paymentIntent)
{
base.SuccessfulPayment(paymentIntent);
// Logica custom: aggiorna ordine, invia email, ecc.
Console.WriteLine($"Payment succeeded: {paymentIntent.Id}");
}
public override void FailedPayment(PaymentIntent paymentIntent)
{
base.FailedPayment(paymentIntent);
// Gestisci fallimento pagamento
Console.WriteLine($"Payment failed: {paymentIntent.Id}");
}
}
// Registra in Program.cs
builder.Services.AddScoped<IStripeEventHandler, MyEventHandler>();
Configurazione webhook
Configura l'endpoint webhook su Stripe Dashboard → Developers → Webhooks:
- URL:
https://tuo-dominio.com/api/stripwebhook/hook - Eventi: seleziona gli eventi che vuoi ricevere
License
LGPL-3.0-or-later
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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 was computed. 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.
-
net9.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Omnia.Utility (>= 1.0.1)
- Stripe.net (>= 48.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.