1
0
mirror of https://github.com/bitwarden/server synced 2025-12-31 15:43:16 +00:00

[PM-27117] Sync Stripe Customer details for Organizations and Providers in API & Admin (#6679)

* Sync Stripe customer details for Provider / Organization in API & Admin

* Remove unnecessary var

* Fix logical operator

* Remove customer ID check from callers

* Fix failing tests

* Missed conflicts
This commit is contained in:
Alex Morask
2025-12-16 07:59:05 -06:00
committed by GitHub
parent 2ecd6c8d5f
commit 39a6719361
11 changed files with 377 additions and 34 deletions

View File

@@ -67,7 +67,7 @@ public class OrganizationUpdateCommand(
var shouldUpdateBilling = originalName != organization.Name ||
originalBillingEmail != organization.BillingEmail;
if (!shouldUpdateBilling || string.IsNullOrWhiteSpace(organization.GatewayCustomerId))
if (!shouldUpdateBilling)
{
return;
}

View File

@@ -61,10 +61,6 @@ public interface IOrganizationBillingService
/// Updates the organization name and email on the Stripe customer entry.
/// This only updates Stripe, not the Bitwarden database.
/// </summary>
/// <remarks>
/// The caller should ensure that the organization has a GatewayCustomerId before calling this method.
/// </remarks>
/// <param name="organization">The organization to update in Stripe.</param>
/// <exception cref="BillingException">Thrown when the organization does not have a GatewayCustomerId.</exception>
Task UpdateOrganizationNameAndEmail(Organization organization);
}

View File

@@ -177,13 +177,25 @@ public class OrganizationBillingService(
public async Task UpdateOrganizationNameAndEmail(Organization organization)
{
if (organization.GatewayCustomerId is null)
if (string.IsNullOrWhiteSpace(organization.GatewayCustomerId))
{
throw new BillingException("Cannot update an organization in Stripe without a GatewayCustomerId.");
logger.LogWarning(
"Organization ({OrganizationId}) has no Stripe customer to update",
organization.Id);
return;
}
var newDisplayName = organization.DisplayName();
// Organization.DisplayName() can return null - handle gracefully
if (string.IsNullOrWhiteSpace(newDisplayName))
{
logger.LogWarning(
"Organization ({OrganizationId}) has no name to update in Stripe",
organization.Id);
return;
}
await stripeAdapter.UpdateCustomerAsync(organization.GatewayCustomerId,
new CustomerUpdateOptions
{
@@ -196,9 +208,7 @@ public class OrganizationBillingService(
new CustomerInvoiceSettingsCustomFieldOptions
{
Name = organization.SubscriberType(),
Value = newDisplayName.Length <= 30
? newDisplayName
: newDisplayName[..30]
Value = newDisplayName
}]
},
});

View File

@@ -113,4 +113,11 @@ public interface IProviderBillingService
TaxInformation taxInformation);
Task UpdateSeatMinimums(UpdateProviderSeatMinimumsCommand command);
/// <summary>
/// Updates the provider name and email on the Stripe customer entry.
/// This only updates Stripe, not the Bitwarden database.
/// </summary>
/// <param name="provider">The provider to update in Stripe.</param>
Task UpdateProviderNameAndEmail(Provider provider);
}