Skip to content

Commit 5382a31

Browse files
arthurdedeusMattBro
authored andcommitted
feat(stripe-mock): Add subscription_metadata and charge_metadata config (#53596)
1 parent 3ccfcd6 commit 5382a31

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

services/stripe-mock/src/stripe_mock/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class MockConfig(BaseModel):
8888
seed: int = 42
8989

9090
customer_metadata: dict[str, str] = {}
91+
subscription_metadata: dict[str, str] = {}
92+
charge_metadata: dict[str, str] = {}
9193

9294
customer_types: dict[str, int] = {
9395
"loyalists_monthly": 12,

services/stripe-mock/src/stripe_mock/data/scenarios.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ def add_customer_lifecycle(
145145
if start_date > self.data_end:
146146
return
147147

148-
merged_metadata = {**self.cfg.customer_metadata, **(persona_metadata or {})}
148+
customer_metadata = {**self.cfg.customer_metadata, **(persona_metadata or {})}
149+
subscription_metadata = {**self.cfg.subscription_metadata, **(persona_metadata or {})}
149150

150151
cust_idx = _next_id("cus")
151152
customer = make_customer(
152-
cust_idx, start_date, name=name, email=email, currency=currency, metadata=merged_metadata
153+
cust_idx, start_date, name=name, email=email, currency=currency, metadata=customer_metadata
153154
)
154155
self.customers.append(customer)
155156

@@ -175,7 +176,7 @@ def add_customer_lifecycle(
175176
currency=currency,
176177
interval=interval,
177178
product_id=product_id,
178-
metadata=merged_metadata,
179+
metadata=subscription_metadata,
179180
)
180181
if trial_days > 0:
181182
from datetime import timedelta
@@ -284,13 +285,15 @@ def add_customer_lifecycle(
284285
sub["latest_invoice"] = invoice["id"]
285286

286287
ch_idx = _next_id("ch")
288+
charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})}
287289
charge = make_charge(
288290
ch_idx,
289291
invoice_date,
290292
amount=invoice_amount,
291293
currency=currency,
292294
customer_id=customer["id"],
293295
invoice_id=invoice["id"],
296+
metadata=charge_metadata,
294297
)
295298
self.charges.append(charge)
296299

services/stripe-mock/stripe-mock.config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
# end_date: "2026-03-01"
1010
# seed: 42
1111

12-
# --- Customer metadata (injected into every customer.metadata field) ---
12+
# --- Metadata (injected into the metadata field of each object type) ---
1313
# customer_metadata:
1414
# source: "stripe-mock"
1515
# environment: "development"
16+
# subscription_metadata:
17+
# posthog_person_distinct_id: "your_distinct_id"
18+
# charge_metadata: {}
1619

1720
# --- Customer persona distribution (count per type) ---
1821
# customer_types:

0 commit comments

Comments
 (0)