diff --git a/src/comissions.app.api/Controllers/Admin/AdminSellerRequestsController.cs b/src/comissions.app.api/Controllers/Admin/AdminSellerRequestsController.cs index e069cce..bbe0932 100644 --- a/src/comissions.app.api/Controllers/Admin/AdminSellerRequestsController.cs +++ b/src/comissions.app.api/Controllers/Admin/AdminSellerRequestsController.cs @@ -1,6 +1,7 @@ using comissions.app.api.Models.SellerProfileRequest; using ArtPlatform.Database; using ArtPlatform.Database.Entities; +using comissions.app.api.Services.Payment; using comissions.app.database; using comissions.app.database.Entities; using Microsoft.AspNetCore.Authorization; @@ -15,9 +16,11 @@ namespace comissions.app.api.Controllers; public class AdminSellerRequestsController : Controller { private readonly ApplicationDbContext _dbContext; + private readonly IPaymentService _paymentService; - public AdminSellerRequestsController(ApplicationDbContext dbContext) + public AdminSellerRequestsController(ApplicationDbContext dbContext, IPaymentService paymentService) { + _paymentService = paymentService; _dbContext = dbContext; } @@ -69,12 +72,13 @@ public class AdminSellerRequestsController : Controller request.Accepted = true; request.AcceptedDate = DateTime.UtcNow; - + var accountId = _paymentService.CreateSellerAccount(); var newSellerProfile = new UserSellerProfile() { UserId = userId, AgeRestricted = false, Biography = string.Empty, + StripeAccountId = accountId, SocialMediaLinks = new List(){} }; _dbContext.UserSellerProfiles.Add(newSellerProfile); diff --git a/src/comissions.app.api/Controllers/SellerProfileController.cs b/src/comissions.app.api/Controllers/SellerProfileController.cs index d2e49cf..7359fae 100644 --- a/src/comissions.app.api/Controllers/SellerProfileController.cs +++ b/src/comissions.app.api/Controllers/SellerProfileController.cs @@ -206,37 +206,9 @@ public class SellerProfileController : Controller return Ok(); } - [HttpPost] - [Authorize("write:seller-profile")] - [Route("Payment")] - public async Task CreatePaymentAccount() - { - var userId = User.GetUserId(); - var existingSellerProfile = await _dbContext.UserSellerProfiles.FirstOrDefaultAsync(sellerProfile=>sellerProfile.UserId==userId); - if (existingSellerProfile == null) - { - var sellerProfileRequest = await _dbContext.SellerProfileRequests.FirstOrDefaultAsync(request=>request.UserId==userId && request.Accepted==false); - if(sellerProfileRequest!=null) - return BadRequest(); - return Unauthorized(); - } - - if(existingSellerProfile.Suspended) - return BadRequest(); - if(existingSellerProfile.StripeAccountId!=null) - return BadRequest(); - - var accountId = _paymentService.CreateSellerAccount(); - existingSellerProfile.StripeAccountId = accountId; - existingSellerProfile = _dbContext.UserSellerProfiles.Update(existingSellerProfile).Entity; - await _dbContext.SaveChangesAsync(); - var result = _paymentService.CreateSellerAccountOnboardingUrl(accountId); - return Ok(new SellerOnboardUrlModel(){ OnboardUrl= result }); - } - [HttpGet] [Authorize("write:seller-profile")] - [Route("Payment/Onboarded")] + [Route("Onboard")] public async Task PaymentAccountStatus() { var userId = User.GetUserId(); @@ -264,7 +236,7 @@ public class SellerProfileController : Controller [HttpGet] [Authorize("write:seller-profile")] - [Route("Payment")] + [Route("Onboard/Url")] public async Task GetPaymentAccount() { var userId = User.GetUserId();