using Hutopy.Infrastructure.Payments.Stripe.Configuration; using Hutopy.Modules.Memberships.Contracts; using Microsoft.Extensions.Options; using Stripe; namespace Hutopy.Infrastructure.Payments.Stripe.Services; public sealed class MembershipTierProcessor( IOptions stripeOptions) : IMembershipTierProcessor { public async Task CreateAsync( Guid creatorId, Guid tierId, string productName, string currencyCode, decimal amount) { StripeConfiguration.ApiKey = stripeOptions.Value.SecretKey; // Create the product var productService = new ProductService(); var product = await productService.CreateAsync( new ProductCreateOptions { Name = productName, Metadata = { { "creatorId", creatorId.ToString() }, { "tierId", tierId.ToString() } } }); // Create the price for the product var priceService = new PriceService(); await priceService.CreateAsync( new PriceCreateOptions { Product = product.Id, UnitAmountDecimal = amount * 100, // Convert amount to cents Currency = currencyCode, Recurring = new PriceRecurringOptions { Interval = "month" } }); return product.Id; } }