#27 get last receipt, get minimalUser, get my user

This commit is contained in:
Dominic Villemure
2024-05-12 16:40:24 -04:00
parent 3f20563850
commit 5161e3a91a
17 changed files with 216 additions and 24 deletions

View File

@@ -1,11 +1,13 @@
using Hutopy.Domain.Interfaces;
using System.Security.Claims;
using Hutopy.Domain.Interfaces;
using Hutopy.Domain.Models;
using Hutopy.Infrastructure.Identity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
namespace Hutopy.Infrastructure.Services;
public class UserService(UserManager<ApplicationUser> userManager) : IUserService
public class UserService(UserManager<ApplicationUser> userManager, IHttpContextAccessor contextAccessor) : IUserService
{
public async Task CreateUserAsync(string email, string userName, string firstName, string lastName, string password)
{
@@ -38,7 +40,7 @@ public class UserService(UserManager<ApplicationUser> userManager) : IUserServic
UserName = response.UserName,
FirstName = response.FirstName,
LastName = response.LastName,
Email = response.Email
Email = response.Email,
};
return userModel;
@@ -47,13 +49,13 @@ public class UserService(UserManager<ApplicationUser> userManager) : IUserServic
public async Task<UserModel?> GetCurrentUserAsync()
{
// todo: Get the id of the user doing the request.
var userId = "";
if (string.IsNullOrEmpty(userId))
var currentUserId = contextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
if (string.IsNullOrEmpty(currentUserId))
{
return null;
}
return await FindUserByIdAsync(userId);
return await FindUserByIdAsync(currentUserId);
}
public async Task<UserModel?> FindUserByEmailAsync(string email)

View File

@@ -9,7 +9,6 @@ namespace Hutopy.Infrastructure.Stripe;
public class StripeService : IStripeService
{
const string EndpointSecret = "";
private readonly IHttpContextAccessor _httpContextAccessor;
public StripeService(IHttpContextAccessor httpContextAccessor)
@@ -18,7 +17,7 @@ public class StripeService : IStripeService
StripeConfiguration.ApiKey = "";
}
public async Task<string> CreateCheckoutSession(int amount, string currency = "cad")
public async Task<string> CreateCheckoutSession(int amount, string creatorId, string currency = "cad")
{
var options = new SessionCreateOptions
{
@@ -38,7 +37,9 @@ public class StripeService : IStripeService
],
Mode = "payment",
UiMode = "embedded",
ReturnUrl = "https://hutopy.ca/paymentcompleted",
ReturnUrl = $"https://hutopy.ca/paymentcompleted?creatorId={creatorId}",
InvoiceCreation = new SessionInvoiceCreationOptions(){ Enabled = true},
ClientReferenceId = creatorId
};
var service = new SessionService();
@@ -57,7 +58,6 @@ public class StripeService : IStripeService
}
return new Result(false, new List<string>());
}
catch (StripeException e)
{