From 8caa8d03854c6d54ccf7a15875bd7b7f2bb4e8d1 Mon Sep 17 00:00:00 2001 From: rico-agent Date: Sun, 29 Mar 2026 23:10:08 +0200 Subject: [PATCH] =?UTF-8?q?fix(stripe):=20konfigurowalne=20metody=20p?= =?UTF-8?q?=C5=82atno=C5=9Bci=20+=20p24=20wy=C5=82=C4=85czone=20domy=C5=9B?= =?UTF-8?q?lnie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: p24 wymaga aktywacji w Stripe Dashboard, bez niej rzuca StripeException dla PLN. Było hardkodowane ['card','blik','p24']. Zmiany w StripeServiceCaller: - Dodano opcjonalny IConfiguration do konstruktora - Metody płatności czytane z 'Stripe:AllowedPaymentMethods' (gdy niepuste) - Fallback: GetPaymentMethodsForCurrency() — PLN: card+blik (bez p24) - Łatwo włączyć p24 po aktywacji w Stripe Dashboard przez config Przykład konfiguracji: appsettings.json: 'Stripe': { 'AllowedPaymentMethods': ['card','blik','p24'] } env var: Stripe__AllowedPaymentMethods__0=card --- .../StripeServiceCaller.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/TailoredApps.Shared.Payments.Provider.Stripe/StripeServiceCaller.cs b/src/TailoredApps.Shared.Payments.Provider.Stripe/StripeServiceCaller.cs index cb4da85..1816962 100644 --- a/src/TailoredApps.Shared.Payments.Provider.Stripe/StripeServiceCaller.cs +++ b/src/TailoredApps.Shared.Payments.Provider.Stripe/StripeServiceCaller.cs @@ -1,5 +1,6 @@ using global::Stripe; using global::Stripe.Checkout; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; namespace TailoredApps.Shared.Payments.Provider.Stripe; @@ -12,15 +13,17 @@ namespace TailoredApps.Shared.Payments.Provider.Stripe; public class StripeServiceCaller : IStripeServiceCaller { private readonly StripeServiceOptions options; + private readonly IConfiguration? configuration; // Stripe.net services — wstrzykiwane przez DI (możliwe mockowanie w testach) private readonly SessionService sessionService; /// Inicjalizuje instancję callera. - public StripeServiceCaller(IOptions options, SessionService sessionService) + public StripeServiceCaller(IOptions options, SessionService sessionService, IConfiguration? configuration = null) { this.options = options.Value; this.sessionService = sessionService; + this.configuration = configuration; } private RequestOptions RequestOptions => new() { ApiKey = options.SecretKey }; @@ -28,8 +31,14 @@ public StripeServiceCaller(IOptions options, SessionServic /// public async Task CreateCheckoutSessionAsync(Payments.PaymentRequest request) { - // Metody płatności zależne od waluty - var paymentMethods = GetPaymentMethodsForCurrency(request.Currency); + // Metody płatności — z konfiguracji (Stripe:AllowedPaymentMethods) lub domyślne per waluta + var configuredMethods = configuration? + .GetSection("Stripe:AllowedPaymentMethods") + .Get>(); + + var paymentMethods = configuredMethods is { Count: > 0 } + ? configuredMethods + : GetPaymentMethodsForCurrency(request.Currency); var createOptions = new SessionCreateOptions { @@ -111,14 +120,16 @@ private static long ToStripeAmount(decimal amount, string currency) } /// - /// Zwraca listę metod płatności dostępnych dla danej waluty. - /// PLN: karta + BLIK + Przelewy24 (p24). + /// Zwraca domyślną listę metod płatności dla danej waluty. + /// Można nadpisać przez konfigurację: Stripe:AllowedPaymentMethods. + /// PLN: karta + BLIK (p24 wymaga aktywacji w Stripe Dashboard). + /// EUR: karta + SEPA Direct Debit. /// Inne: tylko karta (najbezpieczniejszy fallback). /// private static List GetPaymentMethodsForCurrency(string currency) => currency.ToUpperInvariant() switch { - "PLN" => ["card", "blik", "p24"], + "PLN" => ["card", "blik"], "EUR" => ["card", "sepa_debit"], _ => ["card"], };