Check if user has an existing active subscription based on app_metadata. The presence of stripe_subscription_id or apple_original_transaction_id indicates an ACTIVE subscription. These fields are cleared when subscription ends. Args: app_metadata: User's app_metadata dict
(app_metadata: dict)
| 361 | |
| 362 | |
| 363 | def check_existing_subscription(app_metadata: dict) -> tuple[bool, str | None, str | None]: |
| 364 | """ |
| 365 | Check if user has an existing active subscription based on app_metadata. |
| 366 | |
| 367 | The presence of stripe_subscription_id or apple_original_transaction_id |
| 368 | indicates an ACTIVE subscription. These fields are cleared when subscription ends. |
| 369 | |
| 370 | Args: |
| 371 | app_metadata: User's app_metadata dict (from JWT or Auth0) |
| 372 | |
| 373 | Returns: |
| 374 | (has_subscription, subscription_id, provider) |
| 375 | - has_subscription: True if active subscription exists |
| 376 | - subscription_id: The subscription/transaction ID |
| 377 | - provider: "apple" or "stripe" or None |
| 378 | """ |
| 379 | if not app_metadata or not isinstance(app_metadata, dict): |
| 380 | return False, None, None |
| 381 | |
| 382 | # Check Apple first (arbitrary order, doesn't matter since user can only have one) |
| 383 | apple_id = app_metadata.get('apple_original_transaction_id') |
| 384 | if apple_id: |
| 385 | return True, apple_id, "apple" |
| 386 | |
| 387 | # Check Stripe |
| 388 | stripe_id = app_metadata.get('stripe_subscription_id') |
| 389 | if stripe_id: |
| 390 | return True, stripe_id, "stripe" |
| 391 | |
| 392 | return False, None, None |
no outgoing calls
no test coverage detected