Added endpoint to create a sessionCheckout with stripe
This commit is contained in:
7
src/Application/Common/Interfaces/IStripeService.cs
Normal file
7
src/Application/Common/Interfaces/IStripeService.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Hutopy.Application.Common.Interfaces;
|
||||
|
||||
|
||||
public interface IStripeService
|
||||
{
|
||||
public Task<string> CreateCheckoutSession(int price, string currency);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
|
||||
|
||||
namespace Hutopy.Application.Stripe.Commands;
|
||||
public record CreateSessionCheckoutCommand : IRequest<string>
|
||||
{
|
||||
public required int Price { get; init; }
|
||||
|
||||
public string Currency { get; init; } = "cad";
|
||||
}
|
||||
|
||||
|
||||
public class CreateSessionCheckoutCommandHandler : IRequestHandler<CreateSessionCheckoutCommand, string>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly IStripeService _stripeService;
|
||||
|
||||
|
||||
public CreateSessionCheckoutCommandHandler(IApplicationDbContext context, IStripeService stripeService)
|
||||
{
|
||||
_context = context;
|
||||
_stripeService = stripeService;
|
||||
}
|
||||
|
||||
public async Task<string> Handle(CreateSessionCheckoutCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var stripeSecret = await _stripeService.CreateCheckoutSession(request.Price, request.Currency);
|
||||
|
||||
return stripeSecret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user