PHP
A Composer package that works with plain PHP, Laravel and Symfony. No framework needed.
- PHP 8.1+
- Composer
- Laravel · Symfony
A library written in TypeScript without runtime dependencies. Express, Fastify, Next.js or plain node:http: it runs wherever you do.
Keep the key in an environment variable and out of code that reaches a browser.
npm install https://hisarpay.com/downloads/hisarpay-node-1.0.0.tgzSend your order number as order_id. If the same number comes again, the existing invoice is returned instead of a new one.
import { HisarPay } from '@hisarpay/node';
const hisarpay = new HisarPay(process.env.HISARPAY_API_KEY!);
export async function startPayment(order: { id: string; total: string; title: string }) {
const invoice = await hisarpay.invoices.create({
price_usd: order.total, // "49.90", a decimal string
order_id: order.id, // the same order never gets a second invoice
description: order.title,
success_url: `https://shop.example/orders/${order.id}`,
});
return invoice.payment_url; // redirect the customer here
}The signature is made over the raw body. In Express, define this route before express.json; in Next.js, request.text() is enough.
import express from 'express';
import { HisarPay, SignatureVerificationError } from '@hisarpay/node';
const app = express();
// the raw body: register this route 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'],
process.env.HISARPAY_WEBHOOK_SECRET!,
);
} catch (err) {
if (err instanceof SignatureVerificationError) return res.sendStatus(400);
throw err;
}
if (event.livemode && (event.type === 'invoice.paid' || event.type === 'invoice.overpaid')) {
await markPaid(event.id, event.data.invoice.order_id); // once per event.id
}
res.sendStatus(200);
});// app/webhooks/hisarpay/route.ts
import { HisarPay } from '@hisarpay/node';
export async function POST(request: Request) {
const raw = await request.text();
const ok = HisarPay.webhooks.verify(
raw,
request.headers.get('x-hisarpay-signature'),
process.env.HISARPAY_WEBHOOK_SECRET!,
);
if (!ok) return new Response('bad signature', { status: 400 });
const event = JSON.parse(raw);
// …
return Response.json({ received: true });
}Download the example project from the top of this page: a small shop with three products that verifies the webhook and shows the state of an order. The library is inside; put your test key in .env and start it.
All optional; the defaults suit most shops.
What you find on the client.
| Resource | What it does |
|---|---|
| invoices | Create, retrieve, look up by order, list, cancel, simulate in test mode |
| paymentLinks | Create, update and pause links, read their figures |
| withdrawals | Withdraw to a trusted address, follow its state |
| balances | Balances and the ledger |
| webhookEndpoints · events | Manage endpoints, read and resend events |
| reports | CSV, Excel and PDF reports |
A Composer package that works with plain PHP, Laravel and Symfony. No framework needed.
Sync and async clients, samples for Flask, FastAPI and Django, type definitions included.
A predictable REST API for everything from invoices to withdrawals, with signed webhooks and a test mode.
Sign-up is free; your test keys are ready the moment you confirm your e-mail.