Hangarx

Webhooks

Billing Webhooks

POST/api/webhooks/billing

Handles subscription lifecycle events. Signature verified with webhook secret.

payment.succeeded

Extend subscription period

subscription.updated

Handle plan changes

subscription.cancelled

Downgrade to free tier

payment.failed

Notify user, start grace period

Huggingface Webhooks

POST/api/webhooks/huggingface

Monitors model deployment status and inference endpoint health.

model.deployed

Enable model for inference

endpoint.health_check

Update availability status

Webhook Security

// Signature verification example
import crypto from 'crypto';

export async function POST(req: Request) {
  const body = await req.text();
  const signature = req.headers.get('x-webhook-signature');
  
  // Verify HMAC signature
  const expectedSig = crypto
    .createHmac('sha256', process.env.WEBHOOK_SECRET)
    .update(body)
    .digest('hex');
  
  if (signature !== expectedSig) {
    return new Response('Invalid signature', { status: 401 });
  }
  
  const event = JSON.parse(body);
  // Handle event...
}