#27 small changes for the userTransaction

This commit is contained in:
Dominic Villemure
2024-04-24 19:37:35 -04:00
parent bd6028c524
commit 6883855ecb
4 changed files with 15 additions and 11 deletions

View File

@@ -3,5 +3,5 @@ namespace Hutopy.Application.Common.Interfaces;
public interface IStripeService
{
public Task<string> CreateCheckoutSession(int price, string currency);
public Task<string> CreateCheckoutSession(int amount, string currency);
}

View File

@@ -5,7 +5,7 @@ namespace Hutopy.Application.Stripe.Commands;
public record CreateSessionCheckoutCommand : IRequest<string>
{
public required string CreatorId { get; init; }
public required int Price { get; init; }
public required int Amount { get; init; }
public string Currency { get; init; } = "CAD";
public string TipMessage { get; init; } = string.Empty;
}
@@ -18,11 +18,16 @@ public class CreateSessionCheckoutCommandHandler(
{
public async Task<string> Handle(CreateSessionCheckoutCommand request, CancellationToken cancellationToken)
{
var stripeSecret = await stripeService.CreateCheckoutSession(request.Price, request.Currency);
var stripeSecret = await stripeService.CreateCheckoutSession(request.Amount, request.Currency);
// ReSharper disable once PossibleLossOfFraction
decimal priceInDollars = (request.Amount / 100);
//todo: Need to add this transaction after the confirmation from stripe in the frontEnd ( redirect, re-call backend )
var userTransaction = new UserTransaction
{
Currency = request.Currency, Amount = request.Price, TipMessage = request.TipMessage, ApplicationUserId = request.CreatorId
Currency = request.Currency, Amount = priceInDollars, TipMessage = request.TipMessage, ApplicationUserId = request.CreatorId
};
await dbContext.UserTransactions.AddAsync(userTransaction, cancellationToken);

View File

@@ -1,18 +1,17 @@
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)
public StripeService()
{
StripeConfiguration.ApiKey = configuration["STRIPE_API_KEY"];
StripeConfiguration.ApiKey = "";
}
public async Task<string> CreateCheckoutSession(int price, string currency = "cad")
public async Task<string> CreateCheckoutSession(int amount, string currency = "cad")
{
var options = new SessionCreateOptions
{
@@ -22,7 +21,7 @@ public class StripeService : IStripeService
{
PriceData = new SessionLineItemPriceDataOptions
{
UnitAmount = price,
UnitAmount = amount,
Currency = currency,
ProductData = new SessionLineItemPriceDataProductDataOptions { Name = "Tip", },
},
@@ -32,7 +31,7 @@ public class StripeService : IStripeService
],
Mode = "payment",
UiMode = "embedded",
ReturnUrl = $"https://zealous-bay-08204590f.5.azurestaticapps.net/paymentcompleted",
ReturnUrl = "https://zealous-bay-08204590f.5.azurestaticapps.net/paymentcompleted",
};
var service = new SessionService();

View File

@@ -694,7 +694,7 @@
"creatorId": {
"type": "string"
},
"price": {
"amount": {
"type": "integer",
"format": "int32"
},