diff --git a/src/Core/Billing/Services/Implementations/SubscriberService.cs b/src/Core/Billing/Services/Implementations/SubscriberService.cs index 9daf956221..401d9ce2ca 100644 --- a/src/Core/Billing/Services/Implementations/SubscriberService.cs +++ b/src/Core/Billing/Services/Implementations/SubscriberService.cs @@ -523,8 +523,9 @@ public class SubscriberService( var metadata = customer.Metadata; - if (metadata.ContainsKey(BraintreeCustomerIdKey)) + if (metadata.TryGetValue(BraintreeCustomerIdKey, out var value)) { + metadata[BraintreeCustomerIdOldKey] = value; metadata[BraintreeCustomerIdKey] = null; } diff --git a/src/Core/Billing/Utilities.cs b/src/Core/Billing/Utilities.cs index b8bc1887bc..28527af0c0 100644 --- a/src/Core/Billing/Utilities.cs +++ b/src/Core/Billing/Utilities.cs @@ -7,6 +7,7 @@ namespace Bit.Core.Billing; public static class Utilities { public const string BraintreeCustomerIdKey = "btCustomerId"; + public const string BraintreeCustomerIdOldKey = "btCustomerId_old"; public static async Task GetSubscriptionSuspensionAsync( IStripeAdapter stripeAdapter, diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index 7eb2b402bb..259a4eb757 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -1360,9 +1360,9 @@ public class StripePaymentService : IPaymentService { if (braintreeCustomer?.Id != stripeCustomerMetadata["btCustomerId"]) { - var nowSec = Utilities.CoreHelpers.ToEpocSeconds(DateTime.UtcNow); - stripeCustomerMetadata.Add($"btCustomerId_{nowSec}", stripeCustomerMetadata["btCustomerId"]); + stripeCustomerMetadata["btCustomerId_old"] = stripeCustomerMetadata["btCustomerId"]; } + stripeCustomerMetadata["btCustomerId"] = braintreeCustomer?.Id; } else if (!string.IsNullOrWhiteSpace(braintreeCustomer?.Id))