Node.js
A dependency-free library written in TypeScript, with samples for Express, Next.js and plain http.
- Node.js 18+
- TypeScript
- ESM · CommonJS
A plain Composer package that asks for no framework. On shared hosting or inside Laravel or Symfony, a few lines take the payment.
Without Composer, copy the source folder and write a PSR-4 loader; the sample project does exactly that.
composer config repositories.hisarpay composer https://hisarpay.com/downloads
composer require hisarpay/hisarpay-phpRead the amount from the order on your server, never from the form. Send the customer to payment_url.
<?php
require 'vendor/autoload.php';
use HisarPay\Exception\HisarPayException;
use HisarPay\HisarPay;
$hisarpay = new HisarPay(getenv('HISARPAY_API_KEY'));
try {
$invoice = $hisarpay->invoices->create([
'price_usd' => $order['total'], // "49.90", a decimal string
'order_id' => $order['number'], // the same order never gets a second invoice
'description' => $order['title'],
'success_url' => 'https://shop.example/orders/' . $order['number'],
]);
} catch (HisarPayException $e) {
error_log($e->getMessage() . ' ' . $e->getRequestId());
http_response_code(502);
exit;
}
header('Location: ' . $invoice['payment_url'], true, 303);Read the raw body. In Laravel, keep the route out of the CSRF check and hand the work to a queue.
<?php
use HisarPay\Exception\SignatureVerificationException;
use HisarPay\Webhook;
$raw = file_get_contents('php://input'); // raw bytes, not $_POST
try {
$event = Webhook::constructEvent(
$raw,
$_SERVER['HTTP_X_HISARPAY_SIGNATURE'] ?? null,
getenv('HISARPAY_WEBHOOK_SECRET'),
);
} catch (SignatureVerificationException) {
http_response_code(400);
exit;
}
if ($event['livemode'] && in_array($event['type'], ['invoice.paid', 'invoice.overpaid'], true)) {
markPaid($event['id'], $event['data']['invoice']['order_id']); // once per event id
}
http_response_code(200);<?php
// routes/api.php (no CSRF check on this route)
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use HisarPay\Webhook;
Route::post('/webhooks/hisarpay', function (Request $request) {
$event = Webhook::constructEvent(
$request->getContent(), // raw content
$request->headers->get('X-HisarPay-Signature'),
config('services.hisarpay.webhook_secret'),
);
HandleHisarPayEvent::dispatch($event); // your queued job
return response()->noContent();
});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.
All of them extend HisarPay\Exception\HisarPayException.
| Exception | When |
|---|---|
| ValidationException | One of the fields is wrong (400, 422) |
| AuthenticationException | Key missing, unknown or revoked (401) |
| PermissionDeniedException | Scope missing, IP not allowed, a live-only call with a test key (403) |
| NotFoundException | No such record (404) |
| SignatureVerificationException | The webhook signature does not match |
A dependency-free library written in TypeScript, with samples for Express, Next.js and plain http.
Sync and async clients, samples for Flask, FastAPI and Django, type definitions included.
Separate builds for OpenCart 4 and 3, with a connection test button and configurable order status mapping.
Sign-up is free; your test keys are ready the moment you confirm your e-mail.