From a2d6c3fa3ba30b4f3dcd88c3deb95374c35f28da Mon Sep 17 00:00:00 2001 From: Damien Ostler Date: Wed, 14 Feb 2024 20:28:04 -0500 Subject: [PATCH] fix: added endpoint to get if a account is onboarded, and changed the models of responses --- .../Controllers/SellerProfileController.cs | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/comissions.app.api/Controllers/SellerProfileController.cs b/src/comissions.app.api/Controllers/SellerProfileController.cs index cdda85a..031891f 100644 --- a/src/comissions.app.api/Controllers/SellerProfileController.cs +++ b/src/comissions.app.api/Controllers/SellerProfileController.cs @@ -78,7 +78,7 @@ public class SellerProfileController : Controller return NotFound(); var result = sellerProfileRequest.ToModel(); return Ok(result); - } + } [HttpPost] [Authorize("write:seller-profile")] @@ -230,8 +230,36 @@ public class SellerProfileController : Controller existingSellerProfile.StripeAccountId = accountId; existingSellerProfile = _dbContext.UserSellerProfiles.Update(existingSellerProfile).Entity; await _dbContext.SaveChangesAsync(); - var result = existingSellerProfile.ToModel(); - return Ok(result); + var result = _paymentService.CreateSellerAccountOnboardingUrl(accountId); + return Ok(new { onboardUrl = result }); + } + + [HttpGet] + [Authorize("write:seller-profile")] + [Route("Payment/Onboarded")] + public async Task PaymentAccountStatus() + { + 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.SellerAccountIsOnboarded(accountId); + return Ok(new { onboarded=result }); } [HttpGet] @@ -254,7 +282,7 @@ public class SellerProfileController : Controller return BadRequest(); var result = _paymentService.CreateSellerAccountOnboardingUrl(existingSellerProfile.StripeAccountId); - return Ok(result); + return Ok(new { onboardUrl = result }); } } \ No newline at end of file