ShopBridge PHP SDK helps merchants integrate with the Agentic Commerce Protocol (ACP). The library adheres to the official specifications published in the agentic-commerce-protocol repository and remains compatible with PHP 7.4 and newer.
- Merchant checkout lifecycle support with rich DTOs and validation (
create,update,get,complete,cancel). - Webhook signature verification and event parsing tailored to ACP payloads.
- Product feed builders for ACP-compliant catalog exports (JSON, CSV, TSV, XML).
- Framework-agnostic, PSR-7/17/18 compatible design that runs on PHP 7.4 and newer.
- PHP 7.4+
- Composer 2
- PSR-18 HTTP client and PSR-17 factories (for example
guzzlehttp/guzzletogether withguzzlehttp/psr7)
composer require shopbridge/shopbridge-phpuse GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;
use ShopBridge\Models\Checkout\PaymentData;
use ShopBridge\Requests\Checkout\CheckoutSessionCompleteRequest;
use ShopBridge\Requests\Checkout\CheckoutSessionCreateRequest;
use ShopBridge\Requests\Checkout\CheckoutSessionItemRequest;
use ShopBridge\Requests\Checkout\CheckoutSessionUpdateRequest;
use ShopBridge\ShopBridge;
use ShopBridge\Support\HmacSignatureGenerator;
$httpClient = new GuzzleClient();
$requestFactory = new HttpFactory();
$streamFactory = new HttpFactory();
$signatureGenerator = new HmacSignatureGenerator('merchant-secret');
$shopBridge = new ShopBridge(
$httpClient,
$requestFactory,
$streamFactory,
'https://merchant.example.com',
'sk_live_...',
$signatureGenerator
);
// Create a checkout session
$createRequest = new CheckoutSessionCreateRequest([
new CheckoutSessionItemRequest('sku_123', 1),
]);
$session = $shopBridge->checkout()->createSession($createRequest);
// Update the session
$updateRequest = new CheckoutSessionUpdateRequest([
new CheckoutSessionItemRequest('sku_123', 2),
]);
$session = $shopBridge->checkout()->updateSession($session->getId(), $updateRequest);
// Complete the checkout with a payment token
$completeRequest = new CheckoutSessionCompleteRequest(
new PaymentData('spt_abc123', 'stripe')
);
$session = $shopBridge->checkout()->completeSession($session->getId(), $completeRequest);use ShopBridge\Services\WebhookService;
use ShopBridge\Support\HmacSignatureValidator;
$validator = new HmacSignatureValidator('merchant-secret');
$webhookService = new WebhookService($validator);
try {
$event = $webhookService->parseWebhook($payload, $signatureFromHeader, 'merchant-secret');
// React to the event, for example $event->getData()->getStatus()
} catch (\ShopBridge\Exceptions\InvalidSignatureException $exception) {
// Signature verification failed — reject the request
} catch (\ShopBridge\Exceptions\TransportException $exception) {
// Payload is not valid JSON or is missing required ACP fields
}use PDO;
use ShopBridge\Models\Common\Currency;
use ShopBridge\Models\Common\Money;
use ShopBridge\ProductFeed\CsvFormatter;
use ShopBridge\ProductFeed\Product;
use ShopBridge\ProductFeed\ProductFeedBuilder;
$pdo = new PDO('mysql:host=localhost;dbname=shop', 'user', 'pass');
$builder = new ProductFeedBuilder(null, new CsvFormatter());
$products = (function () use ($pdo): \Generator {
$stmt = $pdo->query('SELECT * FROM products');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
yield new Product(
$row['sku'],
$row['title'],
$row['description'],
$row['link'],
new Money((int) $row['price_minor_units'], new Currency($row['currency'])),
(bool) $row['enable_search'],
(bool) $row['enable_checkout'],
$row['availability'],
(int) $row['inventory_quantity'],
$row['image_main'],
json_decode($row['image_additional'], true) ?? []
);
}
})();
$csv = $builder->buildString($products);
file_put_contents('feed.csv', $csv);
// For very large catalogs, stream chunks instead of building the entire string in memory:
$stream = fopen('feed.csv', 'w');
foreach ($builder->build($products) as $chunk) {
fwrite($stream, $chunk);
}
fclose($stream);We welcome contributions! Here’s how to get involved.
composer install
composer test
composer lintcomposer testruns PHPUnit.composer lintruns PHPStan (phpstan.neon.dist). Keep the report clean before opening a PR.
Helpful reports include:
- What you expected to happen vs. what happened.
- Sample payloads/responses (anonymised), SDK version, PHP version, and
API-Versionheader in use.
- Fork the repo and create a topic branch.
- Add tests/docs that cover the change.
- Run
composer testandcomposer lintlocally. - Ensure the code stays compatible with PHP 7.4 (no enums, union types, constructor property promotion, etc.).
- Reference any related issues or ACP spec updates in the PR description.
The default API-Version lives in src/Http/AcpHttpClient.php.
- ACP documentation: agenticcommerce.dev
- Official specs and examples: agentic-commerce-protocol
The SDK is under active development and not yet recommended for production workloads. If you run into trouble, open an issue and we’ll help out.