Reference
SDKs
Official client libraries. PHP shipping today; Node.js and Python on the roadmap.
The fastest path to a working integration is one of our official SDKs. They wrap the REST API with auto-refresh, idempotency, retry-with-backoff, typed exceptions, and a batteries-included webhook signature verifier — so you write business code, not boilerplate.
PHP
PHP
key2pay/key2pay-php
PHP 8.1+ · curl · openssl · MIT
bash
composer require key2pay/key2pay-php
php
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new \Key2Pay\Client([
'apiKey' => getenv('KEY2PAY_API_KEY'),
'secretKey' => getenv('KEY2PAY_SECRET_KEY'),
'environment' => 'sandbox',
]);
$tx = $client->payments->create([
'amount' => 50,
'paymentMethodId' => '1008', // SPEI MEX, from /payment-methods
'country' => 'MEX',
'userEmail' => 'cliente@ejemplo.com',
'merchantOrderId' => 'ORD-12345',
]);
header('Location: ' . $tx['paymentFormUrl']);Auto-refresh Bearer
Re-mints + retries 401 transparently
Idempotency built-in
UUID v4 per POST · BYO key supported
Typed exceptions
AuthenticationException, InvalidRequest, RateLimit, NotFound, …
Retry with backoff
Honours Retry-After · jittered exponential
Webhook signature verify
HMAC-SHA256 · 24h rotate-secret grace window
Sandbox-Simulate built-in
Pass `sandboxSimulate => 'paid'` for CI
Full reference + webhook handler example + rotation workflow in the package README. Source lives at sdks/php/ in the Key2Pay repo — publish to Packagist is in flight, install meanwhile via VCS:
bash
composer config repositories.key2pay vcs https://github.com/key2pay/key2pay-php composer require key2pay/key2pay-php:dev-main
Other languages — generate from the OpenAPI spec
Until we ship Node.js and Python SDKs, scaffold a typed client straight from the OpenAPI spec:
bash
# Node / TS npx oazapfts https://api.key2pays.com/api/openapi.json src/lib/key2pay-client.ts # Python openapi-python-client generate --url https://api.key2pays.com/api/openapi.json # Go oapi-codegen -package key2pay https://api.key2pays.com/api/openapi.json > key2pay.go
Auto-generated clients give you typed request/response shapes for free, but they don't include the helpers our PHP SDK ships (auto-refresh, webhook signature verifier, retry policy). You'll need to wrap those yourself — the per-language patterns are straightforward; see Webhooks & signing for the HMAC verification snippet.