Skip to content

Commit 8d5b4d3

Browse files
Sai Sridhar Tarraclaude
authored andcommitted
Fix: handle subscription.charged, subscription.halted, invoice.paid, invoice.expired webhooks
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6c58fe1 commit 8d5b4d3

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

backend/services/razorpay_service.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,23 @@ async def handle_webhook(payload: bytes, sig_header: str) -> dict:
114114
await _handle_subscription_activated(
115115
event["payload"]["subscription"]["entity"]
116116
)
117-
elif event_type in ("subscription.cancelled", "subscription.expired", "subscription.completed"):
117+
elif event_type == "subscription.charged":
118+
# Recurring payment succeeded — keep plan active
119+
sub = event["payload"]["subscription"]["entity"]
120+
logger.info("Subscription charged (renewed): %s", sub.get("id"))
121+
elif event_type in (
122+
"subscription.cancelled",
123+
"subscription.expired",
124+
"subscription.completed",
125+
"subscription.halted",
126+
):
118127
await _handle_subscription_deactivated(
119128
event["payload"]["subscription"]["entity"]
120129
)
130+
elif event_type == "invoice.paid":
131+
logger.info("Invoice paid: %s", event["payload"].get("invoice", {}).get("entity", {}).get("id"))
132+
elif event_type == "invoice.expired":
133+
logger.warning("Invoice expired: %s", event["payload"].get("invoice", {}).get("entity", {}).get("id"))
121134
elif event_type == "payment.failed":
122135
logger.warning("Razorpay payment failed: %s", event.get("payload"))
123136

0 commit comments

Comments
 (0)