On this page
What is test mode?
You can create two kinds of API key in the dashboard: live keys starting with hp_live_ and test keys starting with hp_test_. Everything you do with a test key is stored as test data and never mixes with your live data.
- Same API, same behaviour: test invoices use the same endpoints, validation rules and state machine as live invoices.
- Nothing on-chain: test payments are simulated; no transaction is sent to TRON and your real balance never changes.
- Real webhooks: simulations send real, signed webhooks to your endpoints, with
livemode: falsein the event body. - Easy to tell apart: simulated payments are marked
simulated: true, and their transaction IDs start withtest_.
livemode on every event and never apply test events to orders in production.Simulating payments
There are three ways to simulate the outcome of a test invoice:
| Method | Where | Options |
|---|---|---|
| Checkout page | Bottom of the page on test invoices | Paid, partial, expired |
| Dashboard | Invoice details → Simulate | Paid, partial, overpaid, expired |
| API | POST /v1/invoices/{id}/simulate | All four outcomes plus an optional amount |
If the customer has not picked a coin yet, the simulation uses USDT; because USDT needs no exchange rate, simulations work even in an offline development environment.
import { HisarPay } from '@hisarpay/node';
const hisarpay = new HisarPay(process.env.HISARPAY_TEST_KEY!); // hp_test_…
const invoice = await hisarpay.invoices.create({
price_usd: '25.00',
order_id: 'test-order-1',
});
// Runs the real state machine and sends real (test) webhooks
const paid = await hisarpay.invoices.simulate(invoice.id, { outcome: 'paid' });
console.log(paid.status); // 'paid'Trying edge cases
By default, partial pays half of the remaining amount and overpaid pays ten percent more than what remains. Use the amount field to set the amount yourself. Simulating a payment on an expired invoice lets you test the late-payment path too.
// Pays half of the remaining amount, then completes it
await hisarpay.invoices.simulate(invoice.id, { outcome: 'partial' });
await hisarpay.invoices.simulate(invoice.id, { outcome: 'paid' });
// A custom amount for partial or overpaid scenarios
await hisarpay.invoices.simulate(other.id, { outcome: 'overpaid', amount: '30.00' });
// Expire first, then pay: produces a late payment (payment.late === true)
await hisarpay.invoices.simulate(late.id, { outcome: 'expired' });
await hisarpay.invoices.simulate(late.id, { outcome: 'paid' });Testing your webhook handler
Check the connection
Under Developers → Webhooks in the dashboard, send a test.ping event to your endpoint. The delivery log shows the response code and timing. If the response is not a 2xx or takes longer than 10 seconds, fix your handler; deliveries do not follow redirects.
Generate signed requests in unit tests
To cover signature verification in automated tests, use the SDK’s test helper. It produces a valid X-HisarPay-Signature header for the body and secret you give it. See our webhook signature guide for the details of the signature.
import { HisarPay } from '@hisarpay/node';
import { expect, it } from 'vitest';
it('accepts a correctly signed invoice.paid event', async () => {
const payload = JSON.stringify({
id: 'evt_1',
type: 'invoice.paid',
livemode: false,
created_at: new Date().toISOString(),
data: { invoice: { id: 'inv_1', order_id: 'ORD-1', status: 'paid' } },
});
const header = HisarPay.webhooks.generateTestHeader({ payload, secret: 'whsec_test' });
const res = await handleWebhook({ body: payload, signature: header });
expect(res.status).toBe(200);
});A test plan before going live
Run each of these scenarios end to end at least once:
- Happy path: create an invoice, simulate paid, and confirm the order is approved and the customer returns to the success page.
- Partial payment: simulate partial; check the order goes on hold and the customer is told the remaining amount. Then simulate paid to complete it.
- Overpayment: simulate overpaid; confirm the order is approved and the difference is recorded.
- Expiry: simulate expired; check the stock is released.
- Late payment: simulate a payment on an expired invoice; confirm how you handle the
lateflag. - Duplicate delivery: deliver the same event twice; check the order is not processed twice.
- Bad signature: send a request with a tampered body; confirm your handler rejects it.
- Same order number: create two invoices with the same
order_id; check you get the same invoice back.
Idempotency-Key header with write requests to the API. A request repeated after a network error then returns the original result instead of creating a second record. The official SDKs generate the key for you.Common testing mistakes
- Expecting webhooks on a local address: HisarPay cannot reach addresses such as
localhostthat only exist on your machine. During development, use a publicly reachable test URL or a reputable tunnelling service. - Clock drift: the signature timestamp is checked with a 5-minute tolerance, so a server with a wrong clock rejects valid requests.
- Parsing and re-signing JSON: always verify the signature against the raw body.
- Testing only the happy path: in real life, most support tickets come from partial and late payments; do not skip them.
- Leaving a test key in production: when going live, check in both your config files and your deployment environment that the key starts with
hp_live_.
Going live
- Swap the test key for a live key, and keep the live key server-side only, in an environment variable.
- Restrict your API key to your servers’ IP addresses.
- In production, make sure your handler never applies events without
livemode: trueto orders. - Run one last real payment with a small amount and check the records in the dashboard.
Make a habit of logging the request_id returned with every response; when something goes wrong, it lets our support team find the request quickly. The full API reference is in the documentation.
Frequently asked questions
Does test mode spend real money?
Do test payments send webhooks?
How do I test a late payment?
Can I simulate payments on live invoices?
- #Test mode
- #Simulations
- #API
- #Webhooks
Try crypto payments in test mode
No setup or monthly fees. Experiment as much as you like in test mode and go live when you are ready.