# UPIGateway.dev — One-Shot AI Integration Prompt # Copy and paste this prompt into ChatGPT, Claude, Cursor, Windsurf, or Antigravity # when building UPI payment checkout and webhook fulfillment with UPIGateway.dev. You are integrating UPIGateway.dev (https://upigateway.dev), a non-custodial zero-fee UPI payment automation API with instant direct-to-bank settlement in India. Follow these exact API endpoints, security constraints, and integration rules strictly: ## 1. Environment & Secret Rules - Store the merchant token ONLY on the server in `process.env.UPIGATEWAY_USER_TOKEN` (or `os.environ["UPIGATEWAY_USER_TOKEN"]` / `getenv("UPIGATEWAY_USER_TOKEN")`). - NEVER expose `user_token` in frontend JavaScript, React client bundles (`VITE_*`, `NEXT_PUBLIC_*`), mobile apps, or Git commits. - Derive product/subscription `amount` strictly on your server from your database or pricing map. NEVER trust an order price sent from the browser. ## 2. Exact Endpoints (Base Host: https://upigateway.dev/api) ### A. Create Payment Session (`POST https://upigateway.dev/api/create-order`) Headers: `Content-Type: application/json` JSON Body: ```json { "user_token": "", "amount": "499", "order_id": "ORD_UNIQUE_ID", "customer_mobile": "9876543210", "redirect_url": "https://yourdomain.com/payment-return?order_id=ORD_UNIQUE_ID", "remark1": "Plan or Product Name", "remark2": "Internal User or Invoice ID" } ``` Success Response (`HTTP 201`): ```json { "status": true, "message": "Order Created Successfully", "result": { "orderId": "ORD_UNIQUE_ID", "payment_url": "https://upigateway.dev/pay/", "paytm_link": "https://upigateway.dev/pay/", "bhim_link": "https://upigateway.dev/pay/" } } ``` ### B. Verify Order Status (`POST https://upigateway.dev/api/check-order-status`) Headers: `Content-Type: application/json` JSON Body: ```json { "user_token": "", "order_id": "ORD_UNIQUE_ID" } ``` Possible Responses (`HTTP 200`): - Paid: `status === true` AND `result.status === "SUCCESS"` AND `result.txnStatus === "COMPLETED"`, includes `result.utr` (12-digit UTR) and `result.amount`. - Pending: `status === true` AND `result.status === "PENDING"`. - Failed: `status === true` AND `result.status === "FAILURE"`. - Underpaid Tamper Alert: `status === false` AND `result.status === "FLAGGED_UNDERPAID"` — reject fulfillment immediately! ### C. Incoming Webhook (`POST` to your configured webhook endpoint) Payload sent by `UPIGateway-Webhook-Dispatcher/2.0`: ```json { "status": "SUCCESS", "order_id": "ORD_UNIQUE_ID", "customer_mobile": "9876543210", "amount": "499", "remark1": "Plan or Product Name", "remark2": "Internal User or Invoice ID", "utr": "433412345678", "date": "2026-11-30T08:15:00.000Z" } ``` ## 3. Checkout Presentation Rules (Choose One) 1. **Drop-In Modal SDK (Recommended UX)**: Load `` and invoke: `UPIGateway.open({ payment_url: data.payment_url, order_id: data.orderId, theme: "default", onSuccess, onFailure, onDismiss })` 2. **Hosted Checkout Redirect**: Redirect user browser to `result.payment_url`. - NEVER draw custom QR `` elements or raw `upi://pay` links manually in frontend UI; always route through `payment_url` or `sdk.js`. ## 4. Mandatory Idempotent Fulfillment Rules 1. Persist local order row as `PENDING` with expected `amount` BEFORE returning `payment_url` to the client. 2. When webhook arrives OR when user lands on `redirect_url`, DO NOT trust client query params. Call `POST https://upigateway.dev/api/check-order-status` from your backend. 3. Verify ALL four conditions atomically in a database transaction before unlocking goods/plans: - `result.status === "SUCCESS"` (and NOT `"FLAGGED_UNDERPAID"`) - `Number(result.amount) >= expectedOrderAmount` - Local order is still `"PENDING"` (prevent double crediting) - `result.utr` has never been recorded on any other fulfilled order (anti-replay) 4. Always return `HTTP 200 OK` from your webhook handler once processed cleanly. Now implement: 1. Backend order creation endpoint (`/api/payments/create`) 2. Backend webhook + status reconciliation endpoint (`/api/payments/webhook` and `/api/payments/verify`) 3. Frontend checkout button invoking `UPIGateway.open` (with hosted redirect fallback) and clean status polling view.