Open-source, self-hosted payment collection foundation powered by Cloudflare Workers and D1.
Important: PAYNEX currently creates payment links and UPI intents. A UPI intent, app redirect, screenshot, or client-side callback is not proof of payment. Transactions remain
pendinguntil an authorised provider integration verifies them. This repository is not a licensed payment gateway and does not process cards, settle funds, or issue refunds.
- GitHub: source control and deployment workflow
- Cloudflare Workers: API runtime
- Cloudflare D1: merchant, payment-link, transaction, audit and webhook metadata
- No paid plan or billing upgrade is required by this repository's configuration. Cloudflare/GitHub free-tier quotas and policies apply and can change.
Base URL: https://paynex-api.sbn50088.workers.dev
GET /health— service healthGET /api/pay/:linkId— public payment-link detailsPOST /api/pay/:linkId/initiate— create a pending transaction and return a UPI intent if the merchant has a UPI IDPOST /api/v1/payment-links— create a link (requiresx-api-keyor Bearer API key)GET /api/v1/transactions— list merchant transactions (requires API key)
Amounts are integer minor units (for INR, paise). Example: ₹125.00 is 12500.
The production D1 database paynex-db has been created and the schema applied. Schema source: worker/schema.sql.
- Install Node.js 22+.
- From
worker/, runnpm install. - Authenticate Wrangler with a Cloudflare API token that has Workers Scripts Edit and D1 access.
- Run
npx wrangler deploy. - To deploy from GitHub Actions, add repository secret
CLOUDFLARE_API_TOKENwith a narrowly scoped token. Never commit API tokens. - The workflow deploys when files under
worker/change onmain.
The Worker is already deployed in the connected Cloudflare account. GitHub Actions automation will remain inactive until the repository secret is configured.
The V2 merchant flow supports direct-to-merchant UPI intent/QR collection without PAYNEX custody. Under the merchant-only architecture, the merchant checks their own existing UPI/bank app and may submit an explicit attestation through the authenticated merchant API:
POST /api/v1/payment-attempts/{attempt_id}/confirm-direct-upi- Required attestation:
merchant_attests_received_credit: true, the merchant-visible reference, exact credited amount in minor units, currency and credit timestamp. - PAYNEX records
MERCHANT_CONFIRMEDin the separatemerchant_payment_confirmationstable with a unique merchant reference and one confirmation per payment attempt. - Direct UPI initiation remains gated to an active eligible business UPI profile with the existing ownership-verification control; this change does not bypass that eligibility gate or turn a personal UPI profile into an approved merchant collection account.
- This attestation does not set a transaction to
verified, change the order topaid, post a verified ledger entry, trigger fulfilment, or enqueuepayment.succeeded. BANK_VERIFIEDremains unavailable unless a trusted authorised bank/provider evidence source is configured. Customer screenshots, customer-entered UTRs, app redirects and client callbacks are not proof.- V2 statement-import endpoints are disabled. This restricted flow requires no screenshot/file upload, Account Aggregator, Acquirer/PSP API, notification listener or additional bank permission.
This is a merchant-attested operational record, not automatic bank verification. Merchants remain responsible for independently checking the credit and deciding whether to fulfil an order. Do not describe this mode as an automatic payment gateway or bank-confirmed checkout.
- API keys are stored as SHA-256 hashes, never plaintext.
- Do not expose merchant API keys in browser code.
- Restrict
CORS_ORIGINto your actual dashboard/payment origins before production. - Add rate limiting, abuse monitoring, merchant onboarding/KYC, signed webhook delivery, provider-side payment verification, reconciliation and incident procedures before handling real payments.
- Do not add a client endpoint that marks a payment as verified.
- Live payment processing requires an authorised bank/PSP/acquiring-provider relationship and applicable legal/regulatory approvals. Provider fees may apply even if PAYNEX itself charges no platform commission.
Merchant/API-key provisioning is not yet exposed as a public endpoint. No default merchant or API key is seeded. Do not use this as a production payment gateway yet.
A repository change after adding CLOUDFLARE_API_TOKEN triggers the GitHub Actions deployment workflow. Check the Actions tab for the latest Deploy PAYNEX API run and its logs.
The responsive merchant dashboard is served by the same Worker origin at /dashboard (and /). Static files are deployed from dashboard/ using the Workers static-assets binding. The dashboard calls the authenticated summary, transactions and analytics APIs on the same origin.
Open the dashboard URL and enter a merchant API key. The key is kept only in the active page's JavaScript memory, is not written to local/session storage or cookies, and is cleared when you disconnect or close/reload the tab. Do not use shared or untrusted devices. Never embed merchant keys in public source code.
The dashboard is an authenticated merchant interface, not a public payment checkout. Browser-based API-key access is intended for controlled merchant use; for a larger production deployment, prefer an identity-backed session/BFF architecture and stronger account-level access controls.
The merchant dashboard includes payment-link creation, listing, copy-link and disable controls. Creation accepts INR amounts entered in rupees and converts them to paise before calling the authenticated API. Displayed transaction and link amounts are formatted using the currency's minor-unit precision. Links can be disabled only by their owning authenticated merchant. The dashboard does not claim that creating a link processes or verifies a payment.
Merchant self-registration is intentionally not enabled yet: the current schema has merchant status fields but no email-verification, identity/KYC or approval workflow. Do not issue production merchant credentials through an unauthenticated public signup until those controls are implemented.
The merchant dashboard can list active API keys, create a new key, display the plaintext once, copy it, and revoke an existing key. Only SHA-256 hashes are stored in D1. Store generated keys in a password manager or server-side secret manager; never commit or embed them in browser applications. Revoking a key immediately stops authentication with that key.
Worker authentication now requires both a non-revoked API key and an active merchant record. Pending and suspended merchants cannot authenticate. Merchant provisioning remains an operator-controlled process using scripts/provision-merchant.mjs; it is not a public self-service signup. The generated SQL must be reviewed and applied by an authorised operator. Email verification, KYC and an audited approval workflow are still prerequisites before enabling public merchant registration.
Public self-service registration is intentionally not enabled. New merchant records must start in pending status and receive no API key.
- Create a pending application SQL statement locally:
node scripts/provision-merchant.mjs "Business name" "owner@example.com" "merchant@upi" - Review the application and independently verify business ownership, contact email, bank/UPI ownership and all applicable KYC/AML requirements using your approved process.
- An authorised operator records their identity and prepares a conditional approval:
PAYNEX_APPROVER="admin@example.com" node scripts/approve-merchant.mjs "<merchant-uuid>" - Review and apply the generated transaction SQL to the correct D1 database using an authorised operator account. The approval transaction activates only a pending merchant, creates a SHA-256-hashed API key, and writes a
merchant.approvedaudit event. - Verify the merchant status and API-key row in D1 before delivering the one-time plaintext key through an approved secret-delivery channel.
Both scripts only print SQL; neither connects to or mutates D1 automatically. Treat the one-time API key as a secret. If approval SQL does not change the pending row, no key is inserted; do not deliver the printed key unless D1 verification confirms successful activation and key creation. This is an operator workflow, not a substitute for a formal KYC provider, sanctions screening, legal review, or production compliance controls.
A separate restricted admin UI is available at /admin.html. It is protected by the Worker secret ADMIN_API_TOKEN, sent as x-admin-token only while the page remains open. The UI keeps the token in tab memory and clears it on disconnect; do not share the token or use the admin page on untrusted devices.
Configure a strong, randomly generated secret using an authorised Cloudflare account:
npx wrangler secret put ADMIN_API_TOKEN --config worker/wrangler.toml
The admin API is disabled with HTTP 503 until this secret exists. Admin endpoints support listing pending/active/suspended merchants, approving a pending merchant (which activates it and creates a one-time API key), suspending an active merchant, and reactivating a suspended merchant. Status transitions are conditional and recorded in merchant audit history. Deliver a newly issued key only through an approved secret-delivery channel and verify the merchant's KYC/business review before approval. The admin token is a shared bearer secret; production deployments should additionally restrict access through Cloudflare Access or an equivalent identity-aware gateway and rotate the token periodically.
The Worker exposes POST /api/providers/razorpay/webhook. Configure RAZORPAY_WEBHOOK_SECRET as a Cloudflare Worker secret and set the matching webhook secret in the Razorpay dashboard. Subscribe to the payment.captured event. PAYNEX verifies the HMAC-SHA256 signature over the exact raw request body using x-razorpay-signature, requires x-razorpay-event-id, and maps the payment using payment.entity.notes.paynex_transaction_id. It verifies amount (minor units) and currency against the pending PAYNEX transaction before changing its status to verified. Event IDs are stored in provider_events for idempotency, and only then is a merchant payment.succeeded webhook queued.
This is the signed inbound verification adapter only. It does not yet create Razorpay Orders/Checkout sessions or populate the transaction mapping notes; a trusted server-side order-creation flow must do that before real payments can use this callback. Do not expose Razorpay key secrets in the browser. Configure secrets with npx wrangler secret put RAZORPAY_WEBHOOK_SECRET --config worker/wrangler.toml. The deployment workflow does not apply D1 migrations. Apply the provider-events SQL manually with a Cloudflare token that has D1 Edit permission before enabling the Razorpay webhook. Use Razorpay test mode and test credentials first.
Stripe is not integrated yet. No provider credentials are committed to this repository.
The initial automatic migration attempt was blocked because the configured Cloudflare API token does not have permission to import/write to the D1 database (Cloudflare API error 10000). The Worker deploy workflow therefore does not run D1 migrations automatically. Before enabling RAZORPAY_WEBHOOK_SECRET, use a Cloudflare API token with D1 Edit permissions and run from worker/:
npx wrangler d1 execute paynex-db --remote --file=./migrations/0002_provider_events.sqlThen configure the Razorpay webhook secret. Until the migration and secret are configured, the Razorpay callback must not be treated as operational.
LocalProof backend and initial Android companion source are integrated into main and deployed to isolated staging. The Android app uses an Android Keystore P-256 signing key, encrypted API-key storage, explicit notification-listener consent and local-only parsing of allowlisted UPI app notifications. The Worker stores signed device observations as unverified reconciliation hints only. No notification can mark a transaction paid, post a verified ledger entry or trigger fulfilment. The CI debug-APK build and physical Android 16 device validation must pass before rollout. See docs/LOCALPROOF-STATUS.md for current release gates.