Skip to content

Subscriptions: match stripe customer description with org name #9976

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

Merged
merged 1 commit into from
Feb 2, 2023
Merged
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
3 changes: 3 additions & 0 deletions readthedocs/subscriptions/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def update_stripe_customer(sender, instance, created, **kwargs):
if organization.email != stripe_customer.email:
fields_to_update["email"] = organization.email

if organization.name != stripe_customer.description:
fields_to_update["description"] = organization.name

org_metadata = organization.get_stripe_metadata()
current_metadata = stripe_customer.metadata or {}
for key, value in org_metadata.items():
Expand Down
12 changes: 12 additions & 0 deletions readthedocs/subscriptions/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ def setUp(self):
self.organization = get(
Organization,
slug="org",
name="org",
owners=[self.user],
email=email,
stripe_customer=self.stripe_customer,
)
self.stripe_customer.metadata = self.organization.get_stripe_metadata()
self.stripe_customer.description = self.organization.name
self.stripe_customer.save()

@mock.patch("readthedocs.subscriptions.signals.stripe.Customer")
Expand All @@ -36,6 +38,16 @@ def test_update_organization_email(self, customer):
email=new_email,
)

@mock.patch("readthedocs.subscriptions.signals.stripe.Customer")
def test_update_organization_name(self, customer):
new_name = "New organization"
self.organization.name = new_name
self.organization.save()
customer.modify.assert_called_once_with(
self.stripe_customer.id,
description=new_name,
)

@mock.patch("readthedocs.subscriptions.signals.stripe.Customer")
def test_update_organization_slug(self, customer):
new_slug = "new-org"
Expand Down