diff --git a/web/src/padelnomics/billing/stripe.py b/web/src/padelnomics/billing/stripe.py index 8320880..aa86f25 100644 --- a/web/src/padelnomics/billing/stripe.py +++ b/web/src/padelnomics/billing/stripe.py @@ -21,9 +21,6 @@ from ..core import config logger = logging.getLogger(__name__) -# Timeout for all Stripe API calls (seconds) -_STRIPE_TIMEOUT_SECONDS = 10 - def _stripe_client(): """Configure and return the stripe module with our API key.""" @@ -49,7 +46,8 @@ def build_checkout_payload( cancel_url=success_url.rsplit("/success", 1)[0] + "/pricing", automatic_tax={"enabled": True}, tax_id_collection={"enabled": True}, - request_options={"timeout": _STRIPE_TIMEOUT_SECONDS}, + + ) return {"checkout_url": session.url} @@ -78,7 +76,8 @@ def build_multi_item_checkout_payload( cancel_url=success_url.rsplit("/success", 1)[0], automatic_tax={"enabled": True}, tax_id_collection={"enabled": True}, - request_options={"timeout": _STRIPE_TIMEOUT_SECONDS}, + + ) return {"checkout_url": session.url} @@ -108,7 +107,8 @@ def cancel_subscription(provider_subscription_id: str) -> None: s.Subscription.modify( provider_subscription_id, cancel_at_period_end=True, - request_options={"timeout": _STRIPE_TIMEOUT_SECONDS}, + + ) @@ -119,12 +119,14 @@ def get_management_url(provider_subscription_id: str) -> str: # Get customer_id from the subscription sub = s.Subscription.retrieve( provider_subscription_id, - request_options={"timeout": _STRIPE_TIMEOUT_SECONDS}, + + ) portal = s.billing_portal.Session.create( customer=sub.customer, return_url=f"{config.BASE_URL}/billing/success", - request_options={"timeout": _STRIPE_TIMEOUT_SECONDS}, + + ) return portal.url @@ -180,7 +182,8 @@ def parse_webhook(payload: bytes) -> dict: s = _stripe_client() sub = s.Subscription.retrieve( subscription_id, - request_options={"timeout": _STRIPE_TIMEOUT_SECONDS}, + + ) period_end = _unix_to_iso(sub.current_period_end) except Exception: diff --git a/web/src/padelnomics/scripts/setup_stripe.py b/web/src/padelnomics/scripts/setup_stripe.py index d89609a..38fadea 100644 --- a/web/src/padelnomics/scripts/setup_stripe.py +++ b/web/src/padelnomics/scripts/setup_stripe.py @@ -197,10 +197,16 @@ def create(conn): logger.info("Creating webhook endpoint...") logger.info(" URL: %s", webhook_url) - endpoint = stripe.WebhookEndpoint.create( - url=webhook_url, - enabled_events=enabled_events, - ) + try: + endpoint = stripe.WebhookEndpoint.create( + url=webhook_url, + enabled_events=enabled_events, + ) + except stripe.InvalidRequestError as exc: + logger.warning(" Webhook endpoint creation failed: %s", exc.user_message) + logger.info(" For local dev, use Stripe CLI: stripe listen --forward-to %s", webhook_url) + logger.info("Done (products created, webhook skipped).") + return webhook_secret = endpoint.secret logger.info(" ID: %s", endpoint.id)