AUTO UPI PAYMENT GATEWAY - AI INTEGRATION GUIDE (A to Z) Website: https://pg.autoupi.in Docs: https://pg.autoupi.in/docs ===================================================================== INSTRUCTIONS FOR THE AI ASSISTANT --------------------------------- You are integrating the Auto Upi UPI payment gateway into the user's website. Before writing code, ask the user ONLY for these details (nothing else): 1. AUTOUPI_KEY - API key from Dashboard > API & Webhooks (starts with aupi_live_) 2. AUTOUPI_WEBHOOK_SECRET - webhook secret from the same page (starts with whsec_) 3. Backend language / framework (PHP, Laravel, WordPress, Node/Express, Next.js, Python/Django/Flask, etc.) 4. Public HTTPS webhook URL on their site (e.g. https://theirsite.com/autoupi-webhook) 5. Where the "Pay" button should go and how their orders/cart are stored. Then write the complete integration below for their stack. Follow every RULE. RULES (must follow) - Keep the API key and webhook secret ONLY on the server (environment variables). Never in browser JS. - Take the amount from the server-side cart/order, never from browser input. - Show the checkout as a POPUP on the merchant's own page using checkout.js. Do NOT redirect. - Fulfil an order ONLY after the signed webhook OR the order-status API says "paid". - Fulfil once (idempotent) - the webhook may arrive more than once. - Verify the webhook signature with a constant-time compare (hash_equals / timingSafeEqual). - Save order_id against the buyer/cart before opening the popup. PREREQUISITES (merchant does these in the dashboard) - Create an account at https://pg.autoupi.in/signup and log in. - UPI Accounts: save Paytm MID and UPI ID (required before API keys or orders work). - API & Webhooks: generate API key, copy webhook secret, optionally set a default webhook URL. BASICS - Base URL: https://pg.autoupi.in/api/public/v1 - Format: JSON (Content-Type: application/json) - Auth header: X-API-Key: - Order ID: always 15 chars: "ORD" + 12 random A-Z/0-9, unique - Order expiry: 5 minutes after creation. Expired orders can never become paid. - Payment is checked every 3 seconds. Paid only when order ID, exact amount, INR and merchant all match. ===================================================================== 1) CREATE ORDER POST https://pg.autoupi.in/api/public/v1/create-order --------------------------------------------------------------------- Body fields: amount number required INR, 1 to 100000, up to 2 decimals customer_name string optional max 80 chars webhook_url string optional public https:// URL (overrides default) link_type string optional "one_time" (default) curl: curl -X POST https://pg.autoupi.in/api/public/v1/create-order \ -H "X-API-Key: aupi_live_your_key" \ -H "Content-Type: application/json" \ -d '{"amount": 1499, "customer_name": "Rahul Sharma", "webhook_url": "https://yoursite.com/autoupi-webhook.php"}' PHP: true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ["Content-Type: application/json", "X-API-Key: " . getenv("AUTOUPI_KEY")], CURLOPT_POSTFIELDS => json_encode([ "amount" => 1499, "customer_name" => "Rahul Sharma", "webhook_url" => "https://yoursite.com/autoupi-webhook.php", ]), ]); $order = json_decode(curl_exec($ch), true); echo $order["payment_url"]; Node.js: const res = await fetch("https://pg.autoupi.in/api/public/v1/create-order", { method: "POST", headers: { "X-API-Key": process.env.AUTOUPI_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ amount: 1499, customer_name: "Rahul Sharma", webhook_url: "https://yoursite.com/autoupi-webhook", }), }); const order = await res.json(); console.log(order.payment_url); Python: import os, requests res = requests.post( "https://pg.autoupi.in/api/public/v1/create-order", headers={"X-API-Key": os.environ["AUTOUPI_KEY"]}, json={ "amount": 1499, "customer_name": "Rahul Sharma", "webhook_url": "https://yoursite.com/autoupi-webhook", }, timeout=20, ) order = res.json() print(order["payment_url"]) Response 200: { "ok": true, "order_id": "ORDK7Q2M9X4B1ZP", "customer_name": "Rahul Sharma", "amount": 1499, "payable_amount": 1499, "status": "active", "paid_at": null, "created_at": "2026-09-15T10:21:00.000Z", "expires_at": "2026-09-15T10:26:00.000Z", "payment_url": "https://pg.autoupi.in/pay/ORDK7Q2M9X4B1ZP" } ===================================================================== 2) ORDER STATUS GET https://pg.autoupi.in/api/public/v1/order-status?order_id=ORD... --------------------------------------------------------------------- curl "https://pg.autoupi.in/api/public/v1/order-status?order_id=ORDK7Q2M9X4B1ZP" \ -H "X-API-Key: aupi_live_your_key" PHP: true, CURLOPT_HTTPHEADER => ["X-API-Key: " . getenv("AUTOUPI_KEY")], ]); $res = json_decode(curl_exec($ch), true); if (($res["order"]["status"] ?? "") === "paid") { // fulfil once } Node.js: const res = await fetch( "https://pg.autoupi.in/api/public/v1/order-status?order_id=" + encodeURIComponent(orderId), { headers: { "X-API-Key": process.env.AUTOUPI_KEY } }, ); const { order } = await res.json(); if (order.status === "paid") { // fulfil once } Python: import os, requests res = requests.get( "https://pg.autoupi.in/api/public/v1/order-status", params={"order_id": order_id}, headers={"X-API-Key": os.environ["AUTOUPI_KEY"]}, timeout=20, ) if res.json()["order"]["status"] == "paid": pass # fulfil once Response 200: { "ok": true, "order": { "order_id": "ORDK7Q2M9X4B1ZP", "customer_name": "Rahul Sharma", "amount": 1499, "payable_amount": 1499, "status": "paid", "paid_at": "2026-09-15T10:21:44.120Z", "created_at": "2026-09-15T10:21:00.000Z", "expires_at": "2026-09-15T10:26:00.000Z" } } Status values: active - waiting for payment (within 5 minutes) paid - confirmed; safe to fulfil expired - not paid in time (or failed); create a new order ===================================================================== 3) POPUP CHECKOUT (frontend) --------------------------------------------------------------------- Load https://pg.autoupi.in/checkout.js once, then call AutoUpi.open({ url, onSuccess, onFailure }). - url must be the payment_url returned by create-order. - onSuccess({ order_id, status: "paid" }) - onFailure({ order_id, status: "failed" | "cancelled" }) (cancelled = customer pressed Back -> Yes) - AutoUpi.close() closes the popup programmatically. Popup size (set by the script, do not override): - Desktop: up to 860px wide x 520px high (max 94% width, 80% height), centered - Mobile (<=640px): 94% of width x 80% of visible height - 3px blue border, rounded 18px corners, dimmed blurred backdrop, no close X (Back asks to confirm) The popup callback only updates the screen - always confirm on the server. If the site uses CSP, allow https://pg.autoupi.in in script-src and frame-src.

Server endpoint that creates the order for the popup (PHP example): true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ["Content-Type: application/json", "X-API-Key: " . getenv("AUTOUPI_KEY")], // Example price only: use your server's saved cart amount in production. CURLOPT_POSTFIELDS => json_encode(["amount" => 100, "webhook_url" => "https://yoursite.com/autoupi-webhook.php"]), ]); // For complete order saving and error handling, see checkout.php below. header("Content-Type: application/json"); echo curl_exec($ch); ===================================================================== 4) WEBHOOKS --------------------------------------------------------------------- Sent once when an order becomes paid (event "payment.paid"), only to public https URLs. Header: X-AutoUpi-Signature: t=,v1= v1 = HMAC_SHA256(webhook_secret, t + "." + raw_request_body) POST https://yoursite.com/autoupi-webhook.php X-AutoUpi-Signature: t=1789453200,v1=6f3c…9ab { "event": "payment.paid", "order_id": "ORDK7Q2M9X4B1ZP", "amount": 1499, "payable_amount": 1499, "status": "paid", "customer_name": "Rahul Sharma", "paid_at": "2026-09-15T10:21:44.120Z" } signed_payload = "{t}." + raw_request_body v1 = hex(hmac_sha256(webhook_secret, signed_payload)) PHP: { const raw = req.body.toString("utf8"); const parts = Object.fromEntries( String(req.get("X-AutoUpi-Signature") || "").split(",").map((p) => p.split("=")), ); const expected = crypto .createHmac("sha256", process.env.AUTOUPI_WEBHOOK_SECRET) .update(parts.t + "." + raw) .digest("hex"); const ok = parts.v1 && expected.length === parts.v1.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1)); if (!ok) return res.status(401).send("bad signature"); const event = JSON.parse(raw); if (event.event === "payment.paid") { // idempotent: skip if this order_id is already fulfilled markOrderPaid(event.order_id, event.amount); } res.send("ok"); }); Respond 200 quickly. Keep the handler idempotent. Also use order-status as a fallback. ===================================================================== 5) READY-MADE PHP (3 files) --------------------------------------------------------------------- --- autoupi.php --- key = $key; $this->base = $base; } private function request(string $url, ?array $body = null): array { $ch = curl_init($url); $headers = ["X-API-Key: {$this->key}"]; if ($body !== null) { $headers[] = "Content-Type: application/json"; curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); } curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_TIMEOUT => 20]); $res = json_decode(curl_exec($ch), true); curl_close($ch); return is_array($res) ? $res : ["ok" => false, "error" => "network_error"]; } public function createOrder(float $amount, string $customer = "", string $webhook = ""): array { $body = ["amount" => $amount]; if ($customer !== "") $body["customer_name"] = $customer; if ($webhook !== "") $body["webhook_url"] = $webhook; return $this->request($this->base . "/create-order", $body); } public function status(string $orderId): array { return $this->request($this->base . "/order-status?order_id=" . urlencode($orderId)); } public static function verify(string $raw, string $header, string $secret): bool { parse_str(str_replace(",", "&", $header), $p); if (empty($p["t"]) || empty($p["v1"])) return false; return hash_equals(hash_hmac("sha256", $p["t"] . "." . $raw, $secret), $p["v1"]); } } --- checkout.php --- createOrder(1499, "Rahul Sharma", "https://yoursite.com/autoupi-webhook.php"); if (empty($order["ok"])) { http_response_code(400); header("Content-Type: application/json"); echo json_encode(["ok" => false, "error" => "Could not start payment"]); exit; } // store it so the webhook can find the buyer later save_order($order["order_id"], $_SESSION["user_id"], $order["amount"]); // save_order is your application's function, not an SDK method. header("Content-Type: application/json"); echo json_encode(["ok" => true, "order_id" => $order["order_id"], "payment_url" => $order["payment_url"]]); exit; --- autoupi-webhook.php --- Yes on desktop + mobile