Skip to content
HisarPay

Getting started

Quick start

In this guide you create an invoice with a test key, send the customer to the hosted payment page and confirm the payment with a signed webhook. It takes about ten minutes.

How the flow works

  1. Your server asks the HisarPay API to create an invoice.
  2. You redirect the customer to the payment_url in the response. The payment page shows the coin choice, a QR code, the amount to send and the time left.
  3. The customer sends TRX or USDT. Once the payment is confirmed on TRON, the invoice becomes paid.
  4. HisarPay sends a signed invoice.paid event to your server. You verify the signature and fulfil the order.

1. Get a test key

Create a test key in the dashboard under Developers → API keys. Test keys start with hp_test_. Nothing you do with them touches the blockchain or changes your balance.

Terminal
export HISARPAY_API_KEY="hp_test_..."

2. Create an invoice

Give the price in USD and the customer chooses between TRX and USDT on the payment page. order_id ties the invoice to your order. Sending the same order_id again does not open a second invoice; you get the existing one back.

curl -X POST https://hisarpay.com/v1/invoices \
  -H "Authorization: Bearer $HISARPAY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order_1001" \
  -d '{
    "price_usd": "49.90",
    "order_id": "order_1001",
    "description": "Pro plan, 1 month",
    "success_url": "https://shop.example/thanks"
  }'

The response is 201 Created with the full invoice. These are the fields you need at this point:

201 Created
{
  "id": "0b6a3f52-3c1d-4a7e-8f4b-1d2c3e4f5a6b",
  "object": "invoice",
  "livemode": false,
  "type": "choice",
  "status": "pending",
  "token": null,
  "amount": null,
  "price_amount": "49.90",
  "price_currency": "USD",
  "allowed_tokens": ["TRX", "USDT"],
  "order_id": "order_1001",
  "payment_url": "https://hisarpay.com/pay/0b6a3f52-3c1d-4a7e-8f4b-1d2c3e4f5a6b",
  "expires_at": "2026-10-23T10:00:00.000Z",
  "created_at": "2026-10-23T09:00:00.000Z"
}

token and amount are empty because no coin has been chosen yet. When the customer picks one, the rate is locked and the amount is calculated. See Invoices for details.

3. Redirect the customer

Send the customer to payment_url. The payment page works on phones and desktops and speaks Turkish and English. After paying, the customer returns to your success_url.

4. Confirm the payment with a webhook

Add your server’s HTTPS address in the dashboard under Developers → Webhooks. You get a signing secret that starts with whsec_. Verify every event with it, over the raw request body:

import express from 'express';
import { HisarPay, SignatureVerificationError } from '@hisarpay/node';

const app = express();
const secret = process.env.HISARPAY_WEBHOOK_SECRET!; // whsec_…
const LIVE = process.env.HISARPAY_API_KEY!.startsWith('hp_live_');

// express.raw keeps the exact bytes; register it before any express.json()
app.post('/webhooks/hisarpay', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;
  try {
    event = HisarPay.webhooks.constructEvent(req.body, req.headers['x-hisarpay-signature'], secret);
  } catch (err) {
    if (err instanceof SignatureVerificationError) return res.status(400).send(err.message);
    throw err;
  }
  // test events arrive here too, and anyone can mark a test invoice as paid
  if (event.livemode !== LIVE) return res.sendStatus(200);
  if (event.type === 'invoice.paid' || event.type === 'invoice.overpaid') {
    // fulfil the order once; record the event id
    await fulfillOrder(event.data.invoice.order_id, event.id);
  }
  res.sendStatus(200);
});

The same event can arrive more than once, so store event ids and skip repeats. The Webhooks guide covers the signature format, event types and the retry schedule.

5. Simulate the payment

Test mode needs no real transfer. Move the invoice to the outcome you want; HisarPay runs the same state machine as in live mode and sends the same webhooks:

curl -X POST https://hisarpay.com/v1/invoices/0b6a3f52-3c1d-4a7e-8f4b-1d2c3e4f5a6b/simulate \
  -H "Authorization: Bearer $HISARPAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "outcome": "paid"
  }'

Try partial, overpaid and expired too. The Test mode and simulation guide lists every scenario.

Go-live checklist

  • Once your account application is approved, create a key that starts with hp_live_ and select only the scopes you need.
  • Restrict the key to your servers’ IP addresses (IP allowlist).
  • Make sure your webhook endpoint uses HTTPS and verifies signatures, and test that the same event is never processed twice.
  • Handle invoice.partial and invoice.expired as well: show the customer what is still due, and release the stock of orders that expire.
  • Swap the test key for the live key. No other code change is needed.