Search by

iexexchanger / exchanger-sdk-php

devexchanger

PHP client for the iEXExchanger Public API.

Package info

github.com/iexexchanger/exchanger-sdk-php

pkg:composer/iexexchanger/exchanger-sdk-php

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-12-05 22:50 UTC

This package is auto-updated.

Last update: 2026-12-05 23:05:09 UTC


README

A PHP 8.5 client for all 79 iEXExchanger Public API v3 operations and incoming v2 webhooks. Operations by public method · Executable examples · Russian quickstart

Install from GitHub

Run these commands in the consuming project after the v0.1.0 release is available. The SDK installs Guzzle as its default transport and PSR-17 factory. The built-in transport requires PHP's cURL extension linked to libcurl 8.3.0 or newer. It fails at client construction when those requirements are unmet.

composer config repositories.exchanger vcs https://github.com/iexexchanger/exchanger-sdk-php
composer require 'iexexchanger/exchanger-sdk-php:^0.1'

For a local checkout during development, use a Composer path repository and require iexexchanger/exchanger-sdk-php:@dev instead.

Call the public and private endpoints

use IEXExchanger\Sdk\Api\RequestOptions;
use IEXExchanger\Sdk\Client;
use IEXExchanger\Sdk\Config;
use IEXExchanger\Sdk\Credentials;

$client = new Client(new Config(
    origin: 'https://exchange.example',
    credentials: new Credentials(bearerToken: $token, hmacSecret: $secret),
    locale: 'en',
    timeoutSeconds: 30,
    connectTimeoutSeconds: 5,
));
$public = $client->platform()->ping();
$signed = $client->platform()->privatePing(new RequestOptions(locale: 'ru'));

printf("%s %s\n", $signed->result->siteName, $signed->metadata->requestId);

Load $token and $secret from your application's secret store. The SDK sends credentials and HMAC v2 headers only for private operations. A fresh timestamp and nonce are generated for each private call. Public ping also works with a configuration that omits credentials.

Supply the installation origin, such as https://exchange.example, to Config. Each API method supplies its own path. For a local HTTP sandbox, enable allowInsecureLoopback and use a literal loopback IP host in 127.0.0.0/8 or [::1]; the hostname localhost is rejected for HTTP because its resolution can change. The built-in Guzzle transport sends these HTTP loopback requests directly, bypassing environment proxy settings. It uses cURL, has bounded connection and total timeouts, follows no redirects, sends no cookies, and does not retry or debug-log requests. You can inject your own PSR-18 client and PSR-17 factories through the other Client constructor parameters; the injected transport must return redirects, preserve signed request bytes, and disable automatic retries and debug logging. The caller owns response-header limits for an injected transport.

Opaque path identifiers are bounded before percent encoding. An identifier consisting only of . or .. is rejected because HTTP clients may normalize navigation segments after the SDK has signed the path. The internal executor also rejects raw or percent-encoded dot segments in a complete path before dispatch.

The API response body is limited to 2 MiB and 50,000 JSON structural tokens by default. The built-in Guzzle transport requests Accept-Encoding: identity, disables automatic decompression, and applies the byte bound to raw response entity bytes during download, including chunked responses. It rejects a response with any non-identity Content-Encoding before reading its body. This keeps the wire limit effective even if an origin ignores the requested encoding. The decoder enforces both bounds for injected PSR-18 transports, whose own network buffering and decompression remain the application's responsibility. Use pagination for large collections. If a legitimate response needs more room, set Config(maxResponseBytes: ..., maxResponseTokens: ...) and provision PHP memory for the decoded object graph, which can be much larger than the wire body. Exceeding either bound raises ProtocolException with available HTTP metadata.

Response headers are limited to 256 fields and 64 KiB; repeated field values each count toward the field limit. The built-in transport checks incoming header lines before Guzzle builds its response and checks the parsed map again before body decoding. It also requires libcurl 8.3 or newer, which has its own aggregate header limit. Rejection metadata retains only the HTTP status and short request, correlation, and retry headers. Injected PSR-18 transports must bound header buffering before returning their response; the decoder applies the parsed-map limit afterward.

Outgoing JSON is limited to 4 MiB by default, configurable with Config(maxRequestBodyBytes: ...). Raw JSON is size-checked before validation. Structured arrays and stdClass objects are checked for their encoded bytes, including JSON escapes and punctuation, at most 64 nesting levels, and 50,000 structural nodes before encoding. Dynamic exchange and verification maps are checked against the configured limit before conversion to JSON objects; numeric field IDs retain their object-key representation. The exact encoded byte limit is checked again after encoding. Custom objects and JsonSerializable are rejected on this structured path because their output can expand unpredictably; encode them yourself and supply the exact JSON string if needed. CreateOrderRequest::toJson(maxBytes: ...) applies the same default limit before you persist bytes for an idempotent retry.

Multipart uploads accept at most 64 MiB of file contents by default, configurable with Config(maxUploadBytes: ...). The SDK checks this before building the request and writes multipart framing to a temporary stream in bounded chunks; the file digest still covers only the original bytes. Check the installation's advertised intent or field limit and bound file reading in your application before constructing Upload. Raising the SDK limit also requires sufficient temporary disk space for one multipart body. Filenames are limited to 4,096 bytes and media types to 255 bytes.

Routine print_r, var_dump, and json_encode of Upload show only redacted metadata; they omit the filename and file contents, including invalid UTF-8 bytes. Multipart signing and transmission still use its explicit public filename, contents, and contentType properties. Explicit var_export and native serialize include those public values, so do not use them for diagnostics.

Responses expose the typed result, localized message, and metadata. The metadata includes the HTTP status, request and correlation IDs, and the server timestamp when available. API rejections throw ApiException with the server's machine-readable errorCode. An unexpected HTTP response throws ProtocolException, and a failed HTTP exchange throws TransportException.

Routine print_r, var_dump, and json_encode of PaymentInstructions and FieldUpload hide checkout links, account details, file tokens, and raw result objects. Read their public properties explicitly when processing a payment or attaching a field upload. The generic Response and ResponseMetadata remain data-bearing, so avoid logging an entire API response or an explicit var_export/native serialize of these public result objects.

Webhook event and delivery pages and order receipt pages accept at most 100 items, matching the server page limit. A malformed larger page raises ProtocolException before item hydration.

ApiException::getMessage() contains a fixed diagnostic independent of server text. The server's exact localized text is available only through localizedMessage(). The public errorCode remains available for application decisions; control characters are escaped and long codes are limited, while rawErrorCode() returns the exact server value. Routine exception strings, print_r/var_dump, and json_encode omit server-provided message, code, details, and metadata. Treat explicit access to those fields, var_export of the exception, response metadata, and typed customer results as sensitive application data. The SDK removes raw result arguments from malformed-response exception traces.

ProtocolException keeps its specific field description in getMessage() and exposes HTTP metadata for explicit recovery and diagnostics. Its print_r/var_dump and JSON representations show only a fixed description and numeric HTTP status, avoiding accidental export of response headers or envelope fields. As with other exceptions, avoid logging an explicitly retrieved metadata object without selecting safe fields.

Exchange and payment

Use exchange() for payment systems, routes, capabilities, quotes and simulation. Use orders() for preflight, execution, payment instructions, payment status and receipts.

use IEXExchanger\Sdk\Api\Exchange\CreateOrderRequest;
use IEXExchanger\Sdk\Api\Exchange\QuoteRequest;

$pricing = new QuoteRequest(amount: '10', routeId: $routeId);
$quote = $client->exchange()->quote($pricing)->result;
$input = new CreateOrderRequest(
    quote: $pricing,
    fromRequisite: $fromRequisite,
    toRequisite: $toRequisite,
    snapshot: $quote->snapshot,
);
$preflight = $client->orders()->preflight($input)->result;
if (!$preflight->canCreateOrder) {
    throw new RuntimeException('Preflight declined the order.');
}

$body = $input->toJson();
// Persist the exact body and operation key together before sending them.
$created = $client->orders()->create($body, $operationKey);

Reuse the saved body and key after an ambiguous failure. For receipts, reuse the exact file bytes, filename and media type. The response metadata exposes idempotencyReplayed. Payment confirmation and provider-confirmed payment are separate fields.

List methods accept documented filters and pagination. Queries are limited to 1,024 encoded parameters, 64 KiB after encoding, and 65,536 visited array entries including omitted values. Request a smaller page or narrower filter when a query reaches a bound. With cursor pagination, keep the filters and sort and use the server's next cursor. Receipts return their own after-ID continuation. RequestOptions accepts a locale, correlation ID and an optional idempotency key on writes.

Opaque identifiers placed in URL path segments are limited to 4,096 input bytes and 8,192 bytes after percent encoding. The complete API-relative path is limited to 16,384 bytes. The SDK checks these limits before allocating an escaped URL or sending a request; accepted identifiers keep the same percent-encoded wire representation.

RequestOptions, request DTOs, and VerificationQuery hide sensitive values from ordinary print_r, var_dump, and json_encode diagnostics. Generic json_encode($request) now returns redacted diagnostics; call the documented toPayload(), toJson(), or toQuery() method when you need the exact API payload. Public properties remain accessible for application logic. Explicit var_export and native serialize of these public objects can still include their values; select safe fields before exporting them.

Verification, partner and webhooks

  • verification() handles order, identity and card verification, including single-file upload intents.
  • partner() handles balance, exchanges, referrals and payouts. An omitted amount selects the available balance. Supply an exact decimal string and a durable operation key for a payout of a specific amount.
  • account() exposes the integration's customer profile and reviews.
  • webhooks() manages subscriptions and delivery history. For incoming events, construct IEXExchanger\Sdk\Api\Webhooks\Verifier with the subscription secret. Pass the original headers and raw body to verify() and store the authenticated event ID for deduplication.
  • platform() exposes scopes, usage, health and the published contracts and schemas.

The webhook verifier rejects bodies above 1 MiB, more than 256 header values, more than 64 KiB of aggregate headers, and event types longer than 128 bytes by default. Its constructor accepts maxBodyBytes, maxHeaderFields, maxHeaderBytes, and maxEventTypeBytes for installations with different limits. These checks run before header normalization, the body digest, and HMAC. Bound headers at your HTTP server or ingress before PHP materializes them, and apply the same body limit while reading the request; then pass the original bytes to verify(). The receiver example returns HTTP 431 when the header count is exceeded. A valid signature does not replace event-ID deduplication.

For subscription creation and secret rotation, save the returned secret and the operation's idempotency key. Replay recovery lasts only while the server retains its idempotency record. The current JPcoin default is 24 hours and installations can configure 1–720 hours. After that window, inspect the subscription state before retrying: a late create can add another endpoint, and a late rotation can replace the secret again.

Webhook endpoint responses expose the exact callback url property for application use. Routine print_r/var_dump and json_encode of an endpoint redact that URL, because its query string may contain a bearer token. Explicit var_export of the public endpoint object still includes its URL; select safe fields before logging or exporting it.

Development checks

composer install
composer validate --strict
composer test
composer analyse
composer lint

Optional live testing uses IEX_SDK_TEST_ORIGIN, IEX_SDK_TEST_BEARER_TOKEN, and IEX_SDK_TEST_HMAC_SECRET. Set those environment variables for an isolated test installation, then run composer test:live. The test sends one public ping and two consecutive signed pings and checks the returned types and tracing identifiers.