Node.js
A dependency-free library written in TypeScript, with samples for Express, Next.js and plain http.
- Node.js 18+
- TypeScript
- ESM · CommonJS
Building your own app or a platform plugin? The SDKs save you the plumbing. All three share the same resource names and the same error model, so moving between them is easy.
Install it with your language’s package manager. The Node.js library has no runtime dependencies.
npm install https://hisarpay.com/downloads/hisarpay-node-1.0.0.tgzcomposer config repositories.hisarpay composer https://hisarpay.com/downloads
composer require hisarpay/hisarpay-phppip install https://hisarpay.com/downloads/hisarpay-1.0.0-py3-none-any.whlRead the API key from the environment and create an invoice. Redirect the customer to the payment_url in the response.
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',
success_url: 'https://shop.example/thanks',
});
// send the customer to the hosted payment page
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',
'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",
"success_url": "https://shop.example/thanks",
})
print(invoice["payment_url"])Fulfil orders on the signed invoice.paid notification, not on the customer’s return from the payment page. Verify the signature against the raw request body; parsed and re-serialised JSON will not match.
import { HisarPay } from '@hisarpay/node';
// rawBody: the request body exactly as received (Buffer or string)
const event = HisarPay.webhooks.constructEvent(
rawBody,
req.headers['x-hisarpay-signature'],
process.env.HISARPAY_WEBHOOK_SECRET!,
);
if (event.livemode && event.type === 'invoice.paid') {
await fulfillOrder(event.data.invoice.order_id);
}<?php
use HisarPay\Webhook;
$event = Webhook::constructEvent(
file_get_contents('php://input'),
$_SERVER['HTTP_X_HISARPAY_SIGNATURE'] ?? null,
getenv('HISARPAY_WEBHOOK_SECRET'),
);
if ($event['livemode'] && $event['type'] === 'invoice.paid') {
fulfillOrder($event['data']['invoice']['order_id']);
}from hisarpay import webhooks
event = webhooks.construct_event(
request.get_data(), # raw bytes
request.headers.get(webhooks.SIGNATURE_HEADER),
os.environ["HISARPAY_WEBHOOK_SECRET"],
)
if event["livemode"] and event["type"] == "invoice.paid":
fulfil_order(event["data"]["invoice"]["order_id"])Options available in all three libraries. Node.js and PHP use camelCase, Python uses snake_case.
All three libraries expose the same resources: invoices, paymentLinks, withdrawals, balances, reports, webhookEndpoints and events. Python spells them in snake_case (payment_links and so on).
| Package | File |
|---|---|
| @hisarpay/node | hisarpay-node-1.0.0.tgz |
| hisarpay/hisarpay-php | hisarpay-php-1.0.0.zip |
| hisarpay | hisarpay-1.0.0-py3-none-any.whl |
A dependency-free library written in TypeScript, with samples for Express, Next.js and plain http.
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.
Sign-up is free; your test keys are ready the moment you confirm your e-mail.