mirror of
https://github.com/bitwarden/server.git
synced 2025-04-22 05:25:10 -05:00
Admin: Update Stripe Customer Email on Organization Edit (#3281)
* Admin: Update Stripe customer email on organization billing email update * Conner's feedback
This commit is contained in:
parent
44baba9229
commit
0b72eb8e45
@ -19,6 +19,7 @@ using Bit.Core.Utilities;
|
|||||||
using Bit.Core.Vault.Repositories;
|
using Bit.Core.Vault.Repositories;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Stripe;
|
||||||
|
|
||||||
namespace Bit.Admin.Controllers;
|
namespace Bit.Admin.Controllers;
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ public class OrganizationsController : Controller
|
|||||||
private readonly ISecretRepository _secretRepository;
|
private readonly ISecretRepository _secretRepository;
|
||||||
private readonly IProjectRepository _projectRepository;
|
private readonly IProjectRepository _projectRepository;
|
||||||
private readonly IServiceAccountRepository _serviceAccountRepository;
|
private readonly IServiceAccountRepository _serviceAccountRepository;
|
||||||
|
private readonly IStripeSyncService _stripeSyncService;
|
||||||
|
|
||||||
public OrganizationsController(
|
public OrganizationsController(
|
||||||
IOrganizationService organizationService,
|
IOrganizationService organizationService,
|
||||||
@ -70,7 +72,8 @@ public class OrganizationsController : Controller
|
|||||||
ICurrentContext currentContext,
|
ICurrentContext currentContext,
|
||||||
ISecretRepository secretRepository,
|
ISecretRepository secretRepository,
|
||||||
IProjectRepository projectRepository,
|
IProjectRepository projectRepository,
|
||||||
IServiceAccountRepository serviceAccountRepository)
|
IServiceAccountRepository serviceAccountRepository,
|
||||||
|
IStripeSyncService stripeSyncService)
|
||||||
{
|
{
|
||||||
_organizationService = organizationService;
|
_organizationService = organizationService;
|
||||||
_organizationRepository = organizationRepository;
|
_organizationRepository = organizationRepository;
|
||||||
@ -94,6 +97,7 @@ public class OrganizationsController : Controller
|
|||||||
_secretRepository = secretRepository;
|
_secretRepository = secretRepository;
|
||||||
_projectRepository = projectRepository;
|
_projectRepository = projectRepository;
|
||||||
_serviceAccountRepository = serviceAccountRepository;
|
_serviceAccountRepository = serviceAccountRepository;
|
||||||
|
_stripeSyncService = stripeSyncService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[RequirePermission(Permission.Org_List_View)]
|
[RequirePermission(Permission.Org_List_View)]
|
||||||
@ -208,6 +212,16 @@ public class OrganizationsController : Controller
|
|||||||
throw new BadRequestException("Plan does not support Secrets Manager");
|
throw new BadRequestException("Plan does not support Secrets Manager");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _stripeSyncService.UpdateCustomerEmailAddress(organization.GatewayCustomerId, organization.BillingEmail);
|
||||||
|
}
|
||||||
|
catch (StripeException stripeException)
|
||||||
|
{
|
||||||
|
_logger.LogError(stripeException, "Failed to update billing email address in Stripe for Organization with ID '{organizationId}'", organization.Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
await _organizationRepository.ReplaceAsync(organization);
|
await _organizationRepository.ReplaceAsync(organization);
|
||||||
await _applicationCacheService.UpsertOrganizationAbilityAsync(organization);
|
await _applicationCacheService.UpsertOrganizationAbilityAsync(organization);
|
||||||
await _referenceEventService.RaiseEventAsync(new ReferenceEvent(ReferenceEventType.OrganizationEditedByAdmin, organization, _currentContext)
|
await _referenceEventService.RaiseEventAsync(new ReferenceEvent(ReferenceEventType.OrganizationEditedByAdmin, organization, _currentContext)
|
||||||
@ -215,6 +229,7 @@ public class OrganizationsController : Controller
|
|||||||
EventRaisedByUser = _userService.GetUserName(User),
|
EventRaisedByUser = _userService.GetUserName(User),
|
||||||
SalesAssistedTrialStarted = model.SalesAssistedTrialStarted,
|
SalesAssistedTrialStarted = model.SalesAssistedTrialStarted,
|
||||||
});
|
});
|
||||||
|
|
||||||
return RedirectToAction("Edit", new { id });
|
return RedirectToAction("Edit", new { id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,13 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<input type="email" class="form-control" asp-for="BillingEmail" readonly='@(!canEditBilling)'>
|
<input
|
||||||
|
type="text"
|
||||||
|
class="form-control"
|
||||||
|
asp-for="BillingEmail"
|
||||||
|
readonly='@(!canEditBilling)'
|
||||||
|
pattern="@(@"[^@\s]+@[^@\s]+\.[^@\s]+")"
|
||||||
|
title="Email address must be in the format 'address@domain.com'.">
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user