Search by

pereval-dating / pereval-php

popov100

PHP client for the Pereval dating network partner API

v1.0.0 2026-12-04 13:34 UTC

This package is auto-updated.

Last update: 2026-12-04 15:50:29 UTC


README

Version Tests License: MIT API documentation ยท API reference

Integrate a dating site with the Pereval partner API. Protocol 1.0.1 covers 30 core operations. This client also supports nine optional commerce operations, authenticated photos and signed webhooks.

Install

Requires PHP 7.4 or 8.x with JSON. The default transport requires cURL. Use a supported PHP release in production. Older versions are compatibility targets only. No framework, background daemon or third-party PHP library is required.

composer require pereval-dating/pereval-php

For Symfony service registration, signed webhook controllers and Messenger, see pereval-symfony.

Without Composer, extract the ZIP outside the web root and load autoload.php from the extracted directory instead of vendor/autoload.php.

First request

Keep credentials on the server. Use a sandbox key and run php examples/quickstart.php with PEREVAL_API_KEY set, or make the same read-only request in your application:

require __DIR__ . '/vendor/autoload.php';

$client = new Pereval\Client((string) getenv('PEREVAL_API_KEY'));
$caps = $client->capabilities->get();
if (($caps['mode'] ?? null) !== 'sandbox') {
    throw new RuntimeException('Expected a sandbox key');
}
echo $caps['protocol_version'];

Check the expected mode explicitly before writes. Use separate credentials, storage and event cursors for sandbox and live. The constructor also accepts an HTTPS origin, webhook secret, commerce key, optional transport, logger and middleware, in that order.

Integrate one member

Ask for consent before synchronizing an account. Build the profile from the member's choices, including the actual consent timestamp and text version. See the member schema. Never infer consent from a site registration.

$member = $client->members->upsert($localId, $profile);
$page = $client->feed->list($localId, ['limit' => 10]);
foreach ($page['items'] as $candidate) {
    // Keep the peer's network_id separate from your own external member IDs.
    $peerId = $candidate['network_id'];
}

Use members->remove($localId, 'left_network') when consent is withdrawn. Use account_deleted for account deletion.

Services

Methods return associative arrays with the API field names, including pagination fields. HTTP 204 and successful health checks return an empty array. Photo downloads return bytes and content_type. Serve them only to the authorized viewer with private, no-store caching. Treat SVG as untrusted content and never inline it. MCP returns the JSON-RPC result.

Service Methods
capabilities get
health live, ready
languages list
members upsert, upsertBatch, touchBatch, deactivate, restore, reinstate, touch, remove
feed list
likes create, withdraw, undoDislike, dislike, dislikeBatch, list
matches list, end, clearHistory
messages send, list, markRead
events list
moderation block, report
photos createCheck, getCheck, browse
commerce catalog, balance, quote, order, grants, incognito, setIncognito, boost, setDelivery
webhooks verify, parse
mcp call

HTTP clients, middleware and logging

All integrations are optional. Only install the packages you use. The last three arguments of the client are a Transport, a Logger and a list of Middleware instances. Defaults are cURL, no logging and an empty list. The same client configuration applies to all services.

Guzzle 7 and other PSR-18 clients

Run composer require guzzlehttp/guzzle:^7.5. Keep your existing Guzzle HandlerStack, including any native middleware. The adapter accepts a PSR-18 client and PSR-17 request and stream factories.

$factory = new GuzzleHttp\Psr7\HttpFactory();
$http = new GuzzleHttp\Client(['connect_timeout' => 5, 'timeout' => 20]);
$transport = new Pereval\Psr18Transport($http, $factory, $factory);
$client = new Pereval\Client($key, $origin, '', '', $transport);

Configure timeouts, TLS verification and redirect handling on third-party clients. Use a client that returns redirects and 4xx/5xx responses to the SDK. Do not forward partner headers to another origin. PSR-18 clients may buffer the body before the SDK reads it.

Symfony HttpClient

Run composer require symfony/http-client. Pass an existing Symfony client or decorator directly. This adapter disables redirects and buffering and sets a 20-second maximum duration per request.

$http = Symfony\Component\HttpClient\HttpClient::create();
$transport = new Pereval\SymfonyTransport($http);
$client = new Pereval\Client($key, $origin, '', '', $transport);

Custom extensions and PSR-3 logging

Implement Transport::send to accept a method, full URL, list of header lines and nullable raw body. Return [HTTP status, content type, raw bytes], including for non-2xx responses. Throw on transport failure. Preserve TLS checks and disable redirects. Your own transport needs no PHP packages or cURL.

Implement Logger::log or use Psr3Logger with any PSR-3 logger such as Monolog. Implement Middleware::wrap to decorate a transport, or adapt a function directly. The first registered layer is outermost. Native client middleware runs inside it.

$logger = new Pereval\Psr3Logger($applicationLogger);
$trace = new Pereval\CallableMiddleware(static function (
    Pereval\Transport $next, string $method, string $url, array $headers, ?string $body
): array {
    $headers[] = 'X-Request-ID: ' . bin2hex(random_bytes(16));
    return $next->send($method, $url, $headers, $body);
});
$client = new Pereval\Client($key, $origin, '', '', $transport, $logger, [$trace]);

The SDK emits one log record per transport call chain with method, HTTP status (null on transport failure) and duration in milliseconds. Logging is synchronous. Logger exceptions cannot change the result. Use a buffered logger for slow sinks. Only trusted middleware should handle raw requests. Third-party debug logging can expose headers and member data independently of SDK logging. See custom implementations and adapter tests.

Delivery and retries

  • Messaging sends a greeting after a mutual like. Store references before sending. A client message ID must be unique per sender across matches.
  • Webhooks verifies the original request body. Store each event once by ID before acknowledging delivery. Map the returned status to your framework's HTTP response.
  • Polling works with cron. Load the last saved cursor (initially 0), pass your event and cursor storage callbacks, and prevent overlapping runs. If storage fails, throw and replay the page. Deduplicate by event ID across both delivery channels.

The default cURL transport makes one request per call, disables redirects and sets a 5-second connect timeout and a 20-second request timeout. Responses are limited to 15 MiB. Catch Pereval\ApiException for HTTP errors (getCode() is the status, error and detail hold API fields), Pereval\RpcException for RPC failures and JsonException for malformed JSON. Custom clients can throw their own exceptions. cURL failures throw RuntimeException. Retry writes only with appropriate idempotency guarantees. Never log keys, raw request bodies or personal data.

Development

From a source checkout run php tests/run.php for offline coverage of all 39 operations. Use composer install and composer test:integrations to include Guzzle, Symfony HttpClient and Monolog.

MIT licensed. See LICENSE.