Skip to content

A self-hosted UPI & COD payment gateway with zero per-transaction platform fees, universal JavaScript checkout integration, dynamic QR payments, WhatsApp OTP authentication, and automated payment verification.

JavaScript

docs: document new auth variables and the COD webhook rule

Abhi Pareeke685a5401bdb
diff --git a/AGENTS.md b/AGENTS.md
index cc3d64d..bc32506 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -159,6 +159,8 @@ The frontend script emits normalized DOM `CustomEvent`s on `window`:
}
```
+> **PAYMENT METHOD RULE**: `event: "SUCCESS"` is also sent when a customer places a **Cash on Delivery** order (`method: "COD"`) or a counter payment is confirmed (`CASH_COUNTER` / `CARD_COUNTER`). For `COD` no money has been received yet. Always check `payload.method` before you treat an order as **paid**: fulfil prepaid goods only when `method` is `UPI` (or a counter method your till has confirmed), and route `COD` orders into your cash-on-delivery flow.
+
### Polyglot Webhook Verification Implementations:
#### 1. Node.js (Express)
@@ -176,8 +178,8 @@ app.post('/api/webhook', express.raw({ type: 'application/json' }), (req, res) =
}
const payload = JSON.parse(req.body.toString('utf8'));
- if (payload.event === 'SUCCESS') {
- // Authoritatively mark order as PAID in merchant database
+ if (payload.event === 'SUCCESS' && payload.method === 'UPI') {
+ // Authoritatively mark order as PAID in merchant database (COD: payload.method === 'COD' means "order placed", not paid)
db.orders.markPaid(payload.orderId, {
utr: payload.utr,
amount: payload.amount,
@@ -207,8 +209,9 @@ async def youpi_webhook(request: Request):
raise HTTPException(status_code=401, detail="Invalid webhook signature")
payload = json.loads(raw_body.decode("utf-8"))
- if payload.get("event") == "SUCCESS":
+ if payload.get("event") == "SUCCESS" and payload.get("method") == "UPI":
# Authoritatively mark order as PAID: payload["orderId"], payload["utr"], payload["amount"]
+ # (method == "COD" means the order was placed and cash is due on delivery - not paid)
pass
return {"received": True}
```
@@ -228,8 +231,9 @@ if (!hash_equals($expected, $signature)) {
}
$payload = json_decode($rawPayload, true);
-if (($payload['event'] ?? '') === 'SUCCESS') {
+if (($payload['event'] ?? '') === 'SUCCESS' && ($payload['method'] ?? '') === 'UPI') {
// Authoritatively mark order as PAID: $payload['orderId'], $payload['utr'], $payload['amount']
+ // ($payload['method'] === 'COD' means the order was placed and cash is due on delivery - not paid)
}
http_response_code(200);
@@ -277,9 +281,11 @@ func youpiWebhookHandler(w http.ResponseWriter, r *http.Request) {
UTR string `json:"utr"`
Amount string `json:"amount"`
AmountPaise int64 `json:"amountPaise"`
+ Method string `json:"method"`
}
- if err := json.Unmarshal(rawBody, &payload); err == nil && payload.Event == "SUCCESS" {
+ if err := json.Unmarshal(rawBody, &payload); err == nil && payload.Event == "SUCCESS" && payload.Method == "UPI" {
// Authoritatively mark order as PAID: payload.OrderId, payload.UTR, payload.Amount
+ // (Method == "COD" means the order was placed and cash is due on delivery - not paid)
}
w.WriteHeader(http.StatusOK)
diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md
index b5b04d8..9f2a942 100644
--- a/docs/CONFIGURATION.md
+++ b/docs/CONFIGURATION.md
@@ -20,7 +20,13 @@
| `PAYMENT_ACTIVE_WINDOW_MS` | `300000` | Duration of active payment slot (5 minutes = 300,000ms) |
| `PAYMENT_PROCESSING_WINDOW_MS` | `30000` | Duration of verification slot (30 seconds = 30,000ms) |
| `LATE_OBSERVATION_WINDOW_MS` | `1800000` | Safety window for matching late observations (30 minutes) |
-| `ANDROID_ENROLLMENT_SECRET` | `32+ chars` | Ephemeral secret token used to authorize device QR pairing |
+| `ANDROID_ENROLLMENT_SECRET` | auto-generated | Secret used to authorize device QR pairing. If unset, a random value is created in `data/.secrets/android_enrollment_secret` |
+| `ADMIN_API_TOKEN` | auto-generated | Bearer token required by `/api/v1/admin/*` (the Merchant Admin page asks for it once per tab). If unset, a random value is created in `data/.secrets/admin_api_token` |
+| `OBSERVER_API_TOKEN` | auto-generated | Bearer token the local Gmail/SMS observers use to submit observations (`data/.secrets/observer_api_token`) |
+| `COIN_STORE_WEBHOOK_SECRET` | auto-generated | Webhook secret seeded for the default merchant and used by the demo coin store (`data/.secrets/coin_store_webhook_secret`) |
+| `YOUPI_EXPOSE_DEV_OTP` | unset | Set to `true` for local development to get the OTP in the `send-otp` response. Ignored when `NODE_ENV=production` |
+| `YOUPI_ALLOW_DEV_TOOLS` | unset | Developer test-mode / simulator endpoints (`/admin/dev/*`, `simulate-observation`) are refused when `NODE_ENV=production` unless this is `true` |
+| `GMAIL_REDIRECT_URI` | derived | Gmail OAuth redirect URI. Defaults to `<gmail host from your configured domain>/oauth/callback` |
| `ANDROID_HEARTBEAT_TIMEOUT_MS` | `180000` | Inactivity window before Android device is marked DISCONNECTED |
---