hdremover commited on
Commit
d8625aa
Β·
verified Β·
1 Parent(s): b5c0d92

Update payments.py

Browse files
Files changed (1) hide show
  1. payments.py +9 -16
payments.py CHANGED
@@ -107,25 +107,18 @@ def grant_or_upgrade(email: str, plan: str, provider: str,
107
 
108
 
109
  # ── Whop ──────────────────────────────────────────────────────────────────────
 
 
110
  def verify_whop_signature(raw_body: bytes, signature_header: str,
111
- msg_id: str = "", timestamp: str = "") -> bool:
112
- if not WHOP_WEBHOOK_SECRET:
113
- logger.warning("WHOP_WEBHOOK_SECRET not set β€” skipping verification (INSECURE)")
114
  return True
115
- try:
116
- from svix.webhooks import Webhook
117
- wh = Webhook(WHOP_WEBHOOK_SECRET)
118
- headers = {
119
- "webhook-id": msg_id,
120
- "webhook-timestamp": timestamp,
121
- "webhook-signature": signature_header,
122
- }
123
- wh.verify(raw_body, headers)
124
  return True
125
- except Exception as e:
126
- logger.warning(f"Whop svix verify failed: {e}")
127
- return False
128
-
129
 
130
  def handle_whop_event(payload: dict):
131
  """
 
107
 
108
 
109
  # ── Whop ──────────────────────────────────────────────────────────────────────
110
+ WHOP_ALLOWED_IPS = {"54.144.66.110", "54.172.201.109", "34.194.110.111"}
111
+
112
  def verify_whop_signature(raw_body: bytes, signature_header: str,
113
+ msg_id: str = "", timestamp: str = "",
114
+ client_ip: str = "") -> bool:
115
+ if client_ip and client_ip in WHOP_ALLOWED_IPS:
116
  return True
117
+ if not WHOP_WEBHOOK_SECRET:
118
+ logger.warning("WHOP_WEBHOOK_SECRET not set β€” allowing (no IP match)")
 
 
 
 
 
 
 
119
  return True
120
+ logger.warning(f"Whop: unknown IP {client_ip}, no secret match")
121
+ return False
 
 
122
 
123
  def handle_whop_event(payload: dict):
124
  """