mirror of
https://github.com/D4M13N-D3V/comissions-app-core-api.git
synced 2025-03-14 10:04:55 +00:00
fix: payout endpoint
This commit is contained in:
parent
b6eaee0831
commit
a07a41d530
@ -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]
|
||||
|
10
src/comissions.app.api/Models/PayoutModel.cs
Normal file
10
src/comissions.app.api/Models/PayoutModel.cs
Normal 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; }
|
||||
}
|
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user