Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,24 +13,32 @@ 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;

/// <summary>Inicjalizuje instancję callera.</summary>
public StripeServiceCaller(IOptions<StripeServiceOptions> options, SessionService sessionService)
public StripeServiceCaller(IOptions<StripeServiceOptions> options, SessionService sessionService, IConfiguration? configuration = null)
{
this.options = options.Value;
this.sessionService = sessionService;
this.configuration = configuration;
}

private RequestOptions RequestOptions => new() { ApiKey = options.SecretKey };

/// <inheritdoc/>
public async Task<Session> 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<List<string>>();

var paymentMethods = configuredMethods is { Count: > 0 }
? configuredMethods
: GetPaymentMethodsForCurrency(request.Currency);

var createOptions = new SessionCreateOptions
{
Expand Down Expand Up @@ -111,14 +120,16 @@ private static long ToStripeAmount(decimal amount, string currency)
}

/// <summary>
/// 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ę: <c>Stripe:AllowedPaymentMethods</c>.
/// PLN: karta + BLIK (p24 wymaga aktywacji w Stripe Dashboard).
/// EUR: karta + SEPA Direct Debit.
/// Inne: tylko karta (najbezpieczniejszy fallback).
/// </summary>
private static List<string> GetPaymentMethodsForCurrency(string currency) =>
currency.ToUpperInvariant() switch
{
"PLN" => ["card", "blik", "p24"],
"PLN" => ["card", "blik"],
"EUR" => ["card", "sepa_debit"],
_ => ["card"],
};
Expand Down
Loading