Documentation menu

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:

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

  1. Install TronLink and switch it to Nile Testnet.
  2. Get test TRX and test USDT from the Nile faucet: https://nileex.io/join/getJoinPage
  3. Create an invoice on a Nile project and open its checkout_url.
  4. Pay with Pay with TronLink, or send exactly amount_due to pay_address by hand.

What to expect:

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:

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

Edit this page on GitHub