2024-04-16 13:55:00 -04:00
|
|
|
|
using Bit.Api.Billing.Models.Responses;
|
2024-03-28 08:46:12 -04:00
|
|
|
|
using Bit.Core;
|
2024-05-23 10:17:00 -04:00
|
|
|
|
using Bit.Core.Billing.Services;
|
2024-03-28 08:46:12 -04:00
|
|
|
|
using Bit.Core.Context;
|
|
|
|
|
|
using Bit.Core.Services;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Billing.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
[Route("providers/{providerId:guid}/billing")]
|
|
|
|
|
|
[Authorize("Application")]
|
|
|
|
|
|
public class ProviderBillingController(
|
|
|
|
|
|
ICurrentContext currentContext,
|
|
|
|
|
|
IFeatureService featureService,
|
2024-05-23 10:17:00 -04:00
|
|
|
|
IProviderBillingService providerBillingService) : Controller
|
2024-03-28 08:46:12 -04:00
|
|
|
|
{
|
|
|
|
|
|
[HttpGet("subscription")]
|
|
|
|
|
|
public async Task<IResult> GetSubscriptionAsync([FromRoute] Guid providerId)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!featureService.IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling))
|
|
|
|
|
|
{
|
|
|
|
|
|
return TypedResults.NotFound();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!currentContext.ProviderProviderAdmin(providerId))
|
|
|
|
|
|
{
|
|
|
|
|
|
return TypedResults.Unauthorized();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-23 10:17:00 -04:00
|
|
|
|
var providerSubscriptionDTO = await providerBillingService.GetSubscriptionDTO(providerId);
|
2024-03-28 08:46:12 -04:00
|
|
|
|
|
2024-04-16 13:55:00 -04:00
|
|
|
|
if (providerSubscriptionDTO == null)
|
2024-03-28 08:46:12 -04:00
|
|
|
|
{
|
|
|
|
|
|
return TypedResults.NotFound();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-16 13:55:00 -04:00
|
|
|
|
var (providerPlans, subscription) = providerSubscriptionDTO;
|
2024-03-28 08:46:12 -04:00
|
|
|
|
|
2024-04-16 13:55:00 -04:00
|
|
|
|
var providerSubscriptionResponse = ProviderSubscriptionResponse.From(providerPlans, subscription);
|
2024-03-28 08:46:12 -04:00
|
|
|
|
|
2024-04-16 13:55:00 -04:00
|
|
|
|
return TypedResults.Ok(providerSubscriptionResponse);
|
2024-03-28 08:46:12 -04:00
|
|
|
|
}
|
2024-05-23 10:17:00 -04:00
|
|
|
|
|
|
|
|
|
|
[HttpGet("payment-information")]
|
|
|
|
|
|
public async Task<IResult> GetPaymentInformationAsync([FromRoute] Guid providerId)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!featureService.IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling))
|
|
|
|
|
|
{
|
|
|
|
|
|
return TypedResults.NotFound();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!currentContext.ProviderProviderAdmin(providerId))
|
|
|
|
|
|
{
|
|
|
|
|
|
return TypedResults.Unauthorized();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var providerPaymentInformationDto = await providerBillingService.GetPaymentInformationAsync(providerId);
|
|
|
|
|
|
|
|
|
|
|
|
if (providerPaymentInformationDto == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return TypedResults.NotFound();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var (paymentSource, taxInfo) = providerPaymentInformationDto;
|
|
|
|
|
|
|
|
|
|
|
|
var providerPaymentInformationResponse = PaymentInformationResponse.From(paymentSource, taxInfo);
|
|
|
|
|
|
|
|
|
|
|
|
return TypedResults.Ok(providerPaymentInformationResponse);
|
|
|
|
|
|
}
|
2024-03-28 08:46:12 -04:00
|
|
|
|
}
|