fix(billing): extract current_period_end from Stripe subscription items

Stripe API 2026-02+ moved current_period_end from subscription to
subscription items. Add _get_period_end() helper that falls back to
items[0].current_period_end when the subscription-level field is None.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-03-03 18:05:55 +01:00
parent 72c4de91b0
commit 7da6a4737d
2 changed files with 33 additions and 4 deletions

View File

@@ -393,6 +393,18 @@ class TestStripeParseWebhook:
ev = stripe_parse_webhook(payload)
assert ev["event_type"] == ""
def test_period_end_from_items_fallback(self):
"""Stripe API 2026-02+ puts current_period_end on items, not subscription."""
payload = _stripe_event(
"customer.subscription.created",
{"id": "sub_123", "customer": "cus_456", "status": "active",
"items": {"data": [{"price": {"id": "price_abc"}, "current_period_end": 1740000000}]}},
metadata={"user_id": "42"},
)
ev = stripe_parse_webhook(payload)
assert ev["current_period_end"] is not None
assert "2025-02-19" in ev["current_period_end"]
def test_trialing_status_maps_to_on_trial(self):
payload = _stripe_event(
"customer.subscription.created",