44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using Stripe;
|
|
using Stripe.Checkout;
|
|
using Hutopy.Application.Common.Interfaces;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace Hutopy.Infrastructure.Stripe;
|
|
|
|
public class StripeService : IStripeService
|
|
{
|
|
public StripeService(IConfiguration configuration)
|
|
{
|
|
StripeConfiguration.ApiKey = configuration["STRIPE_API_KEY"];
|
|
}
|
|
|
|
public async Task<string> CreateCheckoutSession(int price, string currency = "cad")
|
|
{
|
|
var options = new SessionCreateOptions
|
|
{
|
|
LineItems =
|
|
[
|
|
new SessionLineItemOptions
|
|
{
|
|
PriceData = new SessionLineItemPriceDataOptions
|
|
{
|
|
UnitAmount = price,
|
|
Currency = currency,
|
|
ProductData = new SessionLineItemPriceDataProductDataOptions { Name = "Tip", },
|
|
},
|
|
Quantity = 1,
|
|
}
|
|
|
|
],
|
|
Mode = "payment",
|
|
UiMode = "embedded",
|
|
ReturnUrl = $"https://zealous-bay-08204590f.5.azurestaticapps.net/paymentcompleted",
|
|
};
|
|
|
|
var service = new SessionService();
|
|
Session session = await service.CreateAsync(options);
|
|
|
|
return session.ClientSecret;
|
|
}
|
|
}
|