Skip to content

Commit bf386ec

Browse files
author
Eayshwary
committed
ic
0 parents  commit bf386ec

File tree

175 files changed

+11221
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+11221
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (C) 2016, Rocket Internet SE
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the "Software"),
7+
to deal in the Software without restriction, including without limitation
8+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
and/or sell copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## 1) Requirements
2+
3+
PHP 5.5 and later.
4+
5+
### Composer
6+
You can install the sdk via [Composer](http://getcomposer.org/). Run the following command:
7+
8+
```bash
9+
composer require rocket-labs/sellercenter-sdk-php
10+
```
11+
12+
To use the sdk code, use Composer's [autoload](https://getcomposer.org/doc/00-intro.md#autoloading):
13+
14+
```php
15+
require_once('vendor/autoload.php');
16+
```
17+
18+
## 2) Implemented methods
19+
20+
These methods can be accessed through `RocketLabs\SellerCenterSdk\Endpoint\Endpoints` class:
21+
22+
- Order endpoint - `Endpoints::order()`
23+
- GetOrders
24+
- GetOrder
25+
- GetDocument
26+
- GetOrderItems
27+
- SetStatusToCanceled
28+
- SetStatusToPackedByMarketplace
29+
- SetStatusToReadyToShip
30+
31+
All another methods you can call with `GenericRequest`, for more information please look at [this sample](samples/genericGetter.php) for GET-methods or [this one](samples/genericPost.php) for POST-methods.
32+
33+
## 3) Samples
34+
To understand how to work with the SDK, please look at [samples](samples/).
35+
To make the samples work, change the API settings in [samples/config/config.php](samples/config/config.php).
36+
You need to set up the SellerCenter URL (only https is supported), your login and API key.
37+
> **API key** can be found in your SellerCenter account under Settings > Manage Users. If a given user has no API key yet, generate it by clicking a corresponding link.
38+
39+
After this you can run any sample and see the real results requests.
40+
41+
> **Please note**, that POST requests could affect on your real products, orders etc. Make sure that SKUs or Order IDs
42+
in samples are not intersect with data in your SellerCenter account.
43+
44+
### 3.1) Generic Samples
45+
You can access every API Method by using the GenericRequest class and the core implementation.
46+
47+
**see sample in action**
48+
```bash
49+
cd samples
50+
php ./genericGetter.php
51+
```
52+
53+
### 3.1) Endpoints Samples
54+
For the most important API endpoints the SDK provides facades for simple API usage. See [endpoint samples here](samples/endpoint/).
55+
56+
The following code describes the pattern how to use the endpoints implementation:
57+
```php
58+
<?php
59+
use RocketLabs\SellerCenterSdk\Core\Client;
60+
use RocketLabs\SellerCenterSdk\Core\Configuration;
61+
use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;
62+
63+
// create client instance with your credetials
64+
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
65+
66+
// get response for a certain api call with fluent interface:
67+
// Endpoints - name of endpoint - api method to call - call($client)
68+
$response = Endpoints::orders()->getOrder(12)->call($client);
69+
70+
// Or, for some complex methods, RequestBuilders can be used,
71+
// In such cases API command will have following structure:
72+
// Endpoints - name of endpoint - api method to call - some builder's setters - build - call($client)
73+
$response = Endpoints::orders()->getOrders()->setSorting('created_at', 'ASC')->setLimit(12)->build()->call($client);
74+
```
75+
76+
**see a sample in action**
77+
78+
open file of a sample. For example `samples/endpoint/order/getOrder.php`, and change the variable `$orderId` to contain order id of your seller.
79+
Then run it in the console:
80+
81+
```bash
82+
php ./samples/endpoint/order/getOrder.php
83+
```
84+

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "rocket-labs/sellercenter-sdk-php",
3+
"description": "SellerCenter SDK for PHP",
4+
"license": "MIT",
5+
"require": {
6+
"php": ">=5.5",
7+
"guzzlehttp/guzzle": "~6.1",
8+
"psr/http-message": "~1.0"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "~4.8,<5.2"
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"": "src"
16+
}
17+
},
18+
"minimum-stability": "stable"
19+
}

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false"
11+
bootstrap="./test/bootstrap.php"
12+
>
13+
<testsuites>
14+
<testsuite name="RocketLabs\SellerCenterSdk Unit Test Suite">
15+
<directory>./test</directory>
16+
</testsuite>
17+
</testsuites>
18+
<filter>
19+
<whitelist>
20+
<directory>./src/</directory>
21+
</whitelist>
22+
</filter>
23+
</phpunit>

samples/config/config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
const SC_API_URL = 'https://sellercenter.api.url/';
4+
const SC_API_USER = 'api@sellercenter.net';
5+
const SC_API_KEY = '9ffe39feb6efcdafc2ac3c045c7ec4fa3cf26924';

samples/endpoint/feed/feedList.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
use RocketLabs\SellerCenterSdk\Core\Client;
4+
use RocketLabs\SellerCenterSdk\Core\Configuration;
5+
use RocketLabs\SellerCenterSdk\Core\Response\ErrorResponse;
6+
use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;
7+
use RocketLabs\SellerCenterSdk\Endpoint\Feed\Model\Feed;
8+
9+
require_once __DIR__ . '/../../../vendor/autoload.php';
10+
require_once __DIR__ . '/../../config/config.php';
11+
12+
/**
13+
* @param string $label
14+
* @param int|string|float $value
15+
*/
16+
function printOut($label, $value)
17+
{
18+
printf("% 20s %s \n", $label, $value);
19+
}
20+
21+
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
22+
23+
$response = Endpoints::feed()->feedList()->call($client);
24+
25+
if ($response instanceof ErrorResponse) {
26+
printf("ERROR !\n");
27+
printf("%s\n", $response->getMessage());
28+
} else {
29+
30+
/** @var Feed $feed */
31+
foreach ($response->getFeeds() as $feed) {
32+
printOut('Feed', $feed->getFeed());
33+
printOut('Status', $feed->getStatus());
34+
printOut('Action', $feed->getAction());
35+
printOut('Creation Data', $feed->getCreationDate()->format('Y-m-d H:i:s'));
36+
printOut('Updated Date', $feed->getUpdatedDate()->format('Y-m-d H:i:s'));
37+
printOut('Source', $feed->getSource());
38+
printOut('Total Records', $feed->getTotalRecords());
39+
printOut('Processed Records', $feed->getProcessedRecords());
40+
printOut('Failed Records', $feed->getFailedRecords());
41+
42+
$failureReports = $feed->getFailureReports();
43+
if (!is_null($failureReports)) {
44+
printOut('Failure Reports', 'MimeType: ' . $failureReports->getMimeType());
45+
printOut('File', $failureReports->getFile());
46+
} else {
47+
printOut('Failure Reports', '');
48+
}
49+
50+
echo "\n";
51+
}
52+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use RocketLabs\SellerCenterSdk\Core\Client;
4+
use RocketLabs\SellerCenterSdk\Core\Configuration;
5+
use RocketLabs\SellerCenterSdk\Core\Response\ErrorResponse;
6+
use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;
7+
8+
require_once __DIR__ . '/../../../vendor/autoload.php';
9+
require_once __DIR__ . '/../../config/config.php';
10+
11+
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
12+
13+
$orderItemIds = [1, 2]; // Please change the set of Order Item IDs for Your system.
14+
$documentType = 'invoice';
15+
16+
$response = Endpoints::order()->getDocument($orderItemIds, $documentType)->call($client);
17+
18+
if ($response instanceof ErrorResponse) {
19+
/** @var ErrorResponse $response */
20+
printf("ERROR !\n");
21+
printf("%s\n", $response->getMessage());
22+
} else {
23+
$doc = $response->getDocument();
24+
printf("Document type : %s\n", $doc->getType());
25+
printf("Document mime type : %s\n", $doc->getMimeType());
26+
}

samples/endpoint/order/getOrder.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use RocketLabs\SellerCenterSdk\Core\Client;
4+
use RocketLabs\SellerCenterSdk\Core\Configuration;
5+
use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;
6+
use RocketLabs\SellerCenterSdk\Endpoint\Order\Response\GetOrder;
7+
8+
require_once __DIR__ . '/../../../vendor/autoload.php';
9+
require_once __DIR__ . '/../../config/config.php';
10+
11+
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
12+
13+
$orderId = 1; // Please change the OrderId for Your system.
14+
15+
$response = Endpoints::order()->getOrder($orderId)->call($client);
16+
17+
if ($response instanceof GetOrder) {
18+
$order = $response->getOrder();
19+
printf("ORDER #%d (%s)\n\n", $order->getOrderId(), $order->getOrderNumber());
20+
21+
printf("ITEMS: %d\nITEM STATUSES:\n", $order->getItemsCount());
22+
23+
foreach ($order->getStatuses() as $status) {
24+
printf("\t- %s\n", $status);
25+
}
26+
27+
$address = $order->getAddressBilling();
28+
29+
printf(
30+
"\nBILLING ADDRESS:\n%s %s %s %s %s %s %s %s %s\n",
31+
$address->getPostCode(),
32+
$address->getCountry(),
33+
$address->getRegion(),
34+
$address->getCity(),
35+
$address->getAddress(),
36+
$address->getAddress2(),
37+
$address->getAddress3(),
38+
$address->getAddress4(),
39+
$address->getAddress5()
40+
);
41+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use RocketLabs\SellerCenterSdk\Core\Client;
4+
use RocketLabs\SellerCenterSdk\Core\Configuration;
5+
use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;
6+
use RocketLabs\SellerCenterSdk\Endpoint\Order\Model\Item;
7+
8+
require_once __DIR__ . '/../../../vendor/autoload.php';
9+
require_once __DIR__ . '/../../config/config.php';
10+
11+
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
12+
13+
$orderId = 1; // Please change the OrderId for Your system.
14+
15+
$response = Endpoints::order()->getOrderItems($orderId)->call($client);
16+
17+
printf("Items for the order:\n");
18+
19+
foreach ($response->getItems() as $item) {
20+
/** @var Item $item */
21+
printf(" #%6d : %s \n", $item->getOrderItemId(), $item->getName());
22+
}

samples/endpoint/order/getOrders.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use RocketLabs\SellerCenterSdk\Core\Client;
4+
use RocketLabs\SellerCenterSdk\Core\Configuration;
5+
use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;
6+
7+
require_once __DIR__ . '/../../../vendor/autoload.php';
8+
require_once __DIR__ . '/../../config/config.php';
9+
10+
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
11+
12+
$response = Endpoints::order()->getOrders()
13+
->setCreatedAfter(new DateTime('2016-04-01 00:00:00'))
14+
->setLimit(10)
15+
->build()
16+
->call($client);
17+
18+
/**
19+
* @var $order \RocketLabs\SellerCenterSdk\Endpoint\Order\Model\Order
20+
*/
21+
foreach ($response->getOrders() as $order) {
22+
printf(
23+
"ORDER % 8d %s %6.2f %s %s\n",
24+
$order->getOrderId(),
25+
$order->getCreatedAt()->format('Y-m-d H:i:s'),
26+
$order->getPrice(),
27+
$order->getCustomerFirstName(),
28+
$order->getCustomerLastName()
29+
);
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use RocketLabs\SellerCenterSdk\Core\Client;
4+
use RocketLabs\SellerCenterSdk\Core\Configuration;
5+
use RocketLabs\SellerCenterSdk\Core\Response\SuccessResponseInterface;
6+
use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;
7+
8+
require_once __DIR__ . '/../../../vendor/autoload.php';
9+
require_once __DIR__ . '/../../config/config.php';
10+
11+
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
12+
13+
$orderItemId = 1; // Please change the OrderItemId for Your system.
14+
$reason = 'cancel';
15+
$reasonDetail = 'Cancel';
16+
17+
$response = Endpoints::order()->setStatusToCanceled($orderItemId, $reason, $reasonDetail)
18+
->call($client);
19+
20+
if ($response instanceof SuccessResponseInterface) {
21+
printf("The order item has been successfully canceled\n");
22+
} else {
23+
printf("Unable to cancel the order item\n{$response->getMessage()}");
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use RocketLabs\SellerCenterSdk\Core\Client;
4+
use RocketLabs\SellerCenterSdk\Core\Configuration;
5+
use RocketLabs\SellerCenterSdk\Core\Response\SuccessResponseInterface;
6+
use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;
7+
8+
require_once __DIR__ . '/../../../vendor/autoload.php';
9+
require_once __DIR__ . '/../../config/config.php';
10+
11+
$client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));
12+
13+
$orderItemIds = [1, 2]; // Please change the set of Order Item IDs for Your system.
14+
$deliveryType = 'dropship';
15+
$shipmentProvider = 'CJGLS';
16+
17+
$response = Endpoints::order()
18+
->setStatusToPackedByMarketplace($orderItemIds, $deliveryType, $shipmentProvider)
19+
->call($client);
20+
21+
if ($response instanceof SuccessResponseInterface) {
22+
printf("Statuses of order items have been changed to \"Packed By Marketplace\"\n");
23+
} else {
24+
printf("Unable to change statuses of the order items\n");
25+
}

0 commit comments

Comments
 (0)