fix: payout endpoint

This commit is contained in:
Damien Ostler 2024-02-25 02:00:02 -05:00
parent b6eaee0831
commit a07a41d530
4 changed files with 42 additions and 4 deletions

View File

@ -6,6 +6,7 @@ using comissions.app.api.Services.Payment;
using comissions.app.api.Services.Storage;
using comissions.app.database;
using comissions.app.database.Entities;
using comissions.app.database.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -66,10 +67,11 @@ public class ArtistController : Controller
var result = Artist.ToStatsModel();
return Ok(result);
}
[HttpGet]
[Authorize("read:artist")]
[Route("PayoutDashboard")]
public async Task<IActionResult> PayoutDashboard()
[Route("Payout")]
public async Task<IActionResult> Payout()
{
var userId = User.GetUserId();
var Artist = await _dbContext.UserArtists.Include(x=>x.Requests).FirstOrDefaultAsync(Artist=>Artist.UserId==userId);
@ -80,8 +82,16 @@ public class ArtistController : Controller
return BadRequest();
return Unauthorized();
}
var url = _paymentService.CreateDashboardUrl(Artist.StripeAccountId);
return Ok(new {url});
var account = _paymentService.GetAccount(Artist.StripeAccountId);
var balance = _paymentService.GetBalance(Artist.StripeAccountId);
var result = new PayoutModel()
{
Enabled = account.PayoutsEnabled,
Balance = balance,
PayoutUrl = _paymentService.CreateDashboardUrl(Artist.StripeAccountId)
};
return Ok(result);
}
[HttpPut]

View File

@ -0,0 +1,10 @@
namespace comissions.app.database.Models;
public class PayoutModel
{
public int PayoutDelayDays { get; set; }
public string Interval { get; set; }
public double Balance { get; set; }
public bool Enabled { get; set; }
public string PayoutUrl { get; set; }
}

View File

@ -1,4 +1,6 @@
using Stripe;
namespace comissions.app.api.Services.Payment;
public interface IPaymentService
@ -9,4 +11,6 @@ public interface IPaymentService
bool ArtistAccountIsOnboarded(string accountId);
string Charge(int orderArtistServiceId, string? sellerStripeAccountId, double orderPrice);
string CreateDashboardUrl(string accountId);
Account GetAccount(string? artistStripeAccountId);
double GetBalance(string accountId);
}

View File

@ -135,4 +135,18 @@ public class StripePaymentServiceProvider:IPaymentService
var url = service.Create(accountId);
return url.Url;
}
public Account GetAccount(string? artistStripeAccountId)
{
var AccountService = new AccountService();
var account = AccountService.Get(artistStripeAccountId);
return account;
}
public double GetBalance(string accountId)
{
var balanceService = new BalanceService();
var balance = balanceService.Get();
return balance.Available[0].Amount/100;
}
}