Reference

SDKs

Official client libraries. PHP available now (source in-repo, Packagist publish pending); 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
# Packagist publish pending — install from the repo source (see "Install" below).
# Once published: 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' => 'sbx_spei',  // sandbox test rail; in prod use the 4-digit code from /payment-methods
    'country'         => 'MEX',
    'userEmail'       => 'test@test.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

Install (Packagist publish pending): the full source ships in the Key2Pay repo at sdks/php/(with README, webhook handler example, and rotation workflow). Until it's on Packagist, add it as a local path repository and require it:

bash
# Copy sdks/php/ into your project (e.g. ./vendor-src/key2pay-php), then:
composer config repositories.key2pay path ./vendor-src/key2pay-php
composer require key2pay/key2pay-php:@dev

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.key2pay.ai/api/openapi.json src/lib/key2pay-client.ts

# Python
openapi-python-client generate --url https://api.key2pay.ai/api/openapi.json

# Go
oapi-codegen -package key2pay https://api.key2pay.ai/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.