ecomlogic/php-sdk

PHP client for eComlogic API

v1.0.7 2017-10-24 14:00 UTC

This package is auto-updated.

Last update: 2024-11-08 10:04:30 UTC


README

PHP-client for eComlogic API.

Requirements

  • PHP 5.4 and above
  • PHP's cURL support

Install

  1. Get composer

  2. Run into your project directory:

composer require ecomlogic-com/php-sdk 1.* --no-dev

If you have not used composer before, include autoloader into your project.

require 'path/to/vendor/autoload.php';

Usage

Get order

$client = new \Ecomlogic\ApiClient(
    'https://demo.ecomlogic.com',
    'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
    'v5'
);


try {
    $response = $client->request->ordersGet('M-2342');
} catch (\Ecomlogic\Exception\CurlException $e) {
    echo "Connection error: " . $e->getMessage();
}

if ($response->isSuccessful()) {
    echo $response->order['totalSumm'];
    // or $response['order']['totalSumm'];
    // or
    //    $order = $response->getOrder();
    //    $order['totalSumm'];
} else {
    echo sprintf(
        "Error: [HTTP-code %s] %s",
        $response->getStatusCode(),
        $response->getErrorMsg()
    );

    // error details
    if (isset($response['errors'])) {
        print_r($response['errors']);
    }
}

Create order

$client = new \Ecomlogic\ApiClient(
    'https://demo.ecomlogic.com',
    'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
    'v4'
);

try {
    $response = $client->request->ordersCreate(array(
        'externalId' => 'some-shop-order-id',
        'firstName' => 'John',
        'lastName' => 'Doe',
        'items' => array(
            //...
        ),
        'delivery' => array(
            'code' => 'dhl',
        )
    ));
} catch (\Ecomlogic\Exception\CurlException $e) {
    echo "Connection error: " . $e->getMessage();
}

if ($response->isSuccessful() && 201 === $response->getStatusCode()) {
    echo 'Order successfully created. Order ID into eComlogic = ' . $response->id;
        // or $response['id'];
        // or $response->getId();
} else {
    echo sprintf(
        "Error: [HTTP-code %s] %s",
        $response->getStatusCode(),
        $response->getErrorMsg()
    );

    // error details
    if (isset($response['errors'])) {
        print_r($response['errors']);
    }
}