MCPcopy Create free account
hub / github.com/Roy3838/Observer / check_existing_subscription

Function check_existing_subscription

api/auth0_manager.py:392–427  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

390
391
392def check_existing_subscription(app_metadata: dict) -> tuple[bool, str | None, str | None]:
393 """
394 Check if user has an existing active subscription based on app_metadata.
395
396 The presence of stripe_subscription_id or apple_original_transaction_id
397 indicates an ACTIVE subscription. These fields are cleared when subscription ends.
398
399 Args:
400 app_metadata: User's app_metadata dict (from JWT or Auth0)
401
402 Returns:
403 (has_subscription, subscription_id, provider)
404 - has_subscription: True if active subscription exists
405 - subscription_id: The subscription/transaction ID
406 - provider: "apple" or "stripe" or None
407 """
408 if not app_metadata or not isinstance(app_metadata, dict):
409 return False, None, None
410
411 # Enterprise seat. Checked first because an org member is billed through the
412 # org's Stripe customer, never their own, so no personal ID will be present.
413 org_id = app_metadata.get('org_id')
414 if org_id:
415 return True, org_id, "org"
416
417 # Check Apple first (arbitrary order, doesn't matter since user can only have one)
418 apple_id = app_metadata.get('apple_original_transaction_id')
419 if apple_id:
420 return True, apple_id, "apple"
421
422 # Check Stripe
423 stripe_id = app_metadata.get('stripe_subscription_id')
424 if stripe_id:
425 return True, stripe_id, "stripe"
426
427 return False, None, None

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected