22
33# Connect PHP SDK
44
5+ [ ![ Build Status] ( https://travis-ci.com/ingrammicro/connect-php-sdk.svg?branch=master )] ( https://travis-ci.com/ingrammicro/connect-php-sdk ) [ ![ Latest Stable Version] ( https://poser.pugx.org/apsconnect/connect-sdk/v/stable )] ( https://packagist.org/packages/apsconnect/connect-sdk ) [ ![ License] ( https://poser.pugx.org/apsconnect/connect-sdk/license )] ( https://packagist.org/packages/apsconnect/connect-sdk ) [ ![ codecov] ( https://codecov.io/gh/ingrammicro/connect-php-sdk/branch/master/graph/badge.svg )] ( https://codecov.io/gh/ingrammicro/connect-php-sdk )
6+
57## Getting Started
68Connect PHP SDK allows an easy and fast integration with [ Connect] ( http://connect.cloud.im/ ) fulfillment API. Thanks to it you can automate the fulfillment of orders generated by your products.
79
@@ -29,13 +31,17 @@ Your code may use any scheduler to execute, from a simple cron to a cloud schedu
2931Connect PHP SDK is available on [ Packagist] ( https://packagist.org/packages/apsconnect/connect-sdk ) (using semantic versioning), and installation via [ Composer] ( https://getcomposer.org ) is the recommended way to install Connect PHP SDK. Just add this line to your ` composer.json ` file:
3032
3133``` json
32- "apsconnect/connect-sdk" : " ~1.0"
34+ {
35+ "require" : {
36+ "apsconnect/connect-sdk" : " ^1.0"
37+ }
38+ }
3339```
3440
3541or run
3642
3743``` sh
38- composer require apsconnect/connect-sdk
44+ composer require apsconnect/connect-sdk --no-dev --prefer-dist --classmap-authoritative
3945```
4046
4147Note that the ` vendor ` folder and the ` vendor/autoload.php ` script are generated by Composer
@@ -50,32 +56,25 @@ require_once "vendor/autoload.php";
5056/**
5157 * Class ProductRequests
5258 */
53- class ProductRequests extends \Connect\RequestsProcessor
59+ class ProductRequests extends \Connect\FulfillmentAutomation
5460{
55- /**
56- * ProductRequests constructor.
57- * @param $config
58- * @throws ReflectionException
59- * @throws \Connect\ConfigException
60- * @throws \Connect\ConfigPropertyInvalid
61- * @throws \Connect\ConfigPropertyMissed
62- */
63- function __construct($config)
64- {
65- parent::__construct($config);
66- }
61+
6762
6863 /**
6964 * @param \Connect\Request $request
7065 * @return string|void
66+ * @return \Connect\ActivationTemplateResponse
67+ * @return \Connect\ActivationTileResponse
7168 * @throws Exception
7269 * @throws \Connect\Exception
7370 * @throws \Connect\Fail
7471 * @throws \Connect\Skip
72+ * @throws \Connect\Inquire
7573 */
76- function processRequest($request)
74+
75+ public function processRequest($request)
7776 {
78- Connect\Logger::get() ->info("Processing Request: " . $request->id . " for asset: " . $request->asset->id);
77+ $this->logger ->info("Processing Request: " . $request->id . " for asset: " . $request->asset->id);
7978 switch ($request->type) {
8079 case "purchase":
8180 if($request->asset->params['email']->value == ""){
@@ -85,7 +84,7 @@ class ProductRequests extends \Connect\RequestsProcessor
8584 }
8685 foreach ($request->asset->items as $item) {
8786 if ($item->quantity > 1000000) {
88- Connect\Logger::get() ->info("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
87+ $this->logger ->info("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
8988 throw new \Connect\Fail("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
9089 }
9190 else {
@@ -112,11 +111,11 @@ class ProductRequests extends \Connect\RequestsProcessor
112111
113112//Main Code Block
114113try {
115- $apiConfig = array(
114+ $apiConfig = new \Connect\Config([
116115 'apiKey' => 'Key_Available_in_ui',
117116 'apiEndpoint' => 'https://api.connect.cloud.im/public/v1',
118117 'products' => 'CN-631-322-641' #Optional value
119- );
118+ ] );
120119 $requests = new ProductRequests($apiConfig);
121120 $requests->process();
122121
0 commit comments