Skip to content

Commit 35ad26d

Browse files
authored
Merge pull request #32 from ingrammicro/v17-dev
New functionalities for Connect v17 Updated models
2 parents 7eb8b72 + 7dfb341 commit 35ad26d

File tree

146 files changed

+4523
-219
lines changed

Some content is hidden

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

146 files changed

+4523
-219
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,5 @@ fabric.properties
226226
composer.lock
227227

228228
# codecov
229-
coverage.xml
229+
coverage.xml
230+
.php_cs.cache

README.md

Lines changed: 134 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
[![PHP Version](https://img.shields.io/packagist/php-v/apsconnect/connect-sdk.svg?style=flat&branch=master)](https://packagist.org/packages/apsconnect/connect-sdk)
77

88
## Getting Started
9-
Connect PHP SDK allows an easy and fast integration with [Connect](http://connect.cloud.im/) fulfillment API and usage API. Thanks to it you can automate the fulfillment of orders generated by your products and report usage for it.
9+
Connect PHP SDK allows an easy and fast integration with [Connect](http://connect.cloud.im/) Fulfillment and Usage APIs with PHP-based integrations. This SDK enables you to automate fulfillment of orders for your products and report usage data for them.
1010

11-
In order to use this library, please ensure that you have read first the documentation available on Connect knowladge base article located [here](http://help.vendor.connect.cloud.im/support/solutions/articles/43000030735-fulfillment-management-module), this one will provide you a great information on the rest api that this library implements.
11+
Before using the library, please first to go through the documentation in the Connect knowledge base, which could be used as a source of information on the rest APIs used by this SDK.
1212

1313
## Class Features
1414

15-
This library may be consumed in your project in order to automate the fulfillment of requests and perform the usage reporting, this class once imported into your project will allow you to:
15+
This library can be utilized in your project for the automation of the fulfillment logic as well as usage reporting. This class, once imported into your project, will enable you to:
1616

17-
- Connect to Connect using your api credentials
18-
- List all requests, and even filter them:
19-
- for a concrete product
20-
- for a concrete status
21-
- for a concrete asset
22-
- etc..
17+
- Establish connectivity to Connect APIs
18+
- List all requests and apply filters like
19+
- Filter requests by Product
20+
- Filter requests by Status
21+
- Filter requests by Asset
22+
- etc.
2323
- Process each request and obtain full details of the request
24-
- Modify for each request the activation parameters in order to:
25-
- Inquiry for changes
24+
- Modify parameters of a request in order to:
25+
- Inquire for changes
2626
- Store information into the fulfillment request
2727
- Change the status of the requests from it's initial pending state to either inquiring, failed or approved.
2828
- Generate and upload usage files to report usage for active contracts and listings
@@ -34,12 +34,12 @@ This library may be consumed in your project in order to automate the fulfillmen
3434
Your code may use any scheduler to execute, from a simple cron to a cloud scheduler like the ones available in Azure, Google, Amazon or other cloud platforms.
3535

3636
## Installation & loading
37-
Connect 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:
37+
Connect PHP SDK is available through [Packagist](https://packagist.org/packages/apsconnect/connect-sdk) (using semantic versioning), and installation via the [Composer](https://getcomposer.org) is the recommended way to install the Connect PHP SDK. Just add these lines to your `composer.json` file:
3838

3939
```json
4040
{
4141
"require": {
42-
"apsconnect/connect-sdk": "^16.0"
42+
"apsconnect/connect-sdk": "^17.0"
4343
}
4444
}
4545
```
@@ -52,7 +52,9 @@ composer require apsconnect/connect-sdk --no-dev --prefer-dist --classmap-author
5252

5353
Note that the `vendor` folder and the `vendor/autoload.php` script are generated by Composer
5454

55-
## A Simple Example of fulfillment
55+
## A Simple Example of the fulfillment
56+
57+
This example demonstrates a script that will retrieve all requests in the status pending and process them based on their type (purchase, change, cancel, suspend or resume)
5658

5759
```php
5860
<?php
@@ -67,20 +69,38 @@ class ProductRequests extends \Connect\FulfillmentAutomation
6769
$this->logger->info("Processing Request: " . $request->id . " for asset: " . $request->asset->id);
6870
switch ($request->type) {
6971
case "purchase":
70-
if($request->asset->params['email']->value == ""){
72+
//Get value of a parameter with id "email"
73+
$email = $request->asset->getParameterByID('email');
74+
if($email->value == ""){
7175
throw new \Connect\Inquire(array(
7276
$request->asset->params['email']->error("Email address has not been provided, please provide one")
7377
));
7478
}
79+
//Get value for a concrete item using MPN
80+
$itemX = $request->asset->getItemByMPN('itemX');
7581
foreach ($request->asset->items as $item) {
7682
if ($item->quantity > 1000000) {
7783
$this->logger->info("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
7884
throw new \Connect\Fail("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
7985
}
8086
else {
81-
//Do some provisoning operation
87+
//Do some provisioning operation
8288
//Update the parameters to store data
8389
$paramsUpdate[] = new \Connect\Param('ActivationKey', 'somevalue');
90+
$request->requestProcessor->fulfillment->updateParameters($request, $paramsUpdate);
91+
//Potential actions to be done with a request:
92+
// Set a parameter that requires changes and move request to inquire
93+
if($requiresChanges){
94+
throw new \Connect\Inquire([
95+
new \Connect\Param([
96+
"id" => "email",
97+
"value_error" => "Invalid email"
98+
])
99+
]);
100+
}
101+
//Fail request
102+
throw new \Connect\Fail("Request Can't be processed");
103+
//Approve a template
84104
//We may use a template defined on vendor portal as activation response, this will be what customer sees on panel
85105
return new \Connect\ActivationTemplateResponse("TL-497-535-242");
86106
// We may use arbitrary output to be returned as approval, this will be seen on customer panel. Please see that output must be in markup format
@@ -93,6 +113,12 @@ class ProductRequests extends \Connect\FulfillmentAutomation
93113
//Handle cancellation request
94114
case "change":
95115
//Handle change request
116+
//get added items:
117+
$newItems = $request->getNewItems();
118+
// get removed items:
119+
$removed = $request->getRemovedItems();
120+
// Get changed items, in other words the ones that quantity has been modified
121+
$changed = $request->getChangedItems();
96122
default:
97123
throw new \Connect\Fail("Operation not supported:".$request->type);
98124
}
@@ -107,7 +133,7 @@ class ProductRequests extends \Connect\FulfillmentAutomation
107133
//Main Code Block
108134

109135
try {
110-
136+
//In case Config is not passed into constructor, configuration from config.json is used
111137
$requests = new ProductRequests(new \Connect\Config([
112138
'apiKey' => 'Key_Available_in_ui',
113139
'apiEndpoint' => 'https://api.connect.cloud.im/public/v1',
@@ -204,7 +230,7 @@ class UsageFilesWorkflow extends \Connect\UsageFileAutomation
204230
//Provider use case, needs to be reviewed and accept it
205231
throw new \Connect\Usage\Accept("File looks good");
206232
default:
207-
throw new \Connect\Usage\Skip("not controled status");
233+
throw new \Connect\Usage\Skip("not valid status");
208234
}
209235
}
210236
}
@@ -223,3 +249,93 @@ try {
223249
print "Error processing usage for active listing requests:" . $e->getMessage();
224250
}
225251
```
252+
253+
## Client class
254+
255+
Starting with the Connect PHP SDK version 17 the Client class has been introduced. This class allows running multiple operations in Connect like get the list of requests, configurations, etc. Client class may be instantiated from any application to obtain information needed to run an operation, like, for example, get the Asset information in the context of an action. Client will provide access to:
256+
* Directory
257+
* Fulfillment
258+
* Tier Configurations
259+
260+
### Creating a Client
261+
262+
This is an example to create a client:
263+
264+
```php
265+
<?php
266+
require_once ("./vendor/autoload.php");
267+
268+
##Note that in case of no Configuration passed to constructor, system will check if config.json exists
269+
$connect = new Connect\ConnectClient(new \Connect\Config([
270+
"apiKey" => "SU-677-956-738:ca95348138a3c122943ba968a9b69e42d30bde6c",
271+
"apiEndpoint" => "https://api.cnct.info/public/v1",
272+
"logLevel"=> 7,
273+
"timeout" => 60,
274+
"sslVerifyHost"=> false
275+
]));
276+
$connect->directory->listTierConfigs()
277+
```
278+
279+
### Connect Client usage examples:
280+
281+
* Retrieve Tier Configurations
282+
```php
283+
<?php
284+
$connect = new Connect\ConnectClient();
285+
$tierConfigurations = $connect->directory->listTierConfigs();
286+
$tierConfigurations = $connect->directory->listTierConfigs(["account.id" => 'T-0-123123132123123']);
287+
```
288+
289+
* Retrieve Tier Configuration
290+
```php
291+
<?php
292+
$connect = new Connect\ConnectClient();
293+
$tierConfiguration = $connect->directory->getTierConfigById('TC-000-000-000');
294+
```
295+
296+
* Retrieve list of Assets
297+
```php
298+
<?php
299+
$connect = new Connect\ConnectClient();
300+
$assets = $connect->directory->listAssets();
301+
$assets = $connect->directory->listAssets(["product.id" => "PRD-XXXX-XXXX-XXXX"]);
302+
```
303+
304+
* Retrieve an Asset
305+
```php
306+
<?php
307+
$connect = new Connect\ConnectClient();
308+
$asset = $connect->directory->getAssetById('AS-123-123-123');
309+
```
310+
311+
* Get Products Information
312+
```php
313+
<?php
314+
$connect = new Connect\ConnectClient();
315+
$products = $connect->directory->listProducts();
316+
```
317+
318+
* Get Product Information
319+
```php
320+
<?php
321+
$connect = new Connect\ConnectClient();
322+
$product = $connect->directory->getProduct('PRD-XXXX-XXXX-XXXX');
323+
```
324+
325+
* List all requests
326+
327+
In case of no filter, pending ones are returned
328+
```php
329+
<?php
330+
$connect = new Connect\ConnectClient();
331+
$requests = $connect->fulfillment->listRequests();
332+
$requests = $connect->fulfillment->listRequests(['status' => 'approved']);
333+
```
334+
335+
* Get Concrete request
336+
337+
```php
338+
<?php
339+
$connect = new Connect\ConnectClient();
340+
$request = $connect->fulfillment->getRequest('PR-XXXX-XXXX-XXXXX');
341+
```

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "^5.7",
19-
"mockery/mockery": "^1.0"
19+
"mockery/mockery": "^1.0",
20+
"lukascivil/treewalker": "^0.9"
2021
},
2122
"autoload": {
2223
"psr-4": {

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
ignoreErrors:
3+
- '#PHPDoc tag @throws with type GuzzleHttp\\Exception\\GuzzleException is not subtype of Throwable#'
4+
- '#PHPDoc tag @throws with type Exception|GuzzleHttp\\Exception\\GuzzleException is not subtype of Throwable#'
5+
- '#PHPDoc tag @throws with type GuzzleHttp\\Exception\\GuzzleException|LogicException is not subtype of Throwable#'

phpunit.xml

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,76 @@
99
<log type="coverage-clover" target="coverage.xml"/>
1010
</logging>
1111
<testsuites>
12+
<testsuite name="Directory Services">
13+
<file> tests/Unit/DirectoryTests/AssetTest.php</file>
14+
<file> tests/Unit/DirectoryTests/ProductTest.php</file>
15+
<file> tests/Unit/DirectoryTests/TierConfigTest.php</file>
16+
</testsuite>
1217
<testsuite name="Fail">
13-
<file>tests/Unit/FailTest.php</file>
18+
<file>tests/Unit/FulfillmentTests/FailTest.php</file>
1419
</testsuite>
1520
<testsuite name="Inquire">
16-
<file>tests/Unit/InquireTest.php</file>
21+
<file>tests/Unit/FulfillmentTests/InquireTest.php</file>
1722
</testsuite>
1823
<testsuite name="Message">
1924
<file>tests/Unit/MessageTest.php</file>
2025
</testsuite>
2126
<testsuite name="Skip">
22-
<file>tests/Unit/SkipTest.php</file>
27+
<file>tests/Unit/FulfillmentTests/SkipTest.php</file>
2328
</testsuite>
2429
<testsuite name="ActivationTemplateResponse">
25-
<file>tests/Unit/ActivationTemplateResponseTest.php</file>
30+
<file>tests/Unit/FulfillmentTests/ActivationTemplateResponseTest.php</file>
2631
</testsuite>
2732
<testsuite name="Logger">
2833
<file>tests/Unit/Logger/LogRecordTest.php</file>
2934
<file>tests/Unit/Logger/LogSessionTest.php</file>
3035
<file>tests/Unit/LoggerTest.php</file>
3136
</testsuite>
3237
<testsuite name="ActivationTileResponse">
33-
<file>tests/Unit/ActivationTileResponseTest.php</file>
38+
<file>tests/Unit/FulfillmentTests/ActivationTileResponseTest.php</file>
3439
</testsuite>
3540
<testsuite name="RequestTest">
36-
<file>tests/Unit/RequestTest.php</file>
41+
<file>tests/Unit/FulfillmentTests/RequestTest.php</file>
3742
</testsuite>
3843
<testsuite name="Configuration">
3944
<file>tests/Unit/ConfigTest.php</file>
4045
<file>tests/Unit/Config/VaultConfigTest.php</file>
4146
</testsuite>
4247
<testsuite name="Application">
43-
<file>tests/Unit/FulfillmentAutomationTest.php</file>
48+
<file>tests/Unit/FulfillmentTests/FulfillmentAutomationTest.php</file>
4449
</testsuite>
4550
<testsuite name="Models">
46-
<file>tests/Unit/ModelTest.php</file>
47-
<file>tests/Unit/ParamTest.php</file>
48-
<file>tests/Unit/AssetTest.php</file>
49-
<file>tests/Unit/ContactInfoTest.php</file>
51+
<file>tests/Unit/ModelsTests/ModelTest.php</file>
52+
<file>tests/Unit/ModelsTests/ParamTest.php</file>
53+
<file>tests/Unit/ModelsTests/AssetTest.php</file>
54+
<file>tests/Unit/ModelsTests/ContactInfoTest.php</file>
55+
</testsuite>
56+
<testsuite name="Model API Consistency">
57+
<file>tests/Unit/ModelsTests/StructureTest.php</file>
5058
</testsuite>
5159
<testsuite name="RequestStructure">
52-
<file>tests/Unit/RequestStructureTest.php</file>
60+
<file>tests/Unit/ModelsTests/RequestStructureTest.php</file>
5361
</testsuite>
5462
<testsuite name="TierRequests">
55-
<file>tests/Unit/TierRequestTest.php</file>
63+
<file>tests/Unit/FulfillmentTests/TierRequestTest.php</file>
5664
</testsuite>
5765
<testsuite name="Usage Responses">
58-
<file>tests/Unit/AcceptTest.php</file>
59-
<file>tests/Unit/AcceptResponseTest.php</file>
60-
<file>tests/Unit/CloseTest.php</file>
61-
<file>tests/Unit/DeleteTest.php</file>
62-
<file>tests/Unit/RejectTest.php</file>
63-
<file>tests/Unit/RejectResponseTest.php</file>
64-
<file>tests/Unit/UsageSkipTest.php</file>
65-
<file>tests/Unit/SubmitTest.php</file>
66-
<file>tests/Unit/FileRetrieveExceptionTest.php</file>
67-
<file>tests/Unit/FileCreationExceptionTest.php</file>
66+
<file>tests/Unit/UsageTests/AcceptTest.php</file>
67+
<file>tests/Unit/UsageTests/AcceptResponseTest.php</file>
68+
<file>tests/Unit/UsageTests/CloseTest.php</file>
69+
<file>tests/Unit/UsageTests/DeleteTest.php</file>
70+
<file>tests/Unit/UsageTests/RejectTest.php</file>
71+
<file>tests/Unit/UsageTests/UsageSkipTest.php</file>
72+
<file>tests/Unit/UsageTests/SubmitTest.php</file>
73+
<file>tests/Unit/UsageTests/FileRetrieveExceptionTest.php</file>
74+
<file>tests/Unit/UsageTests/FileCreationExceptionTest.php</file>
6875
</testsuite>
6976
<testsuite name="Usage Automation">
70-
<file>tests/Unit/UsageAutomationBasicsTest.php</file>
71-
<file>tests/Unit/UsageAutomationTest.php</file>
77+
<file>tests/Unit/UsageTests/UsageAutomationBasicsTest.php</file>
78+
<file>tests/Unit/UsageTests/UsageAutomationTest.php</file>
7279
</testsuite>
7380
<testsuite name="Usage File Automation">
74-
<file>tests/Unit/UsageFileAutomationTest.php</file>
81+
<file>tests/Unit/UsageTests/UsageFileAutomationTest.php</file>
7582
</testsuite>
7683
</testsuites>
7784
</phpunit>

src/Account.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
class Account extends Model
1616
{
1717
/**
18-
* @var
18+
* @var string
1919
*/
2020
public $id;
2121
/**
22-
* @var
22+
* @var string
2323
*/
2424
public $name;
2525

2626
/**
27-
* @var
27+
* @var string
2828
*/
2929

3030
public $external_uid;
3131

3232
/**
33-
* @var
33+
* @var string
3434
*/
3535
public $external_id;
3636

src/Activation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class Activation extends Model
1616
{
1717
/**
18-
* @var
18+
* @var string
1919
*/
2020
public $link;
2121
}

0 commit comments

Comments
 (0)