![]() |
VOOZH | about |
dotnet add package Omnia.PaymentStripe --version 1.3.3
NuGet\Install-Package Omnia.PaymentStripe -Version 1.3.3
<PackageReference Include="Omnia.PaymentStripe" Version="1.3.3" />
<PackageVersion Include="Omnia.PaymentStripe" Version="1.3.3" />Directory.Packages.props
<PackageReference Include="Omnia.PaymentStripe" />Project file
paket add Omnia.PaymentStripe --version 1.3.3
#r "nuget: Omnia.PaymentStripe, 1.3.3"
#:package Omnia.PaymentStripe@1.3.3
#addin nuget:?package=Omnia.PaymentStripe&version=1.3.3Install as a Cake Addin
#tool nuget:?package=Omnia.PaymentStripe&version=1.3.3Install as a Cake Tool
Libreria ASP.NET Core per integrazione completa con Stripe: pagamenti, clienti, webhook, subscriptions.
dotnet add package Omnia.PaymentStripe
{
"Stripe": {
"SecretKey": "sk_test_...",
"PublishableKey": "pk_test_...",
"WebhookSecret": "whsec_...",
"DefaultCurrency": "usd"
}
}
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";
}
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();
La libreria fornisce controller REST pronti all'uso:
/api/paymentPOST /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/api/customerPOST /create - Crea un cliente StripePUT /{id} - Aggiorna un clienteDELETE /{id} - Cancella un clienteGET /{id} - Recupera dettagli clienteGET /list - Elenca clienti (paginato)/api/stripwebhookPOST /hook - Gestisce webhook Stripepublic 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" }
);
}
}
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" }
);
}
}
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>();
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>();
Configura l'endpoint webhook su Stripe Dashboard → Developers → Webhooks:
https://tuo-dominio.com/api/stripwebhook/hookLGPL-3.0-or-later
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.