-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-27117] Sync Stripe Customer details for Organizations and Providers in API & Admin #6679
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
Open
amorask-bitwarden
wants to merge
8
commits into
main
Choose a base branch
from
billing/PM-27117/org-prov-custom-invoice-field
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7d60297
Sync Stripe customer details for Provider / Organization in API & Admin
amorask-bitwarden 1d02380
Remove unnecessary var
amorask-bitwarden 5459a30
Merge branch 'main' into billing/PM-27117/org-prov-custom-invoice-field
amorask-bitwarden c521c37
Fix logical operator
amorask-bitwarden 5e75587
Merge branch 'main' into billing/PM-27117/org-prov-custom-invoice-field
amorask-bitwarden 8982bcb
Remove customer ID check from callers
amorask-bitwarden f37b42e
Merge branch 'main' into billing/PM-27117/org-prov-custom-invoice-field
amorask-bitwarden c827b38
Fix failing tests
amorask-bitwarden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2151,4 +2151,151 @@ await stripeAdapter.Received(1).SubscriptionUpdateAsync(provider.GatewaySubscrip | |
| } | ||
|
|
||
| #endregion | ||
|
|
||
| #region UpdateProviderNameAndEmail | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task UpdateProviderNameAndEmail_NullGatewayCustomerId_LogsWarningAndReturns( | ||
| Provider provider, | ||
| SutProvider<ProviderBillingService> sutProvider) | ||
| { | ||
| // Arrange | ||
| provider.GatewayCustomerId = null; | ||
| var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>(); | ||
|
|
||
| // Act | ||
| await sutProvider.Sut.UpdateProviderNameAndEmail(provider); | ||
|
|
||
| // Assert | ||
| await stripeAdapter.DidNotReceive().CustomerUpdateAsync( | ||
| Arg.Any<string>(), | ||
| Arg.Any<CustomerUpdateOptions>()); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task UpdateProviderNameAndEmail_EmptyGatewayCustomerId_LogsWarningAndReturns( | ||
| Provider provider, | ||
| SutProvider<ProviderBillingService> sutProvider) | ||
| { | ||
| // Arrange | ||
| provider.GatewayCustomerId = ""; | ||
| var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>(); | ||
|
|
||
| // Act | ||
| await sutProvider.Sut.UpdateProviderNameAndEmail(provider); | ||
|
|
||
| // Assert | ||
| await stripeAdapter.DidNotReceive().CustomerUpdateAsync( | ||
| Arg.Any<string>(), | ||
| Arg.Any<CustomerUpdateOptions>()); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task UpdateProviderNameAndEmail_NullProviderName_LogsWarningAndReturns( | ||
| Provider provider, | ||
| SutProvider<ProviderBillingService> sutProvider) | ||
| { | ||
| // Arrange | ||
| provider.Name = null; | ||
| provider.GatewayCustomerId = "cus_test123"; | ||
| var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>(); | ||
|
|
||
| // Act | ||
| await sutProvider.Sut.UpdateProviderNameAndEmail(provider); | ||
|
|
||
| // Assert | ||
| await stripeAdapter.DidNotReceive().CustomerUpdateAsync( | ||
| Arg.Any<string>(), | ||
| Arg.Any<CustomerUpdateOptions>()); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task UpdateProviderNameAndEmail_EmptyProviderName_LogsWarningAndReturns( | ||
| Provider provider, | ||
| SutProvider<ProviderBillingService> sutProvider) | ||
| { | ||
| // Arrange | ||
| provider.Name = ""; | ||
| provider.GatewayCustomerId = "cus_test123"; | ||
| var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>(); | ||
|
|
||
| // Act | ||
| await sutProvider.Sut.UpdateProviderNameAndEmail(provider); | ||
|
|
||
| // Assert | ||
| await stripeAdapter.DidNotReceive().CustomerUpdateAsync( | ||
| Arg.Any<string>(), | ||
| Arg.Any<CustomerUpdateOptions>()); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task UpdateProviderNameAndEmail_ValidProvider_CallsStripeWithCorrectParameters( | ||
| Provider provider, | ||
| SutProvider<ProviderBillingService> sutProvider) | ||
| { | ||
| // Arrange | ||
| provider.Name = "Test Provider"; | ||
| provider.BillingEmail = "[email protected]"; | ||
| provider.GatewayCustomerId = "cus_test123"; | ||
| var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>(); | ||
|
|
||
| // Act | ||
| await sutProvider.Sut.UpdateProviderNameAndEmail(provider); | ||
|
|
||
| // Assert | ||
| await stripeAdapter.Received(1).CustomerUpdateAsync( | ||
| provider.GatewayCustomerId, | ||
| Arg.Is<CustomerUpdateOptions>(options => | ||
| options.Email == provider.BillingEmail && | ||
| options.Description == provider.Name && | ||
| options.InvoiceSettings.CustomFields.Count == 1 && | ||
| options.InvoiceSettings.CustomFields[0].Name == "Provider" && | ||
| options.InvoiceSettings.CustomFields[0].Value == provider.Name)); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task UpdateProviderNameAndEmail_LongProviderName_UsesFullName( | ||
| Provider provider, | ||
| SutProvider<ProviderBillingService> sutProvider) | ||
| { | ||
| // Arrange | ||
| var longName = new string('A', 50); // 50 characters | ||
| provider.Name = longName; | ||
| provider.BillingEmail = "[email protected]"; | ||
| provider.GatewayCustomerId = "cus_test123"; | ||
| var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>(); | ||
|
|
||
| // Act | ||
| await sutProvider.Sut.UpdateProviderNameAndEmail(provider); | ||
|
|
||
| // Assert | ||
| await stripeAdapter.Received(1).CustomerUpdateAsync( | ||
| provider.GatewayCustomerId, | ||
| Arg.Is<CustomerUpdateOptions>(options => | ||
| options.InvoiceSettings.CustomFields[0].Value == longName)); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task UpdateProviderNameAndEmail_NullBillingEmail_UpdatesWithNull( | ||
| Provider provider, | ||
| SutProvider<ProviderBillingService> sutProvider) | ||
| { | ||
| // Arrange | ||
| provider.Name = "Test Provider"; | ||
| provider.BillingEmail = null; | ||
| provider.GatewayCustomerId = "cus_test123"; | ||
| var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>(); | ||
|
|
||
| // Act | ||
| await sutProvider.Sut.UpdateProviderNameAndEmail(provider); | ||
|
|
||
| // Assert | ||
| await stripeAdapter.Received(1).CustomerUpdateAsync( | ||
| provider.GatewayCustomerId, | ||
| Arg.Is<CustomerUpdateOptions>(options => | ||
| options.Email == null && | ||
| options.Description == provider.Name)); | ||
| } | ||
|
|
||
| #endregion | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐จ (non-blocking) This bit of boilerplate is repeated a few times. Is there a way to simplify things for the callers?
GatewayCustomerIdis null. Can we remove that check from the callers? (That has another benefit, which is that callers don't have to know about the significance of this property, which is effectively billing metadata.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the Customer ID check from the callers here: 8982bcb
With regards to your second bullet, I didn't see a way to do it that would constitute any meaningful difference. Could use a new DTO to capture previous name / email prior to the database update, but that's the same process with a different flavor.