Testing
Test your integration in three stages: simulated payments, real transfers on the Nile testnet, then the edge cases your store has to survive. Do all of it on a testnet project before you take real money.
Level 1: simulated payments
No wallet needed. The gateway marks an invoice paid without a transfer and sends a real, signed invoice.paid webhook, so your whole webhook path runs.
Set up a testnet project with simulation on:
- Dashboard project: Admin, + New project, pick Nile testnet and tick Allow simulated payments. Use that project's API key and webhook secret.
- Single-store mode:
NETWORK=nileandALLOW_SIMULATION=truein.env.
Simulation is refused on mainnet, by design.
# Create an invoice
curl -s -X POST https://pay.example.com/api/v1/invoices \
-H "Authorization: Bearer $QIRSH_API_KEY" -H "Content-Type: application/json" \
-d '{"amount":"10","order_id":"TEST-1"}'
# Pay it (fires a signed invoice.paid webhook)
curl -s -X POST https://pay.example.com/api/v1/invoices/<inv_id>/simulate-payment \
-H "Authorization: Bearer $QIRSH_API_KEY"Or open the project's Invoices tab and press Simulate paid on a pending invoice.
The simulated invoice gets a tx_id starting with simtx_ and from_address T_SIMULATED_SENDER. In forwarder mode no funds arrive, so nothing is swept.
Level 2: real transfers on Nile
- Install TronLink and switch it to Nile Testnet.
- Get test TRX and test USDT from the Nile faucet: https://nileex.io/join/getJoinPage
- Create an invoice on a Nile project and open its
checkout_url. - Pay with Pay with TronLink, or send exactly
amount_duetopay_addressby hand.
What to expect:
- The checkout switches to Confirming within one poll (
POLL_INTERVAL_SECONDS, 10 s by default). Your store getsinvoice.confirming. - About a minute later the transfer is solidified. The checkout shows Payment received, your store gets
invoice.paid, and the shopper is sent tosuccess_url.
Nile USDT has its own contract (TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf). Testnet transfers never match mainnet invoices and the other way round.
The store checklist
Every store should pass these before going live.
| Scenario | How | Expected |
|---|---|---|
| Happy path | Pay the exact amount | Order paid once, from the webhook only |
| Duplicate webhook | Redeliver a delivered event with POST /api/v1/webhooks/:id/retry |
No second fulfilment |
| Forged webhook | curl -X POST <store webhook> -d '{"type":"invoice.paid"}' without a signature, or with a wrong one |
400, order unchanged |
| Stale signature | Replay a captured request more than 5 minutes later | 400 |
| Store down | Stop the store, pay, start it again | Webhook retried (10 s, 30 s, 2 min, 10 min...) and processed |
| Expiry | Create with "ttl_minutes": 5 and don't pay |
invoice.expired, order released |
| Wrong amount | On Nile, send the base amount without the unique digits | Invoice stays pending, the transfer is listed as unmatched in the dashboard |
| Manual settlement | Dashboard, Transfers, Assign... that transfer to the invoice | invoice.paid with settled_manually: true and the real amount_paid. The store holds an underpaid order for review |
| Arabic checkout | Open checkout_url?lang=ar, or create with "locale": "ar" |
Right-to-left page; amount and address stay left to right |
| Thank-you page without paying | Open success_url directly |
Order still shows unpaid |
| Retry checkout | Start checkout twice for one order | Same checkout_url (idempotent on order_id) |
| Price change | Change the order total while its invoice is open, then start checkout | 409 order_conflict; your store handles it |
Forwarder mode on Nile
Only if the project uses, or will use, forwarder mode. The operator needs a fee wallet with faucet TRX, a Nile factory and a Nile project switched to Address per invoice (see Operator guide). Use real Nile USDT: simulated payments settle the invoice but move nothing.
| Scenario | How | Expected |
|---|---|---|
| Round amount | Create {"amount":"10"} |
deposit_mode: "forwarder", amount_due: "10", pay_address is a new address, forwarder is filled in |
| Happy path | Send exactly 10 USDT to pay_address |
invoice.confirming, invoice.paid, later invoice.swept. The wallet receives 10 USDT |
| Fulfil on paid only | Watch the store while the sweep is pending | Fulfilled once at invoice.paid; invoice.swept changes nothing |
| Partial, then top-up | Send 4, then 6 | After 4: still pending, amount_received: "4", checkout asks for the remaining 6. After 6: paid, swept once |
| Partial at expiry | ttl_minutes: 5, send 4, wait |
invoice.expired with amount_received: "4". Accept asks for confirmation, then sends invoice.paid with settled_manually: true and amount_paid: "4". The store must not ship a 10 USDT order for it |
| Late payment | Let an invoice expire, then pay in full | Stays expired; settled only when someone presses Accept |
| Overpayment | Send 12 to a 10 invoice | paid with amount_paid: "12" |
| Customer pays the wallet | Send to the project wallet instead of pay_address |
Listed as unmatched; forwarder invoices never match by amount |
| Wrong asset | Send Nile TRX to a fresh deposit address | Not counted as payment; an admin can move it with Recover... |
| Recovery without the database | npm run admin -- recover-forwarder --network nile --factory T... --destination <wallet> --invoice <id>, plus --collector T... --fee <fee> for an invoice with a network fee |
Prints the same address as pay_address and its balance |
| Network fee, merchant pays | Operator sets FEE_COLLECTOR_ADDRESS_NILE and a project fee of 1.5 paid by the store. Create {"amount":"10"} and pay 10 |
amount_due: "10", network_fee.payer: "merchant", amount_net: "8.5". After the sweep the wallet has 8.5 more, the collector 1.5, sweep.fee_paid: "1.5". The store fulfils on amount_paid: "10" |
| Network fee, customer pays | Same fee, paid by the customer. Create {"amount":"10"} |
amount_due: "11.5" and a fee line on the checkout. Pay 11.5: amount_paid: "11.5", amount_net: "10". The store compares with its own price (10), not amount_due |
| Too small after the fee | Merchant pays a 1.5 fee, create {"amount":"2"} |
400 amount_too_small naming 2.5 USDT as the minimum |
| Fee wallet empty | Drain the fee wallet, pay an invoice | Invoice still becomes paid; the sweep waits and resumes after a top-up |
The full list, including the rollout checks before mainnet, is in skills/qirsh-test-payments/SKILL.md.
Testing your webhook handler locally
The gateway must reach your store over the network. Options:
- A tunnel. Expose the local store, for example
cloudflared tunnel --url http://localhost:3000, and set the project's webhook URL to the tunnel'shttps://address plus your route. - A local gateway. Run Qirsh on your machine in single-store mode with
WEBHOOK_URL=http://localhost:3000/webhooks/qirsh. The single-store project may use local URLs. Dashboard projects needALLOW_PRIVATE_WEBHOOKS=truefor that, which is for development only.
Then press Send test event in the project's settings (or POST /api/v1/webhooks/test). It sends a signed ping and shows the status your endpoint answered.
To unit-test the signature check without a gateway, use the fixed secret, body and signature from the worked example. Your verifier must accept it with the timestamp check disabled, and reject it after you change one byte of the body.
Testing the gateway itself
For contributors working on this repo:
npm ci
npm test # vitest: unit tests and full payment flows
npm run typecheck # server and SDK- Tests never touch the network.
FakeChainintest/helpers.tsplays TronGrid: you push transfers into it and the watcher reads them. It also implements the forwarder chain port (balances, flush estimates, sweeps). test/flow.test.tscovers invoices, the watcher and webhooks end to end. Any behaviour change there needs a test.test/forwarders.test.tscovers forwarder mode againstFakeChain.test/contracts.test.tscompiles the Solidity incontracts/and runs it on an in-process EVM. It also checks thatcontracts/artifacts/forwarders.jsonmatches a fresh compile, so runnpm run contracts:buildafter changing a contract.- Money is integer base units everywhere (
src/money.ts). Tests should use strings like"10.004213", never floats.