Provides logic shared between Pricemotion integrations for PHP e-commerce systems

v1.2.2 2022-08-09 09:47 UTC

This package is auto-updated.

Last update: 2024-12-09 14:41:16 UTC


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 required 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();
}