# Paynex.php

Single-file PHP 7.4+ client (cURL). Works in WHMCS modules, Laravel, WordPress, plain PHP.

```php
require 'Paynex.php';
$px = new Paynex('https://pay.example.com', getenv('PAYNEX_KEY_ID'), getenv('PAYNEX_SECRET'));

// 1. redirect the customer
$p = $px->createPayment([
    'amount' => '1500.00', 'merchant_ref' => 'INV-1042', 'description' => 'Hosting renewal',
    'customer' => ['name' => 'Rahim', 'email' => 'r@example.com', 'phone' => '017…'],
    'return_url' => 'https://shop.example.com/invoice/1042', 'cancel_url' => 'https://shop.example.com/invoice/1042',
], 'INV-1042-1500.00');
header('Location: ' . $p['checkout_url']);

// 2. webhook.php
$ev = Paynex::verifyWebhook(getenv('PAYNEX_WEBHOOK_SECRET'), $_SERVER['HTTP_X_PG_SIGNATURE'] ?? null, file_get_contents('php://input'));
if ($ev['event'] === 'payment.paid') {
    $full = $px->getPayment($ev['data']['id']);          // source of truth
    if ($full['status'] === 'paid') markInvoicePaid($full['merchant_ref'], $full['id']); // idempotent by id
}
http_response_code(200);

// 3. return page (UX only)
$ok = Paynex::verifyReturn(getenv('PAYNEX_WEBHOOK_SECRET'), $_GET);
```
