1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 01:22:50 -05:00

Start subscription for provider during setup process. (#3957)

This commit is contained in:
Alex Morask
2024-04-10 14:10:53 -04:00
committed by GitHub
parent 2c36784cda
commit 3cdfbdb22d
14 changed files with 749 additions and 17 deletions

View File

@ -724,7 +724,7 @@ public class OrganizationsController : Controller
[HttpPut("{id}/tax")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task PutTaxInfo(string id, [FromBody] OrganizationTaxInfoUpdateRequestModel model)
public async Task PutTaxInfo(string id, [FromBody] ExpandedTaxInfoUpdateRequestModel model)
{
var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid))

View File

@ -1,9 +1,12 @@
using Bit.Api.AdminConsole.Models.Request.Providers;
using Bit.Api.AdminConsole.Models.Response.Providers;
using Bit.Core;
using Bit.Core.AdminConsole.Repositories;
using Bit.Core.AdminConsole.Services;
using Bit.Core.Billing.Commands;
using Bit.Core.Context;
using Bit.Core.Exceptions;
using Bit.Core.Models.Business;
using Bit.Core.Services;
using Bit.Core.Settings;
using Microsoft.AspNetCore.Authorization;
@ -20,15 +23,23 @@ public class ProvidersController : Controller
private readonly IProviderService _providerService;
private readonly ICurrentContext _currentContext;
private readonly GlobalSettings _globalSettings;
private readonly IFeatureService _featureService;
private readonly IStartSubscriptionCommand _startSubscriptionCommand;
private readonly ILogger<ProvidersController> _logger;
public ProvidersController(IUserService userService, IProviderRepository providerRepository,
IProviderService providerService, ICurrentContext currentContext, GlobalSettings globalSettings)
IProviderService providerService, ICurrentContext currentContext, GlobalSettings globalSettings,
IFeatureService featureService, IStartSubscriptionCommand startSubscriptionCommand,
ILogger<ProvidersController> logger)
{
_userService = userService;
_providerRepository = providerRepository;
_providerService = providerService;
_currentContext = currentContext;
_globalSettings = globalSettings;
_featureService = featureService;
_startSubscriptionCommand = startSubscriptionCommand;
_logger = logger;
}
[HttpGet("{id:guid}")]
@ -86,6 +97,30 @@ public class ProvidersController : Controller
var response =
await _providerService.CompleteSetupAsync(model.ToProvider(provider), userId, model.Token, model.Key);
if (_featureService.IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling))
{
var taxInfo = new TaxInfo
{
BillingAddressCountry = model.TaxInfo.Country,
BillingAddressPostalCode = model.TaxInfo.PostalCode,
TaxIdNumber = model.TaxInfo.TaxId,
BillingAddressLine1 = model.TaxInfo.Line1,
BillingAddressLine2 = model.TaxInfo.Line2,
BillingAddressCity = model.TaxInfo.City,
BillingAddressState = model.TaxInfo.State
};
try
{
await _startSubscriptionCommand.StartSubscription(provider, taxInfo);
}
catch
{
// We don't want to trap the user on the setup page, so we'll let this go through but the provider will be in an un-billable state.
_logger.LogError("Failed to create subscription for provider with ID {ID} during setup", provider.Id);
}
}
return new ProviderResponseModel(response);
}
}

View File

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Bit.Api.Models.Request;
using Bit.Core.AdminConsole.Entities.Provider;
using Bit.Core.Utilities;
@ -22,6 +23,7 @@ public class ProviderSetupRequestModel
public string Token { get; set; }
[Required]
public string Key { get; set; }
public ExpandedTaxInfoUpdateRequestModel TaxInfo { get; set; }
public virtual Provider ToProvider(Provider provider)
{

View File

@ -1,8 +1,8 @@
using Bit.Api.Models.Request.Accounts;
namespace Bit.Api.Models.Request.Organizations;
namespace Bit.Api.Models.Request;
public class OrganizationTaxInfoUpdateRequestModel : TaxInfoUpdateRequestModel
public class ExpandedTaxInfoUpdateRequestModel : TaxInfoUpdateRequestModel
{
public string TaxId { get; set; }
public string Line1 { get; set; }

View File

@ -1,10 +1,9 @@
using System.ComponentModel.DataAnnotations;
using Bit.Api.Models.Request.Organizations;
using Bit.Core.Enums;
namespace Bit.Api.Models.Request;
public class PaymentRequestModel : OrganizationTaxInfoUpdateRequestModel
public class PaymentRequestModel : ExpandedTaxInfoUpdateRequestModel
{
[Required]
public PaymentMethodType? PaymentMethodType { get; set; }