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
- Your server asks the HisarPay API to create an invoice.
- You redirect the customer to the
payment_urlin the response. The payment page shows the coin choice, a QR code, the amount to send and the time left. - The customer sends TRX or USDT. Once the payment is confirmed on TRON, the invoice becomes
paid. - HisarPay sends a signed
invoice.paidevent 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.
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"
}'import { HisarPay } from '@hisarpay/node';
const hisarpay = new HisarPay(process.env.HISARPAY_API_KEY!);
const invoice = await hisarpay.invoices.create({
price_usd: '49.90',
order_id: 'order_1001',
description: 'Pro plan, 1 month',
success_url: 'https://shop.example/thanks',
});
console.log(invoice.payment_url);<?php
require 'vendor/autoload.php';
$hisarpay = new \HisarPay\HisarPay(getenv('HISARPAY_API_KEY'));
$invoice = $hisarpay->invoices->create([
'price_usd' => '49.90',
'order_id' => 'order_1001',
'description' => 'Pro plan, 1 month',
'success_url' => 'https://shop.example/thanks',
]);
header('Location: ' . $invoice['payment_url']);import os
from hisarpay import HisarPay
client = HisarPay(os.environ["HISARPAY_API_KEY"])
invoice = client.invoices.create({
"price_usd": "49.90",
"order_id": "order_1001",
"description": "Pro plan, 1 month",
"success_url": "https://shop.example/thanks",
})
print(invoice["payment_url"])The response is 201 Created with the full invoice. These are the fields you need at this point:
{
"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);
});<?php
use HisarPay\Exception\SignatureVerificationException;
use HisarPay\Webhook;
$payload = file_get_contents('php://input'); // raw bytes
$header = $_SERVER['HTTP_X_HISARPAY_SIGNATURE'] ?? null;
try {
$event = Webhook::constructEvent($payload, $header, getenv('HISARPAY_WEBHOOK_SECRET'));
} catch (SignatureVerificationException $e) {
http_response_code(400);
exit;
}
// test events arrive here too, and anyone can mark a test invoice as paid
$live = str_starts_with((string) getenv('HISARPAY_API_KEY'), 'hp_live_');
if ($event['livemode'] === $live && in_array($event['type'], ['invoice.paid', 'invoice.overpaid'], true)) {
// fulfil the order once; record the event id
fulfill_order($event['data']['invoice']['order_id'], $event['id']);
}
http_response_code(200);import os
from flask import Flask, abort, request
from hisarpay import SignatureVerificationError, webhooks
app = Flask(__name__)
SECRET = os.environ["HISARPAY_WEBHOOK_SECRET"]
LIVE = os.environ["HISARPAY_API_KEY"].startswith("hp_live_")
@app.post("/webhooks/hisarpay")
def hisarpay_webhook():
try:
event = webhooks.construct_event(
request.get_data(), # raw bytes, not request.json
request.headers.get("X-HisarPay-Signature"),
SECRET,
)
except SignatureVerificationError:
abort(400)
# test events arrive here too, and anyone can mark a test invoice as paid
if event["livemode"] is LIVE and event["type"] in ("invoice.paid", "invoice.overpaid"):
# fulfil the order once; record the event id
fulfill_order(event["data"]["invoice"]["order_id"], event["id"])
return "", 200The 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"
}'await hisarpay.invoices.simulate(invoice.id, { outcome: 'paid' });$hisarpay->invoices->simulate($invoice['id'], ['outcome' => 'paid']);client.invoices.simulate(invoice["id"], {"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.partialandinvoice.expiredas 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.