Docs

Webhooks

Receive real-time events when users purchase, install, or uninstall your app.

Event types

app.purchasedA user paid for your app. Revenue split processed immediately.
app.installedA user installed your free app.
app.uninstalledA user removed your app.
app.refundedA purchase was refunded. Revenue share reversed.

Payload structure

POST https://yourapp.com/webhooks/wynai
{
  "event": "app.purchased",
  "app_id": "your-app-id",
  "user_id": "firebase_uid_abc123",
  "purchase_id": "APP-1714380000-uid12345",
  "amount_vnd": 99000,
  "developer_share_vnd": 79200,
  "timestamp": "2026-04-30T10:00:00Z"
}

Signature verification

Every webhook request includes an X-WynAI-Signature header. Verify it using your client_secret:

webhook-handler.js (Node.js)
import crypto from 'crypto';

app.post('/webhooks/wynai', express.raw({ type: '*/*' }), (req, res) => {
  const signature = req.headers['x-wynai-signature'];
  const expected = crypto
    .createHmac('sha256', process.env.WYNAI_CLIENT_SECRET)
    .update(req.body)
    .digest('hex');

  if (signature !== `sha256=${expected}`) {
    return res.status(401).send('Invalid signature');
  }

  const event = JSON.parse(req.body);

  if (event.event === 'app.purchased') {
    // Unlock premium features for event.user_id
    await grantAccess(event.user_id, event.app_id);
  }

  res.sendStatus(200);
});
Always use express.raw() (not express.json()) so the raw body is preserved for HMAC verification. Parsing JSON first will corrupt the signature check.

Retry policy

If your endpoint returns a non-2xx status, WynAI retries up to 5 times with exponential backoff:

Attempt 2:+5s
Attempt 3:+30s
Attempt 4:+5min
Attempt 5:+30min
Attempt 6:+2h

After all retries fail, the event is marked failed. View failed webhooks in Webhook Logs.

Best practices

  • Respond with 200 immediately, process async.
  • Make your handler idempotent — the same event may arrive twice.
  • Store the purchase_id to deduplicate events.
  • Verify signature before doing anything with the payload.