Skip to content
HisarPay
  • Integrations
  • Published:
  • Reading time: 5 min read
  • Türkçe oku

End-to-end testing in test mode: try every scenario with simulations

The riskiest moment of a payment integration is when the first real customer pays, unless you have already tried every scenario by then. HisarPay’s test mode uses the real state machine and real webhooks but never sends anything on-chain. This article shows how to use it and which scenarios to run before going live.

On this page
  1. What is test mode?
  2. Simulating payments
  3. Testing your webhook handler
  4. A test plan before going live
  5. Common testing mistakes
  6. Going live
  7. Frequently asked questions

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: false in the event body.
  • Easy to tell apart: simulated payments are marked simulated: true, and their transaction IDs start with test_.
Check livemodeTest and live events can reach the same webhook endpoint. Your handler should check 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:

MethodWhereOptions
Checkout pageBottom of the page on test invoicesPaid, partial, expired
DashboardInvoice details → SimulatePaid, partial, overpaid, expired
APIPOST /v1/invoices/{id}/simulateAll 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.

Simulating a paid invoiceTypeScript
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.

Partial, overpaid and late payment scenariosTypeScript
// 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.

A unit test for a webhook handlerTypeScript
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:

  1. Happy path: create an invoice, simulate paid, and confirm the order is approved and the customer returns to the success page.
  2. Partial payment: simulate partial; check the order goes on hold and the customer is told the remaining amount. Then simulate paid to complete it.
  3. Overpayment: simulate overpaid; confirm the order is approved and the difference is recorded.
  4. Expiry: simulate expired; check the stock is released.
  5. Late payment: simulate a payment on an expired invoice; confirm how you handle the late flag.
  6. Duplicate delivery: deliver the same event twice; check the order is not processed twice.
  7. Bad signature: send a request with a tampered body; confirm your handler rejects it.
  8. Same order number: create two invoices with the same order_id; check you get the same invoice back.
Make retries safeSend an 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 localhost that 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: true to 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?
No. Payments on test invoices are simulated; nothing is sent to the TRON network and your real balance never changes.
Do test payments send webhooks?
Yes. Simulations run the real state machine and send real, signed webhooks to your endpoints. The livemode field in the event body is false.
How do I test a late payment?
Simulate the invoice as expired first, then run a paid simulation on the same invoice. The payment is flagged as late.
Can I simulate payments on live invoices?
No. Simulation only works on invoices created with test keys; requests for a live invoice are rejected.
  • #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.

More guides that go well with this one.