# USDTPay > Non-custodial USDT payment gateway on TRON (TRC-20). Merchants create an invoice > over a REST API, send the customer to a hosted checkout, and receive a signed > webhook when the payment is final on chain. Funds go directly to the merchant's > own TRON address; the platform never holds them. Docs: https://usdtpay.ge/docs Human-readable version of this file: https://usdtpay.ge/docs/ai-integration ## Authentication All merchant API requests: `Authorization: Bearer ` Keys look like sk_live_… (TRON mainnet) or sk_test_… (TRON Nile testnet). Read the key from the environment. Never hard-code it, never log it, never put it in a prompt. A key is shown once at creation and stored only as a hash. Base URL: https://api.usdtpay.ge ## Create an invoice POST /api/v1/invoices Headers: Authorization, Content-Type: application/json, Idempotency-Key: Body: amount string decimal, required, e.g. "19.99" (never a float) currency USD | EUR | GEL (default USD) asset USDT (default) network TRON (default) external_id your order id, unique per merchant description shown on checkout customer { email, external_id, name, metadata } expires_in seconds, 300-86400, default 1800 success_url, cancel_url webhook_url optional per-invoice target metadata object, returned unchanged in webhooks 201 returns: id (inv_…), status, amount, currency, crypto_amount, asset, network, payment_address, checkout_url, expires_at, created_at. Redirect the customer to checkout_url. Store id and external_id against the order. ## Other endpoints GET /api/v1/me verify the key GET /api/v1/invoices filters: status, external_id, created_from, created_to, per_page GET /api/v1/invoices/{id} POST /api/v1/invoices/{id}/cancel only while pending GET /api/v1/payments filters: status, invoice_id GET /api/v1/payments/{id} GET /api/v1/transactions/{id-or-hash} ## Webhooks — the only source of truth for "paid" Headers on every delivery: X-Payment-Signature: v1= X-Payment-Timestamp: X-Payment-Event: X-Payment-Event-Id: evt_… Verification: expected = hex hmac_sha256(key = USDTPAY_WEBHOOK_SECRET, message = timestamp + "." + RAW_BODY) compare in constant time; reject when |now - timestamp| > 300 seconds. Use the raw request body. Parse JSON only after verifying. Body: { "id": "evt_…", "type": "payment.paid", "created_at": "…", "environment": "live", "data": { "invoice_id", "external_id", "status", "amount", "currency", "crypto_amount", "received_amount", "asset", "network", "payment_address", "payment_id", "transaction_hash", "confirmations", "required_confirmations", "metadata" } } Types: invoice.created, invoice.expired, invoice.cancelled, payment.detected, payment.confirming, payment.confirmed, payment.paid, payment.underpaid, payment.overpaid, payment.failed. ## Integration rules 1. Fulfil the order only on payment.paid (and payment.overpaid if you accept extra). Never on the browser redirect. Never on payment.detected or payment.confirming. 2. Delivery is at-least-once. De-duplicate on the event id; reprocessing must be a no-op. 3. Answer 2xx within 10 seconds. Retries: 1m, 5m, 15m, 1h, 6h, 24h, then failed. 4. Amounts are decimal strings. Use decimal or integer types, never floats. 5. payment.underpaid / payment.overpaid mean the amount did not match: record, alert, do not fulfil automatically. 6. Test and live are fully isolated: a sk_test_ key sees only testnet invoices. ## Errors {"error": {"code": "...", "message": "...", "request_id": "req_…"}} Common codes: invalid_api_key, unauthorized, forbidden, merchant_inactive, validation_error, invalid_request, unsupported_asset, unsupported_network, no_payment_address, duplicate_external_id, idempotency_key_reused, invoice_not_found, invoice_not_cancellable, payment_not_found, rate_limit_exceeded, internal_error. Log request_id; quote it in support requests. ## Payment lifecycle invoice: pending -> detected -> confirming -> paid pending -> expired | cancelled detected/confirming -> underpaid | overpaid | failed A payment is confirmed after the network's required confirmations (19 on TRON) and once the block is solidified — roughly one minute after the transfer.