PHP SDK
The official PHP 8+ library: invoices, payouts and webhook signature checks in one class.
Installation
With Composer (recommended):
composer require mercanpay/mercanpay-php
Without Composer, download the zip, copy the src/ folder into your project and require the two files. Only ext-curl and ext-json are needed.
Creating an invoice
use MercanPay\MercanPay;
$zp = new MercanPay('https://mercanpay.com', getenv('MERCANPAY_API_KEY'));
// USD-priced invoice: the customer picks the coin on the payment page
$invoice = $zp->createUsdInvoice('25', [
'order_id' => 'order-1001',
'callback_url' => 'https://shop.example/mercanpay-webhook.php',
]);
header('Location: ' . $invoice['payment_url']);
Verifying webhooks
$body = file_get_contents('php://input');
if (!MercanPay::verifyWebhook(getenv('MERCANPAY_WEBHOOK_SECRET'), $body, $_SERVER['HTTP_X_MERCANPAY_SIGNATURE'] ?? '')) {
http_response_code(401);
exit;
}
$event = json_decode($body, true);
if ($event['type'] === 'invoice.paid') {
// mark the order as paid (the same event can arrive more than once)
}
Payouts
$w = $zp->createWithdrawal('USDT', '10', 'T...', 'payout-2026-001');
echo $w['status']; // queued -> processing -> completed
The API key needs the withdrawals scope and the address must be saved for code-free payouts in the panel. See the documentation for every endpoint.