PHP SDK
The official PHP client library for the RevKeen API
Build and bill on RevKeen from any PHP 8.1+ project. PSR-4 autoloading, typed request classes, PSR-3 logging hooks, auto-pagination, webhook verification, and automatic retries.
Repo: github.com/RevKeen/sdk-php · Releases · Issues · Packagist
Generated from packages/openapi/openapi.json. See the versioning page for the compatibility matrix.
Install
composer require revkeen/sdk-phpRequires PHP 8.1+ with ext-json and ext-mbstring.
Quick start
<?php
require __DIR__ . '/vendor/autoload.php';
use RevKeen\RevKeenClient;
$client = new RevKeenClient([
'api_key' => getenv('REVKEEN_API_KEY'),
]);
$customer = $client->customers->create([
'email' => 'ops@acme.example',
'name' => 'Acme Inc.',
]);
echo $customer->id;Every endpoint in the API reference is available as a method on a resource group ($client->customers, $client->invoices, etc.).
What's inside
- PSR-4 autoloading — drop-in for any modern PHP framework
- Typed response objects — hydrated into typed value classes, not
stdClass - PSR-3 logging — inject any PSR-3 logger to audit requests
- Automatic pagination —
$client->invoices->autoPagingList()yields one at a time - Automatic retries — exponential backoff on
5xx,429, network errors - Idempotency keys — attached automatically on safe-to-retry mutations
- Webhook verification —
WebhookVerifier::verify($body, $signature, $secret) - OAuth 2.1 + API-key auth — both first-class
Authentication
use RevKeen\RevKeenClient;
$client = new RevKeenClient([
'api_key' => getenv('REVKEEN_API_KEY'),
]);use RevKeen\RevKeenClient;
$client = new RevKeenClient([
'oauth' => [
'client_id' => getenv('REVKEEN_CLIENT_ID'),
'client_secret' => getenv('REVKEEN_CLIENT_SECRET'),
'scopes' => ['customers:read', 'invoices:write'],
],
]);Common workflows
Create a customer and invoice
$customer = $client->customers->create([
'email' => 'ops@acme.example',
'name' => 'Acme Inc.',
]);
$invoice = $client->invoices->create([
'customer_id' => $customer->id,
'currency' => 'USD',
'lines' => [[
'description' => 'Pro plan — January 2026',
'unit_amount_minor' => 9999,
'quantity' => 1,
]],
]);
$client->invoices->finalize($invoice->id);
$client->invoices->send($invoice->id);Iterate with auto-pagination
foreach ($client->invoices->autoPagingList(['status' => 'open']) as $invoice) {
echo $invoice->id . ': ' . $invoice->amount_due_minor . PHP_EOL;
}Verify a webhook
use RevKeen\Webhooks\WebhookVerifier;
use RevKeen\Exception\SignatureException;
$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_REVKEEN_SIGNATURE'] ?? '';
$secret = getenv('REVKEEN_WEBHOOK_SECRET');
try {
$event = WebhookVerifier::verify($rawBody, $signature, $secret);
if ($event->type === 'invoice.paid') {
fulfil($event->data->object);
}
http_response_code(200);
} catch (SignatureException $e) {
http_response_code(400);
exit('invalid signature');
}See webhook signing for the wire format.
Error handling
use RevKeen\Exception\RevKeenException;
try {
$client->customers->retrieve('cus_does_not_exist');
} catch (RevKeenException $e) {
echo $e->getCode(); // "resource_missing"
echo $e->getStatusCode(); // 404
echo $e->getRequestId(); // "req_01HT..."
throw $e;
}See the errors page for the full code table.
Idempotency
use Ramsey\Uuid\Uuid;
$refund = $client->refunds->create(
[
'charge' => 'ch_01HT...',
'amount_minor' => 1500,
],
['idempotency_key' => Uuid::uuid4()->toString()],
);See idempotency for the replay contract.
Retries and timeouts
$client = new RevKeenClient([
'api_key' => getenv('REVKEEN_API_KEY'),
'max_retries' => 3, // default 2
'timeout' => 30, // seconds, default 60
]);Retries apply to 5xx, 429, and network errors on safe methods. Non-idempotent mutations without an idempotency key never retry.
Framework adapters
// config/services.php
return [
'revkeen' => [
'api_key' => env('REVKEEN_API_KEY'),
],
];
// app/Providers/AppServiceProvider.php
use RevKeen\RevKeenClient;
public function register(): void
{
$this->app->singleton(RevKeenClient::class, fn () => new RevKeenClient([
'api_key' => config('services.revkeen.api_key'),
]));
}# config/services.yaml
services:
RevKeen\RevKeenClient:
arguments:
- api_key: '%env(REVKEEN_API_KEY)%'<?php
require __DIR__ . '/vendor/autoload.php';
$client = new RevKeen\RevKeenClient([
'api_key' => getenv('REVKEEN_API_KEY'),
]);Compatibility
| PHP version | Status |
|---|---|
| 8.3 | Supported |
| 8.2 | Supported |
| 8.1 | Supported |
| 8.0 and earlier | Not supported |
API version pinned via api_version in the constructor config. See versioning.