Added endpoint to create a sessionCheckout with stripe
This commit is contained in:
46
src/Infrastructure/Stripe/StripeService.cs
Normal file
46
src/Infrastructure/Stripe/StripeService.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user