Official PHP SDK for the Selivery Enterprise API.
- Require via Composer:
composer require selivery/enterprise-sdk-php - Requires PHP ^8.2 with
ext-opensslandext-json.
send(...) automatically:
- looks up the phone's public key,
- generates a crypto‑random vector (default 32 chars),
- encrypts each secret value using RSA PKCS#1 v1.5 (
openssl_public_encrypt) with that vector, and - includes the resolved
key_uuidand the generatedvectorin the request.
No sender parameter is needed (it is derived from the template on the service).
use Selivery\Enterprise\EnterpriseClient;
$client = new EnterpriseClient(getenv('SELIVERY_SECRET') ?: '');
/** @var Selivery\Enterprise\Models\SendResult $response */
$response = $client->send(
phone: '+12025550123',
idTemplate: 1,
// Vector is generated automatically and used for encryption and request body
secrets: [
['placeholder' => 'code', 'values' => '123456'],
]
);Difference from send:
- send encrypts values locally in the SDK and sends only encrypted chunks to Selivery. This means even Selivery (or any intermediary) cannot read your values.
- sendLight accepts plaintext values; Selivery encrypts them as the very first step on the server and then handles only encrypted values afterward. Both methods are secure; send offers an even stricter privacy boundary since plaintext never leaves your process.
/** @var Selivery\Enterprise\Models\SendResult $response */
$response = $client->sendLight(
phone: '+12025550123',
idTemplate: 1,
secrets: [
['key' => 'code', 'values' => '123456'],
]
);Inject any PSR-16 cache to enable automatic caching and refresh of OAuth tokens.
use Selivery\Enterprise\EnterpriseClient;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;
$pool = new FilesystemAdapter(namespace: 'selivery', defaultLifetime: 0);
$psr16 = new Psr16Cache($pool);
// Options (optional):
// - base_url: override API base URL
// - timeout: request timeout in seconds
// - cache_key: override default key (default: selivery_enterprise_sdk_tokens:{sha1(baseUrl)})
// - token_safety_window: seconds before expiry to refresh (default: 60)
$client = new EnterpriseClient(
secret: getenv('SELIVERY_SECRET') ?: '',
cache: $psr16,
options: [
'token_safety_window' => 60,
// 'cache_key' => 'custom_key_per_env',
]
);
// The SDK generates tokens automatically on the first request,
// then reuses and refreshes them through the cache.- Send message:
SELIVERY_SECRET=your-secret php examples/service_send.php - Send light message:
SELIVERY_SECRET=your-secret php examples/service_send_light.php
EnterpriseClientis the only public entry point. Callsend(...)orsendLight(...)on it directly.- The SDK uses your secret only for
generate-token. - Service requests use the generated
access_tokenautomatically. - If a cache is provided, the SDK stores both access and refresh tokens and refreshes the access token when needed.
- POST endpoints accept JSON bodies; include
Content-Type: application/json. - The
senderfield has been removed from SDK methods and requests; it is derived from the template server‑side. - Token cache key default:
selivery_enterprise_sdk_tokens:{sha1(baseUrl)}. Avoid putting secrets in cache keys. - Safety window default: 60s. Treats token as expired when
now >= expires_at - safety_window.
- Symfony Cache:
Psr16CacheoverFilesystemAdapter(disk) orRedisAdapter(Redis). - Any PSR-16 provider is supported: pass your
Psr\SimpleCache\CacheInterfacetoEnterpriseClient.
See examples:
- Symfony filesystem cache:
php examples/cache_symfony.php - Symfony Redis cache:
php examples/cache_redis_symfony.php