From 6883855ecbd491f29f233839593a0e7adb9e5a3b Mon Sep 17 00:00:00 2001 From: Dominic Villemure Date: Wed, 24 Apr 2024 19:37:35 -0400 Subject: [PATCH] #27 small changes for the userTransaction --- src/Application/Common/Interfaces/IStripeService.cs | 2 +- .../Stripe/Commands/CreateSessionCheckoutCommand.cs | 11 ++++++++--- src/Infrastructure/Stripe/StripeService.cs | 11 +++++------ src/Web/wwwroot/api/specification.json | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Application/Common/Interfaces/IStripeService.cs b/src/Application/Common/Interfaces/IStripeService.cs index 1231a8e..75edbe9 100644 --- a/src/Application/Common/Interfaces/IStripeService.cs +++ b/src/Application/Common/Interfaces/IStripeService.cs @@ -3,5 +3,5 @@ namespace Hutopy.Application.Common.Interfaces; public interface IStripeService { - public Task CreateCheckoutSession(int price, string currency); + public Task CreateCheckoutSession(int amount, string currency); } diff --git a/src/Application/Stripe/Commands/CreateSessionCheckoutCommand.cs b/src/Application/Stripe/Commands/CreateSessionCheckoutCommand.cs index 9014f97..b428733 100644 --- a/src/Application/Stripe/Commands/CreateSessionCheckoutCommand.cs +++ b/src/Application/Stripe/Commands/CreateSessionCheckoutCommand.cs @@ -5,7 +5,7 @@ namespace Hutopy.Application.Stripe.Commands; public record CreateSessionCheckoutCommand : IRequest { 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 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); diff --git a/src/Infrastructure/Stripe/StripeService.cs b/src/Infrastructure/Stripe/StripeService.cs index 154c541..881b6c4 100644 --- a/src/Infrastructure/Stripe/StripeService.cs +++ b/src/Infrastructure/Stripe/StripeService.cs @@ -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 CreateCheckoutSession(int price, string currency = "cad") + public async Task 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(); diff --git a/src/Web/wwwroot/api/specification.json b/src/Web/wwwroot/api/specification.json index 5e5b6e3..1bdd8f1 100644 --- a/src/Web/wwwroot/api/specification.json +++ b/src/Web/wwwroot/api/specification.json @@ -694,7 +694,7 @@ "creatorId": { "type": "string" }, - "price": { + "amount": { "type": "integer", "format": "int32" },