pricemotion / sdk
为PHP电子商务系统提供Pricemotion集成共享逻辑
v1.2.2
2022-08-09 09:47 UTC
Requires
- php: >=7.4
- ext-curl: *
- ext-dom: *
- ext-json: *
- ext-sodium: *
Requires (Dev)
- phpunit/phpunit: ^9.5
- psr/log: ^3.0
- symfony/cache: ^6.0
README
此SDK用于Pricemotion与不同电子商务系统的内部集成。客户也可以使用它来集成自定义或不受支持的系统。
目前此SDK不提供Pricemotion API的完整接口。它包含处理webhook请求的逻辑,以及处理Pricemotion API返回的XML的逻辑。
链接
入门
安装简单,无论是否使用Composer。
使用Composer
运行
composer require pricemotion/sdk
确保在您的脚本中包含vendor/autoload.php
。
不使用Composer
从GitHub的发行页面下载源代码。
解压。
在您的脚本中包含autoload.php
。
依赖注入
如果您使用支持自动依赖注入(autowiring)的框架,如Symfony,或者已手动集成依赖容器(如PHP-DI)到项目中,您应该能够使用它来自动初始化此SDK中的大多数类。
处理webhook
需要一个缓存来存储Pricemotion的公钥,以便在每次请求时不必检索。支持实现Symfony缓存协议的任何缓存。
例如,您可以使用Composer安装symfony/cache
,并按如下方式初始化它
use Symfony\Component\Cache\Adapter\FilesystemAdapter; $cache = new FilesystemAdapter();
缓存准备就绪后,您可以按如下方式解码传入的webhook请求
use Pricemotion\Sdk\Crypto\SignatureVerifier; use Pricemotion\Sdk\Api\WebhookRequestFactory; $body = file_get_contents('php://input'); $signatureVerifier = new SignatureVerifier($cache); $webhookRequestFactory = new WebhookRequestFactory($signatureVerifier); $webhookRequest = $webhookRequestFactory->createFromRequestBody($body); $product = $webhookRequest->getProduct();
使用产品数据
获取EAN
$product->getEan()->toString();
获取产品名称
$product->getName();
获取价格统计信息
$product->getLowestPrice(); $product->getAveragePrice(); $product->getMedianPrice(); $product->getHighestPrice();
获取从最低到最高价格排序的报价
foreach ($product->getOffers() as $offer) { $offer->getSeller(); $offer->getPrice(); }