diff --git a/services/stripe-mock/src/stripe_mock/config.py b/services/stripe-mock/src/stripe_mock/config.py index 47512e467474..270f26af2367 100644 --- a/services/stripe-mock/src/stripe_mock/config.py +++ b/services/stripe-mock/src/stripe_mock/config.py @@ -88,6 +88,8 @@ class MockConfig(BaseModel): seed: int = 42 customer_metadata: dict[str, str] = {} + subscription_metadata: dict[str, str] = {} + charge_metadata: dict[str, str] = {} customer_types: dict[str, int] = { "loyalists_monthly": 12, diff --git a/services/stripe-mock/src/stripe_mock/data/scenarios.py b/services/stripe-mock/src/stripe_mock/data/scenarios.py index b3365ed54011..757197c7a59f 100644 --- a/services/stripe-mock/src/stripe_mock/data/scenarios.py +++ b/services/stripe-mock/src/stripe_mock/data/scenarios.py @@ -145,11 +145,12 @@ def add_customer_lifecycle( if start_date > self.data_end: return - merged_metadata = {**self.cfg.customer_metadata, **(persona_metadata or {})} + customer_metadata = {**self.cfg.customer_metadata, **(persona_metadata or {})} + subscription_metadata = {**self.cfg.subscription_metadata, **(persona_metadata or {})} cust_idx = _next_id("cus") customer = make_customer( - cust_idx, start_date, name=name, email=email, currency=currency, metadata=merged_metadata + cust_idx, start_date, name=name, email=email, currency=currency, metadata=customer_metadata ) self.customers.append(customer) @@ -175,7 +176,7 @@ def add_customer_lifecycle( currency=currency, interval=interval, product_id=product_id, - metadata=merged_metadata, + metadata=subscription_metadata, ) if trial_days > 0: from datetime import timedelta @@ -284,6 +285,7 @@ def add_customer_lifecycle( sub["latest_invoice"] = invoice["id"] ch_idx = _next_id("ch") + charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})} charge = make_charge( ch_idx, invoice_date, @@ -291,6 +293,7 @@ def add_customer_lifecycle( currency=currency, customer_id=customer["id"], invoice_id=invoice["id"], + metadata=charge_metadata, ) self.charges.append(charge) diff --git a/services/stripe-mock/stripe-mock.config.yaml b/services/stripe-mock/stripe-mock.config.yaml index 52362e565a38..8b761502edf6 100644 --- a/services/stripe-mock/stripe-mock.config.yaml +++ b/services/stripe-mock/stripe-mock.config.yaml @@ -9,10 +9,13 @@ # end_date: "2026-03-01" # seed: 42 -# --- Customer metadata (injected into every customer.metadata field) --- +# --- Metadata (injected into the metadata field of each object type) --- # customer_metadata: # source: "stripe-mock" # environment: "development" +# subscription_metadata: +# posthog_person_distinct_id: "your_distinct_id" +# charge_metadata: {} # --- Customer persona distribution (count per type) --- # customer_types: