Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
corporate: Use StripeCustomerData dataclass to create stripe Customer.
Lauryn Menard63abf063b7ad
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex a4174e18455..a062c4770e1 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -3,6 +3,7 @@ import mathimport osimport secretsfrom abc import ABC, abstractmethod+from dataclasses import dataclassfrom datetime import datetime, timedeltafrom decimal import Decimalfrom functools import wraps@@ -316,6 +317,13 @@ def stripe_get_customer(stripe_customer_id: str) -> stripe.Customer:)+@dataclass+class StripeCustomerData:+ description: str+ email: str+ metadata: Dict[str, Any]++class BillingSession(ABC):@abstractmethoddef get_customer(self) -> Optional[Customer]:@@ -328,7 +336,7 @@ class BillingSession(ABC):pass@abstractmethod- def get_data_for_stripe_customer(self) -> Dict[str, Any]:+ def get_data_for_stripe_customer(self) -> StripeCustomerData:pass@abstractmethod@@ -339,12 +347,9 @@ class BillingSession(ABC):def create_stripe_customer(self, payment_method: Optional[str] = None) -> Customer:stripe_customer_data = self.get_data_for_stripe_customer()stripe_customer = stripe.Customer.create(- description=stripe_customer_data["description"],- email=stripe_customer_data["email"],- metadata={- "realm_id": stripe_customer_data["realm_id"],- "realm_str": stripe_customer_data["realm_str"],- },+ description=stripe_customer_data.description,+ email=stripe_customer_data.email,+ metadata=stripe_customer_data.metadata,payment_method=payment_method,)stripe.Customer.modify(@@ -425,13 +430,16 @@ class RealmBillingSession(BillingSession):)@override- def get_data_for_stripe_customer(self) -> Dict[str, Any]:- data: Dict[str, Any] = {}- data["description"] = f"{self.realm.string_id} ({self.realm.name})"- data["email"] = self.user.delivery_email- data["realm_id"] = self.realm.id- data["realm_str"] = self.realm.string_id- return data+ def get_data_for_stripe_customer(self) -> StripeCustomerData:+ metadata: Dict[str, Any] = {}+ metadata["realm_id"] = self.realm.id+ metadata["realm_str"] = self.realm.string_id+ realm_stripe_customer_data = StripeCustomerData(+ description=f"{self.realm.string_id} ({self.realm.name})",+ email=self.user.delivery_email,+ metadata=metadata,+ )+ return realm_stripe_customer_data@overridedef update_or_create_customer(self, stripe_customer_id: str) -> Customer:diff --git a/zilencer/management/commands/populate_billing_realms.py b/zilencer/management/commands/populate_billing_realms.pyindex d90fba4f566..3f23d2b3ad5 100644--- a/zilencer/management/commands/populate_billing_realms.py+++ b/zilencer/management/commands/populate_billing_realms.py@@ -7,7 +7,7 @@ from django.core.management.base import BaseCommandfrom django.utils.timezone import now as timezone_nowfrom typing_extensions import override-from corporate.lib.stripe import add_months, RealmBillingSession+from corporate.lib.stripe import RealmBillingSession, add_monthsfrom corporate.models import Customer, CustomerPlan, LicenseLedgerfrom zerver.actions.create_realm import do_create_realmfrom zerver.actions.create_user import do_create_user