Search by

cigalpay / cigalpay-php-sdk

cigalpay

Official CigalPay PHP SDK: accept crypto payments (BTC, ETH, USDT, SOL and more) in your app, SaaS or website.

v2.3.0 2026-11-11 21:37 UTC

This package is auto-updated.

Last update: 2026-11-23 23:56:59 UTC


README

Official PHP library for CigalPay: accept crypto payments (BTC, ETH, USDT, SOL, LTC, DOGE and more) in your app, SaaS or website. Payments are priced in USD or EUR, and the customer picks the coin on the CigalPay checkout page.

  • PHP 7.4+ with curl and json. No other dependencies.
  • Hosted checkout in one call.
  • Webhook signature check that matches CigalPay byte for byte.

Install

composer require cigalpay/cigalpay-php-sdk

Credentials

Get these from your dashboard under Settings → API credentials:

Value Used for
Account ID createCheckout()
API key the payment API (createPayment(), getPayment()…)
Notification signing secret verifyWebhook()

Keep them on your server, in environment variables. Never put them in front-end code.

1. Create a checkout

use Cigalpay\CigalPay;

$cigalpay = new CigalPay([
    'accountId' => getenv('CIGALPAY_ACCOUNT_ID'),
    'apiKey'    => getenv('CIGALPAY_API_KEY'),
]);

$checkout = $cigalpay->createCheckout([
    'amount'      => 49.90,
    'currency'    => 'USD',                // or 'EUR'
    'orderId'     => 'order-1042',         // your reference, sent back as extraId
    'description' => 'Pro plan - 1 month',
    'returnUrl'   => 'https://example.com/thanks',
    'notifyUrl'   => 'https://example.com/cigalpay/webhook',
    'lang'        => 'en',                 // en, fr, es, de
    'feePaidBy'   => 'customer',           // optional: 'customer' adds the processing fee to the price; omit to use your dashboard setting
]);

// save $checkout['id'] with the order, then:
header('Location: ' . $checkout['chargeLink']);

2. Receive the payment notification

CigalPay POSTs the payment to notifyUrl each time its status changes. The x-cigalpay-sig header signs the body. Pass the body exactly as received:

use Cigalpay\CigalPay;

$raw = file_get_contents('php://input');
$sig = isset($_SERVER['HTTP_X_CIGALPAY_SIG']) ? $_SERVER['HTTP_X_CIGALPAY_SIG'] : '';

if (!CigalPay::verifyWebhook($raw, $sig, getenv('CIGALPAY_IPN_SECRET'))) {
    http_response_code(401);
    exit;
}

$payment = CigalPay::parseWebhook($raw);

$order = find_order($payment['extraId']);

if (CigalPay::isPaid($payment['status']) && $order
    && isset($payment['checkoutId']) && hash_equals($order->cigalpay_checkout_id, $payment['checkoutId'])) {
    // CONFIRMED or FINISHED, for the checkout you created: mark the order paid (only once)
}

http_response_code(200);

Statuses: WAITING, CONFIRMING, CONFIRMED, SENDING, FINISHED, PARTIALLY_PAID, EXPIRED, FAILED (constants CigalPay::STATUS_*). Ship only on CONFIRMED or FINISHED.

The same payment can be notified more than once, so make your handler idempotent.

Always compare checkoutId with the id that createCheckout() returned for that order. Anyone can create a checkout with your account ID and one of your order references, so extraId alone doesn't prove the order was paid in full. checkoutAmount and checkoutCurrency give the checkout's price. When the customer paid the processing fee, checkoutFee and checkoutTotal (price + fee) are added; checkoutAmount stays your price.

Test without paying: in the dashboard, Settings → API → Test notification sends a signed sample to your URL. It carries test: true and the order reference cigalpay-test, so your server can ignore it.

Payment API

Use the payment API if you build your own payment page. It needs apiKey.

$payment = $cigalpay->createPayment([
    'amount'    => 0.0015,
    'currency'  => 'BTC',
    'orderId'   => 'order-1042',
    'notifyUrl' => 'https://example.com/cigalpay/webhook',
    'returnUrl' => 'https://example.com/thanks',
]);

$cigalpay->getPayment($payment['id']);
$cigalpay->getPaymentsByOrder('order-1042');
$cigalpay->getActivePayments();
$cigalpay->getSupportedCoins();

Your own payment page (white label)

Turn on White label in your dashboard (Settings → White label). Your server creates the checkout, then asks for the address to show on your page. The customer never sees a CigalPay payment page.

$checkout = $cigalpay->createCheckout(['amount' => 49.9, 'currency' => 'USD', 'orderId' => '1042', 'description' => 'Order #1042', 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl]);

// A coin accepted directly:
$payment = $cigalpay->payCheckout(['checkoutId' => $checkout['id'], 'coin' => 'BTC']);

// A coin converted at payment: pass the paying customer as your server sees them.
$swap = $cigalpay->payCheckout(['checkoutId' => $checkout['id'], 'swapCoin' => 'XRP', 'customer' => ['ip' => $_SERVER['REMOTE_ADDR'], 'userAgent' => $_SERVER['HTTP_USER_AGENT'] ?? null]]);

Show the returned address and exact amount, and confirm the order from the signed notification, as with a hosted checkout. Use getSwapCoins() and quoteCheckout() to list converted coins and show what the customer would send. Keep your API key on your server.

To send a payment to a specific wallet, add labelled addresses in Settings → Forwarding, each confirmed by email and used after 24 hours, then pass forwardLabel to payCheckout(). Your API key can only pick among those addresses, never add one. List them with getForwardingLabels(). An unknown or inactive label is refused.

To add your customers' wallets from your server, ask support to approve your account, then create a forwarding key in Settings → White label, limited to your server's IPs. Verify each wallet with your customer, then call addForwardingAddress({ currency, label, address }). It's used after 24 hours. You get an email with a cancel link for each new wallet, and the number of new wallets a day is limited. You are responsible for checking these wallets with your customers. List them with getForwardingAddresses().

With white label on, CigalPay sends your customer no refund emails. Collect their address on your side and call refundToAddress() with your forwarding key: there's no refund page, and it goes to review like every refund. Check progress with getRefunds().

Refunds

Refund a paid payment from your server. It needs apiKey.

$res = $cigalpay->createRefund([
    'paymentId'      => $payment['id'],   // the `id` in the payment notification
    'checkoutAmount' => 20.00,            // in the checkout's USD / EUR, or 'amount' in the coin paid
    'customerEmail'  => 'customer@example.com',
    'reason'         => 'Returned item',
]);
$res['link'];                              // the customer enters their address here

$cigalpay->getRefunds($payment['id']);     // status: awaiting_address, pending_review, sent...
  • The refund and its network fee come out of your CigalPay balance in the payment's coin. A payment forwarded to your own wallet can't be refunded this way: refund it from that wallet.
  • checkoutAmount is converted at the payment's rate, so the customer gets back the same share of the coin they sent.
  • CigalPay's fee on the payment is not refunded.

Errors

Every API failure throws Cigalpay\Exceptions\CigalpayException:

  • getStatus() is the HTTP status (0 = network error).
  • getBody() is the parsed reply.
try {
    $cigalpay->getActivePayments();
} catch (\Cigalpay\Exceptions\CigalpayException $e) {
    error_log($e->getStatus() . ' ' . $e->getMessage());
}

Upgrading from 1.x

  • Cigalpay\CigalpaySDK still works. It now points to the current API (the old api.cigalpay.icu host is gone).
  • New code should use Cigalpay\CigalPay.
  • getInvoiceStatus() was removed: use getPayment().

Tests

composer test

The tests need Node.js to sign the test notifications the same way CigalPay does.

License

MIT