Skip to content
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
2 changes: 2 additions & 0 deletions services/stripe-mock/src/stripe_mock/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions services/stripe-mock/src/stripe_mock/data/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -284,13 +285,15 @@ def add_customer_lifecycle(
sub["latest_invoice"] = invoice["id"]

ch_idx = _next_id("ch")
charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 charge_metadata computed inside loop

Unlike customer_metadata and subscription_metadata (which are built once before the loop on lines 148–149), charge_metadata is recomputed on every monthly iteration even though neither self.cfg.charge_metadata nor persona_metadata changes during the loop. For consistency, hoist it alongside the other two metadata variables before the loop starts:

Suggested change
charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})}
charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})}

(Add this line after line 149, and remove it from inside the loop.)

Prompt To Fix With AI
This is a comment left during a code review.
Path: services/stripe-mock/src/stripe_mock/data/scenarios.py
Line: 288

Comment:
**`charge_metadata` computed inside loop**

Unlike `customer_metadata` and `subscription_metadata` (which are built once before the loop on lines 148–149), `charge_metadata` is recomputed on every monthly iteration even though neither `self.cfg.charge_metadata` nor `persona_metadata` changes during the loop. For consistency, hoist it alongside the other two metadata variables before the loop starts:

```suggestion
            charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})}
```

(Add this line after line 149, and remove it from inside the loop.)

How can I resolve this? If you propose a fix, please make it concise.

charge = make_charge(
ch_idx,
invoice_date,
amount=invoice_amount,
currency=currency,
customer_id=customer["id"],
invoice_id=invoice["id"],
metadata=charge_metadata,
)
self.charges.append(charge)

Expand Down
5 changes: 4 additions & 1 deletion services/stripe-mock/stripe-mock.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading