mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
Updated customer metadata to only store one old btCustomerId (#4997)
* Updated customer metadata to only store one old btCustomerId * Updated to include case where old key already exists * Updated SubscriberService to also save btCustomerId_old on the Stripe Customer's metadata --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
This commit is contained in:
parent
c76d615fad
commit
44bf5619c8
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<SubscriptionSuspension> GetSubscriptionSuspensionAsync(
|
||||
IStripeAdapter stripeAdapter,
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user