pricemotion / sdk
Provides logic shared between Pricemotion integrations for PHP e-commerce systems
Installs: 1 286
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
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
This SDK is used internally for Pricemotion's integrations with different e-commerce systems. It may also be used by customers to integrate with custom or unsupported systems.
Currently this SDK does not provide a complete interface for Pricemotion's API. What it does contain is logic for handling webhook requests, and for processing the XML returned by the Pricemotion API.
Links:
Getting started
Installation is easy, whether you use Composer or not.
With Composer
Run:
composer require pricemotion/sdk
Make sure that vendor/autoload.php
is require
d in your scripts.
Without Composer
Download the source code from the Releases page on GitHub.
Extract it.
Require autoload.php
in your scripts.
Dependency injection
If you use a framework that supports automatic dependency injection (autowiring) such as Symfony, or have manually integrated a dependency container such as PHP-DI in your project, you should be able to use it to automatically initialize most of the classes in this SDK.
Handling webhooks
A cache is required for storing Pricemotion's public keys, so that they do not have to retrieved on each request. Any cache that implements Symfony's cache contract is supported.
For example, you might install symfony/cache
using Composer and initialize it
as follows:
use Symfony\Component\Cache\Adapter\FilesystemAdapter; $cache = new FilesystemAdapter();
With the cache ready, you can decode incoming webhook requests as follows:
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();
Using product data
Getting the EAN:
$product->getEan()->toString();
Getting the product name:
$product->getName();
Getting the price statistics:
$product->getLowestPrice(); $product->getAveragePrice(); $product->getMedianPrice(); $product->getHighestPrice();
Getting the offers ranked from lowest to highest price:
foreach ($product->getOffers() as $offer) { $offer->getSeller(); $offer->getPrice(); }