Integrate with an AI assistant

Paste one of the prompts below into Claude, ChatGPT, Cursor, Copilot or any coding agent and it will write the integration for you. Each prompt is self-contained: it carries the API contract, so the assistant does not have to guess.

Two rules before you start.

  • Never paste a real API key into a prompt. The prompts below tell the assistant to read USDTPAY_API_KEY and USDTPAY_WEBHOOK_SECRET from the environment, which is where they belong. A key pasted into a chat should be rotated.
  • Read the diff before you ship it. An assistant that marks orders paid on the redirect instead of the webhook has written a free-money bug; the prompts say so explicitly, but check.

Machine-readable summary for agents that can fetch a URL: https://usdtpay.ge/llms.txt — point your assistant at it with "read https://usdtpay.ge/llms.txt and integrate it".

1. The context prompt

Give this to the assistant first, in any project. Everything after it can be one sentence ("now add it to my checkout").

You are integrating USDTPay (https://usdtpay.ge), a non-custodial USDT payment gateway on the TRON network (TRC-20). Use only this contract; do not invent endpoints or fields.

BASE URL: https://api.usdtpay.ge
AUTH: header `Authorization: Bearer <USDTPAY_API_KEY>` — a secret key that looks like sk_live_… (mainnet) or sk_test_… (TRON Nile testnet). Read it from the environment, never hard-code it.

CREATE AN INVOICE
POST /api/v1/invoices
Headers: Authorization, Content-Type: application/json, Idempotency-Key: <stable id per order, e.g. order-123>
Body: {
  "amount": "19.99",            // decimal STRING, never a float
  "currency": "USD",            // USD | EUR | GEL
  "asset": "USDT",              // optional, default USDT
  "network": "TRON",            // optional, default TRON
  "external_id": "ORDER-123",   // your order id; unique per merchant
  "description": "Pro plan",
  "customer": { "email": "buyer@example.com", "external_id": "42" },
  "expires_in": 1800,           // seconds, 300–86400
  "success_url": "https://yourapp.com/thanks",
  "cancel_url": "https://yourapp.com/cart",
  "metadata": { "order_id": "123" }   // returned unchanged in webhooks
}
201 response: {
  "id": "inv_01j…", "status": "pending", "amount": "19.99", "currency": "USD",
  "crypto_amount": "19.99", "asset": "USDT", "network": "TRON",
  "payment_address": "T…", "checkout_url": "https://usdtpay.ge/i/inv_01j…",
  "expires_at": "…", "created_at": "…"
}
Redirect the customer to checkout_url. Store id and external_id against the order.

OTHER ENDPOINTS
GET  /api/v1/invoices/{id}        one invoice
GET  /api/v1/invoices             list; filters: status, external_id, created_from, created_to, per_page
POST /api/v1/invoices/{id}/cancel cancel while pending
GET  /api/v1/payments             list; GET /api/v1/payments/{id} one payment
GET  /api/v1/me                   verify the key works

WEBHOOKS (the only source of truth for "paid")
POST from USDTPay to your URL. Headers:
  X-Payment-Signature: v1=<hex hmac>
  X-Payment-Timestamp: <unix seconds>
  X-Payment-Event: <event type>
  X-Payment-Event-Id: evt_…
Verify: hex_hmac_sha256(secret = USDTPAY_WEBHOOK_SECRET, message = timestamp + "." + RAW_REQUEST_BODY)
Compare in constant time. Reject if |now - timestamp| > 300 seconds (replay protection).
Body: {
  "id": "evt_01j…", "type": "payment.paid", "created_at": "…", "environment": "live",
  "data": { "invoice_id": "inv_…", "external_id": "ORDER-123", "status": "paid",
            "amount": "19.99", "currency": "USD", "crypto_amount": "19.99",
            "received_amount": "19.99", "asset": "USDT", "network": "TRON",
            "payment_id": "pay_…", "transaction_hash": "…", "metadata": {…} } }
Event types: invoice.created, invoice.expired, invoice.cancelled, payment.detected,
payment.confirming, payment.confirmed, payment.paid, payment.underpaid,
payment.overpaid, payment.failed.

RULES YOU MUST FOLLOW
1. Fulfil the order ONLY on "payment.paid" (and "payment.overpaid" if you accept extra). Never on the redirect back from checkout, and never on payment.detected/confirming — those are not final.
2. Delivery is at-least-once: de-duplicate on the event id ("id", evt_…). Processing the same event twice must be harmless.
3. Respond 2xx within 10 seconds or it is retried (1m, 5m, 15m, 1h, 6h, 24h). Do slow work asynchronously.
4. Use the RAW request body for the signature — parse the JSON only after verifying.
5. Money is decimal strings. Never parse amounts into floats; use decimal/integer types.
6. payment.underpaid and payment.overpaid mean the amount did not match: record them, alert an operator, do not fulfil automatically.
7. Errors come back as {"error":{"code","message","request_id"}} with codes like invalid_api_key, validation_error, invoice_not_found, rate_limit_exceeded. Log request_id.

2. Task prompts

Append one of these after the context prompt.

Laravel / PHP

Add USDTPay checkout to this Laravel app:
1. config/services.php entry reading USDTPAY_BASE_URL, USDTPAY_API_KEY, USDTPAY_WEBHOOK_SECRET from env, plus .env.example lines.
2. App\Services\UsdtPayClient with createInvoice(Order $order): string returning checkout_url, using Http::withToken(...)->withHeaders(['Idempotency-Key' => 'order-'.$order->id]) and a 15s timeout. Log failures with the response's error.request_id; never log the key.
3. A controller action that calls it and redirects the customer.
4. POST route /webhooks/usdtpay excluded from CSRF: verify the signature against the raw body, reject bad ones with 400, then dispatch a queued job and return 200 immediately.
5. The job: find the order by data.external_id, ignore it if already paid (idempotent), mark paid on payment.paid, flag for review on payment.underpaid/overpaid.
6. A webhook_events table (event_id unique) so replays are dropped at the database level.
7. Feature tests with Http::fake() for creation, and signed/unsigned/replayed webhook requests. No real network calls in tests.

Node.js / Express

Add USDTPay checkout to this Express app:
1. lib/usdtpay.js — createInvoice({ amount, currency, externalId, customerEmail, successUrl, cancelUrl, metadata }) using fetch with the Authorization and Idempotency-Key headers; throw an error carrying error.code and error.request_id on non-2xx.
2. POST /checkout — creates the invoice and responds with { checkoutUrl }.
3. POST /webhooks/usdtpay mounted with express.raw({ type: 'application/json' }) so the raw body is available: verify the HMAC with crypto.timingSafeEqual, check the timestamp window, then respond 200 fast and handle the event after responding.
4. Idempotent handler keyed on the event id, stored in the database with a unique index.
5. Jest tests covering a valid signature, a tampered body, an expired timestamp and a duplicate event.
Use only built-in crypto — no extra dependencies.

Next.js (App Router)

Add USDTPay to this Next.js app:
1. app/api/checkout/route.ts — POST that creates an invoice server-side (never expose the key to the browser) and returns checkout_url.
2. app/api/webhooks/usdtpay/route.ts — POST reading the raw body with await req.text() BEFORE JSON.parse, verifying the HMAC with node:crypto, returning 400 on failure and 200 on success. Set export const runtime = 'nodejs'.
3. A client component with a "Pay with USDT" button that posts to /api/checkout and does window.location.assign(checkout_url).
4. Persist processed event ids to make retries harmless.

Python (FastAPI or Django)

Add USDTPay to this Python app:
1. usdtpay.py — create_invoice(...) with httpx (15s timeout), Authorization and Idempotency-Key headers; raise a typed error carrying code and request_id.
2. A checkout view returning a redirect to checkout_url.
3. A webhook endpoint that reads the RAW body, verifies hmac.compare_digest(hmac.new(secret, f"{ts}.".encode() + raw, "sha256").hexdigest(), sig), enforces a 300-second window, and returns 200 quickly.
4. Amounts as decimal.Decimal, never float.
5. A processed_webhooks table with a unique event id; handler is idempotent.
6. pytest tests with responses/respx — no live calls.

Telegram bot

Add USDT payments to this Telegram bot:
1. On /buy, create a USDTPay invoice with external_id "tg-<chat_id>-<order>" and metadata {"chat_id": <id>} and reply with an inline keyboard button linking to checkout_url.
2. A small HTTP endpoint for webhooks that verifies the HMAC as described, then on payment.paid reads data.metadata.chat_id, grants access and sends a confirmation message.
3. De-duplicate on the event id so a retry does not message the user twice or grant twice.

3. Verification prompt

After the assistant has written the code, ask it to check its own work:

Review the USDTPay integration you just wrote against this checklist and fix anything that fails:
1. Is the order fulfilled ONLY on payment.paid from a verified webhook — never on the browser redirect, never on payment.detected/confirming?
2. Is the signature computed over the RAW body (no re-serialisation) and compared in constant time?
3. Is a timestamp older than 300 seconds rejected?
4. Is the handler idempotent — does the same event id arriving twice change nothing the second time?
5. Does the endpoint answer within 10 seconds, moving slow work off the request?
6. Are amounts decimal strings/decimals end to end, with no float parsing?
7. Are underpaid/overpaid handled explicitly rather than treated as paid?
8. Are the API key and webhook secret read from the environment, absent from logs, and missing from the repository?
9. Do the tests cover: valid webhook, wrong signature, stale timestamp, duplicate event, invoice creation failure?
Show me the diff for anything you change.

4. Test it before going live

Ask your assistant to send a fake webhook to your own endpoint — this signs a payload exactly like USDTPay does, so you can check the handler without waiting for a real payment:

SECRET='whsec_your_endpoint_secret'
BODY='{"id":"evt_test_1","type":"payment.paid","created_at":"2026-01-01T12:00:00+00:00","environment":"test","data":{"invoice_id":"inv_test_1","external_id":"ORDER-123","status":"paid","amount":"19.99","currency":"USD","crypto_amount":"19.99","received_amount":"19.99","asset":"USDT","network":"TRON","payment_id":"pay_test_1","transaction_hash":"0000000000000000000000000000000000000000000000000000000000000001","metadata":{"order_id":"123"}}}'
TS=$(date +%s)
SIG=$(printf '%s.%s' "$TS" "$BODY" | openssl dgst -sha256 -hmac "$SECRET" -r | cut -d' ' -f1)
curl -i -X POST http://localhost:8000/webhooks/usdtpay \
  -H "Content-Type: application/json" \
  -H "X-Payment-Timestamp: $TS" \
  -H "X-Payment-Event: payment.paid" \
  -H "X-Payment-Event-Id: evt_test_1" \
  -H "X-Payment-Signature: v1=$SIG" \
  --data "$BODY"

Expect 200. Then flip one character of the signature and expect 400 — if a tampered request is accepted, stop and fix it before taking real money.

For a real end-to-end run, use a sk_test_ key and a TEST webhook endpoint: invoices go to the TRON Nile testnet, so no real funds move. See Testnet.