Agentic Commerce Protocol for Magento 2
October 10, 2025 ยท View on GitHub
95% OpenAI ACP Spec Compliant | Pre-Production | Awaiting Platform Access
Enable ChatGPT purchases directly from your Magento 2 store using the Agentic Commerce Protocol (ACP) - an open standard by OpenAI and Stripe.
โ ๏ธ Status: This module is spec-compliant and fully tested with unit/integration tests, but has NOT been tested with actual OpenAI ChatGPT platform access. We are awaiting approval from OpenAI's merchant program. Use at your own risk until platform testing is complete.
๐ Features
โ OpenAI ACP Specification Compliance (95%)
Checkout Session API:
- Enhanced response schema with
line_items,total_details,fulfillment_options - All monetary values as integers (cents) per spec
- Correct status enums:
not_ready_for_payment,ready_for_payment,completed,cancelled - Order tracking with
order_urlandconfirmation_email_sent - Shipping method selection via
fulfillment_option_id
Product Feed:
- Spec-compliant fields:
id,title,link,brand,images,inventory_quantity - Configurable product variants with individual pricing
- Multiple image support (full gallery)
- Real-time inventory levels
- Per-product control flags (
acp_enable_search,acp_enable_checkout) - CLI feed generation (
bin/magento acp:feed:generate) - Automated feed regeneration (cron every 6 hours)
- Static file support for large catalogs (10k+ products)
Security Headers:
Idempotency-Keyvalidation (Redis-backed, 24hr cache)Request-Idtracking for correlationTimestampvalidation (5min tolerance, prevents replay attacks)SignatureHMAC SHA256 validation (optional, configurable)API-Versioncompatibility checking
Core Functionality
- โ Full REST API (5 endpoints: create, get, update, complete, cancel)
- โ Real Magento Quote integration (pricing, taxes, discounts, inventory)
- โ Stripe Delegated Payment with official SDK
- โ
Webhook notifications (
order.created,order.updated) - โ Multi-currency support
- โ Database persistence with proper ResourceModel pattern
- โ Automated session cleanup cron job
Security & Enterprise Features
- โ Bearer token API authentication
- โ Idempotency key duplicate prevention
- โ Timestamp-based replay attack prevention
- โ HMAC signature validation (configurable)
- โ Encrypted secret storage
- โ ACL permissions
- โ Comprehensive audit logging
Developer Experience
- โ 39 Tests (31 unit + 8 integration) covering critical paths
- โ Monetary conversion accuracy tests
- โ Security validation tests
- โ End-to-end API flow tests
- โ PSR-12 compliant code
- โ Proper Magento service contracts
- โ Full dependency injection
- โ Type-safe (strict_types everywhere)
๐ Requirements
- Magento: 2.4.6+
- PHP: 8.1+
- Composer: 2.x
- Redis: For caching (idempotency keys)
- Stripe Account: For payment processing
๐ฆ Installation
Via Composer (Recommended)
composer require run-as-root/module-agentic-commerce-protocol
bin/magento module:enable RunAsRoot_AgenticCommerceProtocol
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush
Manual Installation
git clone https://github.com/run-as-root/ACP-for-Magento-2.git
mkdir -p app/code/RunAsRoot/AgenticCommerceProtocol
cp -r ACP-for-Magento-2/* app/code/RunAsRoot/AgenticCommerceProtocol/
bin/magento module:enable RunAsRoot_AgenticCommerceProtocol
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush
โ๏ธ Configuration
Navigate to Stores > Configuration > Agentic Commerce Protocol
1. General Settings
- Enable Module: Turn on/off the ACP functionality
- API Key: Generate secure key for OpenAI authentication
- Test Mode: Enable verbose logging for development
- Session Retention: Days to keep completed sessions (default: 30)
2. Security Settings (NEW)
- Enable Signature Validation: HMAC SHA256 request signing
- Signature Secret: Shared secret for signature verification
- Timestamp Tolerance: Replay attack window (default: 300 seconds)
3. Product Feed
- Enable Product Feed: Allow ChatGPT product discovery
- Include Categories: Filter by category (empty = all)
- Maximum Products: Limit feed size (default: 1000)
4. Webhook Settings
- Enable Webhooks: Send order events to OpenAI
- Endpoint URL: OpenAI webhook receiver
- Signing Secret: HMAC signature for webhooks
5. Stripe Payment
- Enable Stripe: Use Stripe for payment processing
- Secret Key: Your Stripe API key (sk_live_* or sk_test_*)
- Test Mode: Use Stripe test environment
๐ API Endpoints
Checkout Session API (Requires Authentication)
All endpoints require these headers:
Authorization: Bearer <api-key>
Idempotency-Key: <unique-request-id>
Request-Id: <correlation-id>
Timestamp: <unix-timestamp>
Create Session
POST /rest/V1/acp/checkout_sessions
Content-Type: application/json
{
"items": [
{"sku": "24-MB01", "quantity": 2}
]
}
Update Session
POST /rest/V1/acp/checkout_sessions/{id}
{
"buyer": {
"email": "customer@example.com",
"first_name": "John",
"last_name": "Doe"
},
"fulfillment_address": {
"first_name": "John",
"last_name": "Doe",
"address_line1": "123 Main St",
"city": "New York",
"state": "NY",
"postal_code": "10001",
"country": "US"
},
"fulfillment_option_id": "flatrate_flatrate"
}
Get Session
GET /rest/V1/acp/checkout_sessions/{id}
Complete Session
POST /rest/V1/acp/checkout_sessions/{id}/complete
{
"payment_data": {
"token": "pm_stripe_token_here"
}
}
Cancel Session
POST /rest/V1/acp/checkout_sessions/{id}/cancel
Product Feed (Public)
GET /acp/feed
Returns JSON feed with all visible products in ACP format.
๐ง CLI Commands
Generate Static Product Feed
bin/magento acp:feed:generate
# Options:
bin/magento acp:feed:generate --store=1 --output=custom_feed.json
Generates a static JSON feed file in var/acp/feed.json for improved performance with large catalogs.
Benefits:
- Pre-generate feeds for 10k+ product catalogs
- Reduce real-time server load
- Automated regeneration via cron (every 6 hours)
- Custom output paths for multi-store setups
๐งช Testing
Run Unit Tests (31 tests)
cd Test/Unit
../../../vendor/bin/phpunit
Run Integration Tests (8 tests)
cd magento
bin/magento dev:tests:run integration RunAsRoot_AgenticCommerceProtocol
Test Coverage:
- โ Monetary conversion accuracy
- โ Security header validation
- โ Response schema compliance
- โ End-to-end checkout flows
- โ Idempotency and replay protection
๐๏ธ Architecture
Follows Magento 2 best practices:
Structure:
Model/
โโโ Response/ # ACP response builders
โ โโโ CheckoutSessionResponseBuilder.php
โ โโโ LineItemBuilder.php
โ โโโ TotalDetailsBuilder.php
โ โโโ FulfillmentOptionsBuilder.php
โโโ Auth/ # Security validators
โ โโโ HeaderValidator.php
โ โโโ IdempotencyManager.php
โ โโโ SignatureValidator.php
โ โโโ TimestampValidator.php
โโโ CheckoutSessionManagement.php
โโโ Order/OrderManagement.php
โโโ Feed/ProductFeedGenerator.php
Plugin/
โโโ ApiAuthenticationPlugin.php
โโโ CheckoutSessionResponsePlugin.php
Test/
โโโ Unit/ # 31 unit tests
โโโ Integration/ # 8 integration tests
Patterns Used:
- Service Contracts (
Api/) - Dependency Injection (constructor)
- Plugin/Interceptor pattern
- Repository pattern
- Builder pattern (responses)
- Strategy pattern (validators)
๐ค Contributing
- Fork the repository
- Create feature branch (
git checkout -b feature/awesome-feature) - Write tests for new functionality
- Ensure all tests pass
- Commit with clear message (
git commit -m 'feat: add awesome feature') - Push and open Pull Request
Quality Standards:
- โ Unit tests required for new code
- โ Integration tests for API changes
- โ PSR-12 coding standards
- โ Type hints and strict_types
- โ PHPStan level 8 compliance
๐ License
MIT License - see LICENSE file
๐ Resources
๐ฌ Support
Issues & Questions: GitHub Issues
Maintainer: run_as_root GmbH info@run-as-root.sh
Version: 1.5 (OpenAI Certification Ready)
๐ฏ OpenAI Certification Status
Current Compliance: 95% (Spec-Compliant, Awaiting Platform Testing)
Completed:
- โ All required response fields per ACP spec
- โ Correct monetary value format (cents)
- โ Proper status enums
- โ Complete header validation
- โ Product feed spec compliance
- โ Security features (idempotency, replay protection)
- โ 39 comprehensive tests (unit + integration)
Status:
- โ Code complete and spec-compliant
- โ Unit and integration tests passing
- โณ Awaiting OpenAI platform access for live testing
- โณ Merchant application submitted, pending approval
NOT YET TESTED WITH:
- โ Actual ChatGPT Instant Checkout interface
- โ Real OpenAI API calls
- โ OpenAI conformance test suite
Timeline:
- โณ Awaiting OpenAI merchant program approval
- Platform testing & conformance tests (est. 2-3 weeks)
- Bug fixes from platform testing (est. 1-2 weeks)
- Final certification submission
- Production deployment
Application: https://chatgpt.com/merchants