hashco / hash-php
The official PHP library for the Hash crypto payment API: invoices in US dollars, hosted checkout and signed webhooks.
Requires
- php: ^8.1
- ext-json: *
Requires (Dev)
- guzzlehttp/guzzle: ^7.8
- opis/json-schema: ^2.3
- php-http/discovery: ^1.19
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.5
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
Suggests
- ext-curl: The default HTTP transport. Without it, pass a PSR-18 client or install php-http/discovery.
- guzzlehttp/guzzle: A PSR-18 HTTP client.
- php-http/discovery: To find an installed PSR-18 client when ext-curl is missing.
- psr/http-client: To pass your own PSR-18 HTTP client.
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-24 21:47:52 UTC
README
The official PHP library for the Hash API.
Installation
composer require hashco/hash-php
Requires PHP 8.1 or later with ext-curl. Any PSR-18 client can be used instead. No dependencies.
Usage
Create an invoice on your server and send the customer to the hosted checkout:
use Hash\HashClient; $hash = new HashClient(getenv('HASH_SECRET_KEY')); $invoice = $hash->invoices->create([ 'price_usd' => '48.50', 'order_id' => '7731', 'success_url' => 'https://shop.example/orders/7731', ]); header('Location: '.$invoice->pay_url, true, 303);
Ship the order when a verified invoice.paid webhook arrives, never on the redirect:
use Hash\Exception\SignatureVerificationException; use Hash\Webhook; try { $event = Webhook::constructEvent( file_get_contents('php://input'), $_SERVER, getenv('HASH_WEBHOOK_SECRET') ); } catch (SignatureVerificationException) { http_response_code(400); exit; } if ($event->type === 'invoice.paid') { markOrderPaid($event->invoice()->order_id, $event->id); }
Lists can be paged through with autoPagingIterator():
foreach ($hash->invoices->list(['status' => 'paid'])->autoPagingIterator() as $invoice) { echo $invoice->id; }
Every POST and PATCH is sent with an Idempotency-Key, so retries are safe. Failures throw typed exceptions such as ConflictException, ValidationException and RateLimitException.
Documentation
The full documentation is at docs.hash.bh.
Security
If you discover a security vulnerability, please report it privately through GitHub instead of opening an issue.
License
The Hash PHP library is open-sourced software licensed under the MIT license.