From b6eaee0831a8ed65d4c8d8121aaa69c1d2732b2f Mon Sep 17 00:00:00 2001 From: Damien Ostler Date: Sun, 25 Feb 2024 01:41:01 -0500 Subject: [PATCH] fix: added endpoint to get stripe dashboard url --- .../Controllers/ArtistController.cs | 17 +++++++++++++++++ .../Services/Payment/IPaymentService.cs | 1 + .../Payment/StripePaymentServiceProvider.cs | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/src/comissions.app.api/Controllers/ArtistController.cs b/src/comissions.app.api/Controllers/ArtistController.cs index db0760b..b12d05c 100644 --- a/src/comissions.app.api/Controllers/ArtistController.cs +++ b/src/comissions.app.api/Controllers/ArtistController.cs @@ -66,6 +66,23 @@ public class ArtistController : Controller var result = Artist.ToStatsModel(); return Ok(result); } + [HttpGet] + [Authorize("read:artist")] + [Route("PayoutDashboard")] + public async Task PayoutDashboard() + { + var userId = User.GetUserId(); + var Artist = await _dbContext.UserArtists.Include(x=>x.Requests).FirstOrDefaultAsync(Artist=>Artist.UserId==userId); + if(Artist==null) + { + var ArtistRequest = await _dbContext.ArtistRequests.FirstOrDefaultAsync(request=>request.UserId==userId && request.Accepted==false); + if(ArtistRequest!=null) + return BadRequest(); + return Unauthorized(); + } + var url = _paymentService.CreateDashboardUrl(Artist.StripeAccountId); + return Ok(new {url}); + } [HttpPut] [Authorize("write:artist")] diff --git a/src/comissions.app.api/Services/Payment/IPaymentService.cs b/src/comissions.app.api/Services/Payment/IPaymentService.cs index e1ff8ad..5044203 100644 --- a/src/comissions.app.api/Services/Payment/IPaymentService.cs +++ b/src/comissions.app.api/Services/Payment/IPaymentService.cs @@ -8,4 +8,5 @@ public interface IPaymentService string CreateArtistAccountOnboardingUrl(string accountId); bool ArtistAccountIsOnboarded(string accountId); string Charge(int orderArtistServiceId, string? sellerStripeAccountId, double orderPrice); + string CreateDashboardUrl(string accountId); } \ No newline at end of file diff --git a/src/comissions.app.api/Services/Payment/StripePaymentServiceProvider.cs b/src/comissions.app.api/Services/Payment/StripePaymentServiceProvider.cs index b12b377..8eded3b 100644 --- a/src/comissions.app.api/Services/Payment/StripePaymentServiceProvider.cs +++ b/src/comissions.app.api/Services/Payment/StripePaymentServiceProvider.cs @@ -128,4 +128,11 @@ public class StripePaymentServiceProvider:IPaymentService var session = service.Create(options, requestOptions); return session.Url; } + + public string CreateDashboardUrl(string accountId) + { + var service = new LoginLinkService(); + var url = service.Create(accountId); + return url.Url; + } } \ No newline at end of file