HappyWan

Operations & Billing · 6 min read · Verified 2026-12-02

Credits, Billing SKUs & NOWPayments Webhook Architecture

How HappyWan Video calculates per-second credits, settles global crypto orders via NOWPayments HMAC-SHA512 IPN webhooks, handles underpayment tolerance, and enforces idempotent ledger refunds.

Exact Billing SKUs & Credit Accounting

Credits are integer units deducted atomically inside SQLite transactions (`BEGIN IMMEDIATE`) and recorded in `credit_ledger`. All listed USD prices are all-in (including payment processing and instant credit delivery, with zero hidden surcharges). All live credit packs and subscription tiers below map 1:1 to `POST /api/billing/checkout`.

SKU IDTypePrice (USD)Credits GrantedEffective Rate
`payg_spark`One-time (never expires)$19.001,000$0.0190 / cr
`payg_showrunner`One-time (never expires)$59.003,500$0.0169 / cr
`sub_filmmaker_monthly`Monthly subscription$35.00 / mo2,100 / mo$0.0167 / cr
`sub_filmmaker_annual`Annual subscription (upfront)$372.00 / yr ($31/mo)25,200 upfront$0.0148 / cr
`sub_studiopro_monthly`Monthly subscription$89.00 / mo5,600 / mo$0.0159 / cr
`sub_studiopro_annual`Annual subscription (upfront)$984.00 / yr ($82/mo)67,200 upfront$0.0146 / cr
`sub_enterprise_monthly`Monthly subscription$219.00 / mo14,400 / mo$0.0152 / cr
`sub_enterprise_annual`Annual subscription (upfront)$2,460.00 / yr ($205/mo)172,800 upfront$0.0142 / cr

NOWPayments Crypto Checkout & IPN Verification

HappyWan Video integrates NOWPayments hosted crypto invoices for borderless settlement in USDT, USDC, BTC, ETH, and 100+ digital currencies. When checkout initiates, HappyWan creates a `pending` row in `billing_orders` and registers `/api/billing/webhooks/nowpayments` as the `ipn_callback_url`.

Upon receiving an IPN callback, the webhook handler canonicalizes the raw JSON body with recursively sorted object keys (preserving exact floating-point tokens), computes an `HMAC-SHA512` digest against `NOWPAYMENTS_IPN_SECRET`, and validates the `x-nowpayments-sig` header in constant time (`crypto.timingSafeEqual`).

  • Intermediate statuses (`waiting`, `confirming`, `confirmed`, `sending`) update tracking metadata without crediting prematurely.
  • Terminal settlement occurs on `finished`, or on `partially_paid` when `actually_paid >= 99%` of `pay_amount` (protecting buyers from minor exchange withdrawal dust).
  • Strict currency (`usd`), exact cent amount, and invoice ID cross-checks block tampered callbacks before `settlePaidOrder()` executes idempotently.
  • Duplicate webhook deliveries are safely absorbed via `status != 'paid'` conditional updates so credits are never double-minted.

Automatic Render Failure Refunds

When `GET /api/jobs/{id}` detects an upstream `failed`, `cancelled`, `expired`, or moderation-filtered empty output, HappyWan automatically appends a compensating positive credit delta referencing the job ID. Engineering teams can audit every debit and refund cleanly in `/studio/billing`.

Python — Safe Idempotent Job Wrapperpython
import os, time, uuid, requests

API_KEY = os.environ["HAPPYWAN_API_KEY"]
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
    "Idempotency-Key": f"render-{uuid.uuid4()}",
}

payload = {
    "engine": "wan-3.0-pro",
    "mode": "text-to-video",
    "prompt": "Slow drone push over misty emerald terraced tea fields at sunrise, golden light breaking through low clouds, soft wind.",
    "duration": 10,
    "resolution": "2k",
    "aspectRatio": "16:9",
    "generateAudio": True,
    "enablePromptExpansion": False,
}

res = requests.post("https://happywanvideo.ai/api/jobs", headers=HEADERS, json=payload, timeout=30)
res.raise_for_status()
job_id = res.json()["job"]["id"]

while True:
    time.sleep(5)
    poll = requests.get(f"https://happywanvideo.ai/api/jobs/{job_id}", headers={"Authorization": f"Bearer {API_KEY}"}, timeout=20).json()["job"]
    if poll["status"] == "completed":
        print("Output MP4:", poll["outputUrl"])
        break
    if poll["status"] in ("failed", "refunded"):
        raise RuntimeError(f"Auto-refunded failure: {poll.get('errorMessage')}")
Webhooks & Billing — HappyWan API Docs