Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated customer metadata to only store one old btCustomerId #4997

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,9 @@ await stripeAdapter.PaymentMethodAttachAsync(token,

var metadata = customer.Metadata;

if (metadata.ContainsKey(BraintreeCustomerIdKey))
if (metadata.TryGetValue(BraintreeCustomerIdKey, out var value))
{
metadata[BraintreeCustomerIdOldKey] = value;
metadata[BraintreeCustomerIdKey] = null;
}

Expand Down
1 change: 1 addition & 0 deletions src/Core/Billing/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Services/Implementations/StripePaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@
}
else
{
invoice = await _stripeAdapter.InvoiceFinalizeInvoiceAsync(subResponse.LatestInvoiceId,

Check warning on line 847 in src/Core/Services/Implementations/StripePaymentService.cs

View workflow job for this annotation

GitHub Actions / Quality scan

'subResponse' is null on at least one execution path. (https://rules.sonarsource.com/csharp/RSPEC-2259)
new InvoiceFinalizeOptions { AutoAdvance = false, });
await _stripeAdapter.InvoiceSendInvoiceAsync(invoice.Id, new InvoiceSendOptions());
paymentIntentClientSecret = null;
Expand All @@ -869,7 +869,7 @@
else if (!invoice.Paid)
{
// Pay invoice with no charge to customer this completes the invoice immediately without waiting the scheduled 1h
invoice = await _stripeAdapter.InvoicePayAsync(subResponse.LatestInvoiceId);

Check warning on line 872 in src/Core/Services/Implementations/StripePaymentService.cs

View workflow job for this annotation

GitHub Actions / Quality scan

'subResponse' is null on at least one execution path. (https://rules.sonarsource.com/csharp/RSPEC-2259)
paymentIntentClientSecret = null;
}

Expand Down Expand Up @@ -1360,9 +1360,9 @@
{
if (braintreeCustomer?.Id != stripeCustomerMetadata["btCustomerId"])
{
var nowSec = Utilities.CoreHelpers.ToEpocSeconds(DateTime.UtcNow);
stripeCustomerMetadata.Add($"btCustomerId_{nowSec}", stripeCustomerMetadata["btCustomerId"]);
stripeCustomerMetadata["btCustomerId_old"] = stripeCustomerMetadata["btCustomerId"];

Check warning on line 1363 in src/Core/Services/Implementations/StripePaymentService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/StripePaymentService.cs#L1363

Added line #L1363 was not covered by tests
}

stripeCustomerMetadata["btCustomerId"] = braintreeCustomer?.Id;
}
else if (!string.IsNullOrWhiteSpace(braintreeCustomer?.Id))
Expand Down
Loading