mirror of
https://github.com/D4M13N-D3V/comissions-app-core-api.git
synced 2025-03-14 10:04:55 +00:00
fix: updated routes for onboarding
This commit is contained in:
parent
ccde0d3fa7
commit
ff448b218c
@ -1,6 +1,7 @@
|
|||||||
using comissions.app.api.Models.SellerProfileRequest;
|
using comissions.app.api.Models.SellerProfileRequest;
|
||||||
using ArtPlatform.Database;
|
using ArtPlatform.Database;
|
||||||
using ArtPlatform.Database.Entities;
|
using ArtPlatform.Database.Entities;
|
||||||
|
using comissions.app.api.Services.Payment;
|
||||||
using comissions.app.database;
|
using comissions.app.database;
|
||||||
using comissions.app.database.Entities;
|
using comissions.app.database.Entities;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@ -15,9 +16,11 @@ namespace comissions.app.api.Controllers;
|
|||||||
public class AdminSellerRequestsController : Controller
|
public class AdminSellerRequestsController : Controller
|
||||||
{
|
{
|
||||||
private readonly ApplicationDbContext _dbContext;
|
private readonly ApplicationDbContext _dbContext;
|
||||||
|
private readonly IPaymentService _paymentService;
|
||||||
|
|
||||||
public AdminSellerRequestsController(ApplicationDbContext dbContext)
|
public AdminSellerRequestsController(ApplicationDbContext dbContext, IPaymentService paymentService)
|
||||||
{
|
{
|
||||||
|
_paymentService = paymentService;
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,12 +72,13 @@ public class AdminSellerRequestsController : Controller
|
|||||||
|
|
||||||
request.Accepted = true;
|
request.Accepted = true;
|
||||||
request.AcceptedDate = DateTime.UtcNow;
|
request.AcceptedDate = DateTime.UtcNow;
|
||||||
|
var accountId = _paymentService.CreateSellerAccount();
|
||||||
var newSellerProfile = new UserSellerProfile()
|
var newSellerProfile = new UserSellerProfile()
|
||||||
{
|
{
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
AgeRestricted = false,
|
AgeRestricted = false,
|
||||||
Biography = string.Empty,
|
Biography = string.Empty,
|
||||||
|
StripeAccountId = accountId,
|
||||||
SocialMediaLinks = new List<string>(){}
|
SocialMediaLinks = new List<string>(){}
|
||||||
};
|
};
|
||||||
_dbContext.UserSellerProfiles.Add(newSellerProfile);
|
_dbContext.UserSellerProfiles.Add(newSellerProfile);
|
||||||
|
@ -206,37 +206,9 @@ public class SellerProfileController : Controller
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
|
||||||
[Authorize("write:seller-profile")]
|
|
||||||
[Route("Payment")]
|
|
||||||
public async Task<IActionResult> 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]
|
[HttpGet]
|
||||||
[Authorize("write:seller-profile")]
|
[Authorize("write:seller-profile")]
|
||||||
[Route("Payment/Onboarded")]
|
[Route("Onboard")]
|
||||||
public async Task<IActionResult> PaymentAccountStatus()
|
public async Task<IActionResult> PaymentAccountStatus()
|
||||||
{
|
{
|
||||||
var userId = User.GetUserId();
|
var userId = User.GetUserId();
|
||||||
@ -264,7 +236,7 @@ public class SellerProfileController : Controller
|
|||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authorize("write:seller-profile")]
|
[Authorize("write:seller-profile")]
|
||||||
[Route("Payment")]
|
[Route("Onboard/Url")]
|
||||||
public async Task<IActionResult> GetPaymentAccount()
|
public async Task<IActionResult> GetPaymentAccount()
|
||||||
{
|
{
|
||||||
var userId = User.GetUserId();
|
var userId = User.GetUserId();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user