Search by

instantpay-sa / instantpay-php

alajme0085

Official PHP library for the InstantPay API (Saudi merchant payments).

Package info

github.com/alajme0085/instantpay-php

pkg:composer/instantpay-sa/instantpay-php

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-09-30 06:43 UTC

This package is auto-updated.

Last update: 2026-10-23 15:52:18 UTC


README

Official PHP library for the InstantPay API. PHP 7.4+, needs only the curl and json extensions. Without Composer, require 'src/autoload.php'.

$ip = new \InstantPay\Client(getenv('INSTANTPAY_API_KEY'), [
    'base_url' => 'https://instantpay-api.onrender.com', // demo sandbox; omit for production
]);

$checkout = $ip->paymentIntents->create([
    'amount' => '250.00',
    'description' => 'Order 1001',
    'reference' => '1001',
    'return_url' => 'https://shop.example.sa/orders/1001',
]);
header('Location: ' . $checkout['checkout_url']);

foreach ($ip->payments->all(['state' => 'settled']) as $payment) { /* every page */ }

$ip->refunds->create(['payment_id' => 'pay_…', 'amount' => '20.00', 'reason' => 'One item returned']);

// Webhooks: the raw body, then the event (throws on a bad or old signature)
$event = \InstantPay\Webhook::constructEvent(
    file_get_contents('php://input'),
    $_SERVER['HTTP_INSTANTPAY_SIGNATURE'] ?? null,
    getenv('INSTANTPAY_WEBHOOK_SECRET')
);

Errors are InstantPay\InstantPayException with getStatus(), getErrorCode(), getParam() and getRequestId(). Options: base_url, timeout (30), max_retries (2), transport. Tests: php tests/run.php.