Skip to content
HisarPay

Official libraries for Node.js, PHP and Python

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.

  • Node.js
  • PHP
  • Python

What it does

  • Retries network errors, timeouts, 429s and 5xx responses with exponential backoff.
  • Adds an idempotency key to every POST, so a retry never creates a second invoice or payout.
  • Verifies webhook signatures with a constant-time comparison and supports secret rotation.
  • Amounts travel as decimal strings everywhere, so there are no floating-point rounding errors.
  • Auto-paginating list helpers and detailed error classes.
Creating an invoice from a terminal

Requirements

Node.js
18 or later · ESM and CommonJS
PHP
8.1 or later · curl and json extensions
Python
3.9 or later · sync and async clients
HisarPay
An API key (test or live)

Setup

  1. Step 1

    Install the library

    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.tgz
  2. Step 2

    Create your first invoice

    Read 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);
  3. Step 3

    Verify the webhook

    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);
    }

Client options

Options available in all three libraries. Node.js and PHP use camelCase, Python uses snake_case.

baseUrl / base_url
Defaults to https://hisarpay.com. Point it at a local API during development.
timeoutMs / timeout
Per-attempt timeout. Defaults to 30 seconds; Node.js takes milliseconds, PHP and Python take seconds.
maxRetries / max_retries
Retries after the first attempt. Defaults to 2.
idempotencyKey / idempotency_key
A key for one POST request. The library generates one if you leave it out.

Packages

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).

PackageFile
@hisarpay/nodehisarpay-node-1.0.0.tgz
hisarpay/hisarpay-phphisarpay-php-1.0.0.zip
hisarpayhisarpay-1.0.0-py3-none-any.whl

Frequently asked questions

There is no SDK for my language. What now?
The API is plain REST and works with any HTTP client. You can also generate a client from the OpenAPI definition. Webhook signatures are standard HMAC-SHA256, so verifying them takes a few lines in any language.
How do I test?
Use a key that starts with hp_test_. Test invoices never touch the blockchain; trigger payments with the simulate endpoint or the buttons on the payment page and try the full webhook flow end to end.
Why are amounts strings?
USDT and TRX have six decimal places. Turning them into floating-point numbers can introduce small errors. If you need arithmetic, use your language’s decimal type (BigInt, bcmath, Decimal).
Which licence are the libraries under?
All three are MIT licensed. You can read the source and adapt it to your project.

Node.js

A dependency-free library written in TypeScript, with samples for Express, Next.js and plain http.

  • Node.js 18+
  • TypeScript
  • ESM · CommonJS

PHP

A Composer package that works with plain PHP, Laravel and Symfony. No framework needed.

  • PHP 8.1+
  • Composer
  • Laravel · Symfony

Python

Sync and async clients, samples for Flask, FastAPI and Django, type definitions included.

  • Python 3.9+
  • sync · async
  • Flask · FastAPI · Django

Your first collection is an e-mail away

Sign-up is free; your test keys are ready the moment you confirm your e-mail.