Added endpoint to create a sessionCheckout with stripe

This commit is contained in:
Dominic Villemure
2024-03-20 01:10:44 -04:00
parent 0689a3d85c
commit 2b810772b3
8 changed files with 157 additions and 7 deletions

View File

@@ -0,0 +1,46 @@
using Stripe;
using Stripe.Checkout;
using Hutopy.Application.Common.Interfaces;
namespace Hutopy.Infrastructure.Stripe;
public class StripeService : IStripeService
{
public StripeService()
{
// I removed the key to push. Will need to be in config.
StripeConfiguration.ApiKey = "";
}
public async Task<string> CreateCheckoutSession(int price, string currency = "cad")
{
var options = new SessionCreateOptions
{
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
PriceData = new SessionLineItemPriceDataOptions
{
UnitAmount = price,
Currency = currency,
ProductData = new SessionLineItemPriceDataProductDataOptions
{
Name = "Tip",
},
},
Quantity = 1,
},
},
Mode = "payment",
UiMode = "embedded",
ReturnUrl = "http://localhost:5174",
};
var service = new SessionService();
Session session = await service.CreateAsync(options);
return session.ClientSecret;
}
}