├── .github └── workflows │ ├── netlicensing-php-dependency.yml │ └── php.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── common └── Constants.php ├── composer.json ├── converter ├── ItemToArrayConverter.php ├── ItemToCountryConverter.php ├── ItemToLicenseConverter.php ├── ItemToLicenseTemplateConverter.php ├── ItemToLicenseeConverter.php ├── ItemToPaymentMethodConverter.php ├── ItemToProductConverter.php ├── ItemToProductModuleConverter.php ├── ItemToTokenConverter.php ├── ItemToTransactionConverter.php └── ItemsToArrayConverter.php ├── demo └── NetLicensingDemo.php ├── entity ├── BaseEntity.php ├── Country.php ├── License.php ├── LicenseTemplate.php ├── LicenseTransactionJoin.php ├── Licensee.php ├── PaymentMethod.php ├── Product.php ├── ProductDiscount.php ├── ProductModule.php ├── Token.php ├── Transaction.php └── traits │ └── Properties.php ├── examples ├── OfflineValidation.php ├── OfflineValidationTest.php ├── README.md └── resources │ ├── Isb-DEMO.xml │ ├── rsa_public.pem │ └── rsa_public_wrong.pem ├── exception ├── BadSignatureException.php ├── MalformedArgumentsException.php ├── NetLicensingException.php └── RestException.php ├── netlicensing.php ├── phpunit.xml ├── service ├── LicenseService.php ├── LicenseTemplateService.php ├── LicenseeService.php ├── NetLicensingService.php ├── PaymentMethodService.php ├── ProductModuleService.php ├── ProductService.php ├── TokenService.php ├── TransactionService.php ├── UtilityService.php └── ValidationService.php ├── tests └── DummyTest.php ├── util ├── CheckUtils.php └── SignatureUtils.php └── vo ├── Context.php ├── NetLicensingCurl.php ├── Page.php ├── ValidationParameters.php └── ValidationResults.php /.github/workflows/netlicensing-php-dependency.yml: -------------------------------------------------------------------------------- 1 | name: PHP Client - Dependency Test 2 | 3 | on: 4 | schedule: 5 | - cron: '*/30 * * * *' 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Init project 14 | run: | 15 | composer create-project composer/semver netlicensing-php-dependency 16 | 17 | - name: Install dependencies 18 | run: | 19 | composer require labs64/netlicensingclient-php 20 | composer install --prefer-dist --no-progress --no-suggest 21 | -------------------------------------------------------------------------------- /.github/workflows/php.yml: -------------------------------------------------------------------------------- 1 | name: PHP Composer 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Setup PHP 21 | uses: shivammathur/setup-php@v2 22 | with: 23 | php-version: '7.4' 24 | 25 | - name: Validate composer.json and composer.lock 26 | run: composer validate --strict 27 | 28 | - name: Cache Composer packages 29 | id: composer-cache 30 | uses: actions/cache@v3 31 | with: 32 | path: vendor 33 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} 34 | restore-keys: | 35 | ${{ runner.os }}-php- 36 | 37 | - name: Install dependencies 38 | run: composer install --prefer-dist --no-progress 39 | 40 | # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" 41 | # Docs: https://getcomposer.org/doc/articles/scripts.md 42 | 43 | - name: Run test suite 44 | run: | 45 | cd ./demo 46 | php ./NetLicensingDemo.php 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Include your project-specific ignores in this file 2 | # Read about how to use .gitignore: https://help.github.com/articles/ignoring-files 3 | *.phar 4 | composer.lock 5 | vendor/ 6 | .idea/ 7 | *.iml 8 | .DS_Store 9 | Thumbs.db 10 | .buildpath 11 | .project 12 | .settings* 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.0 5 | - 7.1 6 | 7 | before_script: 8 | - composer update 9 | - cd demo 10 | - php NetLicensingDemo.php 11 | - cd .. 12 | 13 | script: 14 | - vendor/bin/phpunit 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Innovative License Management Solution 2 | 3 | # [Labs64 NetLicensing](https://netlicensing.io) Client (PHP) 4 | 5 | [![Build Status](https://travis-ci.org/Labs64/NetLicensingClient-php.svg?branch=master)](https://travis-ci.org/Labs64/NetLicensingClient-php) 6 | [![Latest Stable Version](https://poser.pugx.org/labs64/netlicensingclient-php/v/stable)](https://packagist.org/packages/labs64/netlicensingclient-php) 7 | [![Total Downloads](https://poser.pugx.org/labs64/netlicensingclient-php/downloads)](https://packagist.org/packages/labs64/netlicensingclient-php) 8 | [![Apache License 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/Labs64/NetLicensingClient-php/blob/master/LICENSE) 9 | [![📖 Documentation](https://img.shields.io/badge/📖%20Documentation-Wiki-AB6543.svg)](https://netlicensing.io/wiki/restful-api) 10 | [![NetLicensing @ LinkedIn](https://img.shields.io/badge/NetLicensing-0077B5.svg?logo=LinkedIn)](https://www.linkedin.com/showcase/netlicensing) 11 | 12 | PHP wrapper for Labs64 NetLicensing [RESTful API](https://netlicensing.io/wiki/restful-api) 13 | 14 | Visit Labs64 NetLicensing at https://netlicensing.io 15 | 16 | ## Installation 17 | 18 | ``` 19 | $ composer require labs64/netlicensingclient-php 20 | ``` 21 | 22 | ## Usage 23 | 24 | ``` 25 | { 26 | "require": { 27 | "labs64/netlicensingclient-php": "^2.5.0" 28 | } 29 | } 30 | ``` 31 | 32 | ## Contributing 33 | 34 | Bug, feature requests and other issues should be reported to the [GitHub Project]. We accept code and documentation contributions via Pull Requests on GitHub as well. 35 | 36 | - [PSR-2 Coding Standard] is used by the project. 37 | - Keep the documentation up to date. Make sure `README.md` and other relevant documentation is kept up to date with your changes. 38 | - One pull request per feature. Try to keep your changes focused on solving a single problem. This will make it easier for us to review the change and easier for you to make sure you have updated the necessary tests and documentation. 39 | 40 | ## License 41 | 42 | Labs64 NetLicensing Client (PHP) is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for more details. 43 | 44 | --- 45 | 46 | Visit Labs64 NetLicensing at https://netlicensing.io 47 | 48 | [Labs64 NetLicensing]: https://netlicensing.io 49 | [RESTful API]: http://l64.cc/nl10 50 | [GitHub project]: https://github.com/Labs64/NetLicensingClient-php 51 | [PSR-2 Coding Standard]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md 52 | -------------------------------------------------------------------------------- /common/Constants.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | 12 | class Constants 13 | { 14 | const NETLICENSING_VERSION = '2.5.0'; 15 | 16 | const NUMBER = 'number'; 17 | const CASCADE = 'forceCascade'; 18 | const FILTER = 'filter'; 19 | 20 | /** 21 | * Security modes 22 | */ 23 | const BASIC_AUTHENTICATION = 'BASIC_AUTH'; 24 | const APIKEY_IDENTIFICATION = 'APIKEY'; 25 | const ANONYMOUS_IDENTIFICATION = 'ANONYMOUS'; 26 | 27 | /** 28 | * @deprecated 29 | */ 30 | const XML_NS = 'http://netlicensing.labs64.com/schema/context'; 31 | 32 | /** 33 | * Licensing Models 34 | */ 35 | const LICENSING_MODEL_TRY_AND_BUY = "TryAndBuy"; 36 | const LICENSING_MODEL_RENTAL = "Rental"; 37 | const LICENSING_MODEL_SUBSCRIPTION = "Subscription"; 38 | const LICENSING_MODEL_FLOATING = "Floating"; 39 | const LICENSING_MODEL_MULTI_FEATURE = "MultiFeature"; 40 | const LICENSING_MODEL_MULTI_PAY_PER_USE = "PayPerUse"; 41 | const LICENSING_MODEL_PRICING_TABLE = "PricingTable"; 42 | const LICENSING_MODEL_QUOTA = "Quota"; 43 | const LICENSING_MODEL_NODE_LOCKED = "NodeLocked"; 44 | 45 | /** 46 | * Licensee 47 | */ 48 | const LICENSEE_ENDPOINT_PATH = 'licensee'; 49 | const LICENSEE_ENDPOINT_PATH_VALIDATE = 'validate'; 50 | const LICENSEE_ENDPOINT_PATH_TRANSFER = 'transfer'; 51 | const LICENSEE_NUMBER = 'licenseeNumber'; 52 | const LICENSEE_PROP_LICENSEE_NAME = 'licenseeName'; 53 | /** 54 | * @deprecated please use License::LICENSE_PROP_LICENSEE_SECRET instead. 55 | */ 56 | const LICENSEE_PROP_LICENSEE_SECRET = 'licenseeSecret'; 57 | const LICENSEE_SOURCE_LICENSEE_NUMBER = 'sourceLicenseeNumber'; 58 | 59 | /** 60 | * License 61 | */ 62 | const LICENSE_ENDPOINT_PATH = 'license'; 63 | const LICENSE_NUMBER = 'licenseNumber'; 64 | const LICENSE_PROP_LICENSEE_SECRET = 'licenseeSecret'; 65 | 66 | /* 67 | * License Template 68 | */ 69 | const LICENSE_TEMPLATE_ENDPOINT_PATH = 'licensetemplate'; 70 | const LICENSE_TEMPLATE_NUMBER = 'licenseTemplateNumber'; 71 | const LICENSE_TEMPLATE_PROP_LICENSEE_SECRET = 'licenseeSecret'; 72 | 73 | /** 74 | * Payment Method 75 | */ 76 | const PAYMENT_METHOD_ENDPOINT_PATH = 'paymentmethod'; 77 | 78 | /** 79 | * Product Module 80 | */ 81 | const PRODUCT_MODULE_ENDPOINT_PATH = 'productmodule'; 82 | const PRODUCT_MODULE_NUMBER = 'productModuleNumber'; 83 | const PRODUCT_MODULE_PROP_LICENSEE_SECRET_MODE = 'licenseeSecretMode'; 84 | 85 | /* 86 | * Product 87 | */ 88 | const PRODUCT_ENDPOINT_PATH = 'product'; 89 | const PRODUCT_NUMBER = 'productNumber'; 90 | 91 | /* 92 | * Token 93 | */ 94 | const TOKEN_ENDPOINT_PATH = 'token'; 95 | const TOKEN_EXPIRATION_TIME = 'expirationTime'; 96 | 97 | /* 98 | * Transaction 99 | */ 100 | const TRANSACTION_ENDPOINT_PATH = 'transaction'; 101 | const TRANSACTION_NUMBER = 'transactionNumber'; 102 | const TRANSACTION_DATE_CREATED = "datecreated"; 103 | const TRANSACTION_DATE_CLOSED = "dateclosed"; 104 | 105 | /** 106 | * Utility 107 | */ 108 | const UTILITY_ENDPOINT_PATH = 'utility'; 109 | const UTILITY_ENDPOINT_PATH_LICENSE_TYPES = 'licenseTypes'; 110 | const UTILITY_ENDPOINT_PATH_LICENSING_MODELS = 'licensingModels'; 111 | const UTILITY_ENDPOINT_PATH_COUNTRIES = 'countries'; 112 | 113 | /** 114 | * Vendor 115 | */ 116 | const VENDOR_NUMBER = 'vendorNumber'; 117 | 118 | /** 119 | * Warning Level 120 | */ 121 | const WARNING_LEVEL_GREEN = 'GREEN'; 122 | const WARNING_LEVEL_YELLOW = 'YELLOW'; 123 | const WARNING_LEVEL_RED = 'RED'; 124 | } 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "labs64/netlicensingclient-php", 3 | "description": "PHP wrapper for Labs64 NetLicensing RESTful API", 4 | "type": "library", 5 | "keywords": [ 6 | "NetLicensing", 7 | "licensing", 8 | "license", 9 | "software license", 10 | "licensing model", 11 | "license types", 12 | "license management", 13 | "licensing as a service", 14 | "software activation", 15 | "subscription", 16 | "floating", 17 | "pay-per-use", 18 | "client", 19 | "RESTful", 20 | "API", 21 | "REST" 22 | ], 23 | "homepage": "https://netlicensing.io", 24 | "license": "Apache-2.0", 25 | "authors": [ 26 | { 27 | "name": "Labs64 NetLicensing", 28 | "email": "netlicensing@labs64.com", 29 | "homepage": "https://netlicensing.io" 30 | } 31 | ], 32 | "support": { 33 | "email": "netlicensing@labs64.com", 34 | "issues": "https://github.com/Labs64/NetLicensingClient-php/issues", 35 | "wiki": "https://netlicensing.io/wiki/", 36 | "source": "https://github.com/Labs64/NetLicensingClient-php", 37 | "docs": "https://netlicensing.io/wiki/" 38 | }, 39 | "require": { 40 | "php": ">=7.4", 41 | "php-curl-class/php-curl-class": "^11.0.0", 42 | "fr3d/xmldsig": "^3.0", 43 | "ext-mbstring": "*", 44 | "ext-json": "*", 45 | "ext-dom": "*" 46 | }, 47 | "require-dev": { 48 | "phpunit/phpunit": "~6.5.14", 49 | "fzaninotto/faker": "^v1.9.2", 50 | "wp-cli/php-cli-tools": "^v0.11.11" 51 | }, 52 | "autoload": { 53 | "files": [ 54 | "netlicensing.php" 55 | ] 56 | }, 57 | "prefer-stable": true 58 | } 59 | -------------------------------------------------------------------------------- /converter/ItemToArrayConverter.php: -------------------------------------------------------------------------------- 1 | setProductDiscounts($discounts); 17 | 18 | return $product; 19 | } 20 | } -------------------------------------------------------------------------------- /converter/ItemToProductModuleConverter.php: -------------------------------------------------------------------------------- 1 | setLicense(new License(['number' => $licenseTransactionJoin[Constants::LICENSE_NUMBER]])); 23 | $join->setTransaction(new Transaction(['number' => $licenseTransactionJoin[Constants::TRANSACTION_NUMBER]])); 24 | 25 | $joins[] = $join; 26 | } 27 | 28 | $transaction->setLicenseTransactionJoins($joins); 29 | } 30 | 31 | return $transaction; 32 | } 33 | } -------------------------------------------------------------------------------- /converter/ItemsToArrayConverter.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use Exception; 12 | use phpDocumentor\Reflection\Types\Boolean; 13 | 14 | /** 15 | * Defines properties common to all (or most) of other entities. 16 | * 17 | * @package NetLicensing\EntitiesNew 18 | */ 19 | abstract class BaseEntity 20 | { 21 | use Properties; 22 | 23 | /** 24 | * The primary key for the entity. 25 | * 26 | * @var string 27 | */ 28 | protected string $primaryKey = 'number'; 29 | 30 | /** 31 | * Indicates if the entity exists. 32 | * 33 | * @var bool 34 | */ 35 | public bool $exists = false; 36 | 37 | /** 38 | * Create a new entity instance. 39 | * 40 | * @param array $properties 41 | * @param bool $exists 42 | */ 43 | public function __construct(array $properties = [], bool $exists = false) 44 | { 45 | $this->setProperties($properties, true); 46 | 47 | $this->exists = $exists; 48 | } 49 | 50 | /** 51 | * Get the primary key for the entity. 52 | * 53 | * @return string 54 | */ 55 | public function getKeyName(): string 56 | { 57 | return $this->primaryKey; 58 | } 59 | 60 | /** 61 | * Get the value of the entity primary key. 62 | * 63 | * @return mixed 64 | * @throws Exception 65 | */ 66 | public function getKey() 67 | { 68 | return $this->getProperty($this->getKeyName()); 69 | } 70 | 71 | /** 72 | * Dynamically retrieve properties on the entity. 73 | * 74 | * @param string $key 75 | * @return mixed 76 | * @throws Exception 77 | */ 78 | public function __get(string $key) 79 | { 80 | return $this->getProperty($key); 81 | } 82 | 83 | /** 84 | * Dynamically set properties on the entity. 85 | * 86 | * @param string $key 87 | * @param mixed $value 88 | * @return void 89 | */ 90 | public function __set(string $key, $value) 91 | { 92 | $this->setProperty($key, $value); 93 | } 94 | 95 | /** 96 | * Determine if an property on the entity. 97 | * 98 | * @param string $key 99 | * @return bool 100 | * @throws Exception 101 | */ 102 | public function __isset(string $key): bool 103 | { 104 | return !is_null($this->getProperty($key)); 105 | } 106 | 107 | /** 108 | * Unset an property on the entity. 109 | * 110 | * @param string $key 111 | * @return void 112 | */ 113 | public function __unset(string $key) 114 | { 115 | unset($this->properties[$key]); 116 | } 117 | 118 | /** 119 | * Handle dynamic method calls into the entity. 120 | * 121 | * @param string $method 122 | * @param array $parameters 123 | * @return mixed 124 | * @throws Exception 125 | */ 126 | public function __call(string $method, array $parameters) 127 | { 128 | //convert method to snake case 129 | $delimiter = '_'; 130 | $method = preg_replace('/\s+/u', '', $method); 131 | $method = mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $method), 'UTF-8'); 132 | 133 | $methodParts = explode($delimiter, $method); 134 | 135 | //check if need set or get attributes 136 | if (in_array($methodParts[0], ['get', 'set'])) { 137 | 138 | //get attribute name 139 | $key = array_slice($methodParts, 1); 140 | $key = implode('_', $key); 141 | $key = lcfirst(str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $key)))); 142 | 143 | array_unshift($parameters, $key); 144 | 145 | //call getAttribute 146 | if ($methodParts[0] == 'get'){ 147 | return $this->getProperty(...$parameters); 148 | }; 149 | 150 | //call setAttribute 151 | return $this->setProperty(...$parameters); 152 | } 153 | 154 | //trigger error if method undefined 155 | trigger_error('Call to undefined method ' . __CLASS__ . '::' . $method . '()', E_USER_ERROR); 156 | } 157 | 158 | /** 159 | * Convert the entity instance to an array. 160 | * 161 | * @return array 162 | */ 163 | public function toArray(): array 164 | { 165 | return $this->properties; 166 | } 167 | 168 | /** 169 | * Convert the entity instance to an array. 170 | */ 171 | public function asPropertiesMap(): array 172 | { 173 | return $this->properties; 174 | } 175 | 176 | /** 177 | * Convert the entity instance to JSON. 178 | * 179 | * @param int $options 180 | * @return string 181 | */ 182 | public function toJson(int $options = 0): string 183 | { 184 | return json_encode($this->jsonSerialize(), $options); 185 | } 186 | 187 | /** 188 | * Convert the object into something JSON serializable. 189 | * 190 | * @return array 191 | */ 192 | public function jsonSerialize(): array 193 | { 194 | return $this->toArray(); 195 | } 196 | 197 | /** 198 | * Convert the entity to its string representation. 199 | * 200 | * @return string 201 | */ 202 | public function __toString(): string 203 | { 204 | return $this->toJson(); 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /entity/Country.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * NetLicensing Country entity. 13 | * 14 | * Properties visible via NetLicensing API: 15 | * 16 | * @property string $code 17 | * 18 | * @property string $name 19 | * 20 | * @property double $vatPercent 21 | * 22 | * @property boolean $isEu 23 | * 24 | * @method string getCode($default = null) 25 | * @method string getName($default = null) 26 | * @method double getVatPercent($default = null) 27 | * @method boolean getIsEu($default = null) 28 | * @method Country setCode(string $code) 29 | * @method Country setName(string $name) 30 | * @method Country setVatPercent(double $vatPercent) 31 | * @method Country setIsEu(bool $isEu) 32 | * 33 | * @package NetLicensing 34 | */ 35 | class Country extends BaseEntity 36 | { 37 | /** 38 | * The attributes that should be cast to native types. 39 | * 40 | * @var array 41 | */ 42 | protected array $casts = [ 43 | 'vatPercent' => 'double', 44 | 'isEu' => 'boolean_string', 45 | ]; 46 | } 47 | -------------------------------------------------------------------------------- /entity/License.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * License entity used internally by NetLicensing. 13 | * 14 | * Properties visible via NetLicensing API: 15 | * 16 | * Unique number (across all products/licensees of a vendor) that identifies the license. Vendor can 17 | * assign this number when creating a license or let NetLicensing generate one. Read-only after corresponding creation 18 | * transaction status is set to closed. 19 | * @property string $number 20 | * 21 | * Name for the licensed item. Set from license template on creation, if not specified explicitly. 22 | * @property string $name 23 | * 24 | * If set to false, the license is disabled. License can be re-enabled, but as long as it is disabled, 25 | * the license is excluded from the validation process. 26 | * @property boolean $active 27 | * 28 | * price for the license. If >0, it must always be accompanied by the currency specification. Read-only, 29 | * set from license template on creation. 30 | * @property float $price 31 | * 32 | * specifies currency for the license price. Check data types to discover which currencies are 33 | * supported. Read-only, set from license template on creation. 34 | * @property string $currency 35 | * 36 | * If set to true, this license is not shown in NetLicensing Shop as purchased license. Set from license 37 | * template on creation, if not specified explicitly. 38 | * @property boolean $hidden 39 | * 40 | * @property string $startDate 41 | * 42 | * Arbitrary additional user properties of string type may be associated with each license. The name of user property 43 | * must not be equal to any of the fixed property names listed above and must be none of id, deleted, licenseeNumber, 44 | * licenseTemplateNumber. 45 | * 46 | * @method string getNumber($default = null) 47 | * @method string getName($default = null) 48 | * @method boolean getActive($default = null) 49 | * @method double getPrice($default = null) 50 | * @method string getCurrency($default = null) 51 | * @method boolean getHidden($default = null) 52 | * @method boolean getInUse($default = null) 53 | * @method string getParentFeature($default = null) 54 | * @method int getTimeVolume($default = null) 55 | * @method int getStartDate($default = null) 56 | * @method License setNumber(string $number) 57 | * @method License setName(string $name) 58 | * @method License setActive(boolean $active) 59 | * @method License setHidden(boolean $hidden) 60 | * @method License setParentFeature (string $parentFeature) 61 | * @method License setTimeVolume(int $timeVolume) 62 | * @method License setStartDate($startDate) 63 | * 64 | * 65 | * @package NetLicensing 66 | */ 67 | class License extends BaseEntity 68 | { 69 | /** 70 | * The attributes that should be cast to native types. 71 | * 72 | * @var array 73 | */ 74 | protected array $casts = [ 75 | 'active' => 'boolean_string', 76 | 'price' => 'double', 77 | 'hidden' => 'boolean_string', 78 | 'inUse' => 'boolean_string', 79 | 'timeVolume' => 'int', 80 | ]; 81 | 82 | protected ?Licensee $licensee = null; 83 | 84 | protected ?LicenseTemplate $licenseTemplate = null; 85 | 86 | protected array $licenseTransactionJoins = []; 87 | 88 | public function getLicensee(): ?Licensee 89 | { 90 | return $this->licensee; 91 | } 92 | 93 | public function setLicensee(Licensee $licensee): License 94 | { 95 | $licenses = $licensee->getLicenses(); 96 | $licenses[] = $this; 97 | 98 | $licensee->setLicenses($licenses); 99 | $this->licensee = $licensee; 100 | 101 | return $this; 102 | } 103 | 104 | public function getLicenseTemplate(): ?LicenseTemplate 105 | { 106 | return $this->licenseTemplate; 107 | } 108 | 109 | public function setLicenseTemplate(LicenseTemplate $licenseTemplate): License 110 | { 111 | $licenses = $licenseTemplate->getLicenses(); 112 | $licenses[] = $this; 113 | 114 | $licenseTemplate->setLicenses($licenses); 115 | $this->licenseTemplate = $licenseTemplate; 116 | 117 | return $this; 118 | } 119 | 120 | public function getLicenseTransactionJoins(): array 121 | { 122 | return $this->licenseTransactionJoins; 123 | } 124 | 125 | public function setLicenseTransactionJoins(array $licenseTransactionJoins): License 126 | { 127 | $this->licenseTransactionJoins = $licenseTransactionJoins; 128 | return $this; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /entity/LicenseTemplate.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * License template entity used internally by NetLicensing. 13 | * 14 | * Properties visible via NetLicensing API: 15 | * 16 | * Unique number (across all products of a vendor) that identifies the license template. Vendor can 17 | * assign this number when creating a license template or let NetLicensing generate one. Read-only after creation of the 18 | * first license from this license template. 19 | * @property string $number 20 | * 21 | * If set to false, the license template is disabled. Licensee can not obtain any new licenses off this 22 | * license template. 23 | * @property boolean $active 24 | * 25 | * Name for the licensed item. 26 | * @property string $name 27 | * 28 | * Type of licenses created from this license template. Supported types: "FEATURE", "TIMEVOLUME", 29 | * "FLOATING", "QUANTITY" 30 | * @property string $licenseType 31 | * 32 | * Price for the license. If >0, it must always be accompanied by the currency specification. 33 | * @property double $price 34 | * 35 | * Specifies currency for the license price. Check data types to discover which currencies are 36 | * supported. 37 | * @property string $currency 38 | * 39 | * If set to true, every new licensee automatically gets one license out of this license template on 40 | * creation. Automatic licenses must have their price set to 0. 41 | * @property boolean $automatic 42 | * 43 | * If set to true, this license template is not shown in NetLicensing Shop as offered for purchase. 44 | * @property boolean $hidden 45 | * 46 | * If set to true, licenses from this license template are not visible to the end customer, but 47 | * participate in validation. 48 | * @property boolean $hideLicenses 49 | * 50 | * Mandatory for 'TIMEVOLUME' license type. 51 | * @property integer $timeVolume 52 | * 53 | * Mandatory for 'FLOATING' license type. 54 | * @property integer $maxSessions 55 | * 56 | * Mandatory for 'QUANTITY' license type. 57 | * @property integer $quantity 58 | * 59 | * 60 | * @method string getNumber($default = null) 61 | * @method boolean getActive($default = null) 62 | * @method string getName($default = null) 63 | * @method string getLicenseType($default = null) 64 | * @method double getPrice($default = null) 65 | * @method string getCurrency($default = null) 66 | * @method boolean getAutomatic($default = null) 67 | * @method boolean getHidden($default = null) 68 | * @method boolean getHideLicenses($default = null) 69 | * @method integer getTimeVolume($default = null) 70 | * @method integer getMaxSessions($default = null) 71 | * @method integer getQuantity($default = null) 72 | * @method boolean getInUse($default = null) 73 | * @method LicenseTemplate setNumber(string $number) 74 | * @method LicenseTemplate setActive(boolean $active) 75 | * @method LicenseTemplate setName(string $name) 76 | * @method LicenseTemplate setLicenseType(string $licenseType) 77 | * @method LicenseTemplate setPrice($price) 78 | * @method LicenseTemplate setCurrency(string $currency) 79 | * @method LicenseTemplate setAutomatic(boolean $automatic) 80 | * @method LicenseTemplate setHidden(boolean $hidden) 81 | * @method LicenseTemplate setHideLicenses(boolean $hideLicenses) 82 | * @method LicenseTemplate setTimeVolume(int $timeVolume) 83 | * @method LicenseTemplate setMaxSessions(int $maxSessions) 84 | * @method LicenseTemplate setQuantity(int $quantity) 85 | * 86 | * @package NetLicensing 87 | */ 88 | class LicenseTemplate extends BaseEntity 89 | { 90 | /** 91 | * The attributes that should be cast to native types. 92 | * 93 | * @var array 94 | */ 95 | protected array $casts = [ 96 | 'price' => 'double', 97 | 'active' => 'boolean_string', 98 | 'inUse' => 'boolean_string', 99 | 'automatic' => 'boolean_string', 100 | 'hidden' => 'boolean_string', 101 | 'hideLicenses' => 'boolean_string', 102 | 'timeVolume' => 'int', 103 | 'maxSessions' => 'int', 104 | 'quantity' => 'int', 105 | ]; 106 | 107 | protected array $licenses = []; 108 | 109 | public function setLicenses(array $licenses): LicenseTemplate 110 | { 111 | $this->licenses = $licenses; 112 | return $this; 113 | } 114 | 115 | public function getLicenses(): array 116 | { 117 | return $this->licenses; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /entity/LicenseTransactionJoin.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | namespace NetLicensing; 9 | 10 | 11 | class LicenseTransactionJoin 12 | { 13 | protected ?Transaction $transaction = null; 14 | 15 | protected ?License $license = null; 16 | 17 | public function __construct(Transaction $transaction = null, License $license = null) 18 | { 19 | $this->transaction = $transaction; 20 | $this->license = $license; 21 | } 22 | 23 | public function setTransaction(Transaction $transaction): LicenseTransactionJoin 24 | { 25 | $this->transaction = $transaction; 26 | return $this; 27 | } 28 | 29 | public function getTransaction(): ?Transaction 30 | { 31 | return $this->transaction; 32 | } 33 | 34 | public function setLicense(License $license): LicenseTransactionJoin 35 | { 36 | $this->license = $license; 37 | return $this; 38 | } 39 | 40 | public function getLicense(): ?License 41 | { 42 | return $this->license; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /entity/Licensee.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * Licensee entity used internally by NetLicensing. 13 | * 14 | * Properties visible via NetLicensing API: 15 | * 16 | * Unique number (across all products of a vendor) that identifies the licensee. Vendor can assign this 17 | * number when creating a licensee or let NetLicensing generate one. Read-only after creation of the first license for 18 | * the licensee. 19 | * @property string $number 20 | * 21 | * Licensee name. 22 | * @property string $name 23 | * 24 | * If set to false, the licensee is disabled. Licensee can not obtain new licenses, and validation is 25 | * disabled (tbd). 26 | * @property boolean $active 27 | * 28 | * Licensee Secret for licensee 29 | * @property @deprecated string $licenseeSecret 30 | * 31 | * Mark licensee for transfer. 32 | * @property boolean $markedForTransfer 33 | * 34 | * Arbitrary additional user properties of string type may be associated with each licensee. The name of user property 35 | * must not be equal to any of the fixed property names listed above and must be none of id, deleted, productNumber 36 | * 37 | * @method string getNumber($default = null) 38 | * @method string getName($default = null) 39 | * @method string getActive($default = null) 40 | * @method @deprecated string getLicenseeSecret($default = null) 41 | * @method boolean getMarkedForTransfer($default = null) 42 | * @method boolean getInUse($default = null) 43 | * @method Licensee setNumber(string $number) 44 | * @method Licensee setName(string $name) 45 | * @method Licensee setActive(boolean $active) 46 | * @method @deprecated Licensee setLicenseeSecret($licenseeSecret) 47 | * @method Licensee setMarkedForTransfer(boolean $markedForTransfer) 48 | * 49 | * @package NetLicensing 50 | */ 51 | class Licensee extends BaseEntity 52 | { 53 | /** 54 | * The attributes that should be cast to native types. 55 | * 56 | * @var array 57 | */ 58 | protected array $casts = [ 59 | 'active' => 'boolean_string', 60 | 'markedForTransfer' => 'boolean_string', 61 | 'inUse' => 'boolean_string', 62 | ]; 63 | 64 | protected ?Product $product = null; 65 | 66 | protected array $licenses = []; 67 | 68 | public function getProduct(): ?Product 69 | { 70 | return $this->product; 71 | } 72 | 73 | public function setProduct(Product $product): Licensee 74 | { 75 | $licensees = $product->getLicensees(); 76 | 77 | $licensees[] = $this; 78 | $product->setLicensees($licensees); 79 | 80 | $this->product = $product; 81 | 82 | return $this; 83 | } 84 | 85 | public function getLicenses(): array 86 | { 87 | return $this->licenses; 88 | } 89 | 90 | public function setLicenses(array $licenses): Licensee 91 | { 92 | $this->licenses = $licenses; 93 | return $this; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /entity/PaymentMethod.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use Exception; 12 | 13 | /** 14 | * PaymentMethod entity used internally by NetLicensing. 15 | * 16 | * @property string $number 17 | * 18 | * @property boolean $active 19 | * 20 | * @method string getNumber($default = null) 21 | * @method boolean getActive($default = null) 22 | * @method boolean setNumber(string $number) 23 | * @method boolean setActive(boolean $active) 24 | * 25 | * 26 | * @package NetLicensing 27 | */ 28 | class PaymentMethod extends BaseEntity 29 | { 30 | /** 31 | * The attributes that should be cast to native types. 32 | * 33 | * @var array 34 | */ 35 | protected array $casts = [ 36 | 'active' => 'boolean_string', 37 | ]; 38 | 39 | /** 40 | * @throws Exception 41 | */ 42 | public function getPaypalSubject() 43 | { 44 | return $this->getProperty('paypal.subject'); 45 | } 46 | 47 | public function setPaypalSubject($paypalSubject): PaymentMethod 48 | { 49 | $this->properties['paypal.subject'] = $paypalSubject; 50 | return $this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /entity/Product.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * NetLicensing Product entity. 13 | * 14 | * Properties visible via NetLicensing API: 15 | * 16 | * Unique number that identifies the product. Vendor can assign this number when creating a product or 17 | * let NetLicensing generate one. Read-only after creation of the first licensee for the product. 18 | * @property string $number 19 | * 20 | * If set to false, the product is disabled. No new licensees can be registered for the product, 21 | * existing licensees can not obtain new licenses. 22 | * @property boolean $active 23 | * 24 | * Product name. Together with the version identifies the product for the end customer. 25 | * @property string $name 26 | * 27 | * Product version. Convenience parameter, additional to the product name. 28 | * @property float $version 29 | * 30 | * If set to 'true', non-existing licensees will be created at first validation attempt. 31 | * @property boolean $licenseeAutoCreate 32 | * 33 | * Product description. Optional. 34 | * @property string $description 35 | * 36 | * Licensing information. Optional. 37 | * @property string $licensingInfo 38 | * 39 | * @property boolean $inUse 40 | * 41 | * Arbitrary additional user properties of string type may be associated with each product. The name of user property 42 | * must not be equal to any of the fixed property names listed above and must be none of id, deleted. 43 | * 44 | * @method string getNumber($default = null) 45 | * @method boolean getActive($default = null) 46 | * @method string getName($default = null) 47 | * @method string getVersion($default = null) 48 | * @method boolean getLicenseeAutoCreate($default = null) 49 | * @method string getDescription($default = null) 50 | * @method string getLicensingInfo($default = null) 51 | * @method boolean getInUse($default = null) 52 | * @method Product setNumber(string $number) 53 | * @method Product setActive(boolean $active) 54 | * @method Product setName(string $name) 55 | * @method Product setVersion($version) 56 | * @method Product setLicenseeAutoCreate(boolean $licenseeAutoCreate) 57 | * @method Product setDescription(string $description) 58 | * @method Product setLicensingInfo($licensingInfo) 59 | * 60 | * @package NetLicensing\EntitiesNew 61 | */ 62 | class Product extends BaseEntity 63 | { 64 | /** 65 | * The attributes that should be cast to native types. 66 | * 67 | * @var array 68 | */ 69 | protected array $casts = [ 70 | 'version' => 'string', 71 | 'licenseeAutoCreate' => 'boolean_string', 72 | 'active' => 'boolean_string', 73 | 'inUse' => 'boolean_string', 74 | ]; 75 | 76 | protected array $productDiscounts = []; 77 | protected bool $productDiscountsTouched = false; 78 | 79 | protected array $productModules = []; 80 | 81 | protected array $licensees = []; 82 | 83 | public function getProductModules(): array 84 | { 85 | return $this->productModules; 86 | } 87 | 88 | public function setProductModules(array $productModules): Product 89 | { 90 | $this->productModules = $productModules; 91 | return $this; 92 | } 93 | 94 | public function getLicensees(): array 95 | { 96 | return $this->licensees; 97 | } 98 | 99 | public function setLicensees(array $licensees): Product 100 | { 101 | $this->licensees = $licensees; 102 | return $this; 103 | } 104 | 105 | public function getProductDiscounts(): array 106 | { 107 | return $this->productDiscounts; 108 | } 109 | 110 | public function setProductDiscounts($productDiscounts = []): Product 111 | { 112 | $discounts = []; 113 | 114 | 115 | if (!empty($productDiscounts)) { 116 | foreach ($productDiscounts as $productDiscount) { 117 | if (!($productDiscount instanceof ProductDiscount)) { 118 | $productDiscount = new ProductDiscount($productDiscount); 119 | } 120 | $discounts[] = $productDiscount; 121 | } 122 | } 123 | 124 | $this->productDiscounts = $discounts; 125 | $this->productDiscountsTouched = true; 126 | 127 | return $this; 128 | } 129 | 130 | public function addDiscount(ProductDiscount $discount): Product 131 | { 132 | $this->productDiscounts[] = $discount; 133 | $this->productDiscountsTouched = true; 134 | 135 | return $this; 136 | } 137 | 138 | /** 139 | * @deprecated use setProductDiscounts or addDiscount instead 140 | * @param $discount 141 | * @return $this 142 | */ 143 | protected function setDiscount($discount): Product 144 | { 145 | $this->setProductDiscounts([$discount]); 146 | return $this; 147 | } 148 | 149 | public function asPropertiesMap(): array 150 | { 151 | $map = $this->toArray(); 152 | 153 | if ($this->productDiscounts) { 154 | $map['discount'] = []; 155 | foreach ($this->productDiscounts as $productDiscount) { 156 | $map['discount'][] = (string)$productDiscount; 157 | } 158 | } 159 | 160 | if (empty($map['discount']) && $this->productDiscountsTouched) { 161 | $map['discount'] = ''; 162 | } 163 | 164 | return $map; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /entity/ProductDiscount.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * Class ProductDiscount 13 | * 14 | * @property double $totalPrice 15 | * @property string $currency 16 | * @property double $amountFix 17 | * @property double $amountPercent 18 | * 19 | * 20 | * @method double getTotalPrice($default = null) 21 | * @method string getCurrency($default = null) 22 | * @method double getAmountFix($default = null) 23 | * @method double getAmountPercent($default = null) 24 | * @method ProductDiscount setTotalPrice($totalPrice) 25 | * @method ProductDiscount setCurrency(string $currency) 26 | * 27 | * 28 | * @package NetLicensing 29 | */ 30 | class ProductDiscount extends BaseEntity 31 | { 32 | /** 33 | * The attributes that should be cast to native types. 34 | * 35 | * @var array 36 | */ 37 | protected array $casts = [ 38 | 'totalPrice' => 'double', 39 | 'amountFix' => 'double', 40 | 'amountPercent' => 'double', 41 | ]; 42 | 43 | protected ?Product $product = null; 44 | 45 | public function getProduct(): ?Product 46 | { 47 | return $this->product; 48 | } 49 | 50 | public function setProduct(Product $product): ProductDiscount 51 | { 52 | $this->product = $product; 53 | return $this; 54 | } 55 | 56 | public function setAmountFix($amountFix): ProductDiscount 57 | { 58 | $this->setProperty('amountFix', $amountFix) 59 | ->removeProperty('amountPercent'); 60 | 61 | return $this; 62 | } 63 | 64 | public function setAmountPercent($amountPercent): ProductDiscount 65 | { 66 | $this->setProperty('amountPercent', $amountPercent) 67 | ->removeProperty('amountFix'); 68 | 69 | return $this; 70 | } 71 | 72 | public function __toString(): string 73 | { 74 | $totalPrice = $this->getTotalPrice(); 75 | $currency = $this->getCurrency(); 76 | 77 | $amount = ''; 78 | 79 | if (!is_null($this->getAmountFix())) $amount = $this->getAmountFix(); 80 | if (!is_null($this->getAmountPercent())) $amount = $this->getAmountPercent() . '%'; 81 | 82 | return $totalPrice . ';' . $currency . ';' . $amount; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /entity/ProductModule.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * Product module entity used internally by NetLicensing. 13 | * 14 | * Properties visible via NetLicensing API: 15 | * 16 | * Unique number (across all products of a vendor) that identifies the product module. Vendor can assign 17 | * this number when creating a product module or let NetLicensing generate one. Read-only after creation of the first 18 | * licensee for the product. 19 | * @property string $number 20 | * 21 | * If set to false, the product module is disabled. Licensees can not obtain any new licenses for this 22 | * product module. 23 | * @property boolean $active 24 | * 25 | * Product module name that is visible to the end customers in NetLicensing Shop. 26 | * @property string $name 27 | * 28 | * Licensing model applied to this product module. Defines what license templates can be 29 | * configured for the product module and how licenses for this product module are processed during validation. 30 | * @property string $licensingModel 31 | * 32 | * Maximum checkout validity (days). Mandatory for 'Floating' licensing model. 33 | * @property integer $maxCheckoutValidity 34 | * 35 | * Remaining time volume for yellow level. Mandatory for 'Rental' licensing model. 36 | * @property integer $yellowThreshold 37 | * 38 | * Remaining time volume for red level. Mandatory for 'Rental' licensing model. 39 | * @property integer $redThreshold 40 | * 41 | * License template. Mandatory for 'Try & Buy' licensing model. Supported types: "TIMEVOLUME", "FEATURE". 42 | * @property string $licenseTemplate 43 | * 44 | * @method string getNumber($default = null) 45 | * @method boolean getActive($default = null) 46 | * @method string getName($default = null) 47 | * @method string getLicensingModel($default = null) 48 | * @method integer getMaxCheckoutValidity($default = null) 49 | * @method integer getYellowThreshold($default = null) 50 | * @method integer getRedThreshold($default = null) 51 | * @method boolean getInUse($default = null) 52 | * @method ProductModule setNumber(string $number) 53 | * @method ProductModule setActive(boolean $active) 54 | * @method ProductModule setName(string $name) 55 | * @method ProductModule setLicensingModel(string $licensingModel) 56 | * @method ProductModule setMaxCheckoutValidity(int $maxCheckoutValidity) 57 | * @method ProductModule setYellowThreshold(int $yellowThreshold) 58 | * @method ProductModule setRedThreshold(int $redThreshold) 59 | * 60 | * 61 | * @package NetLicensing 62 | */ 63 | class ProductModule extends BaseEntity 64 | { 65 | /** 66 | * The attributes that should be cast to native types. 67 | * 68 | * @var array 69 | */ 70 | protected array $casts = [ 71 | 'active' => 'boolean_string', 72 | 'maxCheckoutValidity' => 'int', 73 | 'yellowThreshold' => 'int', 74 | 'redThreshold' => 'int', 75 | 'inUse' => 'boolean_string', 76 | ]; 77 | 78 | protected ?Product $product = null; 79 | 80 | protected array $licenseTemplates = []; 81 | 82 | public function setProduct(Product $product): ProductModule 83 | { 84 | $this->product = $product; 85 | return $this; 86 | } 87 | 88 | public function getProduct(): ?Product 89 | { 90 | return $this->product; 91 | } 92 | 93 | public function setLicenseTemplates(array $licenseTemplates): ProductModule 94 | { 95 | $this->licenseTemplates = $licenseTemplates; 96 | return $this; 97 | } 98 | 99 | public function getLicenseTemplates(): array 100 | { 101 | return $this->licenseTemplates; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /entity/Token.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * Product module entity used internally by NetLicensing. 13 | * 14 | * Properties visible via NetLicensing API: 15 | * 16 | * Unique number 17 | * @property string $number 18 | * 19 | * If set to false, the token is disabled. 20 | * @property boolean $active 21 | * 22 | * Expiration Time 23 | * @property string $expirationTime 24 | * 25 | * @property string $vendorNumber 26 | * 27 | * Token type to be generated. 28 | * DEFAULT - default one-time token (will be expired after first request) 29 | * SHOP - shop token is used to redirect customer to the netlicensingShop(licenseeNumber is mandatory) 30 | * APIKEY - APIKey-token 31 | * @property string $tokenType 32 | * 33 | * @property string $licenseeNumber 34 | * 35 | * @method string getNumber($default = null) 36 | * @method boolean getActive($default = null) 37 | * @method \DateTime getExpirationTime($default = null) 38 | * @method string getVendorNumber($default = null) 39 | * @method string getTokenType($default = null) 40 | * @method string getLicenseeNumber($default = null) 41 | * @method string getShopURL($default = null) 42 | * @method string getSuccessURL($default = null) 43 | * @method string getSuccessURLTitle($default = null) 44 | * @method string getCancelURL($default = null) 45 | * @method string getCancelURLTitle($default = null) 46 | * @method string getApiKey($default = null) 47 | * @method Token setNumber(string $number) 48 | * @method Token setActive(boolean $active) 49 | * @method Token setExpirationTime(string|int|\DateTime $expirationTime) 50 | * @method Token setVendorNumber(string $vendorNumber) 51 | * @method Token setTokenType(string $tokenType) 52 | * @method Token setLicenseeNumber(string $tokenType) 53 | * @method Token setSuccessURL(string $successURL) 54 | * @method Token setSuccessURLTitle(string $successURLTitle) 55 | * @method Token setCancelURL(string $cancelURL) 56 | * @method Token setCancelURLTitle(string $cancelURLTitle) 57 | * @method Token setApiKey(string $apiKey) 58 | * 59 | * @package NetLicensing 60 | */ 61 | class Token extends BaseEntity 62 | { 63 | /** 64 | * The attributes that should be cast to native types. 65 | * 66 | * @var array 67 | */ 68 | protected array $casts = [ 69 | 'active' => 'boolean_string', 70 | ]; 71 | } 72 | -------------------------------------------------------------------------------- /entity/Transaction.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use Exception; 12 | 13 | /** 14 | * Transaction entity used internally by NetLicensing. 15 | * 16 | * Properties visible via NetLicensing API: 17 | * 18 | * Unique number (across all products of a vendor) that identifies the transaction. This number is 19 | * always generated by NetLicensing. 20 | * @property string $number 21 | * 22 | * always true for transactions 23 | * @property boolean $active 24 | * 25 | * Status of transaction. "CANCELLED", "CLOSED", "PENDING". 26 | * @property string $status 27 | * 28 | * "SHOP". AUTO transaction for internal use only. 29 | * @property string $source 30 | * 31 | * grand total for SHOP transaction (see source). 32 | * @property float $grandTotal 33 | * 34 | * discount for SHOP transaction (see source). 35 | * @property float $discount 36 | * 37 | * specifies currency for money fields (grandTotal and discount). Check data types to discover which 38 | * @property string $currency 39 | * 40 | * Date created. Optional. 41 | * @property string $dateCreated 42 | * 43 | * Date closed. Optional. 44 | * @property string $dateClosed 45 | * 46 | * @method string getNumber($default = null) 47 | * @method string getName($default = null) 48 | * @method boolean getActive($default = null) 49 | * @method string getStatus($default = null) 50 | * @method string getSource($default = null) 51 | * @method float getGrandTotal($default = null) 52 | * @method float getDiscount($default = null) 53 | * @method string getCurrency($default = null) 54 | * @method Transaction setNumber($number) 55 | * @method Transaction setName($name) 56 | * @method Transaction setStatus($status) 57 | * @method Transaction setSource($source) 58 | * @method Transaction setGrandTotal($grandTotal) 59 | * @method Transaction setDiscount($discount) 60 | * @method Transaction setCurrency($currency) 61 | * 62 | * @package NetLicensing 63 | */ 64 | class Transaction extends BaseEntity 65 | { 66 | /** 67 | * The attributes that should be cast to native types. 68 | * 69 | * @var array 70 | */ 71 | protected array $casts = [ 72 | 'active' => 'boolean_string', 73 | 'grandTotal' => 'float', 74 | 'discount' => 'float', 75 | ]; 76 | 77 | protected array $licenseTransactionJoins = []; 78 | 79 | public function __construct(array $properties = [], $exists = false) 80 | { 81 | $properties['active'] = true; 82 | 83 | parent::__construct($properties, $exists); 84 | } 85 | 86 | protected function setActive(): Transaction 87 | { 88 | $this->setProperty('active', true); 89 | return $this; 90 | } 91 | 92 | public function setDateCreated($dateCreated): Transaction 93 | { 94 | return $this->setProperty(Constants::TRANSACTION_DATE_CREATED, $dateCreated); 95 | } 96 | 97 | /** 98 | * @throws Exception 99 | */ 100 | public function getDateCreated($default = null) 101 | { 102 | return $this->getProperty(Constants::TRANSACTION_DATE_CREATED, $default); 103 | } 104 | 105 | public function setDateClosed($dateClosed): Transaction 106 | { 107 | return $this->setProperty(Constants::TRANSACTION_DATE_CLOSED, $dateClosed); 108 | } 109 | 110 | /** 111 | * @throws Exception 112 | */ 113 | public function getDateClosed($default = null) 114 | { 115 | return $this->getProperty(Constants::TRANSACTION_DATE_CLOSED, $default); 116 | } 117 | 118 | public function getLicenseTransactionJoins(): array 119 | { 120 | return $this->licenseTransactionJoins; 121 | } 122 | 123 | public function setLicenseTransactionJoins($licenseTransactionJoins = []): Transaction 124 | { 125 | $this->licenseTransactionJoins = $licenseTransactionJoins; 126 | return $this; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /entity/traits/Properties.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | 12 | use DateTimeInterface; 13 | use Exception; 14 | 15 | trait Properties 16 | { 17 | /** 18 | * The entity properties. 19 | * 20 | * @var array 21 | */ 22 | protected array $properties = []; 23 | 24 | /** 25 | * The entity properties original state. 26 | * 27 | * @var array 28 | */ 29 | protected array $original = []; 30 | 31 | /** 32 | * The properties that should be cast to native types. 33 | * 34 | * @var array 35 | */ 36 | protected array $casts = []; 37 | 38 | /** 39 | * Get an property from the entity. 40 | * 41 | * @param string $property 42 | * @param mixed $default 43 | * @return mixed 44 | * @throws Exception 45 | */ 46 | public function getProperty(string $property, $default = null) 47 | { 48 | if (!$property) return $default; 49 | 50 | $value = $this->properties[$property] ?? $default; 51 | 52 | // If the attribute exists within the cast array, we will convert it to 53 | // an appropriate native PHP type dependant upon the associated value 54 | // given with the key in the pair. Dayle made this comment line up. 55 | if ($this->hasCast($property)) { 56 | return $this->castGetProperty($property, $value); 57 | } 58 | 59 | return $value; 60 | } 61 | 62 | /** 63 | * Get all of the current properties on the entity. 64 | * 65 | * @return array 66 | */ 67 | public function getProperties(): array 68 | { 69 | return $this->properties; 70 | } 71 | 72 | /** 73 | * Set a given property on the entity. 74 | * 75 | * @param string $property 76 | * @param mixed $value 77 | * @return $this 78 | */ 79 | public function setProperty(string $property, $value) 80 | { 81 | $this->properties[$property] = ($this->hasCast($property)) ? $this->castSetProperty($property, $value) : $value; 82 | return $this; 83 | } 84 | 85 | /** 86 | * Alias for setProperty 87 | * 88 | * @param $property 89 | * @param $value 90 | * @return $this 91 | */ 92 | public function addProperty($property, $value) 93 | { 94 | $this->setProperty($property, $value); 95 | return $this; 96 | } 97 | 98 | 99 | /** 100 | * Set the array of entity properties. 101 | * 102 | * @param array $properties 103 | * @param bool $sync 104 | * @return $this 105 | */ 106 | public function setProperties(array $properties, $sync = false) 107 | { 108 | $this->properties = []; 109 | 110 | foreach ($properties as $property => $value) { 111 | $setMethod = 'set' . ucfirst($property); 112 | if (method_exists($this, $setMethod)) { 113 | $this->$setMethod($value); 114 | } else { 115 | $this->setProperty($property, $value); 116 | } 117 | } 118 | 119 | if ($sync) { 120 | $this->syncOriginal(); 121 | } 122 | 123 | return $this; 124 | } 125 | 126 | /** 127 | * Remove property 128 | * 129 | * @param $property 130 | * @return $this 131 | */ 132 | public function removeProperty($property) 133 | { 134 | unset($this->properties[$property]); 135 | return $this; 136 | } 137 | 138 | /** 139 | * Get the entity original attribute values. 140 | * 141 | * @param string|null $property 142 | * @param mixed $default 143 | * @return mixed 144 | */ 145 | public function getOriginal(string $property = null, $default = null) 146 | { 147 | if (is_null($property)) return $this->original; 148 | return $this->original[$property] ?? $default; 149 | } 150 | 151 | 152 | /** 153 | * Sync the original attributes with the current. 154 | * 155 | * @return $this 156 | */ 157 | public function syncOriginal() 158 | { 159 | $this->original = $this->properties; 160 | return $this; 161 | } 162 | 163 | /** 164 | * Sync a single original attribute with its current value. 165 | * 166 | * @param string $property 167 | * @return $this 168 | */ 169 | public function syncOriginalProperty(string $property) 170 | { 171 | $this->original[$property] = $this->properties[$property]; 172 | return $this; 173 | } 174 | 175 | /** 176 | * Determine whether an attribute should be cast to a native type. 177 | * 178 | * @param string $property 179 | * @param array|string|null $types 180 | * @return bool 181 | */ 182 | public function hasCast(string $property, $types = null): bool 183 | { 184 | if (array_key_exists($property, $this->casts)) { 185 | return !$types || in_array($this->getCastType($property), (array)$types, true); 186 | } 187 | 188 | return false; 189 | } 190 | 191 | /** 192 | * Get the type of cast for a entity attribute. 193 | * 194 | * @param string $property 195 | * @return string 196 | */ 197 | protected function getCastType(string $property): string 198 | { 199 | return trim(strtolower($this->casts[$property])); 200 | } 201 | 202 | /** 203 | * Determine if the entity or given property(s) have remained the same. 204 | * 205 | * @param array|string|null $attributes 206 | * @return bool 207 | */ 208 | public function isClean($attributes = null): bool 209 | { 210 | return !$this->isDirty(...func_get_args()); 211 | } 212 | 213 | /** 214 | * Determine if the entity or given property(s) have been modified. 215 | * 216 | * @param array|string|null $properties 217 | * @return bool 218 | */ 219 | public function isDirty($properties = null): bool 220 | { 221 | $dirty = $this->getDirty(); 222 | 223 | // If no specific attributes were provided, we will just see if the dirty array 224 | // already contains any attributes. If it does we will just return that this 225 | // count is greater than zero. Else, we need to check specific attributes. 226 | if (is_null($properties)) { 227 | return count($dirty) > 0; 228 | } 229 | 230 | $properties = is_array($properties) 231 | ? $properties : func_get_args(); 232 | 233 | // Here we will spin through every attribute and see if this is in the array of 234 | // dirty attributes. If it is, we will return true and if we make it through 235 | // all of the attributes for the entire array we will return false at end. 236 | foreach ($properties as $property) { 237 | if (array_key_exists($property, $dirty)) { 238 | return true; 239 | } 240 | } 241 | 242 | return false; 243 | } 244 | 245 | /** 246 | * Get the properties that have been changed since last sync. 247 | * 248 | * @return array 249 | */ 250 | public function getDirty(): array 251 | { 252 | $dirty = []; 253 | 254 | foreach ($this->properties as $property => $value) { 255 | if (!array_key_exists($property, $this->original)) { 256 | $dirty[$property] = $value; 257 | } elseif ($value !== $this->original[$property] && 258 | !$this->originalIsNumericallyEquivalent($property) 259 | ) { 260 | $dirty[$property] = $value; 261 | } 262 | } 263 | 264 | return $dirty; 265 | } 266 | 267 | /** 268 | * Determine if the new and old values for a given key are numerically equivalent. 269 | * 270 | * @param string $property 271 | * @return bool 272 | */ 273 | protected function originalIsNumericallyEquivalent(string $property): bool 274 | { 275 | $current = $this->properties[$property]; 276 | 277 | $original = $this->original[$property]; 278 | 279 | // This method checks if the two values are numerically equivalent even if they 280 | // are different types. This is in case the two values are not the same type 281 | // we can do a fair comparison of the two values to know if this is dirty. 282 | return is_numeric($current) && is_numeric($original) 283 | && strcmp((string)$current, (string)$original) === 0; 284 | } 285 | 286 | /** 287 | * Cast an property to a native PHP type. 288 | * 289 | * @param string $property 290 | * @param mixed $value 291 | * @return mixed 292 | * @throws Exception 293 | */ 294 | protected function castGetProperty(string $property, $value) 295 | { 296 | if (is_null($value)) { 297 | return null; 298 | } 299 | 300 | switch ($this->getCastType($property)) { 301 | case 'int': 302 | case 'integer': 303 | return (int)$value; 304 | case 'real': 305 | case 'float': 306 | case 'double': 307 | return (float)$value; 308 | case 'string': 309 | return (string)$value; 310 | case 'bool': 311 | case 'boolean': 312 | return (bool)$value; 313 | case 'boolean_string': 314 | return ($value == 'true'); 315 | case 'object': 316 | return json_decode($value, false); 317 | case 'array': 318 | case 'json': 319 | return json_decode($value, true); 320 | case 'datetime': 321 | return new \DateTime($value); 322 | default: 323 | return $value; 324 | } 325 | } 326 | 327 | /** 328 | * Cast an property to a native PHP type. 329 | * 330 | * @param string $property 331 | * @param mixed $value 332 | * @return mixed 333 | */ 334 | protected function castSetProperty(string $property, $value) 335 | { 336 | if (is_null($value)) { 337 | return null; 338 | } 339 | 340 | switch ($this->getCastType($property)) { 341 | case 'int': 342 | case 'integer': 343 | return (int)$value; 344 | case 'real': 345 | case 'float': 346 | case 'double': 347 | return (float)$value; 348 | case 'string': 349 | return (string)$value; 350 | case 'bool': 351 | case 'boolean': 352 | return (bool)$value; 353 | case 'boolean_string': 354 | return ($value && $value !== 'false') ? 'true' : 'false'; 355 | case 'object': 356 | return json_decode($value, false); 357 | case 'array': 358 | case 'json': 359 | return json_decode($value, true); 360 | case 'datetime': 361 | return $this->asDateTime($value); 362 | default: 363 | return $value; 364 | } 365 | } 366 | 367 | /** 368 | * Decode the given JSON back into an array or object. 369 | * 370 | * @param string $value 371 | * @param bool $asObject 372 | * @return mixed 373 | */ 374 | protected function fromJson(string $value, bool $asObject = false) 375 | { 376 | return json_decode($value, !$asObject); 377 | } 378 | 379 | /** 380 | * Return a DatetTime/timestamp as time string. 381 | * 382 | * @param $value 383 | * @return string 384 | */ 385 | protected function asDateTime($value): string 386 | { 387 | 388 | // If the value is already a DateTime instance, we will just skip the rest of 389 | // these checks since they will be a waste of time, and hinder performance 390 | // when checking the field. We will just return the DateTime right away. 391 | if ($value instanceof DateTimeInterface) { 392 | return $value->format('Y-m-d\TH:i:sP'); 393 | } 394 | 395 | // If this value is an integer, we will assume it is a UNIX timestamp's value 396 | // and format a Carbon object from this timestamp. This allows flexibility 397 | // when defining your date fields as they might be UNIX timestamps here. 398 | if (is_numeric($value)) { 399 | return (new \DateTime())->setTimestamp($value)->format('Y-m-d\TH:i:sP'); 400 | } 401 | 402 | return $value; 403 | } 404 | } 405 | -------------------------------------------------------------------------------- /examples/OfflineValidation.php: -------------------------------------------------------------------------------- 1 | setPublicKey($publicKey); 16 | 17 | // 2. Read the validation file. 18 | $offlineValidation = file_get_contents(__DIR__ . '../resources/Isb-DEMO.xml'); 19 | 20 | // 3. Validate. ValidationResult is same as if validation would be executed against the 21 | // NetLicensing service online. 22 | $meta = []; 23 | $validationResult = ValidationService::validateOffline($context, $offlineValidation, $meta); 24 | $this->assertNotEmpty($validationResult); 25 | } catch (Exception $e) { 26 | $this->fail($e->getMessage()); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/OfflineValidationTest.php: -------------------------------------------------------------------------------- 1 | setPublicKey($publicKey); 16 | 17 | // 2. Read the validation file. 18 | $offlineValidation = file_get_contents(__DIR__ . '../resources/Isb-DEMO.xml'); 19 | 20 | // 3. Validate. ValidationResult is same as if validation would be executed against the 21 | // NetLicensing service online. 22 | $meta = []; 23 | $validationResult = ValidationService::validateOffline($context, $offlineValidation, $meta); 24 | $this->assertNotEmpty($validationResult); 25 | } catch (Exception $e) { 26 | $this->fail($e->getMessage()); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | **Attention**, when executing these commands, you must be in the root of the project. 4 | 5 | ## Project setup 6 | ``` 7 | composer install 8 | ``` 9 | 10 | ### Run example as phpunit test 11 | ``` 12 | php vendor/phpunit/phpunit/phpunit examples 13 | ``` 14 | -------------------------------------------------------------------------------- /examples/resources/Isb-DEMO.xml: -------------------------------------------------------------------------------- 1 | ICC1F7ZKeQoayrzn1iGtw7Zt96s=jYb0aGBPR9Rn4HVRJhBsIRafzW1k3D/GF7GZ62nT8dwvJszGB0kEXdFrXTj7FhUeiBcBlqxcsEUUKA5XbE7LGbNm+V+f5xZu/+n/d/miufKPAIk6CN5xoZQLDRGRSruW0LiKJsnkbzHvIF4u6G/HUyQpUfrxwiqXb+tYFpiaMgcSHL5xGzRq5Mqusw21Cdq81MhUb9oUoujgisIZWqNyebOqWuzOjNJOy0y2uml4I5U5tBAL1OlrQKjfPUiy369HwMl37A7dR9oVcahb6/YPI039xeLTn+WzyFPIV7f41o6Ytq4Iefl6swj/elNKTHi9bYzcnjmM7ebOd+hinm8feA==Msb-DEMOtrue2021-04-21T20:15:45.694ZModule using "Subscription" licensing modelSubscription -------------------------------------------------------------------------------- /examples/resources/rsa_public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu5grobcnjPhzOvyG05DO 3 | OW6SlUIKa7omhJLIXl8D8fohuHUaZLoGA2Fot4OP/qFSg0DK4egbCbU+pDrasMvK 4 | vNTCMzw0ypzbyBEaYSm6wtEeU45ppawj0HjOh3NRp2Ds0hR8xSMKFRc/4d87hskj 5 | yjKXOqoOZhqjXwYk7ocIe6ADPpF4YCs5eY4/3CL1JnItdlKQRsl8ZJ0Yqe+figf9 6 | agCWvQ0O0faRdmgmr7eUhU9aXNvSJaVJXbg6TjhhxVujzehF8sh/7sxgGwqbyunE 7 | 15OWo6dArRCyNUeROu+9Jp4tET+2RA/PuqQbWW6EbJWBhpkqNdzi9CYuhuUjvk8m 8 | dwIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /examples/resources/rsa_public_wrong.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtq96itv1m00/czFD7IzE 3 | mLiXPpvok1vjqB9VU6kTkq6QFGAfJF1G+m1fbK5NvpiDCsfuofdCFuhVnvLnzrpd 4 | xUlse8erWEr9p9RAyh25NMK9/v0MAEAYV7zRa+ZOh31G54DwR7zk0TxyVzxKpjPi 5 | wQSnv7UCY/IR7remLIYO92K7jAg9ZB4IHTuVulCtSrSQajZ8Ep2rFGPr8OeTsj9c 6 | rBPpmL/ShdJOnL4NR0UnVWSpsCFW6wEqNafcUWnWpb98V49/p7fWDFJ1Tg6+OlVg 7 | lgsNrqrqwJpxDLKnGAkkxHaVxSnZzAYh+HP8CbJmbzzE1GRXNgy3w+smWMv6M996 8 | 9wIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /exception/BadSignatureException.php: -------------------------------------------------------------------------------- 1 | getCode() . "]: " . $this->getMessage() . "\n"; 12 | } 13 | } -------------------------------------------------------------------------------- /exception/MalformedArgumentsException.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use Exception; 12 | 13 | class MalformedArgumentsException extends Exception 14 | { 15 | public function __toString() 16 | { 17 | return get_class($this) . ": [" . $this->getCode() . "]: " . $this->getMessage() . "\n"; 18 | } 19 | } -------------------------------------------------------------------------------- /exception/NetLicensingException.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | namespace NetLicensing; 9 | 10 | use Exception; 11 | 12 | class NetLicensingException extends Exception 13 | { 14 | public function __toString() 15 | { 16 | return get_class($this) . ": [" . $this->getCode() . "]: " . $this->getMessage() . "\n"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /exception/RestException.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | namespace NetLicensing; 9 | 10 | use Exception; 11 | 12 | class RestException extends Exception 13 | { 14 | public function __toString() 15 | { 16 | return get_class($this) . ": [" . $this->getCode() . "]: " . $this->getMessage() . "\n"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /netlicensing.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | require_once(__DIR__ . '/common/Constants.php'); 10 | 11 | require_once(__DIR__ . '/converter/ItemToArrayConverter.php'); 12 | require_once(__DIR__ . '/converter/ItemsToArrayConverter.php'); 13 | require_once(__DIR__ . '/converter/ItemToProductConverter.php'); 14 | require_once(__DIR__ . '/converter/ItemToProductModuleConverter.php'); 15 | require_once(__DIR__ . '/converter/ItemToLicenseTemplateConverter.php'); 16 | require_once(__DIR__ . '/converter/ItemToLicenseeConverter.php'); 17 | require_once(__DIR__ . '/converter/ItemToLicenseConverter.php'); 18 | require_once(__DIR__ . '/converter/ItemToTransactionConverter.php'); 19 | require_once(__DIR__ . '/converter/ItemToTokenConverter.php'); 20 | require_once(__DIR__ . '/converter/ItemToPaymentMethodConverter.php'); 21 | require_once(__DIR__ . '/converter/ItemToCountryConverter.php'); 22 | 23 | require_once(__DIR__ . '/vo/Context.php'); 24 | require_once(__DIR__ . '/vo/NetLicensingCurl.php'); 25 | require_once(__DIR__ . '/vo/ValidationParameters.php'); 26 | require_once(__DIR__ . '/vo/ValidationResults.php'); 27 | require_once(__DIR__ . '/vo/Page.php'); 28 | 29 | require_once(__DIR__ . '/exception/MalformedArgumentsException.php'); 30 | require_once(__DIR__ . '/exception/NetLicensingException.php'); 31 | require_once(__DIR__ . '/exception/RestException.php'); 32 | require_once(__DIR__ . '/exception/BadSignatureException.php'); 33 | 34 | require_once(__DIR__ . '/util/CheckUtils.php'); 35 | require_once(__DIR__ . '/util/SignatureUtils.php'); 36 | 37 | require_once(__DIR__ . '/entity/traits/Properties.php'); 38 | require_once(__DIR__ . '/entity/BaseEntity.php'); 39 | require_once(__DIR__ . '/entity/Product.php'); 40 | require_once(__DIR__ . '/entity/ProductDiscount.php'); 41 | require_once(__DIR__ . '/entity/ProductModule.php'); 42 | require_once(__DIR__ . '/entity/LicenseTemplate.php'); 43 | require_once(__DIR__ . '/entity/Licensee.php'); 44 | require_once(__DIR__ . '/entity/License.php'); 45 | require_once(__DIR__ . '/entity/Transaction.php'); 46 | require_once(__DIR__ . '/entity/Token.php'); 47 | require_once(__DIR__ . '/entity/PaymentMethod.php'); 48 | require_once(__DIR__ . '/entity/Country.php'); 49 | require_once(__DIR__ . '/entity/LicenseTransactionJoin.php'); 50 | 51 | require_once(__DIR__ . '/service/NetLicensingService.php'); 52 | require_once(__DIR__ . '/service/ProductService.php'); 53 | require_once(__DIR__ . '/service/ProductModuleService.php'); 54 | require_once(__DIR__ . '/service/LicenseTemplateService.php'); 55 | require_once(__DIR__ . '/service/UtilityService.php'); 56 | require_once(__DIR__ . '/service/LicenseeService.php'); 57 | require_once(__DIR__ . '/service/LicenseService.php'); 58 | require_once(__DIR__ . '/service/TransactionService.php'); 59 | require_once(__DIR__ . '/service/TokenService.php'); 60 | require_once(__DIR__ . '/service/PaymentMethodService.php'); 61 | require_once(__DIR__ . '/service/ValidationService.php'); -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | ./tests 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /service/LicenseService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * PHP representation of the License Service. See NetLicensingAPI for details: 13 | * https://netlicensing.io/wiki/license-services 14 | * 15 | * @package NetLicensing 16 | */ 17 | class LicenseService 18 | { 19 | /** 20 | * Creates new license object with given properties.See NetLicensingAPI for details: 21 | * https://netlicensing.io/wiki/license-services#create-license 22 | * 23 | * determines the vendor on whose behalf the call is performed 24 | * @param Context $context 25 | * 26 | * parent licensee to which the new license is to be added 27 | * @param string $licenseeNumber 28 | * 29 | * license template that the license is created from 30 | * @param string $licenseTemplateNumber 31 | * 32 | * For privileged logins specifies transaction for the license creation. For regular logins new 33 | * transaction always created implicitly, and the operation will be in a separate transaction. 34 | * Transaction is generated with the provided transactionNumber, or, if transactionNumber is null, with 35 | * auto-generated number. 36 | * @param null|string $transactionNumber 37 | * 38 | * non-null properties will be taken for the new object, null properties will either stay null, or will 39 | * be set to a default value, depending on property. 40 | * @param License $license 41 | * 42 | * @return License|null 43 | * @throws MalformedArgumentsException 44 | * @throws RestException 45 | */ 46 | public static function create(Context $context, string $licenseeNumber, string $licenseTemplateNumber, string $transactionNumber = null, License $license): ?License 47 | { 48 | CheckUtils::paramNotEmpty($licenseeNumber, Constants::LICENSEE_NUMBER); 49 | CheckUtils::paramNotEmpty($licenseTemplateNumber, Constants::LICENSE_TEMPLATE_NUMBER); 50 | 51 | $license->setProperty(Constants::LICENSEE_NUMBER, $licenseeNumber); 52 | $license->setProperty(Constants::LICENSE_TEMPLATE_NUMBER, $licenseTemplateNumber); 53 | 54 | if ($transactionNumber) $license->setProperty(Constants::TRANSACTION_NUMBER, $transactionNumber); 55 | 56 | $response = NetLicensingService::getInstance() 57 | ->post($context, Constants::LICENSE_ENDPOINT_PATH, $license->asPropertiesMap()); 58 | 59 | $createdLicense = null; 60 | 61 | if (!empty($response->items->item[0])) { 62 | $createdLicense = ItemToLicenseConverter::convert($response->items->item[0]); 63 | $createdLicense->exists = true; 64 | } 65 | 66 | return $createdLicense; 67 | } 68 | 69 | /** 70 | * Gets license by its number.See NetLicensingAPI for details: 71 | * https://netlicensing.io/wiki/license-services#get-license 72 | * 73 | * determines the vendor on whose behalf the call is performed 74 | * @param Context $context 75 | * 76 | * the license number 77 | * @param string $number 78 | * 79 | * @return License|null 80 | * @throws MalformedArgumentsException 81 | * @throws RestException 82 | */ 83 | public static function get(Context $context, string $number): ?License 84 | { 85 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 86 | 87 | $response = NetLicensingService::getInstance() 88 | ->get($context, Constants::LICENSE_ENDPOINT_PATH . '/' . $number); 89 | 90 | $license = null; 91 | 92 | if (!empty($response->items->item[0])) { 93 | $license = ItemToLicenseConverter::convert($response->items->item[0]); 94 | $license->exists = true; 95 | } 96 | 97 | return $license; 98 | } 99 | 100 | /** 101 | * Returns licenses of a vendor.See NetLicensingAPI for details: 102 | * https://netlicensing.io/wiki/license-services#licenses-list 103 | * 104 | * determines the vendor on whose behalf the call is performed 105 | * @param Context $context 106 | * 107 | * reserved for the future use, must be omitted / set to NULL 108 | * @param null $filter 109 | * 110 | * return array of licenses (of all products) or empty array if nothing found. 111 | * @return Page 112 | * @throws RestException 113 | */ 114 | public static function getList(Context $context, $filter = null): Page 115 | { 116 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 117 | 118 | $response = NetLicensingService::getInstance() 119 | ->get($context, Constants::LICENSE_ENDPOINT_PATH, $queryParams); 120 | 121 | $licenses = []; 122 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 123 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 124 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 125 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 126 | 127 | if (!empty($response->items->item)) { 128 | foreach ($response->items->item as $item) { 129 | $license = ItemToLicenseConverter::convert($item); 130 | $license->exists = true; 131 | 132 | $licenses[] = $license; 133 | } 134 | } 135 | 136 | return new Page($licenses, $pageNumber, $itemsNumber, $totalPages, $totalItems); 137 | } 138 | 139 | /** 140 | * Updates license properties.See NetLicensingAPI for details: 141 | * https://netlicensing.io/wiki/license-services#update-license 142 | * 143 | * determines the vendor on whose behalf the call is performed 144 | * @param Context $context 145 | * 146 | * license number 147 | * @param string $number 148 | * 149 | * transaction for the license update. Created implicitly if transactionNumber is null. In this case the 150 | * operation will be in a separate transaction. 151 | * @param string|null $transactionNumber 152 | * 153 | * non-null properties will be updated to the provided values, null properties will stay unchanged. 154 | * @param License $license 155 | * 156 | * return updated license. 157 | * @return License|null 158 | * @throws MalformedArgumentsException 159 | * @throws RestException 160 | */ 161 | public static function update(Context $context, string $number, string $transactionNumber = null, License $license): ?License 162 | { 163 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 164 | 165 | if ($transactionNumber) $license->setProperty(Constants::TRANSACTION_NUMBER, $transactionNumber); 166 | 167 | $response = NetLicensingService::getInstance() 168 | ->post($context, Constants::LICENSE_ENDPOINT_PATH . '/' . $number, $license->asPropertiesMap()); 169 | 170 | $updatedLicense = null; 171 | 172 | if (!empty($response->items->item[0])) { 173 | $updatedLicense = ItemToLicenseConverter::convert($response->items->item[0]); 174 | $updatedLicense->exists = true; 175 | } 176 | 177 | return $updatedLicense; 178 | } 179 | 180 | /** 181 | * Deletes license.See NetLicensingAPI for details: 182 | * https://netlicensing.io/wiki/license-services#delete-license 183 | * 184 | * When any license is deleted, corresponding transaction is created automatically. 185 | * 186 | * determines the vendor on whose behalf the call is performed 187 | * @param Context $context 188 | * 189 | * license number 190 | * @param string $number 191 | * 192 | * if true, any entities that depend on the one being deleted will be deleted too 193 | * @param bool $forceCascade 194 | * @throws MalformedArgumentsException 195 | * @throws RestException 196 | */ 197 | public static function delete(Context $context, string $number, bool $forceCascade = false): void 198 | { 199 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 200 | 201 | $queryParams[Constants::CASCADE] = ((bool)$forceCascade) ? 'true' : 'false'; 202 | 203 | NetLicensingService::getInstance() 204 | ->delete($context, Constants::LICENSE_ENDPOINT_PATH . '/' . $number, $queryParams); 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /service/LicenseTemplateService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * PHP representation of the ProductModule Service. See NetLicensingAPI for details: 13 | * https://netlicensing.io/wiki/license-template-services 14 | * 15 | * @package NetLicensing 16 | */ 17 | class LicenseTemplateService 18 | { 19 | /** 20 | * Creates new license template object with given properties.See NetLicensingAPI for details: 21 | * https://netlicensing.io/wiki/license-template-services#create-license-template 22 | * 23 | * determines the vendor on whose behalf the call is performed 24 | * @param Context $context 25 | * 26 | * parent product module to which the new license template is to be added 27 | * @param string $productModuleNumber 28 | * 29 | * non-null properties will be taken for the new object, null properties will either stay null, or will 30 | * be set to a default value, depending on property. 31 | * @param LicenseTemplate $licenseTemplate 32 | * 33 | * the newly created license template object 34 | * @return LicenseTemplate|null 35 | * @throws MalformedArgumentsException 36 | * @throws RestException 37 | */ 38 | public static function create(Context $context, string $productModuleNumber, LicenseTemplate $licenseTemplate): ?LicenseTemplate 39 | { 40 | CheckUtils::paramNotEmpty($productModuleNumber, Constants::PRODUCT_MODULE_NUMBER); 41 | 42 | $licenseTemplate->setProperty(Constants::PRODUCT_MODULE_NUMBER, $productModuleNumber); 43 | 44 | $response = NetLicensingService::getInstance() 45 | ->post($context, Constants::LICENSE_TEMPLATE_ENDPOINT_PATH, $licenseTemplate->asPropertiesMap()); 46 | 47 | $createdLicenseTemplate = null; 48 | 49 | if (!empty($response->items->item[0])) { 50 | $createdLicenseTemplate = ItemToLicenseTemplateConverter::convert($response->items->item[0]); 51 | $createdLicenseTemplate->exists = true; 52 | } 53 | 54 | return $createdLicenseTemplate; 55 | } 56 | 57 | /** 58 | * Gets license template by its number.See NetLicensingAPI for details: 59 | * https://netlicensing.io/wiki/license-template-services#get-license-template 60 | * 61 | * determines the vendor on whose behalf the call is performed 62 | * @param Context $context 63 | * 64 | * the license template number 65 | * @param string $number 66 | * 67 | * return the license template object 68 | * @return LicenseTemplate|null 69 | * @throws MalformedArgumentsException 70 | * @throws RestException 71 | */ 72 | public static function get(Context $context, string $number): ?LicenseTemplate 73 | { 74 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 75 | 76 | $response = NetLicensingService::getInstance() 77 | ->get($context, Constants::LICENSE_TEMPLATE_ENDPOINT_PATH . '/' . $number); 78 | 79 | $licenseTemplate = null; 80 | 81 | if (!empty($response->items->item[0])) { 82 | $licenseTemplate = ItemToLicenseTemplateConverter::convert($response->items->item[0]); 83 | $licenseTemplate->exists = true; 84 | } 85 | 86 | return $licenseTemplate; 87 | } 88 | 89 | /** 90 | * Returns all license templates of a vendor.See NetLicensingAPI for details: 91 | * https://netlicensing.io/wiki/license-template-services#license-templates-list 92 | * 93 | * determines the vendor on whose behalf the call is performed 94 | * @param Context $context 95 | * 96 | * reserved for the future use, must be omitted / set to NULL 97 | * @param string|null $filter 98 | * 99 | * array of license templates (of all products/modules) or null/empty list if nothing found. 100 | * @return Page 101 | * @throws RestException 102 | */ 103 | public static function getList(Context $context, string $filter = null): Page 104 | { 105 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 106 | 107 | $response = NetLicensingService::getInstance() 108 | ->get($context, Constants::LICENSE_TEMPLATE_ENDPOINT_PATH, $queryParams); 109 | 110 | $licenseTemplates = []; 111 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 112 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 113 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 114 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 115 | 116 | if (!empty($response->items->item)) { 117 | foreach ($response->items->item as $item) { 118 | $licenseTemplate = ItemToLicenseTemplateConverter::convert($item); 119 | $licenseTemplate->exists = true; 120 | 121 | $licenseTemplates[] = $licenseTemplate; 122 | } 123 | } 124 | 125 | return new Page($licenseTemplates, $pageNumber, $itemsNumber, $totalPages, $totalItems); 126 | } 127 | 128 | /** 129 | * Updates license template properties.See NetLicensingAPI for details: 130 | * https://netlicensing.io/wiki/license-template-services#update-license-template 131 | * 132 | * determines the vendor on whose behalf the call is performed 133 | * @param Context $context 134 | * 135 | * license template number 136 | * @param string $number 137 | * 138 | * non-null properties will be updated to the provided values, null properties will stay unchanged. 139 | * @param LicenseTemplate $licenseTemplate 140 | * 141 | * updated license template. 142 | * @return LicenseTemplate|null 143 | * @throws RestException 144 | * @throws MalformedArgumentsException 145 | */ 146 | public static function update(Context $context, string $number, LicenseTemplate $licenseTemplate): ?LicenseTemplate 147 | { 148 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 149 | 150 | $response = NetLicensingService::getInstance() 151 | ->post($context, Constants::LICENSE_TEMPLATE_ENDPOINT_PATH . '/' . $number, $licenseTemplate->asPropertiesMap()); 152 | 153 | $updatedLicenseTemplate = null; 154 | 155 | if (!empty($response->items->item[0])) { 156 | $updatedLicenseTemplate = ItemToLicenseTemplateConverter::convert($response->items->item[0]); 157 | $updatedLicenseTemplate->exists = true; 158 | } 159 | 160 | return $updatedLicenseTemplate; 161 | } 162 | 163 | /** 164 | * Deletes license template.See NetLicensingAPI JavaDoc for details: 165 | * https://netlicensing.io/wiki/license-template-services#delete-license-template 166 | * 167 | * determines the vendor on whose behalf the call is performed 168 | * @param Context $context 169 | * 170 | * license template number 171 | * @param string $number 172 | * 173 | * if true, any entities that depend on the one being deleted will be deleted too 174 | * @param bool $forceCascade 175 | * 176 | * @throws MalformedArgumentsException 177 | * @throws RestException 178 | */ 179 | public static function delete(Context $context, string $number, bool $forceCascade = false): void 180 | { 181 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 182 | 183 | $queryParams[Constants::CASCADE] = ($forceCascade) ? 'true' : 'false'; 184 | 185 | NetLicensingService::getInstance() 186 | ->delete($context, Constants::LICENSE_TEMPLATE_ENDPOINT_PATH . '/' . $number, $queryParams); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /service/LicenseeService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use ErrorException; 12 | 13 | /** 14 | * PHP representation of the Licensee Service. See NetLicensingAPI for details: 15 | * https://netlicensing.io/wiki/licensee-services 16 | * 17 | * @package NetLicensing 18 | */ 19 | class LicenseeService 20 | { 21 | /** 22 | * Creates new licensee object with given properties.See NetLicensingAPI for details: 23 | * https://netlicensing.io/wiki/licensee-services#create-licensee 24 | * 25 | * determines the vendor on whose behalf the call is performed 26 | * @param Context $context 27 | * 28 | * parent product to which the new licensee is to be added 29 | * @param string $productNumber 30 | * 31 | * non-null properties will be taken for the new object, null properties will either stay null, or will 32 | * be set to a default value, depending on property. 33 | * @param Licensee $licensee 34 | * 35 | * return the newly created licensee object 36 | * @return Licensee|null 37 | * @throws MalformedArgumentsException 38 | * @throws RestException 39 | */ 40 | public static function create(Context $context, string $productNumber, Licensee $licensee): ?Licensee 41 | { 42 | CheckUtils::paramNotEmpty($productNumber, Constants::PRODUCT_NUMBER); 43 | 44 | $licensee->setProperty(Constants::PRODUCT_NUMBER, $productNumber); 45 | 46 | $response = NetLicensingService::getInstance() 47 | ->post($context, Constants::LICENSEE_ENDPOINT_PATH, $licensee->asPropertiesMap()); 48 | 49 | $createdLicensee = null; 50 | 51 | if (!empty($response->items->item[0])) { 52 | $createdLicensee = ItemToLicenseeConverter::convert($response->items->item[0]); 53 | $createdLicensee->exists = true; 54 | } 55 | 56 | return $createdLicensee; 57 | } 58 | 59 | /** 60 | * Gets licensee by its number.See NetLicensingAPI for details: 61 | * https://netlicensing.io/wiki/licensee-services#get-licensee 62 | * 63 | * determines the vendor on whose behalf the call is performed 64 | * @param Context $context 65 | * 66 | * the licensee number 67 | * @param string $number 68 | * 69 | * return the licensee 70 | * @return Licensee|null 71 | * @throws MalformedArgumentsException 72 | * @throws RestException 73 | */ 74 | public static function get(Context $context, string $number): ?Licensee 75 | { 76 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 77 | 78 | $response = NetLicensingService::getInstance() 79 | ->get($context, Constants::LICENSEE_ENDPOINT_PATH . '/' . $number); 80 | 81 | $licensee = null; 82 | 83 | if (!empty($response->items->item[0])) { 84 | $licensee = ItemToLicenseeConverter::convert($response->items->item[0]); 85 | $licensee->exists = true; 86 | } 87 | 88 | return $licensee; 89 | } 90 | 91 | /** 92 | * Returns all licensees of a vendor.See NetLicensingAPI for details: 93 | * https://netlicensing.io/wiki/licensee-services#licensees-list 94 | * 95 | * determines the vendor on whose behalf the call is performed 96 | * @param Context $context 97 | * 98 | * reserved for the future use, must be omitted / set to NULL 99 | * @param string|null $filter 100 | * 101 | * array of licensees (of all products) or empty array if nothing found. 102 | * @return Page 103 | * @throws RestException 104 | */ 105 | public static function getList(Context $context, string $filter = null): Page 106 | { 107 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 108 | 109 | $response = NetLicensingService::getInstance() 110 | ->get($context, Constants::LICENSEE_ENDPOINT_PATH, $queryParams); 111 | 112 | $licensees = []; 113 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 114 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 115 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 116 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 117 | 118 | if (!empty($response->items->item)) { 119 | foreach ($response->items->item as $item) { 120 | $licensee = ItemToLicenseeConverter::convert($item); 121 | $licensee->exists = true; 122 | 123 | $licensees[] = $licensee; 124 | } 125 | } 126 | 127 | return new Page($licensees, $pageNumber, $itemsNumber, $totalPages, $totalItems); 128 | } 129 | 130 | /** 131 | * Updates licensee properties.See NetLicensingAPI for details: 132 | * https://netlicensing.io/wiki/licensee-services#update-licensee 133 | * 134 | * determines the vendor on whose behalf the call is performed 135 | * @param Context $context 136 | * 137 | * licensee number 138 | * @param string $number 139 | * 140 | * non-null properties will be updated to the provided values, null properties will stay unchanged. 141 | * @param Licensee $licensee 142 | * 143 | * return updated licensee. 144 | * @return Licensee|null 145 | * @throws MalformedArgumentsException 146 | * @throws RestException 147 | */ 148 | public static function update(Context $context, string $number, Licensee $licensee): ?Licensee 149 | { 150 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 151 | 152 | $response = NetLicensingService::getInstance() 153 | ->post($context, Constants::LICENSEE_ENDPOINT_PATH . '/' . $number, $licensee->asPropertiesMap()); 154 | 155 | $updatedLicensee = null; 156 | 157 | if (!empty($response->items->item[0])) { 158 | $updatedLicensee = ItemToLicenseeConverter::convert($response->items->item[0]); 159 | $updatedLicensee->exists = true; 160 | } 161 | 162 | return $updatedLicensee; 163 | } 164 | 165 | /** 166 | * Deletes licensee.See NetLicensingAPI for details: 167 | * https://netlicensing.io/wiki/licensee-services#delete-licensee 168 | * 169 | * determines the vendor on whose behalf the call is performed 170 | * @param Context $context 171 | * 172 | * licensee number 173 | * @param string $number 174 | * 175 | * if true, any entities that depend on the one being deleted will be deleted too 176 | * @param bool $forceCascade 177 | * 178 | * @throws MalformedArgumentsException 179 | * @throws RestException 180 | */ 181 | public static function delete(Context $context, string $number, bool $forceCascade = false): void 182 | { 183 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 184 | 185 | $queryParams[Constants::CASCADE] = ((bool)$forceCascade) ? 'true' : 'false'; 186 | 187 | NetLicensingService::getInstance() 188 | ->delete($context, Constants::LICENSEE_ENDPOINT_PATH . '/' . $number, $queryParams); 189 | } 190 | 191 | 192 | /** 193 | * Validates active licenses of the licensee. 194 | * In the case of multiple product modules validation, required parameters indexes will be added automatically. 195 | * See NetLicensingAPI for details: https://netlicensing.io/wiki/licensee-services#validate-licensee 196 | * 197 | * @param Context $context 198 | * 199 | * licensee number 200 | * @param string $number 201 | * 202 | * optional validation parameters. See ValidationParameters and licensing model documentation for 203 | * details. 204 | * @param ValidationParameters $validationParameters 205 | * 206 | * @param array $meta optional parameter, receiving messages returned within response section. 207 | * 208 | * @return ValidationResults|null 209 | * @throws MalformedArgumentsException 210 | * @throws RestException 211 | */ 212 | public static function validate(Context $context, string $number, ValidationParameters $validationParameters, array &$meta = []): ?ValidationResults 213 | { 214 | return ValidationService::validate($context, $number, $validationParameters, $meta); 215 | } 216 | 217 | /** 218 | * Transfer licenses between licensees. 219 | * https://netlicensing.io/wiki/licensee-services#transfer-licenses 220 | * 221 | * determines the vendor on whose behalf the call is performed 222 | * @param Context $context 223 | * 224 | * the number of the licensee receiving licenses 225 | * @param string $number 226 | * 227 | * the number of the licensee delivering licenses 228 | * @param string $sourceLicenseeNumber 229 | * 230 | * @return void 231 | * @throws MalformedArgumentsException 232 | * @throws RestException 233 | */ 234 | public static function transfer(Context $context, string $number, string $sourceLicenseeNumber): void 235 | { 236 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 237 | CheckUtils::paramNotEmpty($sourceLicenseeNumber, Constants::LICENSEE_SOURCE_LICENSEE_NUMBER); 238 | 239 | $queryParams[Constants::LICENSEE_SOURCE_LICENSEE_NUMBER] = $sourceLicenseeNumber; 240 | 241 | NetLicensingService::getInstance() 242 | ->post($context, Constants::LICENSEE_ENDPOINT_PATH . '/' . $number . '/' . Constants::LICENSEE_ENDPOINT_PATH_TRANSFER, $queryParams); 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /service/NetLicensingService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use Curl\Curl; 12 | use ErrorException; 13 | 14 | class NetLicensingService 15 | { 16 | private static ?NetLicensingService $_instance = null; 17 | 18 | /** 19 | * @var $curl Curl 20 | */ 21 | private $curl; 22 | 23 | /** 24 | * NetLicensingService constructor. 25 | */ 26 | private function __construct() 27 | { 28 | $this->curl = new NetLicensingCurl(); 29 | $this->curl->setHeader('Accept', 'application/json'); 30 | $this->curl->setUserAgent('NetLicensing/PHP ' . Constants::NETLICENSING_VERSION . '/' . PHP_VERSION . ' (https://netlicensing.io)'); 31 | } 32 | 33 | protected function __clone() 34 | { 35 | } 36 | 37 | /** 38 | * @return NetLicensingService|null 39 | */ 40 | static public function getInstance(): ?NetLicensingService 41 | { 42 | if (is_null(self::$_instance)) self::$_instance = new self(); 43 | return self::$_instance; 44 | } 45 | 46 | /** 47 | * Return curl object 48 | * 49 | * @return Curl|NetLicensingCurl 50 | */ 51 | public function curl() 52 | { 53 | return $this->curl; 54 | } 55 | 56 | /** 57 | * Return curl info 58 | * 59 | * @return object 60 | */ 61 | public function lastCurlInfo(): object 62 | { 63 | return (object)$this->curl->toArray(); 64 | } 65 | 66 | /** 67 | * Helper method for performing GET request to NetLicensing API services. Finds and returns first suitable item with 68 | * type resultType from the response. 69 | * 70 | * Context for the NetLicensing API call 71 | * @param Context $context 72 | * 73 | * the REST URL template 74 | * @param $urlTemplate 75 | * 76 | * The REST query parameters values. May be null if there are no parameters. 77 | * @param array $queryParams 78 | * 79 | * @return mixed|null 80 | * @throws RestException 81 | */ 82 | 83 | public function get(Context $context, $urlTemplate, array $queryParams = []) 84 | { 85 | return $this->request($context, 'get', $urlTemplate, $queryParams); 86 | } 87 | 88 | /** 89 | * Helper method for performing POST request to NetLicensing API services. Finds and returns first suitable item 90 | * with type resultType from the response. 91 | * 92 | * context for the NetLicensing API call 93 | * @param Context $context 94 | * 95 | * the REST URL template 96 | * @param $urlTemplate 97 | * 98 | * The REST query parameters values. May be null if there are no parameters. 99 | * @param array $queryParams 100 | * 101 | * @return mixed|null 102 | * @throws RestException 103 | */ 104 | public function post(Context $context, $urlTemplate, array $queryParams = []) 105 | { 106 | return $this->request($context, 'post', $urlTemplate, $queryParams); 107 | } 108 | 109 | /** 110 | * Helper method for performing DELETE request to NetLicensing API services. 111 | * 112 | * context for the NetLicensing API call 113 | * @param Context $context 114 | * 115 | * the REST URL template 116 | * @param $urlTemplate 117 | * 118 | * The REST query parameters values. May be null if there are no parameters. 119 | * @param array $queryParams 120 | * 121 | * @return mixed|null 122 | * @throws RestException 123 | */ 124 | public function delete(Context $context, $urlTemplate, array $queryParams = []) 125 | { 126 | return $this->request($context, 'delete', $urlTemplate, $queryParams); 127 | } 128 | 129 | /** 130 | * @param Context $context 131 | * @param $method 132 | * @param $urlTemplate 133 | * @param array $queryParams 134 | * @return mixed|null 135 | * @throws RestException 136 | */ 137 | public function request(Context $context, $method, $urlTemplate, array $queryParams = []) 138 | { 139 | $restUrl = $context->getBaseUrl() . preg_replace('#/+#', '/', '/' . $urlTemplate); 140 | 141 | // validate http method 142 | $this->validateMethod($method); 143 | 144 | // validate context 145 | $this->validateBaseUrl($context); 146 | 147 | // validate baseUrl + urlTemplate 148 | $this->validateRestUrl($restUrl); 149 | 150 | // configure 151 | $this->configure($context); 152 | 153 | // set vendor 154 | if ($context->getVendorNumber()) { 155 | $queryParams[Constants::VENDOR_NUMBER] = $context->getVendorNumber(); 156 | } 157 | 158 | $response = $this->curl->{$method}($restUrl, $queryParams); 159 | 160 | switch ($this->getStatusCode()) { 161 | case 200: 162 | return $response; 163 | case 204: 164 | return null; 165 | default: 166 | throw new RestException(sprintf("Unsupported response status code %s: %s", 167 | $this->getStatusCode(), $this->getReasonPhrase($response))); 168 | 169 | } 170 | } 171 | 172 | /** 173 | * @param $method 174 | * @throws RestException 175 | */ 176 | protected function validateMethod($method): void 177 | { 178 | if (!in_array(strtolower($method), ['get', 'post', 'delete'])) { 179 | throw new RestException('Invalid request type:' . $method . ', allowed requests types: GET, POST, DELETE.'); 180 | } 181 | } 182 | 183 | /** 184 | * @param Context $context 185 | * @throws RestException 186 | */ 187 | protected function validateBaseUrl(Context $context): void 188 | { 189 | 190 | if (!$context->getBaseUrl()) { 191 | throw new RestException('Base url must be specified'); 192 | } 193 | 194 | if (filter_var($context->getBaseUrl(), FILTER_VALIDATE_URL) === false) { 195 | throw new RestException('Base url "' . $context->getBaseUrl() . '" is not a valid URL'); 196 | } 197 | } 198 | 199 | /** 200 | * @param $restUrl 201 | * @return bool 202 | * @throws RestException 203 | */ 204 | protected function validateRestUrl($restUrl): bool 205 | { 206 | if (filter_var($restUrl, FILTER_VALIDATE_URL) === false) { 207 | throw new RestException('Rest url"' . $restUrl . '" is not a valid URL'); 208 | } 209 | 210 | return true; 211 | } 212 | 213 | /** 214 | * @param Context $context 215 | * @throws RestException 216 | */ 217 | private function configure(Context $context) 218 | { 219 | if (!$context->getSecurityMode()) { 220 | throw new RestException('Security mode must be specified'); 221 | } 222 | 223 | switch ($context->getSecurityMode()) { 224 | case Constants::BASIC_AUTHENTICATION: 225 | if (!$context->getUsername()) throw new RestException('Missing parameter "username"'); 226 | if (!$context->getPassword()) throw new RestException('Missing parameter "password"'); 227 | 228 | $this->curl->setHeader('Authorization', 'Basic ' . base64_encode($context->getUsername() . ":" . $context->getPassword())); 229 | break; 230 | case Constants::APIKEY_IDENTIFICATION: 231 | if (!$context->getApiKey()) throw new RestException('Missing parameter "apiKey"'); 232 | 233 | $this->curl->setHeader('Authorization', 'Basic ' . base64_encode("apiKey:" . $context->getApiKey())); 234 | break; 235 | case Constants::ANONYMOUS_IDENTIFICATION: 236 | break; 237 | default: 238 | throw new RestException("Unknown security mode"); 239 | } 240 | } 241 | 242 | private function getStatusCode(): int 243 | { 244 | return $this->curl->httpStatusCode; 245 | } 246 | 247 | private function getReasonPhrase($response): string 248 | { 249 | return !empty($response->infos->info[0]->value) 250 | ? $response->infos->info[0]->value 251 | : ''; 252 | } 253 | 254 | /** 255 | * Handle dynamic static method calls into the method. 256 | * 257 | * @param string $method 258 | * @param array $parameters 259 | * @return mixed 260 | * @throws ErrorException 261 | */ 262 | public static function __callStatic(string $method, array $parameters) 263 | { 264 | return (new static)->$method(...$parameters); 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /service/PaymentMethodService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * PHP representation of the PaymentMethodService Service. See NetLicensingAPI for details: 13 | * https://netlicensing.io/wiki/payment-method-services 14 | * 15 | * @package NetLicensing 16 | */ 17 | class PaymentMethodService 18 | { 19 | /** 20 | * Gets payment method by its number.See NetLicensingAPI for details: 21 | * https://netlicensing.io/wiki/payment-method-services#get-payment-method 22 | * 23 | * determines the vendor on whose behalf the call is performed 24 | * @param Context $context 25 | * 26 | * the payment method number 27 | * @param $number 28 | * 29 | * return the payment method 30 | * @return PaymentMethod|null 31 | * @throws MalformedArgumentsException 32 | * @throws RestException 33 | */ 34 | public static function get(Context $context, $number): ?PaymentMethod 35 | { 36 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 37 | 38 | $response = NetLicensingService::getInstance() 39 | ->get($context, Constants::PAYMENT_METHOD_ENDPOINT_PATH . '/' . $number); 40 | 41 | $paymentMethod = null; 42 | 43 | if (!empty($response->items->item[0])) { 44 | $paymentMethod = ItemToPaymentMethodConverter::convert($response->items->item[0]); 45 | $paymentMethod->exists = true; 46 | } 47 | 48 | return $paymentMethod; 49 | } 50 | 51 | /** 52 | * Returns payment methods of a vendor.See NetLicensingAPI for details: 53 | * https://netlicensing.io/wiki/payment-method-services#payment-methods-list 54 | * 55 | * determines the vendor on whose behalf the call is performed 56 | * @param Context $context 57 | * 58 | * reserved for the future use, must be omitted / set to NULL 59 | * @param string|null $filter 60 | * 61 | * array of payment method entities or empty array if nothing found. 62 | * @return Page 63 | * @throws RestException 64 | */ 65 | public static function getList(Context $context, string $filter = null): Page 66 | { 67 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 68 | 69 | $response = NetLicensingService::getInstance() 70 | ->get($context, Constants::PAYMENT_METHOD_ENDPOINT_PATH, $queryParams); 71 | 72 | $paymentMethods = []; 73 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 74 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 75 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 76 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 77 | 78 | if (!empty($response->items->item)) { 79 | foreach ($response->items->item as $item) { 80 | $paymentMethod = ItemToPaymentMethodConverter::convert($item); 81 | $paymentMethod->exists = true; 82 | 83 | $paymentMethods[] = $paymentMethod; 84 | } 85 | } 86 | 87 | return new Page($paymentMethods, $pageNumber, $itemsNumber, $totalPages, $totalItems); 88 | } 89 | 90 | /** 91 | * Updates payment method properties.See NetLicensingAPI for details: 92 | * https://netlicensing.io/wiki/payment-method-services#update-payment-method 93 | * 94 | * determines the vendor on whose behalf the call is performed 95 | * @param Context $context 96 | * 97 | * the payment method number 98 | * @param string $number 99 | * 100 | * non-null properties will be updated to the provided values, null properties will stay unchanged. 101 | * @param PaymentMethod $paymentMethod 102 | * 103 | * return updated payment method. 104 | * @return PaymentMethod|null 105 | * @throws MalformedArgumentsException 106 | * @throws RestException 107 | */ 108 | public static function update(Context $context, string $number, PaymentMethod $paymentMethod): ?PaymentMethod 109 | { 110 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 111 | 112 | $response = NetLicensingService::getInstance() 113 | ->post($context, Constants::PAYMENT_METHOD_ENDPOINT_PATH . '/' . $number, $paymentMethod->asPropertiesMap()); 114 | 115 | $paymentMethod = null; 116 | 117 | if (!empty($response->items->item[0])) { 118 | $paymentMethod = ItemToPaymentMethodConverter::convert($response->items->item[0]); 119 | $paymentMethod->exists = true; 120 | } 121 | 122 | return $paymentMethod; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /service/ProductModuleService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * PHP representation of the ProductModule Service. See NetLicensingAPI for details: 13 | * https://netlicensing.io/wiki/product-module-services 14 | * 15 | * @package NetLicensing 16 | */ 17 | class ProductModuleService 18 | { 19 | /** 20 | * Creates new product module object with given properties.See NetLicensingAPI for details: 21 | * https://netlicensing.io/wiki/product-module-services#create-product-module 22 | * 23 | * determines the vendor on whose behalf the call is performed 24 | * @param Context $context 25 | * 26 | * parent product to which the new product module is to be added 27 | * @param string $productNumber 28 | * 29 | * non-null properties will be taken for the new object, null properties will either stay null, or will 30 | * be set to a default value, depending on property. 31 | * @param ProductModule $productModule 32 | * 33 | * the newly created product module object 34 | * @return ProductModule|null 35 | * @throws MalformedArgumentsException 36 | * @throws RestException 37 | */ 38 | public static function create(Context $context, string $productNumber, ProductModule $productModule): ?ProductModule 39 | { 40 | CheckUtils::paramNotEmpty($productNumber, Constants::PRODUCT_NUMBER); 41 | 42 | $productModule->setProperty(Constants::PRODUCT_NUMBER, $productNumber); 43 | 44 | $response = NetLicensingService::getInstance() 45 | ->post($context, Constants::PRODUCT_MODULE_ENDPOINT_PATH, $productModule->asPropertiesMap()); 46 | 47 | $createdProductModule = null; 48 | 49 | if (!empty($response->items->item[0])) { 50 | $createdProductModule = ItemToProductModuleConverter::convert($response->items->item[0]); 51 | $createdProductModule->exists = true; 52 | } 53 | 54 | return $createdProductModule; 55 | } 56 | 57 | /** 58 | * Gets product module by its number.See NetLicensingAPI for details: 59 | * https://netlicensing.io/wiki/product-module-services#get-product-module 60 | * 61 | * determines the vendor on whose behalf the call is performed 62 | * @param Context $context 63 | * 64 | * the product module number 65 | * @param string $number 66 | * 67 | * return the product module object 68 | * @return ProductModule|null 69 | * @throws MalformedArgumentsException 70 | * @throws RestException 71 | */ 72 | public static function get(Context $context, string $number): ?ProductModule 73 | { 74 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 75 | 76 | $response = NetLicensingService::getInstance() 77 | ->get($context, Constants::PRODUCT_MODULE_ENDPOINT_PATH . '/' . $number); 78 | 79 | $productModule = null; 80 | 81 | if (!empty($response->items->item[0])) { 82 | $productModule = ItemToProductModuleConverter::convert($response->items->item[0]); 83 | $productModule->exists = true; 84 | } 85 | 86 | return $productModule; 87 | } 88 | 89 | /** 90 | * Returns all product modules of a vendor.See NetLicensingAPI for details: 91 | * https://netlicensing.io/wiki/product-module-services#product-modules-list 92 | * 93 | * determines the vendor on whose behalf the call is performed 94 | * @param Context $context 95 | * 96 | * reserved for the future use, must be omitted / set to NULL 97 | * @param string|null $filter 98 | * 99 | * array of product modules entities or empty array if nothing found. 100 | * @return Page 101 | * @throws RestException 102 | */ 103 | public static function getList(Context $context, string $filter = null): Page 104 | { 105 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 106 | 107 | $response = NetLicensingService::getInstance() 108 | ->get($context, Constants::PRODUCT_MODULE_ENDPOINT_PATH, $queryParams); 109 | 110 | $productModules = []; 111 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 112 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 113 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 114 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 115 | 116 | if (!empty($response->items->item)) { 117 | foreach ($response->items->item as $item) { 118 | $productModule = ItemToProductModuleConverter::convert($item); 119 | $productModule->exists = true; 120 | 121 | $productModules[] = $productModule; 122 | } 123 | } 124 | 125 | return new Page($productModules, $pageNumber, $itemsNumber, $totalPages, $totalItems); 126 | } 127 | 128 | /** 129 | * Updates product module properties.See NetLicensingAPI for details: 130 | * https://netlicensing.io/wiki/product-module-services#update-product-module 131 | * 132 | * determines the vendor on whose behalf the call is performed 133 | * @param Context $context 134 | * 135 | * product module number 136 | * @param string $number 137 | * 138 | * non-null properties will be updated to the provided values, null properties will stay unchanged. 139 | * @param ProductModule $productModule 140 | * 141 | * updated product module. 142 | * @return ProductModule|null 143 | * @throws MalformedArgumentsException 144 | * @throws RestException 145 | */ 146 | public static function update(Context $context, string $number, ProductModule $productModule): ?ProductModule 147 | { 148 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 149 | 150 | $response = NetLicensingService::getInstance() 151 | ->post($context, Constants::PRODUCT_MODULE_ENDPOINT_PATH . '/' . $number, $productModule->asPropertiesMap()); 152 | 153 | $updatedProductModule = null; 154 | 155 | if (!empty($response->items->item[0])) { 156 | $updatedProductModule = ItemToProductModuleConverter::convert($response->items->item[0]); 157 | $updatedProductModule->exists = true; 158 | } 159 | 160 | return $updatedProductModule; 161 | } 162 | 163 | /** 164 | * Deletes product module.See NetLicensingAPI for details: 165 | * https://netlicensing.io/wiki/product-module-services#delete-product-module 166 | * 167 | * determines the vendor on whose behalf the call is performed 168 | * @param Context $context 169 | * 170 | * product module number 171 | * @param string $number 172 | * 173 | * if true, any entities that depend on the one being deleted will be deleted too 174 | * @param bool $forceCascade 175 | * 176 | * @throws MalformedArgumentsException 177 | * @throws RestException 178 | */ 179 | public static function delete(Context $context, string $number, bool $forceCascade = false): void 180 | { 181 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 182 | 183 | $queryParams[Constants::CASCADE] = ((bool)$forceCascade) ? 'true' : 'false'; 184 | 185 | NetLicensingService::getInstance() 186 | ->delete($context, Constants::PRODUCT_MODULE_ENDPOINT_PATH . '/' . $number, $queryParams); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /service/ProductService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * PHP representation of the Product Service. See NetLicensingAPI for details: 13 | * https://netlicensing.io/wiki/product-services 14 | * 15 | * @package NetLicensing 16 | */ 17 | class ProductService 18 | { 19 | /** 20 | * Creates new product with given properties.See NetLicensingAPI for details: 21 | * https://netlicensing.io/wiki/product-services#create-product 22 | * 23 | * determines the vendor on whose behalf the call is performed 24 | * @param Context $context 25 | * 26 | * non-null properties will be taken for the new object, null properties will either stay null, or will 27 | * be set to a default value, depending on property. 28 | * @param Product $product 29 | * 30 | * return the newly created product object 31 | * @return Product|null 32 | * @throws RestException 33 | */ 34 | public static function create(Context $context, Product $product): ?Product 35 | { 36 | $response = NetLicensingService::getInstance() 37 | ->post($context, Constants::PRODUCT_ENDPOINT_PATH, $product->asPropertiesMap()); 38 | 39 | $createdProduct = null; 40 | 41 | if (!empty($response->items->item[0])) { 42 | $createdProduct = ItemToProductConverter::convert($response->items->item[0]); 43 | $createdProduct->exists = true; 44 | } 45 | 46 | return $createdProduct; 47 | } 48 | 49 | /** 50 | * Gets product by its number.See NetLicensingAPI for details: 51 | * https://netlicensing.io/wiki/product-services#get-product 52 | * 53 | * determines the vendor on whose behalf the call is performed 54 | * @param Context $context 55 | * 56 | * the product number 57 | * @param string $number 58 | * 59 | * return the product object 60 | * @return Product|null 61 | * @throws MalformedArgumentsException 62 | * @throws RestException 63 | */ 64 | public static function get(Context $context, string $number): ?Product 65 | { 66 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 67 | 68 | $response = NetLicensingService::getInstance() 69 | ->get($context, Constants::PRODUCT_ENDPOINT_PATH . '/' . $number); 70 | 71 | $product = null; 72 | 73 | if (!empty($response->items->item[0])) { 74 | $product = ItemToProductConverter::convert($response->items->item[0]); 75 | $product->exists = true; 76 | } 77 | 78 | return $product; 79 | } 80 | 81 | /** 82 | * Returns products of a vendor.See NetLicensingAPI for details: 83 | * https://netlicensing.io/wiki/product-services#products-list 84 | * 85 | * determines the vendor on whose behalf the call is performed 86 | * @param Context $context 87 | * 88 | * reserved for the future use, must be omitted / set to NULL 89 | * @param string|null $filter 90 | * 91 | * array of product entities or empty array if nothing found. 92 | * @return Page 93 | * @throws RestException 94 | */ 95 | public static function getList(Context $context, string $filter = null): Page 96 | { 97 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 98 | 99 | $response = NetLicensingService::getInstance() 100 | ->get($context, Constants::PRODUCT_ENDPOINT_PATH, $queryParams); 101 | 102 | $products = []; 103 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 104 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 105 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 106 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 107 | 108 | if (!empty($response->items->item)) { 109 | foreach ($response->items->item as $item) { 110 | $product = ItemToProductConverter::convert($item); 111 | $product->exists = true; 112 | 113 | $products[] = $product; 114 | } 115 | } 116 | 117 | return new Page($products, $pageNumber, $itemsNumber, $totalPages, $totalItems); 118 | } 119 | 120 | /** 121 | * Updates product properties.See NetLicensingAPI for details: 122 | * https://netlicensing.io/wiki/product-services#update-product 123 | * 124 | * determines the vendor on whose behalf the call is performed 125 | * @param Context $context 126 | * 127 | * product number 128 | * @param string $number 129 | * 130 | * non-null properties will be updated to the provided values, null properties will stay unchanged. 131 | * @param Product $product 132 | * 133 | * updated product. 134 | * @return Product|null 135 | * @throws MalformedArgumentsException 136 | * @throws RestException 137 | */ 138 | public static function update(Context $context, string $number, Product $product): ?Product 139 | { 140 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 141 | 142 | $response = NetLicensingService::getInstance() 143 | ->post($context, Constants::PRODUCT_ENDPOINT_PATH . '/' . $number, $product->asPropertiesMap()); 144 | 145 | $updatedProduct = null; 146 | 147 | if (!empty($response->items->item[0])) { 148 | $updatedProduct = ItemToProductConverter::convert($response->items->item[0]); 149 | $updatedProduct->exists = true; 150 | } 151 | 152 | return $updatedProduct; 153 | } 154 | 155 | /** 156 | * Deletes product.See NetLicensingAPI for details: 157 | * https://netlicensing.io/wiki/product-services#delete-product 158 | * 159 | * determines the vendor on whose behalf the call is performed 160 | * @param Context $context 161 | * 162 | * product number 163 | * @param string $number 164 | * 165 | * if true, any entities that depend on the one being deleted will be deleted too 166 | * @param bool $forceCascade 167 | * 168 | * @throws RestException 169 | * @throws MalformedArgumentsException 170 | */ 171 | public static function delete(Context $context, string $number, bool $forceCascade = false): void 172 | { 173 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 174 | 175 | $queryParams[Constants::CASCADE] = ($forceCascade) ? 'true' : 'false'; 176 | 177 | NetLicensingService::getInstance() 178 | ->delete($context, Constants::PRODUCT_ENDPOINT_PATH . '/' . $number, $queryParams); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /service/TokenService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * PHP representation of the Token Service. See NetLicensingAPI for details: 13 | * https://netlicensing.io/wiki/token-services 14 | * 15 | * @package NetLicensing 16 | */ 17 | class TokenService 18 | { 19 | /** 20 | * Creates new token.See NetLicensingAPI for details: 21 | * https://netlicensing.io/wiki/token-services#create-token 22 | * 23 | * determines the vendor on whose behalf the call is performed 24 | * @param Context $context 25 | * 26 | * non-null properties will be updated to the provided values, null properties will stay unchanged. 27 | * @param Token $token 28 | * 29 | * return created token 30 | * @return Token|null 31 | * @throws RestException 32 | */ 33 | public static function create(Context $context, Token $token): ?Token 34 | { 35 | $response = NetLicensingService::getInstance() 36 | ->post($context, Constants::TOKEN_ENDPOINT_PATH, $token->asPropertiesMap()); 37 | 38 | $createdToken = null; 39 | 40 | if (!empty($response->items->item[0])) { 41 | $createdToken = ItemToTokenConverter::convert($response->items->item[0]); 42 | $createdToken->exists = true; 43 | } 44 | 45 | return $createdToken; 46 | } 47 | 48 | /** 49 | * Gets token by its number..See NetLicensingAPI for details: 50 | * https://netlicensing.io/wiki/token-services#get-token 51 | * 52 | * determines the vendor on whose behalf the call is performed 53 | * @param Context $context 54 | * 55 | * the token number 56 | * @param string $number 57 | * 58 | * return the token 59 | * @return Token|null 60 | * @throws MalformedArgumentsException 61 | * @throws RestException 62 | */ 63 | public static function get(Context $context, string $number): ?Token 64 | { 65 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 66 | 67 | $response = NetLicensingService::getInstance() 68 | ->get($context, Constants::TOKEN_ENDPOINT_PATH . '/' . $number); 69 | 70 | $token = null; 71 | 72 | if (!empty($response->items->item[0])) { 73 | $token = ItemToTokenConverter::convert($response->items->item[0]); 74 | $token->exists = true; 75 | } 76 | 77 | return $token; 78 | } 79 | 80 | /** 81 | * Returns tokens of a vendor.See NetLicensingAPI for details: 82 | * https://netlicensing.io/wiki/token-services#tokens-list 83 | * 84 | * determines the vendor on whose behalf the call is performed 85 | * @param Context $context 86 | * 87 | * reserved for the future use, must be omitted / set to NULL 88 | * @param string|null $filter 89 | * 90 | * array of token entities or empty array if nothing found. 91 | * @return Page 92 | * @throws RestException 93 | */ 94 | public static function getList(Context $context, string $filter = null): Page 95 | { 96 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 97 | 98 | $response = NetLicensingService::getInstance() 99 | ->get($context, Constants::TOKEN_ENDPOINT_PATH, $queryParams); 100 | 101 | $tokens = []; 102 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 103 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 104 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 105 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 106 | 107 | if (!empty($response->items->item)) { 108 | foreach ($response->items->item as $item) { 109 | $token = ItemToTokenConverter::convert($item); 110 | $token->exists = true; 111 | 112 | $tokens[] = $token; 113 | } 114 | } 115 | 116 | return new Page($tokens, $pageNumber, $itemsNumber, $totalPages, $totalItems); 117 | } 118 | 119 | /** 120 | * Delete token by its number.See NetLicensingAPI for details: 121 | * https://netlicensing.io/wiki/token-services#delete-token 122 | * 123 | * determines the vendor on whose behalf the call is performed 124 | * @param Context $context 125 | * 126 | * the token number 127 | * @param string $number 128 | * 129 | * @throws MalformedArgumentsException 130 | * @throws RestException 131 | */ 132 | public static function delete(Context $context, string $number) 133 | { 134 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 135 | 136 | NetLicensingService::getInstance() 137 | ->delete($context, Constants::TOKEN_ENDPOINT_PATH . '/' . $number); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /service/TransactionService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * PHP representation of the Transaction Service. See NetLicensingAPI for details: 13 | * https://netlicensing.io/wiki/transaction-services 14 | * 15 | * Transaction is created each time change to LicenseService licenses happens. For instance licenses are 16 | * obtained by a licensee, licenses disabled by vendor, licenses deleted, etc. Transaction is created no matter what 17 | * source has initiated the change to licenses: it can be either a direct purchase of licenses by a licensee via 18 | * NetLicensing Shop, or licenses can be given to a licensee by a vendor. Licenses can also be assigned implicitly by 19 | * NetLicensing if it is defined so by a license model (e.g. evaluation license may be given automatically). All these 20 | * events are reflected in transactions. Of all the transaction handling routines only read-only routines are exposed to 21 | * the public API, as transactions are only allowed to be created and modified by NetLicensing internally. 22 | * 23 | * @package NetLicensing 24 | */ 25 | class TransactionService 26 | { 27 | /** 28 | * Creates new transaction object with given properties.See NetLicensingAPI for details: 29 | * https://netlicensing.io/wiki/transaction-services#create-transaction 30 | * 31 | * determines the vendor on whose behalf the call is performed 32 | * @param Context $context 33 | * 34 | * non-null properties will be taken for the new object, null properties will either stay null, or will 35 | * be set to a default value, depending on property. 36 | * @param Transaction $transaction 37 | * 38 | * return the newly created transaction object 39 | * @return Transaction|null 40 | * @throws RestException 41 | */ 42 | public static function create(Context $context, Transaction $transaction): ?Transaction 43 | { 44 | $response = NetLicensingService::getInstance() 45 | ->post($context, Constants::TRANSACTION_ENDPOINT_PATH, $transaction->asPropertiesMap()); 46 | 47 | $createdTransaction = null; 48 | 49 | if (!empty($response->items->item[0])) { 50 | $createdTransaction = ItemToTransactionConverter::convert($response->items->item[0]); 51 | $createdTransaction->exists = true; 52 | } 53 | 54 | return $createdTransaction; 55 | } 56 | 57 | /** 58 | * Gets transaction by its number.See NetLicensingAPI for details: 59 | * https://netlicensing.io/wiki/transaction-services#get-transaction 60 | * 61 | * determines the vendor on whose behalf the call is performed 62 | * @param Context $context 63 | * 64 | * the transaction number 65 | * @param $number 66 | * 67 | * return the transaction 68 | * @return Transaction|null 69 | * @throws MalformedArgumentsException 70 | * @throws RestException 71 | */ 72 | public static function get(Context $context, $number): ?Transaction 73 | { 74 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 75 | 76 | $response = NetLicensingService::getInstance() 77 | ->get($context, Constants::TRANSACTION_ENDPOINT_PATH . '/' . $number); 78 | 79 | $transaction = null; 80 | 81 | if (!empty($response->items->item[0])) { 82 | $transaction = ItemToTransactionConverter::convert($response->items->item[0]); 83 | $transaction->exists = true; 84 | } 85 | 86 | return $transaction; 87 | } 88 | 89 | /** 90 | * Returns all transactions of a vendor.See NetLicensingAPI for details: 91 | * https://netlicensing.io/wiki/transaction-services#transactions-list 92 | * 93 | * determines the vendor on whose behalf the call is performed 94 | * @param Context $context 95 | * 96 | * reserved for the future use, must be omitted / set to NULL 97 | * @param string|null $filter 98 | * 99 | * array of transaction entities or empty array if nothing found. 100 | * @return Page 101 | * @throws RestException 102 | */ 103 | public static function getList(Context $context, string $filter = null): Page 104 | { 105 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 106 | 107 | $response = NetLicensingService::getInstance() 108 | ->get($context, Constants::TRANSACTION_ENDPOINT_PATH, $queryParams); 109 | 110 | $transactions = []; 111 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 112 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 113 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 114 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 115 | 116 | if (!empty($response->items->item)) { 117 | foreach ($response->items->item as $item) { 118 | $transaction = ItemToTransactionConverter::convert($item); 119 | $transaction->exists = true; 120 | 121 | $transactions[] = $transaction; 122 | } 123 | } 124 | 125 | return new Page($transactions, $pageNumber, $itemsNumber, $totalPages, $totalItems); 126 | } 127 | 128 | /** 129 | * Updates transaction properties.See NetLicensingAPI for details: 130 | * https://netlicensing.io/wiki/transaction-services#update-transaction 131 | * 132 | * determines the vendor on whose behalf the call is performed 133 | * @param Context $context 134 | * 135 | * transaction number 136 | * @param string $number 137 | * 138 | * non-null properties will be updated to the provided values, null properties will stay unchanged. 139 | * @param Transaction $transaction 140 | * 141 | * return updated transaction. 142 | * @return Transaction|null 143 | * @throws MalformedArgumentsException 144 | * @throws RestException 145 | */ 146 | public static function update(Context $context, string $number, Transaction $transaction): ?Transaction 147 | { 148 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 149 | 150 | $response = NetLicensingService::getInstance() 151 | ->post($context, Constants::TRANSACTION_ENDPOINT_PATH . '/' . $number, $transaction->asPropertiesMap()); 152 | 153 | $updatedTransaction = null; 154 | 155 | if (!empty($response->items->item[0])) { 156 | $updatedTransaction = ItemToTransactionConverter::convert($response->items->item[0]); 157 | $updatedTransaction->exists = true; 158 | } 159 | 160 | return $updatedTransaction; 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /service/UtilityService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * PHP representation of the Utility Service. See NetLicensingAPI for details: 13 | * https://netlicensing.io/wiki/utility-services 14 | * @package NetLicensing 15 | */ 16 | class UtilityService 17 | { 18 | /** 19 | * Returns all license types. See NetLicensingAPI for details: 20 | * https://netlicensing.io/wiki/utility-services#license-types-list 21 | * 22 | * determines the vendor on whose behalf the call is performed 23 | * @param Context $context 24 | * 25 | * array of available license types or empty array if nothing found. 26 | * @return Page 27 | * @throws RestException 28 | */ 29 | public static function listLicenseTypes(Context $context): Page 30 | { 31 | $response = NetLicensingService::getInstance() 32 | ->get($context, Constants::UTILITY_ENDPOINT_PATH . '/' . Constants::UTILITY_ENDPOINT_PATH_LICENSE_TYPES); 33 | 34 | $licenseTypes = []; 35 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 36 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 37 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 38 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 39 | 40 | if (!empty($response->items->item)) { 41 | foreach ($response->items->item as $item) { 42 | $licenseTypes[] = ItemToArrayConverter::convert($item); 43 | } 44 | } 45 | 46 | return new Page($licenseTypes, $pageNumber, $itemsNumber, $totalPages, $totalItems); 47 | } 48 | 49 | /** 50 | * Returns all license models. See NetLicensingAPI for details: 51 | * https://netlicensing.io/wiki/utility-services#licensing-models-list 52 | * 53 | * determines the vendor on whose behalf the call is performed 54 | * @param Context $context 55 | * 56 | * array of available license models or empty array if nothing found. 57 | * @return Page 58 | * @throws RestException 59 | */ 60 | public static function listLicensingModels(Context $context): Page 61 | { 62 | $response = NetLicensingService::getInstance() 63 | ->get($context, Constants::UTILITY_ENDPOINT_PATH . '/' . Constants::UTILITY_ENDPOINT_PATH_LICENSING_MODELS); 64 | 65 | $licensingModels = []; 66 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 67 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 68 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 69 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 70 | 71 | if (!empty($response->items->item)) { 72 | foreach ($response->items->item as $item) { 73 | $licensingModels[] = ItemToArrayConverter::convert($item); 74 | } 75 | } 76 | 77 | return new Page($licensingModels, $pageNumber, $itemsNumber, $totalPages, $totalItems); 78 | } 79 | 80 | /** 81 | * Returns all countries. 82 | * 83 | * determines the vendor on whose behalf the call is performed 84 | * @param Context $context 85 | * 86 | * reserved for the future use, must be omitted / set to NULL 87 | * @param string|null $filter 88 | * 89 | * @return Page 90 | * @throws RestException 91 | */ 92 | public static function listCountries(Context $context, string $filter = null): Page 93 | { 94 | $queryParams = (!is_null($filter)) ? [Constants::FILTER => $filter] : []; 95 | 96 | $response = NetLicensingService::getInstance() 97 | ->get($context, Constants::UTILITY_ENDPOINT_PATH . '/' . Constants::UTILITY_ENDPOINT_PATH_COUNTRIES, $queryParams); 98 | 99 | $countries = []; 100 | $pageNumber = !empty($response->items->pagenumber) ? $response->items->pagenumber : 0; 101 | $itemsNumber = !empty($response->items->itemsnumber) ? $response->items->itemsnumber : 0; 102 | $totalPages = !empty($response->items->totalpages) ? $response->items->totalpages : 0; 103 | $totalItems = !empty($response->items->totalitems) ? $response->items->totalitems : 0; 104 | 105 | if (!empty($response->items->item)) { 106 | foreach ($response->items->item as $item) { 107 | $country = ItemToCountryConverter::convert($item); 108 | $country->exists = true; 109 | 110 | $countries[] = $country; 111 | } 112 | } 113 | 114 | return new Page($countries, $pageNumber, $itemsNumber, $totalPages, $totalItems); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /service/ValidationService.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use DateTime; 12 | use DOMDocument; 13 | use ErrorException; 14 | use Exception; 15 | 16 | class ValidationService 17 | { 18 | /** 19 | * Validates active licenses of the licensee. 20 | * 21 | * @param Context $context determines the vendor on whose behalf the call is performed 22 | * 23 | * @param string $number licensee number 24 | * 25 | * @param ValidationParameters $validationParameters optional validation parameters. See ValidationParameters and 26 | * licensing model documentation for details. 27 | * 28 | * @param array $meta optional parameter, receiving messages returned within response section. 29 | * 30 | * @return ValidationResults|null result of the validation 31 | * @throws MalformedArgumentsException 32 | * @throws RestException 33 | * @throws Exception 34 | */ 35 | static public function validate(Context $context, string $number, ValidationParameters $validationParameters, array &$meta = []): ?ValidationResults 36 | { 37 | return self::convertValidationResult(self::retrieveValidationFile($context, $number, $validationParameters), $meta); 38 | } 39 | 40 | /** 41 | * Retrieves validation file for the given licensee from the server as response string. The response can be 42 | * stored locally for subsequent validation by method {@link validateOffline}, that doesn't require connection to 43 | * the server. 44 | * 45 | * @param Context $context determines the vendor on whose behalf the call is performed 46 | * 47 | * @param string $number licensee number 48 | * 49 | * @param ValidationParameters $validationParameters optional validation parameters. See ValidationParameters and 50 | * licensing model documentation for details. 51 | * 52 | * @return array|mixed|null validation (response), possibly signed, for subsequent use in {@link validateOffline} 53 | * @throws MalformedArgumentsException 54 | * @throws RestException 55 | */ 56 | static public function retrieveValidationFile(Context $context, string $number, ValidationParameters $validationParameters) 57 | { 58 | CheckUtils::paramNotEmpty($number, Constants::NUMBER); 59 | 60 | $urlTemplate = Constants::LICENSEE_ENDPOINT_PATH . '/' . $number . '/' . Constants::LICENSEE_ENDPOINT_PATH_VALIDATE; 61 | $queryParams = self::convertValidationParameters($validationParameters); 62 | 63 | return NetLicensingService::getInstance()->post($context, $urlTemplate, $queryParams); 64 | } 65 | 66 | /** 67 | * Perform validation without connecting to the server (offline) using validation file previously retrieved by 68 | * {@link retrieveValidationFile}. 69 | * 70 | * @param Context $context determines the vendor on whose behalf the call is performed 71 | * 72 | * @param $validationFile string validation file(response) returned by {@link retrieveValidationFile} call 73 | * 74 | * @param array $meta optional parameter, receiving messages returned within response section. 75 | * 76 | * @return ValidationResults|null result of the validation 77 | * @throws BadSignatureException 78 | * @throws Exception 79 | */ 80 | static public function validateOffline(Context $context, string $validationFile, array &$meta = []): ?ValidationResults 81 | { 82 | $validationDoc = new DOMDocument(); 83 | $validationDoc->loadXML($validationFile); 84 | 85 | SignatureUtils::check($context, $validationDoc); 86 | return self::convertValidationResult($validationDoc); 87 | } 88 | 89 | /** 90 | * @param ValidationParameters $validationParameters 91 | * @return array 92 | */ 93 | static private function convertValidationParameters(ValidationParameters $validationParameters): array 94 | { 95 | $queryParams = []; 96 | 97 | if ($validationParameters->getProductNumber()) { 98 | $queryParams[Constants::PRODUCT_NUMBER] = $validationParameters->getProductNumber(); 99 | } 100 | 101 | foreach ($validationParameters->getLicenseeProperties() as $key => $value) { 102 | $queryParams[$key] = $value; 103 | } 104 | 105 | $pmIndex = 0; 106 | 107 | foreach ($validationParameters->getParameters() as $productModuleName => $parameters) { 108 | $queryParams[Constants::PRODUCT_MODULE_NUMBER . $pmIndex] = $productModuleName; 109 | foreach ($parameters as $key => $value) { 110 | $queryParams[$key . $pmIndex] = $value; 111 | } 112 | $pmIndex++; 113 | } 114 | 115 | return $queryParams; 116 | } 117 | 118 | /** 119 | * @param $validationFile 120 | * @param array $meta 121 | * @return ValidationResults|null 122 | * @throws Exception 123 | */ 124 | static private function convertValidationResult($validationFile, array &$meta = []): ?ValidationResults 125 | { 126 | $validationResults = new ValidationResults(); 127 | 128 | if (!empty($validationFile->items->item)) { 129 | foreach ($validationFile->items->item as $item) { 130 | $array = ItemToArrayConverter::convert($item); 131 | $validationResults->setProductModuleValidation($array[Constants::PRODUCT_MODULE_NUMBER], $array); 132 | } 133 | 134 | $validationResults->setTtl(new DateTime($validationFile->ttl)); 135 | } 136 | 137 | if (!empty($validationFile->infos->info)) { 138 | foreach ($validationFile->infos->info as $info) { 139 | $meta[] = $info; 140 | } 141 | } 142 | 143 | return $validationResults; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /tests/DummyTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(true, true); 10 | } 11 | } -------------------------------------------------------------------------------- /util/CheckUtils.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | 12 | class CheckUtils 13 | { 14 | /** 15 | * Ensures that an object reference passed as a parameter to the calling method is not null. 16 | * 17 | * param to check 18 | * @param $parameter 19 | * 20 | * name of the parameter 21 | * @param $parameterName 22 | * 23 | * if parameter is null 24 | * @throws MalformedArgumentsException 25 | */ 26 | public static function paramNotNull($parameter, $parameterName) 27 | { 28 | if (is_null($parameter)) { 29 | throw new MalformedArgumentsException(sprintf("Parameter '%s' cannot be null", $parameterName)); 30 | } 31 | } 32 | 33 | /** 34 | * Ensures that a string passed as a parameter to the calling method is not null or empty. 35 | * 36 | * param to check 37 | * @param $parameter 38 | * 39 | * name of the parameter 40 | * @param $parameterName 41 | * 42 | * if parameter is null or empty 43 | * @throws MalformedArgumentsException 44 | */ 45 | public static function paramNotEmpty($parameter, $parameterName) 46 | { 47 | if (empty($parameter)) { 48 | throw new MalformedArgumentsException(sprintf("Parameter '%s' cannot be null or empty string", $parameterName)); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /util/SignatureUtils.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use DOMDocument; 12 | use Exception; 13 | use FR3D\XmlDSig\Adapter\XmlseclibsAdapter; 14 | 15 | class SignatureUtils 16 | { 17 | /** 18 | * @param Context $context 19 | * @param DOMDocument $response 20 | * @throws BadSignatureException 21 | */ 22 | static public function check(Context $context, DOMDocument $response) 23 | { 24 | if ($context->getPublicKey()) { 25 | try { 26 | $xmlDsig = new XmlseclibsAdapter(); 27 | $xmlDsig->setPublicKey($context->getPublicKey()); 28 | $xmlDsig->setDigestAlgorithm(XmlseclibsAdapter::RSA_SHA1); 29 | $valid = $xmlDsig->verify($response); 30 | 31 | if (!$valid) { 32 | throw new BadSignatureException("Response signature verification failure"); 33 | } 34 | } catch (Exception $e) { 35 | throw new BadSignatureException($e->getMessage()); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /vo/Context.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | /** 12 | * Class Context 13 | * 14 | * Provides calling context for the NetLicensing API calls. 15 | * The Context object may differ depending on the level at which NetLicensing API is called. 16 | * For the internal Java NetLicensing API the Context provides information about the targeted Vendor. 17 | * 18 | * @property string $baseUrl 19 | * Server URL base of the NetLicensing RESTful API. Normally should be "https://go.netlicensing.io". 20 | * 21 | * @property string $username 22 | * Login name of the user sending the requests when securityMode = BASIC_AUTHENTICATION. 23 | * 24 | * @property string $password 25 | * Password of the user sending the requests when securityMode = BASIC_AUTHENTICATION. 26 | * 27 | * @property string $apiKey 28 | * API Key used to identify the request sender when securityMode = APIKEY_IDENTIFICATION. 29 | * 30 | * @property string $securityMode 31 | * Determines the security mode used for accessing the NetLicensing API. 32 | * See https://netlicensing.io/wiki/security for details. 33 | * 34 | * @property string $vendorNumber 35 | * External number of the vendor. 36 | * 37 | * @method string getBaseUrl($default = null) 38 | * @method string getUsername($default = null) 39 | * @method string getPassword($default = null) 40 | * @method string getApiKey($default = null) 41 | * @method string getSecurityMode($default = null) 42 | * @method string getVendorNumber($default = null) 43 | * @method Context setBaseUrl($baseurl) 44 | * @method Context setUsername($username) 45 | * @method Context setPassword($password) 46 | * @method Context setApiKey($apiKey) 47 | * @method Context setSecurityMode($securityMode) 48 | * @method Context setVendorNumber($vendorNumber) 49 | * 50 | * @package NetLicensing\Rest 51 | */ 52 | class Context 53 | { 54 | /** 55 | * @deprecated 56 | * No longer used by internal code and not recommended, will be removed in future versions. 57 | * Use class Constants::BASIC_AUTHENTICATION instead. 58 | */ 59 | const BASIC_AUTHENTICATION = 'BASIC_AUTH'; 60 | /** 61 | * @deprecated 62 | * No longer used by internal code and not recommended, will be removed in future versions. 63 | * Use class Constants::APIKEY_IDENTIFICATION instead. 64 | */ 65 | const APIKEY_IDENTIFICATION = 'APIKEY'; 66 | 67 | /** 68 | * Context defaults 69 | * @var string 70 | */ 71 | protected string $baseUrl = 'https://go.netlicensing.io/core/v2/rest'; 72 | 73 | protected string $securityMode = Constants::BASIC_AUTHENTICATION; 74 | 75 | private string $publicKey = ''; 76 | 77 | /** 78 | * The context values. 79 | * 80 | * @var array 81 | */ 82 | private array $values = []; 83 | 84 | /** 85 | * Create a new context instance. 86 | * 87 | * @param array $values 88 | */ 89 | public function __construct(array $values = []) 90 | { 91 | $this->setValues(array_merge([ 92 | 'baseUrl' => $this->baseUrl, 93 | 'securityMode' => $this->securityMode 94 | ], $values)); 95 | } 96 | 97 | /** 98 | * Get an value from the context. 99 | * 100 | * @param string $key 101 | * @param mixed $default 102 | * @return mixed 103 | */ 104 | public function getValue($key, $default = null) 105 | { 106 | if (!$key) return $default; 107 | 108 | return $this->values[$key] ?? $default; 109 | } 110 | 111 | /** 112 | * Get all of the current value on the context. 113 | * 114 | * @return array 115 | */ 116 | public function getValues(): array 117 | { 118 | return $this->values; 119 | } 120 | 121 | /** 122 | * Set a given values on the context. 123 | * 124 | * @param string $key 125 | * @param mixed $value 126 | * @return $this 127 | */ 128 | public function setValue(string $key, $value): Context 129 | { 130 | $this->values[$key] = $value; 131 | return $this; 132 | } 133 | 134 | /** 135 | * Set the array of context values. 136 | * 137 | * @param array $values 138 | * @return $this 139 | */ 140 | public function setValues(array $values): Context 141 | { 142 | $this->values = $values; 143 | 144 | return $this; 145 | } 146 | 147 | /** 148 | * Sets the public key 149 | * 150 | * @param $publicKey string stored on the client side. 151 | * @return $this 152 | */ 153 | public function setPublicKey(string $publicKey): Context 154 | { 155 | $this->publicKey = $publicKey; 156 | return $this; 157 | } 158 | 159 | public function getPublicKey(): string 160 | { 161 | return $this->publicKey; 162 | } 163 | 164 | /** 165 | * Dynamically retrieve values on the context. 166 | * 167 | * @param string $key 168 | * @return mixed 169 | */ 170 | public function __get(string $key) 171 | { 172 | return $this->getValue($key); 173 | } 174 | 175 | /** 176 | * Dynamically set values on the context. 177 | * 178 | * @param string $key 179 | * @param mixed $value 180 | * @return void 181 | */ 182 | public function __set(string $key, $value) 183 | { 184 | $this->setValue($key, $value); 185 | } 186 | 187 | /** 188 | * Determine if an values exists on the context. 189 | * 190 | * @param string $key 191 | * @return bool 192 | */ 193 | public function __isset(string $key) 194 | { 195 | return !is_null($this->getValue($key)); 196 | } 197 | 198 | /** 199 | * Unset an values on the context. 200 | * 201 | * @param string $key 202 | * @return void 203 | */ 204 | public function __unset(string $key) 205 | { 206 | unset($this->values[$key]); 207 | } 208 | 209 | /** 210 | * Handle dynamic method calls into the context. 211 | * 212 | * @param string $method 213 | * @param array $parameters 214 | * @return mixed 215 | */ 216 | public function __call(string $method, array $parameters) 217 | { 218 | //convert method to snake case 219 | $delimiter = '_'; 220 | $method = preg_replace('/\s+/u', '', $method); 221 | $method = mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $method), 'UTF-8'); 222 | 223 | $methodParts = explode($delimiter, $method); 224 | 225 | //check if need set or get attributes 226 | if (in_array($methodParts[0], ['get', 'set'])) { 227 | 228 | //get attribute name 229 | $key = array_slice($methodParts, 1); 230 | $key = implode('_', $key); 231 | $key = lcfirst(str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $key)))); 232 | 233 | array_unshift($parameters, $key); 234 | 235 | //call getValue 236 | if ($methodParts[0] == 'get') return $this->getValue(...$parameters); 237 | 238 | //call setValue 239 | return $this->setValue(...$parameters); 240 | } 241 | 242 | //trigger error if method undefined 243 | trigger_error('Call to undefined method ' . __CLASS__ . '::' . $method . '()', E_USER_ERROR); 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /vo/NetLicensingCurl.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | 12 | use Curl\Curl; 13 | use ErrorException; 14 | 15 | class NetLicensingCurl extends Curl 16 | { 17 | /** 18 | * Build Post Data 19 | * 20 | * @access public 21 | * @param $data 22 | * 23 | * @return array|string 24 | * @throws ErrorException 25 | */ 26 | public function buildPostData($data) 27 | { 28 | $query = parent::buildPostData($data); 29 | 30 | foreach ($data as $key => $value) { 31 | if (is_array($value)) { 32 | $query = preg_replace('/&' . $key . '%5B%5D=/simU', '&' . $key . '=', $query); 33 | } 34 | } 35 | 36 | return $query; 37 | } 38 | 39 | 40 | public function toArray(): array 41 | { 42 | return [ 43 | 'error' => $this->error, 44 | 'errorCode' => $this->errorCode, 45 | 'errorMessage' => $this->errorMessage, 46 | 'curlError' => $this->curlError, 47 | 'curlErrorCode' => $this->curlErrorCode, 48 | 'curlErrorMessage' => $this->curlErrorMessage, 49 | 'httpError' => $this->httpError, 50 | 'httpStatusCode' => $this->httpStatusCode, 51 | 'httpErrorMessage' => $this->httpErrorMessage, 52 | 'url' => $this->url, 53 | 'effectiveUrl' => $this->effectiveUrl, 54 | 'requestHeaders' => $this->requestHeaders, 55 | 'responseHeaders' => $this->responseHeaders, 56 | 'rawResponseHeaders' => $this->rawResponseHeaders, 57 | 'response' => $this->response, 58 | 'rawResponse' => $this->rawResponse, 59 | ]; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /vo/Page.php: -------------------------------------------------------------------------------- 1 | content = $content; 55 | $this->pageNumber = $pageNumber; 56 | $this->itemsNumber = $itemsNumber; 57 | $this->totalPages = $totalPages; 58 | $this->totalItems = $totalItems; 59 | } 60 | 61 | /** 62 | * Get the slice of items being paginated. 63 | * @return array 64 | */ 65 | public function getContent(): array 66 | { 67 | return $this->content; 68 | } 69 | 70 | /** 71 | * Get the current page. 72 | * 73 | * @return int 74 | */ 75 | public function getPageNumber(): int 76 | { 77 | return $this->pageNumber; 78 | } 79 | 80 | /** 81 | * The number of elements on the page. 82 | * 83 | * @return int 84 | */ 85 | public function getItemsNumber(): int 86 | { 87 | return $this->itemsNumber; 88 | } 89 | 90 | /** 91 | * The number of total pages. 92 | * 93 | * @return int 94 | */ 95 | public function getTotalPages(): int 96 | { 97 | return $this->totalPages; 98 | } 99 | 100 | /** 101 | * The total amount of elements 102 | * 103 | * @return int 104 | */ 105 | public function getTotalItems(): int 106 | { 107 | return $this->totalItems; 108 | } 109 | 110 | /** 111 | * Is there a next page exists 112 | * 113 | * @return bool 114 | */ 115 | public function hasNext(): bool 116 | { 117 | return ($this->totalPages > $this->pageNumber + 1); 118 | } 119 | 120 | /** 121 | * Determine if the given item exists. 122 | * 123 | * @param mixed $offset 124 | * @return bool 125 | */ 126 | public function offsetExists($offset): bool 127 | { 128 | return array_key_exists($offset, $this->content); 129 | } 130 | 131 | /** 132 | * Get the item at the given offset. 133 | * 134 | * @param mixed $offset 135 | * @return mixed 136 | */ 137 | public function offsetGet($offset) 138 | { 139 | return $this->content[$offset]; 140 | } 141 | 142 | /** 143 | * Set the item at the given offset. 144 | * 145 | * @param mixed $offset 146 | * @param mixed $value 147 | * @return void 148 | */ 149 | public function offsetSet($offset, $value) 150 | { 151 | if (is_null($offset)) { 152 | $this->content[] = $value; 153 | } else { 154 | $this->content[$offset] = $value; 155 | } 156 | } 157 | 158 | /** 159 | * Unset the item at the given key. 160 | * 161 | * @param mixed $offset 162 | * @return void 163 | */ 164 | public function offsetUnset($offset) 165 | { 166 | unset($this->content[$offset]); 167 | } 168 | 169 | /** 170 | * Count the number of items in the collection. 171 | * 172 | * @return int 173 | */ 174 | public function count(): int 175 | { 176 | return count($this->content); 177 | } 178 | 179 | /** 180 | * Get an iterator for the items. 181 | * 182 | * @return ArrayIterator 183 | */ 184 | public function getIterator(): ArrayIterator 185 | { 186 | return new ArrayIterator($this->content); 187 | } 188 | 189 | /** 190 | * Get the instance as an array. 191 | * 192 | * @return array 193 | */ 194 | public function toArray(): array 195 | { 196 | return [ 197 | 'content' => $this->getContent(), 198 | 'pageNumber' => $this->getPageNumber(), 199 | 'itemsNumber' => $this->getItemsNumber(), 200 | 'totalPages' => $this->getTotalPages(), 201 | 'totalItems' => $this->getTotalItems(), 202 | 'hasNext' => $this->hasNext(), 203 | ]; 204 | } 205 | 206 | /** 207 | * Convert the object into something JSON serializable. 208 | * 209 | * @return array 210 | */ 211 | public function jsonSerialize(): array 212 | { 213 | return $this->toArray(); 214 | } 215 | 216 | 217 | /** 218 | * Convert the entity to its string representation. 219 | * 220 | * @return string 221 | */ 222 | public function __toString() 223 | { 224 | $contentType = 'UNKNOWN'; 225 | 226 | if ($this->content) { 227 | $contentType = get_class($this->content[0]); 228 | } 229 | 230 | return sprintf('Page %s of %d containing %s instances', $this->getPageNumber(), $this->getTotalPages(), $contentType); 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /vo/ValidationParameters.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | 12 | class ValidationParameters 13 | { 14 | protected string $productNumber; 15 | protected array $licenseeProperties = []; 16 | protected array $parameters = []; 17 | 18 | /** 19 | * Sets the target product 20 | * 21 | * optional productNumber, must be provided in case licensee auto-create is enabled 22 | * @param string $productNumber 23 | * 24 | * @return $this 25 | */ 26 | public function setProductNumber(string $productNumber): ValidationParameters 27 | { 28 | $this->productNumber = $productNumber; 29 | 30 | return $this; 31 | } 32 | 33 | public function getProductNumber(): string 34 | { 35 | return $this->productNumber; 36 | } 37 | 38 | /** 39 | * Get all licensee properties 40 | * 41 | * @return array 42 | */ 43 | public function getLicenseeProperties(): array 44 | { 45 | return $this->licenseeProperties; 46 | } 47 | 48 | /** 49 | * Set licensee property 50 | * 51 | * @param string $key 52 | * @param $value 53 | * @return $this 54 | */ 55 | public function setLicenseeProperty(string $key, $value): ValidationParameters 56 | { 57 | $this->licenseeProperties[$key] = $value; 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * Get licensee property 64 | * 65 | * @param string $key 66 | * @return mixed 67 | */ 68 | public function getLicenseeProperty(string $key) 69 | { 70 | return $this->licenseeProperties[$key]; 71 | } 72 | 73 | /** 74 | * Sets the name for the new licensee 75 | * 76 | * optional human-readable licensee name in case licensee will be auto-created. This parameter must not 77 | * be the name, but can be used to store any other useful string information with new licensees, up to 78 | * 1000 characters. 79 | * @param string $licenseeName 80 | * 81 | * @return $this 82 | */ 83 | public function setLicenseeName(string $licenseeName): ValidationParameters 84 | { 85 | $this->setLicenseeProperty(Constants::LICENSEE_PROP_LICENSEE_NAME, $licenseeName); 86 | 87 | return $this; 88 | } 89 | 90 | public function getLicenseeName() 91 | { 92 | return $this->getLicenseeProperty(Constants::LICENSEE_PROP_LICENSEE_NAME); 93 | } 94 | 95 | /** 96 | * Sets the licensee secret 97 | * 98 | * licensee secret stored on the client side. Refer to Licensee Secret documentation for details. 99 | * @param string $licenseeSecret 100 | * 101 | * @return $this 102 | * @deprecated use 'NodeLocked' licensing model instead 103 | */ 104 | public function setLicenseeSecret(string $licenseeSecret): ValidationParameters 105 | { 106 | $this->setLicenseeProperty(Constants::LICENSE_PROP_LICENSEE_SECRET, $licenseeSecret); 107 | 108 | return $this; 109 | } 110 | 111 | /** 112 | * @deprecated use 'NodeLocked' licensing model instead 113 | */ 114 | public function getLicenseeSecret() 115 | { 116 | return $this->getLicenseeProperty(Constants::LICENSE_PROP_LICENSEE_SECRET); 117 | } 118 | 119 | public function getParameters(): array 120 | { 121 | return $this->parameters; 122 | } 123 | 124 | public function getProductModuleValidationParameters($productModuleNumber) 125 | { 126 | if (empty($this->parameters[$productModuleNumber])) { 127 | $this->parameters[$productModuleNumber] = array(); 128 | } 129 | return $this->parameters[$productModuleNumber]; 130 | } 131 | 132 | public function setProductModuleValidationParameters($productModuleNumber, $productModuleParameters) 133 | { 134 | if (empty($this->parameters[$productModuleNumber])) { 135 | $this->parameters[$productModuleNumber] = array(); 136 | } 137 | $this->parameters[$productModuleNumber] += $productModuleParameters; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /vo/ValidationResults.php: -------------------------------------------------------------------------------- 1 | 4 | * @license Apache-2.0 5 | * @link https://netlicensing.io 6 | * @copyright 2017 Labs64 NetLicensing 7 | */ 8 | 9 | namespace NetLicensing; 10 | 11 | use DateTime; 12 | 13 | /** 14 | * 15 | * @property string $productModuleNumber 16 | * @property boolean $valid 17 | * @property int $remainingQuantity 18 | * @property string $productModuleName 19 | * @property string $licensingModel 20 | * 21 | * @property 22 | * 23 | * @package NetLicensing 24 | */ 25 | class ValidationResults 26 | { 27 | protected array $validators = []; 28 | protected DateTime $ttl; 29 | 30 | public function getValidations(): array 31 | { 32 | return $this->validators; 33 | } 34 | 35 | public function getProductModuleValidation($productModuleNumber) 36 | { 37 | return $this->validators[$productModuleNumber] ?? null; 38 | } 39 | 40 | public function setProductModuleValidation($productModuleNumber, $productModuleValidation): ValidationResults 41 | { 42 | $this->validators[$productModuleNumber] = $productModuleValidation; 43 | return $this; 44 | } 45 | 46 | public function __toString() 47 | { 48 | $data = 'ValidationResult ['; 49 | 50 | foreach ($this->validators as $productModuleNumber => $validator) { 51 | $data .= 'ProductModule<'; 52 | $data .= $productModuleNumber; 53 | $data .= '>'; 54 | 55 | foreach ($validator as $key => $value) { 56 | $data .= $key . '=' . $value; 57 | } 58 | 59 | if ($validator != end($validator)) { 60 | $data .= ','; 61 | } 62 | } 63 | 64 | $data .= ']'; 65 | 66 | return $data; 67 | } 68 | 69 | 70 | public function getTtl(): DateTime 71 | { 72 | return $this->ttl; 73 | } 74 | 75 | public function setTtl(DateTime $ttl): ValidationResults 76 | { 77 | $this->ttl = $ttl; 78 | 79 | return $this; 80 | } 81 | } 82 | --------------------------------------------------------------------------------