atlasflow/order-bridge
Composer 安装命令:
composer require atlasflow/order-bridge
包简介
Serialisation, validation and transport for the Atlas Core Order Bridge API.
README 文档
README
A framework-agnostic PHP package for serialising, validating, and transporting orders between Atlas Core and host applications (ePOS, E-commerce, etc.) according to the Order Bridge API Specification v1.4.2.
Core Concepts
The package owns two things exclusively:
- Serialisation: Converting host application data into spec-compliant JSON payloads.
- Validation: Enforcing all schema and arithmetic rules defined in the specification.
It is designed to be unopinionated about persistence. It does not include Eloquent models, migrations, or database logic. Instead, it defines a set of Interfaces that your application's models must implement.
Key Components
OrderSerialiser: Takes objects implementingOrderInterfaceand produces a fully validated payload array. It handles all complex arithmetic (VAT, line totals, grand totals) usingbcmathinternally.PayloadValidator: Implements all rules from §5 of the spec, including arithmetic verification and idempotency checks.HttpTransport: A thin PSR-18 compatible layer for sending payloads to Atlas Core.InboundParser: The reverse direction—parses and validates JSON from Atlas Core into typed DTOs.TransferIdManager: Utility for generating and managingtransfer_idGUIDs to ensure idempotency.
Installation
composer require atlasflow/order-bridge
Note: Requires PHP 8.4+ and the bcmath extension.
Usage Instructions
1. Implement the Interfaces
The package never touches your models directly. You must create "Adapters" that wrap your models and implement the interfaces in Atlasflow\OrderBridge\Contracts.
use Atlasflow\OrderBridge\Contracts\OrderInterface; use Atlasflow\OrderBridge\Contracts\LineItemInterface; // ... and other contracts class MyOrderAdapter implements OrderInterface { public function __construct(private MyOrderModel $order) {} public function getOriginRef(): string { return $this->order->reference; } public function getStatus(): string { return 'pos'; } // ... implement remaining methods }
2. Serialise and Send
The OrderSerialiser computes all totals for you. You only provide raw values (quantities, unit prices, discount percentages, and VAT rates).
use Atlasflow\OrderBridge\Serialiser\OrderSerialiser; use Atlasflow\OrderBridge\Transport\HttpTransport; // 1. Setup Serialiser $serialiser = new OrderSerialiser([ 'site_id' => 'site_richmond', 'site_name' => 'The Palm Centre', 'source_type' => 'cassa', ]); // 2. Serialise your order(s) // $orders should be an iterable of OrderInterface $payload = $serialiser->serialise($orders, trigger: 'realtime'); // 3. Send via HTTP (requires a PSR-18 client and PSR-17 factories) $transport = new HttpTransport($httpClient, $requestFactory, $streamFactory, $endpointUrl); $result = $transport->send($payload); if ($result->isSuccess()) { // Mark order as synced in your DB }
3. Validate a Payload
You can use the validator independently to dry-run a batch or validate inbound webhooks.
use Atlasflow\OrderBridge\Validator\PayloadValidator; $validator = new PayloadValidator(); $result = $validator->validate($payloadArray); if (!$result->isValid()) { foreach ($result->getViolations() as $violation) { echo "Error in {$violation->field}: {$violation->message}\n"; } }
4. Parse Inbound Payloads
When receiving an export from Atlas Core, use the InboundParser to get typed DTOs.
use Atlasflow\OrderBridge\Parser\InboundParser; $parser = new InboundParser(); try { $envelope = $parser->parse($jsonString); foreach ($envelope->orders as $orderDto) { // Map DTO back to your application models echo $orderDto->originRef; } } catch (ParseException $e) { // Handle malformed JSON or validation failure }
Idempotency
The package automatically generates a transfer_id (UUID v4) during serialisation. Atlas Core uses this ID combined with your site_id to prevent duplicate order processing.
If you need to retry a failed transport attempt:
- Identical Retries: Reuse the same payload (and thus the same
transfer_id). Core will acknowledge the retry without creating duplicate records. - Modified Payloads: If the content changes, you must generate a new
transfer_idby re-serialising the order.
Laravel Integration
The package ships with a first-class Laravel service provider that handles configuration publishing and wires everything up automatically.
Auto-discovery
Laravel 5.5+ will auto-discover the service provider. No manual registration is needed.
Publish the configuration file
php artisan vendor:publish --tag=order-bridge-config
This copies config/order-bridge.php into your application's config/ directory.
Configuration reference
| Key | Default | Description |
|---|---|---|
tolerance |
'0.0001' |
Arithmetic tolerance for §5.3 validation checks. |
monetary_scale |
4 |
Decimal places for all monetary output fields. |
discount_scale |
6 |
Decimal places for discount percentage strings. |
vat_rounding_scale |
2 |
Decimal places to which VAT amounts are rounded before output. Set to 4 to disable the extra rounding step. |
vat_rounding_mode |
'ceil' |
Rounding direction for VAT amounts. 'ceil' rounds toward positive infinity (always up for positive values); 'floor' rounds toward negative infinity. |
Manual registration (without auto-discovery)
Add the provider to config/app.php:
'providers' => [ Atlasflow\OrderBridge\Laravel\OrderBridgeServiceProvider::class, ],
Framework-agnostic usage
Outside of Laravel the package works out of the box with sensible defaults. If you need to override the defaults at runtime, call SchemaVersion::configure() early in your bootstrap:
use Atlasflow\OrderBridge\SchemaVersion; SchemaVersion::configure([ 'vat_rounding_mode' => 'floor', 'vat_rounding_scale' => 2, ]);
License
The MIT License (MIT). Please see License File for more information.
atlasflow/order-bridge 适用场景与选型建议
atlasflow/order-bridge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 56 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「order」 「Bridge」 「ERP」 「atlasflow」 「atlascore」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 atlasflow/order-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atlasflow/order-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 atlasflow/order-bridge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Soluble PHP Java bridge integration
Bridge between JMS Serializer Bundle and Superdesk Web Publisher.
Sylius plugin that adds the possibility to add products to the shopping cart using a button on the product card.
An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).
Builds a Bridge between Zend Expressive and Plugin Managers of Zend\MVC
Módulo base para Magento
统计信息
- 总下载量: 56
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2026-03-31