summaryrefslogtreecommitdiff
path: root/Biz/PodcastItLater
diff options
context:
space:
mode:
Diffstat (limited to 'Biz/PodcastItLater')
-rw-r--r--Biz/PodcastItLater/Billing.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/Biz/PodcastItLater/Billing.py b/Biz/PodcastItLater/Billing.py
index c5cb749..9664b9f 100644
--- a/Biz/PodcastItLater/Billing.py
+++ b/Biz/PodcastItLater/Billing.py
@@ -371,20 +371,35 @@ def _update_subscription_state(subscription: dict[str, typing.Any]) -> None:
)
return
- # Get billing period - handle both dict and object access patterns
- period_start_ts = subscription.get("current_period_start")
+ # Get billing period - try multiple field names for API compatibility
+ period_start_ts = (
+ subscription.get("current_period_start")
+ or subscription.get("billing_cycle_anchor")
+ or subscription.get("start_date")
+ )
period_end_ts = subscription.get("current_period_end")
- if not period_start_ts or not period_end_ts:
+ if not period_start_ts:
logger.warning(
- "Missing period dates in subscription: %s. Available keys: %s",
+ "Missing period start in subscription: %s. Available keys: %s",
subscription_id,
list(subscription.keys()),
)
return
period_start = datetime.fromtimestamp(period_start_ts, tz=timezone.utc)
- period_end = datetime.fromtimestamp(period_end_ts, tz=timezone.utc)
+
+ # Calculate period end if not provided (assume monthly)
+ if not period_end_ts:
+ if period_start.month == 12: # noqa: PLR2004
+ period_end = period_start.replace(
+ year=period_start.year + 1,
+ month=1,
+ )
+ else:
+ period_end = period_start.replace(month=period_start.month + 1)
+ else:
+ period_end = datetime.fromtimestamp(period_end_ts, tz=timezone.utc)
# Determine tier from price ID
items = subscription.get("items", {})