├── LICENCE.txt ├── README.en_US.md ├── composer.json ├── doc ├── en_US │ ├── CONTRIBUTING.md │ ├── CREDENTIALS.md │ ├── INSTALLATION.md │ ├── SYSTEM_REQUIREMENTS.md │ └── usage │ │ ├── API.md │ │ ├── CATALOG.md │ │ ├── ORDERS.md │ │ ├── SHIPMENT.md │ │ ├── catalog │ │ ├── ATTRIBUTES.md │ │ ├── CATEGORIES.md │ │ └── PRODUCTS.md │ │ ├── orders │ │ ├── CANCEL.md │ │ ├── CONSULT.md │ │ ├── DELIVERY.md │ │ ├── INVOICE.md │ │ ├── LABELS.md │ │ ├── QUEUE.md │ │ ├── SHIPPING_EXCEPTION.md │ │ └── TRACKING.md │ │ └── shipment │ │ └── PLPS.md ├── images │ └── logo.png └── pt_BR │ ├── CONTRIBUTING.md │ ├── CREDENTIALS.md │ ├── INSTALLATION.md │ ├── SYSTEM_REQUIREMENTS.md │ └── usage │ ├── API.md │ ├── CATALOG.md │ ├── ORDERS.md │ ├── SHIPMENT.md │ ├── catalog │ ├── ATTRIBUTES.md │ ├── CATEGORIES.md │ └── PRODUCTS.md │ ├── orders │ ├── CANCEL.md │ ├── CONSULT.md │ ├── DELIVERY.md │ ├── INVOICE.md │ ├── LABELS.md │ ├── QUEUE.md │ ├── SHIPPING_EXCEPTION.md │ └── TRACKING.md │ └── shipment │ └── PLPS.md ├── invoice ├── src ├── Api.php ├── Api │ ├── DataTransformer │ │ ├── Builders.php │ │ ├── Catalog │ │ │ ├── Category │ │ │ │ ├── Create.php │ │ │ │ └── Update.php │ │ │ └── Product │ │ │ │ ├── Attribute │ │ │ │ ├── Create.php │ │ │ │ └── Update.php │ │ │ │ ├── Create.php │ │ │ │ ├── Price │ │ │ │ └── Update.php │ │ │ │ ├── Stock │ │ │ │ └── Update.php │ │ │ │ ├── Update.php │ │ │ │ └── Variation │ │ │ │ ├── Create.php │ │ │ │ └── Update.php │ │ ├── DataTransformerAbstract.php │ │ ├── DataTransformerInterface.php │ │ ├── Sales │ │ │ └── Order │ │ │ │ ├── B2WDirectInvoiced.php │ │ │ │ ├── Cancel.php │ │ │ │ ├── Delivery.php │ │ │ │ ├── Invoice.php │ │ │ │ ├── Shipment.php │ │ │ │ ├── ShipmentException.php │ │ │ │ └── Status │ │ │ │ ├── Create.php │ │ │ │ └── Update.php │ │ └── Shipment │ │ │ ├── Order │ │ │ └── Collect.php │ │ │ └── Plp │ │ │ └── Group.php │ ├── EntityInterface │ │ ├── Catalog │ │ │ ├── Category.php │ │ │ ├── Product.php │ │ │ └── Product │ │ │ │ ├── Attribute.php │ │ │ │ ├── MutualMethods.php │ │ │ │ ├── Price.php │ │ │ │ ├── Stock.php │ │ │ │ └── Variation.php │ │ ├── EntityAbstract.php │ │ ├── EntityInterface.php │ │ ├── Getters.php │ │ ├── Questions.php │ │ ├── Sales │ │ │ ├── Freights.php │ │ │ ├── Order.php │ │ │ └── Order │ │ │ │ ├── Queue.php │ │ │ │ └── Status.php │ │ └── Shipment │ │ │ └── Plp.php │ ├── Exception │ │ └── JsonDataConvert.php │ ├── Handler │ │ ├── Request │ │ │ ├── Catalog │ │ │ │ ├── CategoryHandler.php │ │ │ │ ├── Product │ │ │ │ │ ├── AttributeHandler.php │ │ │ │ │ ├── PriceHandler.php │ │ │ │ │ ├── StockHandler.php │ │ │ │ │ └── VariationHandler.php │ │ │ │ └── ProductHandler.php │ │ │ ├── Getters.php │ │ │ ├── HandlerAbstract.php │ │ │ ├── HandlerInterface.php │ │ │ ├── QuestionsHandler.php │ │ │ ├── Sales │ │ │ │ ├── FreightsHandler.php │ │ │ │ ├── Order │ │ │ │ │ ├── QueueHandler.php │ │ │ │ │ └── StatusHandler.php │ │ │ │ ├── OrderHandler.php │ │ │ │ └── SystemHandler.php │ │ │ ├── Shipment │ │ │ │ └── PlpHandler.php │ │ │ └── Sync │ │ │ │ └── ErrorsHandler.php │ │ └── Response │ │ │ ├── HandlerAbstract.php │ │ │ ├── HandlerDefault.php │ │ │ ├── HandlerException.php │ │ │ ├── HandlerInterface.php │ │ │ ├── HandlerInterfaceException.php │ │ │ ├── HandlerInterfaceSuccess.php │ │ │ └── HandlerInvalid.php │ ├── Helpers.php │ ├── Log │ │ ├── Logger.php │ │ ├── LoggerAbstract.php │ │ ├── LoggerInterface.php │ │ ├── Loggerable.php │ │ └── TypeInterface │ │ │ ├── Request.php │ │ │ ├── Response.php │ │ │ ├── ResponsePdf.php │ │ │ ├── TypeAbstract.php │ │ │ ├── TypeInterface.php │ │ │ ├── TypeRequestInterface.php │ │ │ └── TypeResponseInterface.php │ └── Service │ │ ├── ClientBuilder.php │ │ ├── ClientBuilderInterface.php │ │ ├── HeadersBuilder.php │ │ ├── HeadersBuilderInterface.php │ │ ├── HeadersProtection.php │ │ ├── OptionsBuilder.php │ │ ├── OptionsBuilderInterface.php │ │ ├── ServiceAbstract.php │ │ ├── ServiceDefault.php │ │ ├── ServiceInterface.php │ │ ├── ServiceJson.php │ │ ├── ServiceMultipart.php │ │ └── ServicePdf.php ├── ApiInterface.php ├── bootstrap.php └── functions.php └── test └── unit ├── Api ├── DataTransformer │ ├── Catalog │ │ ├── CategoryTest.php │ │ └── Product │ │ │ ├── AttributeTest.php │ │ │ ├── Price │ │ │ └── UpdateTest.php │ │ │ └── Stock │ │ │ └── UpdateTest.php │ └── Sales │ │ └── OrderTest.php ├── EntityInterface │ └── Catalog │ │ ├── Product │ │ ├── AttributeTest.php │ │ ├── PriceTest.php │ │ └── StockTest.php │ │ └── ProductTest.php ├── Handler │ └── Sales │ │ └── OrderHandlerTest.php ├── Service │ ├── ClientBuilderTest.php │ ├── HeadersBuilderTest.php │ ├── OptionsBuilderTest.php │ └── ServiceJsonTest.php └── ServiceTest.php ├── ApiTest.php └── Base.php /README.en_US.md: -------------------------------------------------------------------------------- 1 | ![SkyHub - MarketPlace Intelligence](/doc/images/logo.png) 2 | 3 | # SkyHub - PHP SDK 4 | 5 | This is the official SDK ([Software Developmen Kit](https://pt.wikipedia.org/wiki/Kit_de_desenvolvimento_de_software)) from SkyHub, built in PHP, which you can use to integrate your platform to our system. 6 | 7 | See right below how easy is to use it: 8 | 9 | ```php 10 | productAttribute(); 28 | 29 | /** 30 | * Create an Attribute 31 | * @var SkyHub\Api\Handler\Response\HandlerInterface $response 32 | */ 33 | $response = $requestHandler->create('color', 'Color', [ 34 | 'Blue', 35 | 'White', 36 | 'Green', 37 | 'Yellow' 38 | ]); 39 | 40 | if ($response->success()) { 41 | echo 'SUCCESS!'; 42 | } 43 | ``` 44 | 45 | ## Wiki 46 | 1. [System Requirements](doc/en_US/SYSTEM_REQUIREMENTS.md) 47 | 1. [Credentials](doc/en_US/CREDENTIALS.md) 48 | 1. [Installation and Setup](doc/en_US/INSTALLATION.md) 49 | 1. Using the SDK 50 | 1. [Using the API](doc/en_US/usage/API.md) 51 | 1. [Catalog](doc/en_US/usage/CATALOG.md) 52 | 1. [Product Attributes](doc/en_US/usage/catalog/ATTRIBUTES.md) 53 | 1. [Products](doc/en_US/usage/catalog/PRODUCTS.md) 54 | 1. [Categories](doc/en_US/usage/catalog/CATEGORIES.md) 55 | 1. [Orders](doc/en_US/usage/ORDERS.md) 56 | 1. [Consulting Orders](doc/en_US/usage/orders/CONSULT.md) 57 | 1. [Working With Order Queues](doc/en_US/usage/orders/QUEUE.md) 58 | 1. [Invoicing an Order](doc/en_US/usage/orders/INVOICE.md) 59 | 1. [Canceling an Order](doc/en_US/usage/orders/CANCEL.md) 60 | 1. [Adding an Order Tracking Number](doc/en_US/usage/orders/TRACKING.md) 61 | 1. [Setting an Order as Delivered](doc/en_US/usage/orders/DELIVERY.md) 62 | 1. [Getting Order Tags](doc/en_US/usage/orders/LABELS.md) 63 | 1. [Orders With Shipment Issues (Exceptions)](doc/en_US/usage/orders/SHIPPING_EXCEPTION.md) 64 | 1. [Shipment](doc/en_US/usage/SHIPMENT.md) 65 | 1. [PLP](doc/en_US/usage/shipment/PLPS.md) 66 | 67 | ## Contributing with the code 68 | 69 | Your contribution is always welcome! Please read the [contribution documentation](doc/CONTRIBUTING.md). 70 | 71 | ## Authors 72 | 73 | Tiago Sampaio 74 | 75 | Bruno Gemelli 76 | 77 | ## Support 78 | 79 | For support requests please send an e-mail to the following address: 80 | 81 | sdk@e-smart.com.br 82 | 83 | #### Read in Another Language 84 | 85 | * [Português do Brasil](README.md) 86 | 87 | ## Licence 88 | > SkyHub PHP SDK is a project started into B2W Digital office and distributed as an Open Source Software in March of 2018. 89 | 90 | The code base in this distribution is licenced under OSL 3.0. 91 | 92 | [The Open Software License 3.0 (OSL-3.0)](https://opensource.org/licenses/osl-3.0.php). 93 | 94 | For complete licence information please read LICENSE.txt or contact sdk@e-smart.com.br to request a copy of it. 95 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bittools/skyhub-php", 3 | "description": "This is the official PHP SDK for integration with SkyHub.", 4 | "type": "library", 5 | "require": { 6 | "php": ">=7.0", 7 | "guzzlehttp/guzzle": "^6.3", 8 | "monolog/monolog": "^1.23" 9 | }, 10 | "require-dev": { 11 | "phpunit/phpunit": "^6.5", 12 | "squizlabs/php_codesniffer": "^3.3" 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "SkyHub\\": "src/" 17 | }, 18 | "files": [ 19 | "src/functions.php" 20 | ] 21 | }, 22 | "autoload-dev": { 23 | "psr-4": { 24 | "SkyHubTest\\": "test/" 25 | } 26 | }, 27 | "license": "OSL-3.0", 28 | "authors": [ 29 | { 30 | "name": "Tiago Sampaio", 31 | "email": "tiago@tiagosampaio.com", 32 | "role": "Developer" 33 | } 34 | ], 35 | "support": { 36 | "email": "sdk@e-smart.com.br" 37 | }, 38 | "minimum-stability": "stable", 39 | "prefer-stable": true, 40 | "scripts": { 41 | "phpunit": [ 42 | "vendor/bin/phpunit -c ./phpunit.xml test/unit" 43 | ], 44 | "phpcs": [ 45 | "vendor/bin/phpcs --standard=PSR2 --severity=1 src" 46 | ], 47 | "tests": [ 48 | "@phpunit", 49 | "@phpcs" 50 | ] 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /doc/en_US/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Manual 2 | 3 | If you wish to contribute with the project and make it better, your help is welcome. 4 | The contribution is a great way to lean more about new technologies and it's ecosystem, make it more construtive, bugs free and keep it updated. 5 | 6 | ### How to create a pull request at Github 7 | 8 | * In your account, create a fork of this project at Github. 9 | * Fork at your local machine. The default `remote` of your repository will be `origin`. 10 | * Add the original repository, as a new 'remote' named `upstream`. 11 | ```bash 12 | $ git remote add upstream git@github.com:vendor/repository.git 13 | ``` 14 | * Make sure to frequently update your repository with the original. 15 | * Create a new branch in which you are gonna make the implementation. Create from the `master` branch. 16 | ```bash 17 | $ git checkout -b hotfix/ticket-number 18 | ``` 19 | * Implement your fix or feature, not forgetting to comment the code. 20 | * Follow the project code style, including the corrects identations. 21 | * Execute all tests available to get certified that no part of the SDK was compromised by the new code. 22 | * Write and adapt tests to your code, if necessary. 23 | * Include a documentation of your code. 24 | * Do `git push` of your project to your Github fork, the `remote origin`. 25 | * At github, from your fork, create a new `pull request` from branch. Point to `develop` branch of the original project. 26 | * If the maintainer of the project requests any change in the code, changeyour branch and give a `push` to your Github fork. The `pull request` will be updated automatically. 27 | * Once the code has been approved and merged in the oficial project, you can update your remote `upstream` to your local machine and remove the branches you have created. 28 | 29 | And finally, but not less important: always comment your codes and commits. The message of your commit must describe what it will do with the code. 30 | 31 | [Back](../README.en_US.md) 32 | -------------------------------------------------------------------------------- /doc/en_US/CREDENTIALS.md: -------------------------------------------------------------------------------- 1 | # Credentials for Integration 2 | 3 | To use this integration, it's necessary that you contact SkyHub's commercial and request an account to access the API. 4 | 5 | Two pieces of informations will be made available: 6 | 7 | * E-mail access; 8 | * API key; 9 | 10 | These informations are needed to integrate with SkyHub. 11 | 12 | Read more at [official_documentation](https://skyhub.gelato.io/docs/versions/1.0/autenticacao-e-formato-dos-dados). 13 | 14 | You can get in touch through [contact_page](https://skyhub.com.br/#form_contato). 15 | 16 | [Back](../../README.en_US.md) 17 | 18 | [Continue: Installation and Setup](INSTALLATION.md) 19 | -------------------------------------------------------------------------------- /doc/en_US/INSTALLATION.md: -------------------------------------------------------------------------------- 1 | # SDK installation 2 | 3 | This SDK follow the PSR patterns and uses composer to install all dependencies. 4 | 5 | To install this SDK you need to follow these steps: 6 | 7 | ##### Steps to install 8 | 9 | It's necessary to have [composer](https://getcomposer.org/download/) installed. 10 | 11 | ```bash 12 | # Install Composer 13 | $ curl -sS https://getcomposer.org/installer | php 14 | ``` 15 | 16 | Next step is to execute composer to get all dependencies in it's correct versions: 17 | 18 | ```bash 19 | $ php composer.phar require bittools/skyhub-php 20 | ``` 21 | 22 | Or, in case you already have composer installed: 23 | 24 | ```bash 25 | $ composer require bittools/skyhub-php 26 | ``` 27 | 28 | After installation, you need to call composer's autoload in your php file: 29 | 30 | ```php 31 | require_once 'vendor/autoload.php'; 32 | ``` 33 | 34 | After that, it can be necessary to update the SDK in your enviroment. To do that you can execute the following command: 35 | 36 | ```bash 37 | $ php composer.phar update 38 | ``` 39 | 40 | [Back](../../README.en_US.md) 41 | 42 | [Continue: Using the SDK - API](usage/API.md) 43 | -------------------------------------------------------------------------------- /doc/en_US/SYSTEM_REQUIREMENTS.md: -------------------------------------------------------------------------------- 1 | # System Requirements 2 | 3 | To use the SDK you need to follow the required system requirements below: 4 | 5 | * PHP 5.4 or higher (version 1.1) 6 | * PHP 7.0 or higher (version 1.2) 7 | 8 | [Back](../../README.en_US.md) 9 | 10 | [Continue: Credentials](CREDENTIALS.md) 11 | -------------------------------------------------------------------------------- /doc/en_US/usage/API.md: -------------------------------------------------------------------------------- 1 | # Using the API 2 | 3 | The API class used in the SDK is the needed proxy class to have access to any other API functionality. It's usage is very simple. 4 | 5 | First, you need to import the composer autoload in your php file: 6 | 7 | ```php 8 | productAttribute(); 14 | 15 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 16 | $response = $requestHandler->create('color', 'Color', [ 17 | 'Blue', 18 | 'White' 19 | ]); 20 | 21 | // ... 22 | ``` 23 | 24 | ### Updating Attributes 25 | 26 | When the attribute already exists on SkyHub and you need to update it: 27 | 28 | ```php 29 | // ... 30 | 31 | /** @var SkyHub\Api\Handler\Request\Catalog\Product\AttributeHandler $requestHandler */ 32 | $requestHandler = $api->productAttribute(); 33 | 34 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 35 | $response = $requestHandler->update('color', 'Color', [ 36 | 'Blue', 37 | 'White', 38 | 'Green', 39 | 'Yellow', 40 | 'Black', 41 | 'Red' 42 | ]); 43 | 44 | // ... 45 | ``` 46 | 47 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/attributes). 48 | 49 | [Back](../../../../README.en_US.md) 50 | 51 | [Continue: Products](PRODUCTS.md) 52 | -------------------------------------------------------------------------------- /doc/en_US/usage/catalog/CATEGORIES.md: -------------------------------------------------------------------------------- 1 | # Categories 2 | 3 | The categories creation is simple way made. 4 | 5 | ### Creating a Category 6 | 7 | ```php 8 | // ... 9 | 10 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $requestHandler */ 11 | $requestHandler = $api->category(); 12 | 13 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 14 | $response = $requestHandler->create('category001', 'Category 001'); 15 | 16 | // ... 17 | ``` 18 | 19 | ### Updating a Category 20 | 21 | ```php 22 | // ... 23 | 24 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $requestHandler */ 25 | $requestHandler = $api->category(); 26 | 27 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 28 | $response = $requestHandler->update('category001', 'Updated Category 001 Name'); 29 | 30 | // ... 31 | ``` 32 | 33 | ### Removing a Category 34 | 35 | ```php 36 | // ... 37 | 38 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $requestHandler */ 39 | $requestHandler = $api->category(); 40 | 41 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 42 | $response = $requestHandler->delete('category001'); 43 | 44 | // ... 45 | ``` 46 | 47 | ## Getting a List of Categories 48 | 49 | ```php 50 | // ... 51 | 52 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $requestHandler */ 53 | $requestHandler = $api->category(); 54 | 55 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 56 | $response = $requestHandler->categories(); 57 | 58 | // ... 59 | ``` 60 | 61 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/categories). 62 | 63 | [Back](../../../../README.en_US.md) 64 | 65 | [Continue: Orders](../ORDERS.md) 66 | -------------------------------------------------------------------------------- /doc/en_US/usage/orders/CANCEL.md: -------------------------------------------------------------------------------- 1 | # Cancelling a order 2 | 3 | ```php 4 | // ... 5 | 6 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 7 | $requestHandler = $api->order(); 8 | 9 | $orderId = 'Marketplace-000000001'; 10 | 11 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 12 | $response = $requestHandler->cancel($orderId); 13 | // ... 14 | ``` 15 | 16 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/cancelar-um-pedido). 17 | 18 | [Back](../../../../README.en_US.md) 19 | 20 | [Continue: Adding an Order Track](TRACKING.md) 21 | -------------------------------------------------------------------------------- /doc/en_US/usage/orders/CONSULT.md: -------------------------------------------------------------------------------- 1 | # Requesting Orders 2 | 3 | Orders requesting is made to obtain informations about an order but shouldn't be used to identify new orders. 4 | 5 | To know more about new orders request, see the documentation about [orders queue](QUEUE.md). 6 | 7 | For more information, access the [official documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders). 8 | 9 | Orders searching can be necessary to update order status in your platform, for example. 10 | 11 | ### Requesting an Order 12 | 13 | This method allow to request only an order a time. 14 | 15 | ```php 16 | // ... 17 | 18 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 19 | $requestHandler = $api->order(); 20 | 21 | $orderId = 'Marketplace-000000001'; 22 | 23 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 24 | $response = $requestHandler->order($orderId); 25 | // ... 26 | ``` 27 | 28 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/obter-um-pedido). 29 | 30 | ### Obtaining a List of Orders 31 | 32 | The following method returns a list with all your orders in SkyHub. 33 | 34 | ```php 35 | // ... 36 | 37 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 38 | $requestHandler = $api->order(); 39 | 40 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 41 | $response = $requestHandler->orders(); 42 | // ... 43 | ``` 44 | 45 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/listar-pedidos). 46 | 47 | [Back](../../../../README.en_US.md) 48 | 49 | [Continue: Working With Orders Queue](QUEUE.md) 50 | -------------------------------------------------------------------------------- /doc/en_US/usage/orders/DELIVERY.md: -------------------------------------------------------------------------------- 1 | # Confirming an Order Delivery 2 | 3 | ```php 4 | // ... 5 | 6 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 7 | $requestHandler = $api->order(); 8 | 9 | $orderId = 'Marketplace-000000001'; 10 | 11 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 12 | $response = $requestHandler->delivery($orderId); 13 | // ... 14 | ``` 15 | 16 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/confirmar-entrega). 17 | 18 | [Back](../../../../README.en_US.md) 19 | 20 | [Continue: Getting Order Tags](LABELS.md) 21 | -------------------------------------------------------------------------------- /doc/en_US/usage/orders/INVOICE.md: -------------------------------------------------------------------------------- 1 | # Invoicing an Order 2 | 3 | To invoice an order you need to have in hands the number of the `fiscal note` to send it on request. 4 | 5 | ```php 6 | // ... 7 | 8 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 9 | $requestHandler = $api->order(); 10 | 11 | $nfKey = '99999999999999999999999999999999999999999999'; 12 | 13 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 14 | $response = $requestHandler->invoice($orderId, $nfKey); 15 | // ... 16 | ``` 17 | 18 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/faturar-um-pedido). 19 | 20 | [Back](../../../../README.en_US.md) 21 | 22 | [Continue: Cancelling an Order](CANCEL.md) 23 | -------------------------------------------------------------------------------- /doc/en_US/usage/orders/LABELS.md: -------------------------------------------------------------------------------- 1 | # Getting Order Tags 2 | 3 | ```php 4 | // ... 5 | 6 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 7 | $requestHandler = $api->order(); 8 | 9 | $orderId = 'Marketplace-000000001'; 10 | 11 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 12 | $response = $requestHandler->shipmentLabels($orderId); 13 | // ... 14 | ``` 15 | 16 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/obter-etiqueta-de-frete). 17 | 18 | [Back](../../../../README.en_US.md) 19 | 20 | [Continue: Problems With Orders Delivery](SHIPPING_EXCEPTION.md) 21 | -------------------------------------------------------------------------------- /doc/en_US/usage/orders/QUEUE.md: -------------------------------------------------------------------------------- 1 | # Working With Orders Queues 2 | 3 | The orders queue must be requested to obtain data about new / update orders. 4 | 5 | ### Requesting the Next Order on the Queue 6 | 7 | ```php 8 | // ... 9 | 10 | /** @var \SkyHub\Api\Handler\Request\Sales\Order\QueueHandler $requestHandler */ 11 | $requestHandler = $api->queue(); 12 | 13 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $response */ 14 | $response = $requestHandler->orders(); 15 | 16 | // ... 17 | ``` 18 | 19 | ### Removing an Order from the Queue 20 | 21 | ```php 22 | // ... 23 | 24 | /** @var \SkyHub\Api\Handler\Request\Sales\Order\QueueHandler $requestHandler */ 25 | $requestHandler = $api->queue(); 26 | 27 | $orderId = 'Marketplace-000000001'; 28 | 29 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $response */ 30 | $response = $requestHandler->delete($orderId); 31 | 32 | // ... 33 | ``` 34 | 35 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/queues). 36 | 37 | [Back](../../../../README.en_US.md) 38 | 39 | [Continue: Invoicing an Order](INVOICE.md) 40 | -------------------------------------------------------------------------------- /doc/en_US/usage/orders/SHIPPING_EXCEPTION.md: -------------------------------------------------------------------------------- 1 | # Orders with Delivery Problems 2 | 3 | ### Creating a Transportation Exception to an Order 4 | 5 | ```php 6 | // ... 7 | 8 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 9 | $requestHandler = $api->order(); 10 | 11 | $orderId = 'Marketplace-000000001'; 12 | 13 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 14 | $response = $requestHandler->shipmentException($orderId); 15 | // ... 16 | ``` 17 | 18 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/excecao-de-transporte). 19 | 20 | [Back](../../../../README.en_US.md) -------------------------------------------------------------------------------- /doc/en_US/usage/orders/TRACKING.md: -------------------------------------------------------------------------------- 1 | # Sending Order Delivery Data 2 | 3 | ```php 4 | // ... 5 | 6 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 7 | $requestHandler = $api->order(); 8 | 9 | $items = [ 10 | 'sku' => '1001', 11 | 'qty' => 1, 12 | ]; 13 | 14 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 15 | $response = $requestHandler->shipment( 16 | $orderId, 17 | $items, 18 | 'BR1321830198302DR', 19 | 'Correios', 20 | 'SEDEX', 21 | 'www.correios.com.br' 22 | ); 23 | 24 | // ... 25 | ``` 26 | 27 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/enviar-dados-de-entrega). 28 | 29 | [Back](../../../../README.en_US.md) 30 | 31 | [Continue: Confirming a Product's Delivery](DELIVERY.md) 32 | -------------------------------------------------------------------------------- /doc/en_US/usage/shipment/PLPS.md: -------------------------------------------------------------------------------- 1 | # Posting 2 | 3 | If the integration between SkyHub and marketplace B2W is made through API and you use `B2W Entrega`, you can group your orders into one PLP. 4 | 5 | 6 | ### Obtaining a PLP's List 7 | 8 | You can obtain a list of PLPs using the following code snippet: 9 | 10 | ```php 11 | // ... 12 | 13 | /** @var \SkyHub\Api\Handler\Request\Shipment\PlpHandler $requestHandler */ 14 | $requestHandler = $api->plp(); 15 | 16 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 17 | $response = $requestHandler->plps(); 18 | 19 | // ... 20 | ``` 21 | 22 | 23 | ### Obtaining an Orders List That Can be Grouped 24 | 25 | You can obtain an orders list allowed to be grouped into a single PLP using the following code snippet: 26 | 27 | ```php 28 | // ... 29 | 30 | /** @var \SkyHub\Api\Handler\Request\Shipment\PlpHandler $requestHandler */ 31 | $requestHandler = $api->plp(); 32 | 33 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 34 | $response = $requestHandler->ordersReadyToGroup(); 35 | 36 | // ... 37 | ``` 38 | 39 | 40 | ### Grouping Orders Into a Single PLP 41 | 42 | You can group the orders into a PLP using the following code snippet: 43 | 44 | ```php 45 | // ... 46 | 47 | /** @var \SkyHub\Api\Handler\Request\Shipment\PlpHandler $requestHandler */ 48 | $requestHandler = $api->plp(); 49 | 50 | $orders = array( 51 | 'CODIGO_PEDIDO_001', 52 | 'CODIGO_PEDIDO_002' 53 | ); 54 | 55 | /** 56 | * CREATE A PLP WITH ORDERS 57 | * 58 | * @var SkyHub\Api\Handler\Response\HandlerInterface $response 59 | */ 60 | $response = $requestHandler->group($orders); 61 | 62 | // ... 63 | ``` 64 | 65 | 66 | ### Ungroup a PLP 67 | 68 | You can ungroup a PLP using the following code snippet: 69 | 70 | ```php 71 | // ... 72 | 73 | /** @var \SkyHub\Api\Handler\Request\Shipment\PlpHandler $requestHandler */ 74 | $requestHandler = $api->plp(); 75 | 76 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 77 | $response = $requestHandler->ungroup('PLP_ID'); 78 | 79 | // ... 80 | ``` 81 | 82 | 83 | ### Load PLP 84 | 85 | You can obtain the PDF of your PLP using the following code snippet: 86 | 87 | ```php 88 | // ... 89 | 90 | /** @var SkyHub\Api\ $service */ 91 | $service = new SkyHub\Api\Service\ServicePdf(null); 92 | 93 | /** @var \SkyHub\Api $api */ 94 | $api = new SkyHub\Api($email, $apiKey, null, null, $service); 95 | 96 | /** @var \SkyHub\Api\Handler\Request\Shipment\PlpHandler $requestHandler */ 97 | $requestHandler = $api->plp(); 98 | 99 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 100 | $response = $requestHandler->viewFile('PLP_ID'); 101 | 102 | // ... 103 | ``` 104 | 105 | 106 | For more information, access the [official_documentation](https://skyhub.gelato.io/docs/versions/1.0/resources/postagem-plp). 107 | 108 | [Back](../../../../README.en_US.md) 109 | 110 | -------------------------------------------------------------------------------- /doc/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bittools/skyhub-php/943ec810c9869f67fe801e5051254339445c6392/doc/images/logo.png -------------------------------------------------------------------------------- /doc/pt_BR/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Manual de Contribuição 2 | 3 | Se você deseja contribuir com o projeto para torná-lo melhor, sua ajuda é sempre bem-vinda. 4 | A contribuição é também uma ótima maneira de aprender mais sobre novas tecnologias e seu ecosistema para torná-la mais construtiva, livre de bugs e mantê-la sempre sempre atualizada. 5 | 6 | ### Como criar um pull request no Github 7 | 8 | * Crie um fork deste projeto no Github para sua conta. 9 | * Faça o clone do seu fork em sua máquina local. O `remote` padrão do seu repositório (no caso o fork criado) será `origin`. 10 | * Adicione o repositório original, no caso este, como um novo `remote` chamado `upstream`. 11 | ```bash 12 | $ git remote add upstream git@github.com:vendor/repository.git 13 | ``` 14 | * Se você criou seu fork há algum tempo certifique-se de atualizar seu repositório com o código mais atualizado do repositório original. 15 | * Crie um novo branch no qual você vai fazer sua implementação. Crie a partir do branch `master`. 16 | ```bash 17 | $ git checkout -b hotfix/ticket-number 18 | ``` 19 | * Implemente seu fix ou sua feature, não esquecendo de comentar seu código. 20 | * Siga o estilo de código que existe no projeto, incluindo as indentações corretas. 21 | * Execute todos os testes disponíveis para se certificar que nenhuma parte da SDK foi comprometida pelo novo código. 22 | * Escreva e adapte testes para seu código, caso necessário. 23 | * Inclua a documentação do seu código. 24 | * Dê um `push` do seu projeto para o seu fork no Github, o `remote origin`. 25 | * A partir do seu fork no Github, crie um novo `pull request` do branch. Aponte para o branch `develop` do projeto original. 26 | * Caso o mantenedor do projeto solicite alguma alteração no seu código, altere seu branch e dê um push para seu fork no Github. O Pull Request será atualizado automaticamente. 27 | * Uma vez que o código tenha sido aprovado e mergeado no projeto oficial, você pode atualizar seu remote `upstream` para sua máquina local e remover os branches que criou. 28 | 29 | E por último, mas não menos importante: sempre comente seus códigos e commits. A mensagem do seu commit deve descrever o que o commit, quando aplicado, fará ao código. 30 | 31 | [Voltar](../../README.md) 32 | -------------------------------------------------------------------------------- /doc/pt_BR/CREDENTIALS.md: -------------------------------------------------------------------------------- 1 | # Credenciais para Integração 2 | 3 | Para utlizar essa integração é necessário que você entre em contato com a equipe comercial da SkyHub e solicite uma conta para acesso á API. 4 | Serão passadas duas informações: 5 | 6 | * E-mail de acesso 7 | * Chave API 8 | 9 | Estas duas informações são necessárias para a integração com a SkyHub. 10 | 11 | Saiba mais na [documentação oficial](https://skyhub.gelato.io/docs/versions/1.0/autenticacao-e-formato-dos-dados). 12 | 13 | Você pode entrar em contato através da [página de contato](https://skyhub.com.br/#form_contato) do site da SkyHub. 14 | 15 | [Voltar](../../README.md) 16 | 17 | [Continuar: Instalação e Setup](INSTALLATION.md) 18 | -------------------------------------------------------------------------------- /doc/pt_BR/INSTALLATION.md: -------------------------------------------------------------------------------- 1 | # Instalação da SDK 2 | 3 | Esta SDK segue os padrões PSR e utiliza o composer para a instalação de todas as suas dependências. 4 | Para instalar esta SDK você pode seguir os seguintes passos: 5 | 6 | ##### Passos para a instalação 7 | 8 | É necessário ter o [composer](https://getcomposer.org/download/) instalado no ambiente no qual a SDK será utilizada. 9 | 10 | ```bash 11 | # Install Composer 12 | $ curl -sS https://getcomposer.org/installer | php 13 | ``` 14 | 15 | O próximo passo é executar o composer para que todas as dependências, com suas versões corretas, sejam instaladas: 16 | 17 | ```bash 18 | $ php composer.phar require bittools/skyhub-php 19 | ``` 20 | 21 | Ou, caso você já tenha o composer instalado: 22 | 23 | ```bash 24 | $ composer require bittools/skyhub-php 25 | ``` 26 | 27 | Após a instalação, você precisa colocar uma chamada do autoload do Composer no seu arquivo PHP: 28 | 29 | ```php 30 | require_once 'vendor/autoload.php'; 31 | ``` 32 | 33 | Posteriormente, pode ser necessário fazer a atualização da SDK no seu ambiente. Para isso você poderá executar o seguinte comando: 34 | 35 | ```bash 36 | $ php composer.phar update 37 | ``` 38 | 39 | [Voltar](../../README.md) 40 | 41 | [Continuar: Utilizando a SDK - API](usage/API.md) 42 | -------------------------------------------------------------------------------- /doc/pt_BR/SYSTEM_REQUIREMENTS.md: -------------------------------------------------------------------------------- 1 | # Requisitos do Sistema 2 | 3 | Para você conseguir utilizar essa SDK é necessário conferir alguns requisitos necessários: 4 | 5 | * PHP 5.4 ou superior 6 | 7 | [Voltar](../../README.md) 8 | 9 | [Continuar: Credenciais](CREDENTIALS.md) 10 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/API.md: -------------------------------------------------------------------------------- 1 | # Utilizando a API 2 | 3 | A classe API utilizada na SDK é a proxy necessária para você ter acesso às qualquer outra funcionalidade da API. A utilização dela é realmente simples. 4 | 5 | Primeiramente você precisa importar o autoload do Composer no seu arquivo PHP: 6 | 7 | ```php 8 | productAttribute(); 14 | 15 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 16 | $response = $requestHandler->create('color', 'Color', [ 17 | 'Blue', 18 | 'White' 19 | ]); 20 | 21 | // ... 22 | ``` 23 | 24 | ### Atualizando Atributos 25 | 26 | Quando o atributo já existe na SkyHub e você precisa atualizá-lo: 27 | 28 | ```php 29 | // ... 30 | 31 | /** @var SkyHub\Api\Handler\Request\Catalog\Product\AttributeHandler $requestHandler */ 32 | $requestHandler = $api->productAttribute(); 33 | 34 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 35 | $response = $requestHandler->update('color', 'Color', [ 36 | 'Blue', 37 | 'White', 38 | 'Green', 39 | 'Yellow', 40 | 'Black', 41 | 'Red' 42 | ]); 43 | 44 | // ... 45 | ``` 46 | 47 | Para mais informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/attributes). 48 | 49 | [Voltar](../../../../README.md) 50 | 51 | [Continuar: Produtos](PRODUCTS.md) 52 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/catalog/CATEGORIES.md: -------------------------------------------------------------------------------- 1 | # Categorias 2 | 3 | A criação de categorias é feita de forma bem simples. 4 | 5 | ### Criando uma Categoria 6 | 7 | ```php 8 | // ... 9 | 10 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $requestHandler */ 11 | $requestHandler = $api->category(); 12 | 13 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 14 | $response = $requestHandler->create('category001', 'Category 001'); 15 | 16 | // ... 17 | ``` 18 | 19 | ### Atualizando uma Categoria 20 | 21 | ```php 22 | // ... 23 | 24 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $requestHandler */ 25 | $requestHandler = $api->category(); 26 | 27 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 28 | $response = $requestHandler->update('category001', 'Updated Category 001 Name'); 29 | 30 | // ... 31 | ``` 32 | 33 | ### Excluindo uma Categoria 34 | 35 | ```php 36 | // ... 37 | 38 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $requestHandler */ 39 | $requestHandler = $api->category(); 40 | 41 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 42 | $response = $requestHandler->delete('category001'); 43 | 44 | // ... 45 | ``` 46 | 47 | ### Obtendo uma Lista de Categorias 48 | 49 | ```php 50 | // ... 51 | 52 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $requestHandler */ 53 | $requestHandler = $api->category(); 54 | 55 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 56 | $response = $requestHandler->categories(); 57 | 58 | // ... 59 | ``` 60 | 61 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/categories). 62 | 63 | [Voltar](../../../../README.md) 64 | 65 | [Continuar: Pedidos](../ORDERS.md) 66 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/orders/CANCEL.md: -------------------------------------------------------------------------------- 1 | # Cancelando um Pedido 2 | 3 | ```php 4 | // ... 5 | 6 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 7 | $requestHandler = $api->order(); 8 | 9 | $orderId = 'Marketplace-000000001'; 10 | 11 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 12 | $response = $requestHandler->cancel($orderId); 13 | // ... 14 | ``` 15 | 16 | Para enviar um status customizado, basta passá-lo no último parâmetro. Por exemplo: 17 | ```php 18 | // ... 19 | 20 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 21 | $response = $requestHandler->cancel($orderId, 'order_canceled_custom'); 22 | ``` 23 | 24 | *Observação: o status utilizado DEVE estar previamente cadastrado na SkyHub.* 25 | 26 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/cancelar-um-pedido). 27 | 28 | [Voltar](../../../../README.md) 29 | 30 | [Continuar: Adicionando um Tracking de Pedido](TRACKING.md) 31 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/orders/CONSULT.md: -------------------------------------------------------------------------------- 1 | # Consultando Pedidos 2 | 3 | A consulta de pedidos é feita para obter as informações de um pedido, porém não deve ser utilizada para identificar pedidos novos. 4 | 5 | Para saber mais sobre consulta de pedidos novos, veja a documentação sobre a [fila de pedidos](QUEUE.md). 6 | 7 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders). 8 | 9 | A consulta de pedidos pode ser necessária para atualização de status do pedido em sua plataforma, por exemplo. 10 | 11 | ### Consultando um Pedido 12 | 13 | Este método permite consultar apenas um pedido por vez. 14 | 15 | ```php 16 | // ... 17 | 18 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 19 | $requestHandler = $api->order(); 20 | 21 | $orderId = 'Marketplace-000000001'; 22 | 23 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 24 | $response = $requestHandler->order($orderId); 25 | // ... 26 | ``` 27 | 28 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/obter-um-pedido). 29 | 30 | ### Obter uma Lista de Pedidos 31 | 32 | O método abaixo retorna uma lista com todos os seus pedidos na SkyHub. 33 | 34 | ```php 35 | // ... 36 | 37 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 38 | $requestHandler = $api->order(); 39 | 40 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 41 | $response = $requestHandler->orders(); 42 | // ... 43 | ``` 44 | 45 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/listar-pedidos). 46 | 47 | [Voltar](../../../../README.md) 48 | 49 | [Continuar: Trabalhando com Filas de Pedidos](QUEUE.md) 50 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/orders/DELIVERY.md: -------------------------------------------------------------------------------- 1 | # Confirmar Entrega de um Pedido 2 | 3 | ```php 4 | // ... 5 | 6 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 7 | $requestHandler = $api->order(); 8 | 9 | $orderId = 'Marketplace-000000001'; 10 | 11 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 12 | $response = $requestHandler->delivery($orderId); 13 | // ... 14 | ``` 15 | 16 | Para definir a data de entrega, basta informá-la no segundo parâmetro: 17 | 18 | ```php 19 | // ... 20 | 21 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 22 | $response = $requestHandler->delivery($orderId, '10/09/2019'); 23 | ``` 24 | 25 | Para enviar um status customizado, basta passá-lo no último parâmetro. Por exemplo: 26 | ```php 27 | // ... 28 | 29 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 30 | $response = $requestHandler->delivery($orderId, null, 'complete_custom'); 31 | ``` 32 | 33 | *Observação: o status utilizado DEVE estar previamente cadastrado na SkyHub.* 34 | 35 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/confirmar-entrega). 36 | 37 | [Voltar](../../../../README.md) 38 | 39 | [Continuar: Obtendo Etiquetas de Pedidos](LABELS.md) 40 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/orders/INVOICE.md: -------------------------------------------------------------------------------- 1 | # Faturando um Pedido 2 | 3 | Para faturar um pedido você precisa ter em mãos a chave da nota fiscal para enviá-la na requisição. 4 | 5 | ```php 6 | // ... 7 | 8 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 9 | $requestHandler = $api->order(); 10 | 11 | $nfKey = '99999999999999999999999999999999999999999999'; 12 | 13 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 14 | $response = $requestHandler->invoice($orderId, $nfKey); 15 | // ... 16 | ``` 17 | 18 | Para enviar um status customizado, basta passá-lo no último parâmetro. Por exemplo: 19 | ```php 20 | // ... 21 | 22 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 23 | $response = $requestHandler->invoice($orderId, $nfKey, 'order_invoiced_custom'); 24 | ``` 25 | 26 | *Observação: o status utilizado DEVE estar previamente cadastrado na SkyHub.* 27 | 28 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/faturar-um-pedido). 29 | 30 | [Voltar](../../../../README.md) 31 | 32 | [Continuar: Cancelando um Pedido](CANCEL.md) 33 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/orders/LABELS.md: -------------------------------------------------------------------------------- 1 | # Obter Etiqueta de Frete 2 | 3 | ```php 4 | // ... 5 | 6 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 7 | $requestHandler = $api->order(); 8 | 9 | $orderId = 'Marketplace-000000001'; 10 | 11 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 12 | $response = $requestHandler->shipmentLabels($orderId); 13 | // ... 14 | ``` 15 | 16 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/obter-etiqueta-de-frete). 17 | 18 | [Voltar](../../../../README.md) 19 | 20 | [Continuar: Pedidos com Problemas de Entrega](SHIPPING_EXCEPTION.md) 21 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/orders/QUEUE.md: -------------------------------------------------------------------------------- 1 | # Trabalhando com Filas de Pedidos 2 | 3 | A fila de pedidos é de onde você precisa 4 | 5 | ### Obtendo o Próximo Pedido da Fila de Pedidos 6 | 7 | ```php 8 | // ... 9 | 10 | /** @var \SkyHub\Api\Handler\Request\Sales\Order\QueueHandler $requestHandler */ 11 | $requestHandler = $api->queue(); 12 | 13 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $response */ 14 | $response = $requestHandler->orders(); 15 | 16 | // ... 17 | ``` 18 | 19 | ### Removendo um Pedido da Fila 20 | 21 | ```php 22 | // ... 23 | 24 | /** @var \SkyHub\Api\Handler\Request\Sales\Order\QueueHandler $requestHandler */ 25 | $requestHandler = $api->queue(); 26 | 27 | $orderId = 'Marketplace-000000001'; 28 | 29 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $response */ 30 | $response = $requestHandler->delete($orderId); 31 | 32 | // ... 33 | ``` 34 | 35 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/queues). 36 | 37 | [Voltar](../../../../README.md) 38 | 39 | [Continuar: Faturando um Pedido](INVOICE.md) 40 | -------------------------------------------------------------------------------- /doc/pt_BR/usage/orders/SHIPPING_EXCEPTION.md: -------------------------------------------------------------------------------- 1 | # Pedidos com Problemas de Entrega 2 | 3 | ### Criando uma Exceção de Transporte para um Pedido 4 | 5 | ```php 6 | // ... 7 | 8 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 9 | $requestHandler = $api->order(); 10 | 11 | $orderId = 'Marketplace-000000001'; 12 | 13 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 14 | $response = $requestHandler->shipmentException($orderId); 15 | // ... 16 | ``` 17 | 18 | Para enviar um status customizado, basta passá-lo no último parâmetro. Por exemplo: 19 | ```php 20 | // ... 21 | 22 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 23 | $response = $requestHandler->shipmentException($orderId, '2019-06-06T04:13:00-03:00', 'Problems in transportation.', 'shipment_exception_custom'); 24 | ``` 25 | 26 | *Observação: o status utilizado DEVE estar previamente cadastrado na SkyHub.* 27 | 28 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/excecao-de-transporte). 29 | 30 | [Voltar](../../../../README.md) -------------------------------------------------------------------------------- /doc/pt_BR/usage/orders/TRACKING.md: -------------------------------------------------------------------------------- 1 | # Enviar Dados de Entrega de um Pedido 2 | 3 | ```php 4 | // ... 5 | 6 | /** @var \SkyHub\Api\Handler\Request\Sales\OrderHandler $requestHandler */ 7 | $requestHandler = $api->order(); 8 | 9 | $items = [ 10 | 'sku' => '1001', 11 | 'qty' => 1, 12 | ]; 13 | 14 | /** @var SkyHub\Api\Handler\Response\HandlerInterface $response */ 15 | $response = $requestHandler->shipment( 16 | $orderId, 17 | $items, 18 | 'BR1321830198302DR', 19 | 'Correios', 20 | 'SEDEX', 21 | 'www.correios.com.br' 22 | ); 23 | 24 | // ... 25 | ``` 26 | 27 | Para maiores informações acesse a [documentação oficial](https://skyhub.gelato.io/docs/versions/1.1/resources/orders/endpoints/enviar-dados-de-entrega). 28 | 29 | [Voltar](../../../../README.md) 30 | 31 | [Continuar: Confirmar Entrega de um Pedido](DELIVERY.md) 32 | -------------------------------------------------------------------------------- /invoice: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bittools/skyhub-php/943ec810c9869f67fe801e5051254339445c6392/invoice -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Category/Create.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Catalog\Category; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Create extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * Attribute constructor. 27 | * 28 | * @param string $code 29 | * @param string $name 30 | */ 31 | public function __construct($code, $name) 32 | { 33 | $this->setOutputData([ 34 | 'category' => [ 35 | 'code' => $code, 36 | 'name' => $name 37 | ] 38 | ]); 39 | 40 | parent::__construct(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Category/Update.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Catalog\Category; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Update extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * Attribute constructor. 27 | * 28 | * @param string $code 29 | * @param string $name 30 | */ 31 | public function __construct($code, $name) 32 | { 33 | $this->setOutputData([ 34 | 'category' => [ 35 | 'name' => $name 36 | ] 37 | ]); 38 | 39 | parent::__construct(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Product/Attribute/Create.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Catalog\Product\Attribute; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Create extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * Attribute constructor. 27 | * 28 | * @param string $code 29 | * @param string $label 30 | * @param array $options 31 | */ 32 | public function __construct($code, $label, array $options = []) 33 | { 34 | $this->setOutputData([ 35 | 'attribute' => [ 36 | 'name' => $code, 37 | 'label' => $label, 38 | 'options' => $options 39 | ] 40 | ]); 41 | 42 | parent::__construct(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Product/Attribute/Update.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Catalog\Product\Attribute; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Update extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * Attribute constructor. 27 | * 28 | * @param string $code 29 | * @param string $label 30 | * @param array $options 31 | */ 32 | public function __construct($code, $label, array $options = []) 33 | { 34 | $this->setOutputData([ 35 | 'attribute' => [ 36 | 'label' => $label, 37 | 'options' => $options 38 | ] 39 | ]); 40 | 41 | parent::__construct(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Product/Price/Update.php: -------------------------------------------------------------------------------- 1 | (float) $price 38 | ]; 39 | 40 | if ($promotionalPrice) { 41 | $product['promotional_price'] = (float) $promotionalPrice; 42 | } 43 | 44 | if ($platformPrices) { 45 | foreach ($platformPrices as $specificationCode => $specificationValue) { 46 | $product['specifications'][] = [ 47 | 'key' => $specificationCode, 48 | 'value' => $specificationValue 49 | ]; 50 | } 51 | } 52 | 53 | $this->setOutputData([ 54 | 'product' => $product 55 | ]); 56 | 57 | parent::__construct(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Product/Stock/Update.php: -------------------------------------------------------------------------------- 1 | setOutputData([ 35 | 'product' => [ 36 | 'qty' => $qty, 37 | ] 38 | ]); 39 | 40 | parent::__construct(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Product/Update.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Catalog\Product; 19 | 20 | class Update extends Create 21 | { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Product/Variation/Create.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Catalog\Product\Variation; 19 | 20 | use SkyHub\Api\DataTransformer\Builders; 21 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 22 | 23 | class Create extends DataTransformerAbstract 24 | { 25 | 26 | use Builders; 27 | 28 | 29 | /** 30 | * CreateVariation constructor. 31 | * 32 | * @param string $sku 33 | * @param string $qty 34 | * @param string $ean 35 | * @param array $images 36 | * @param array $specifications 37 | */ 38 | public function __construct($sku, $qty = null, $ean = null, array $images = [], array $specifications = []) 39 | { 40 | $variation['sku'] = (string) $sku; 41 | 42 | if ($qty !== null) { 43 | $variation['qty'] = (int) $qty; 44 | } 45 | 46 | if ($ean) { 47 | $variation['ean'] = (string) $ean; 48 | } 49 | 50 | /** Build product variation's images. */ 51 | $this->buildProductImages($variation, (array) $images); 52 | 53 | /** Build product variation's specifications. */ 54 | $this->buildProductSpecifications($variation, (array) $specifications); 55 | 56 | $this->setOutputData(['variation' => $variation]); 57 | 58 | parent::__construct(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Catalog/Product/Variation/Update.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Catalog\Product\Variation; 19 | 20 | class Update extends Create 21 | { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/DataTransformerAbstract.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer; 19 | 20 | abstract class DataTransformerAbstract implements DataTransformerInterface 21 | { 22 | 23 | /** @var array */ 24 | protected $outputData = []; 25 | 26 | 27 | /** 28 | * DataTransformerAbstract constructor. 29 | */ 30 | public function __construct() 31 | { 32 | } 33 | 34 | 35 | /** 36 | * @return $this 37 | */ 38 | protected function prepareOutput() 39 | { 40 | return $this; 41 | } 42 | 43 | 44 | /** 45 | * @param string|array $data 46 | * 47 | * @return $this 48 | */ 49 | protected function setOutputData($data) 50 | { 51 | $this->outputData = $data; 52 | return $this; 53 | } 54 | 55 | 56 | /** 57 | * @return array|mixed 58 | */ 59 | public function output() 60 | { 61 | $this->prepareOutput(); 62 | return $this->outputData; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/DataTransformerInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer; 19 | 20 | interface DataTransformerInterface 21 | { 22 | 23 | /** 24 | * @return mixed 25 | */ 26 | public function output(); 27 | } 28 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Sales/Order/B2WDirectInvoiced.php: -------------------------------------------------------------------------------- 1 | 'file', 45 | 'headers' => ['Content-Type' => 'text/xml'], 46 | 'contents' => $this->openFile($pathFile, $fileName), 47 | 'filename' => $fileName 48 | ], 49 | [ 50 | 'name' => 'status', 51 | 'contents' => $status 52 | ], 53 | [ 54 | 'name' => 'volume_qty', 55 | 'contents' => $volumeQty, 56 | ], 57 | [ 58 | 'name' => 'issue_date', 59 | 'contents' => $issueDate, 60 | ] 61 | ]; 62 | 63 | $this->setOutputData($param); 64 | 65 | parent::__construct(); 66 | } 67 | 68 | /** 69 | * Open de file xml and validate file 70 | * 71 | * @param string $pathFile 72 | * @return void 73 | */ 74 | protected function openFile($pathFile, $fileName) 75 | { 76 | $info = pathinfo($pathFile); 77 | if (!isset($info['extension'])) { 78 | $info = pathinfo($fileName); 79 | } 80 | 81 | if (!isset($info['extension'])) { 82 | $info['extension'] = ''; 83 | } 84 | 85 | $extension = strtolower($info['extension']); 86 | 87 | if ($extension !== 'xml') { 88 | throw new \Exception('File invalid.'); 89 | } 90 | 91 | if (!is_file($pathFile)) { 92 | throw new \Exception("File don't exist."); 93 | } 94 | 95 | return file_get_contents($pathFile, 'r'); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Sales/Order/Cancel.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Sales\Order; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Cancel extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * Attribute constructor. 27 | * 28 | * @param string|null $status 29 | */ 30 | public function __construct($status = null) 31 | { 32 | if ($status) { 33 | $this->setOutputData(['status' => $status]); 34 | } 35 | 36 | parent::__construct(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Sales/Order/Delivery.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Sales\Order; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Delivery extends DataTransformerAbstract 23 | { 24 | /** 25 | * Delivery constructor. 26 | * 27 | * @param string|null $date 28 | * @param string|null $status 29 | */ 30 | public function __construct($date = null, $status = null) 31 | { 32 | $outputData = []; 33 | 34 | if ($status) { 35 | $outputData['status'] = $status; 36 | } 37 | 38 | if ($date) { 39 | $outputData['delivered_date'] = $date; 40 | } 41 | 42 | $this->setOutputData($outputData); 43 | 44 | parent::__construct(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Sales/Order/Invoice.php: -------------------------------------------------------------------------------- 1 | [ 33 | 'key' => $invoiceKey 34 | ] 35 | ]; 36 | 37 | if ($status) { 38 | $param['status'] = $status; 39 | } 40 | 41 | $this->setOutputData($param); 42 | 43 | parent::__construct(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Sales/Order/Shipment.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Sales\Order; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Shipment extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * Shipment constructor. 27 | * 28 | * @param string $orderId 29 | * @param array $items 30 | * @param string $trackCode 31 | * @param string $trackCarrier 32 | * @param string $trackMethod 33 | * @param string $trackUrl 34 | * @param string $status 35 | */ 36 | public function __construct( 37 | $orderId, 38 | array $items, 39 | $trackCode, 40 | $trackCarrier, 41 | $trackMethod, 42 | $trackUrl, 43 | $status = null 44 | ) { 45 | $shipment = [ 46 | 'shipment' => [ 47 | 'code' => $orderId, 48 | 'track' => [ 49 | 'code' => $trackCode, 50 | 'carrier' => $trackCarrier, 51 | 'method' => $trackMethod, 52 | 'url' => $trackUrl, 53 | ] 54 | ] 55 | ]; 56 | 57 | if ($status) { 58 | $shipment['status'] = $status; 59 | } 60 | 61 | /** @var array $item */ 62 | foreach ($items as $item) { 63 | $shipment['items'][] = [ 64 | 'sku' => $item['sku'], 65 | 'qty' => $item['qty'], 66 | ]; 67 | } 68 | 69 | $this->setOutputData($shipment); 70 | 71 | parent::__construct(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Sales/Order/ShipmentException.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Sales\Order; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class ShipmentException extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * ShipmentException constructor. 27 | * 28 | * @param string $orderId 29 | * @param string $datetime 30 | * @param string $observation 31 | * @param string|null $status 32 | */ 33 | public function __construct($orderId, $datetime, $observation, $status = null) 34 | { 35 | /** 36 | * @todo Convert the $datetime to the correct format: '2012-10-06T04:13:00-03:00' 37 | */ 38 | $shipmentException = [ 39 | 'shipment_exception' => [ 40 | 'occurrence_date' => $datetime, 41 | 'observation' => $observation 42 | ] 43 | ]; 44 | 45 | if ($status) { 46 | $shipmentException['status'] = $status; 47 | } 48 | 49 | $this->setOutputData($shipmentException); 50 | 51 | parent::__construct(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Sales/Order/Status/Create.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Sales\Order\Status; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Create extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * Create constructor. 27 | * 28 | * @param string $code 29 | * @param string $label 30 | * @param string $type 31 | */ 32 | public function __construct($code, $label, $type) 33 | { 34 | $this->setOutputData([ 35 | 'status' => [ 36 | 'code' => $code, 37 | 'label' => $label, 38 | 'type' => $type 39 | ] 40 | ]); 41 | 42 | parent::__construct(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Sales/Order/Status/Update.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Sales\Order\Status; 19 | 20 | class Update extends Create 21 | { 22 | 23 | /** 24 | * Create constructor. 25 | * 26 | * @param string $code 27 | * @param string $label 28 | * @param string $type 29 | */ 30 | public function __construct($code, $label, $type) 31 | { 32 | parent::__construct($code, $label, $type); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Shipment/Order/Collect.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Shipment\Order; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Collect extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * PLP orders grouper constructor. 27 | * 28 | * @param array $orders 29 | */ 30 | public function __construct(array $orders = []) 31 | { 32 | $this->setOutputData([ 33 | 'order_codes' => $orders 34 | ]); 35 | 36 | parent::__construct(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Api/DataTransformer/Shipment/Plp/Group.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\DataTransformer\Shipment\Plp; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerAbstract; 21 | 22 | class Group extends DataTransformerAbstract 23 | { 24 | 25 | /** 26 | * PLP orders grouper constructor. 27 | * 28 | * @param array $orders 29 | */ 30 | public function __construct(array $orders = []) 31 | { 32 | $this->setOutputData([ 33 | 'order_remote_codes' => $orders 34 | ]); 35 | 36 | parent::__construct(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Catalog/Category.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface\Catalog; 19 | 20 | use SkyHub\Api\EntityInterface\Catalog\Product\MutualMethods; 21 | use SkyHub\Api\EntityInterface\Catalog\Product\Variation; 22 | use SkyHub\Api\EntityInterface\EntityAbstract; 23 | 24 | class Category extends EntityAbstract 25 | { 26 | 27 | /** 28 | * @param string $code 29 | * 30 | * @return $this 31 | */ 32 | public function setCode($code) 33 | { 34 | $this->setData('code', (string) $code); 35 | return $this; 36 | } 37 | 38 | 39 | /** 40 | * @param string $name 41 | * 42 | * @return $this 43 | */ 44 | public function setName($name) 45 | { 46 | $this->setData('name', (string) $name); 47 | return $this; 48 | } 49 | 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function getCode() 55 | { 56 | return (string) $this->getData('code'); 57 | } 58 | 59 | 60 | /** 61 | * @return string 62 | */ 63 | public function getName() 64 | { 65 | return (string) $this->getData('name'); 66 | } 67 | 68 | 69 | /** 70 | * @return array 71 | */ 72 | public function export() 73 | { 74 | return [ 75 | 'category' => (array) $this->getData() 76 | ]; 77 | } 78 | 79 | 80 | /** 81 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 82 | */ 83 | public function create() 84 | { 85 | $this->validate(); 86 | 87 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $handler */ 88 | $handler = $this->requestHandler(); 89 | 90 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $response */ 91 | $response = $handler->create($this->getCode(), $this->getName()); 92 | 93 | return $response; 94 | } 95 | 96 | 97 | /** 98 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 99 | */ 100 | public function update() 101 | { 102 | $this->validate(); 103 | 104 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $handler */ 105 | $handler = $this->requestHandler(); 106 | 107 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $response */ 108 | $response = $handler->create($this->getCode(), $this->getName()); 109 | 110 | return $response; 111 | } 112 | 113 | 114 | /** 115 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 116 | */ 117 | public function delete() 118 | { 119 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $handler */ 120 | $handler = $this->requestHandler(); 121 | 122 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $response */ 123 | $response = $handler->delete($this->getCode()); 124 | 125 | return $response; 126 | } 127 | 128 | 129 | /** 130 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 131 | */ 132 | public function categories() 133 | { 134 | /** @var \SkyHub\Api\Handler\Request\Catalog\CategoryHandler $handler */ 135 | $handler = $this->requestHandler(); 136 | return $handler->categories(); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Catalog/Product/Attribute.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface\Catalog\Product; 19 | 20 | use SkyHub\Api\DataTransformer\Catalog\Product\Attribute\Create; 21 | use SkyHub\Api\EntityInterface\EntityAbstract; 22 | use SkyHub\Api\Handler\Response\HandlerDefault; 23 | use SkyHub\Api\Handler\Response\HandlerException; 24 | 25 | class Attribute extends EntityAbstract 26 | { 27 | 28 | /** 29 | * @param string $code 30 | * 31 | * @return $this 32 | */ 33 | public function setCode($code) 34 | { 35 | $this->setData('code', (string) $code); 36 | return $this; 37 | } 38 | 39 | 40 | /** 41 | * @return string 42 | */ 43 | public function getCode() 44 | { 45 | return (string) $this->getData('code'); 46 | } 47 | 48 | 49 | /** 50 | * @param string $label 51 | * 52 | * @return $this 53 | */ 54 | public function setLabel($label) 55 | { 56 | $this->setData('label', $label); 57 | return $this; 58 | } 59 | 60 | 61 | /** 62 | * @return string 63 | */ 64 | public function getLabel() 65 | { 66 | return (string) $this->getData('label'); 67 | } 68 | 69 | 70 | /** 71 | * @param string|integer $value 72 | * 73 | * @return $this 74 | */ 75 | public function addOption($value) 76 | { 77 | $options = (array) $this->getOptions(); 78 | $options[] = $value; 79 | 80 | $this->setData('options', $options); 81 | 82 | return $this; 83 | } 84 | 85 | 86 | /** 87 | * @return array 88 | */ 89 | public function getOptions() 90 | { 91 | return (array) $this->getData('options'); 92 | } 93 | 94 | 95 | /** 96 | * @return array|bool|mixed|string 97 | */ 98 | public function export() 99 | { 100 | return (array) [ 101 | 'attribute' => (array) $this->getData() 102 | ]; 103 | } 104 | 105 | 106 | /** 107 | * @return HandlerDefault|HandlerException 108 | */ 109 | public function create() 110 | { 111 | $this->validate(); 112 | 113 | /** @var \SkyHub\Api\Handler\Request\Catalog\Product\AttributeHandler $handler */ 114 | $handler = $this->requestHandler(); 115 | 116 | /** @var HandlerDefault|HandlerException $response */ 117 | $response = $handler->create($this->getCode(), $this->getLabel(), $this->getOptions()); 118 | 119 | return $response; 120 | } 121 | 122 | 123 | /** 124 | * @return HandlerDefault|HandlerException 125 | */ 126 | public function update() 127 | { 128 | $this->validate(); 129 | 130 | /** @var \SkyHub\Api\Handler\Request\Catalog\Product\AttributeHandler $handler */ 131 | $handler = $this->requestHandler(); 132 | 133 | /** @var HandlerDefault|HandlerException $response */ 134 | $response = $handler->update($this->getCode(), $this->getLabel(), $this->getOptions()); 135 | 136 | return $response; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Catalog/Product/MutualMethods.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface\Catalog\Product; 19 | 20 | trait MutualMethods 21 | { 22 | 23 | /** 24 | * @param string $sku 25 | * 26 | * @return $this 27 | */ 28 | public function setSku($sku) 29 | { 30 | $this->data['sku'] = (string) $sku; 31 | return $this; 32 | } 33 | 34 | 35 | /** 36 | * @return string 37 | */ 38 | public function getSku() 39 | { 40 | return $this->getData('sku'); 41 | } 42 | 43 | 44 | /** 45 | * @param float $qty 46 | * 47 | * @return $this 48 | */ 49 | public function setQty($qty) 50 | { 51 | $this->data['qty'] = (float) $qty; 52 | return $this; 53 | } 54 | 55 | 56 | /** 57 | * @return string 58 | */ 59 | public function getQty() 60 | { 61 | return (int) $this->getData('qty'); 62 | } 63 | 64 | 65 | /** 66 | * @param int $ean 67 | * 68 | * @return $this 69 | */ 70 | public function setEan($ean) 71 | { 72 | $this->data['ean'] = (string) $ean; 73 | return $this; 74 | } 75 | 76 | 77 | /** 78 | * @return string 79 | */ 80 | public function getEan() 81 | { 82 | return (string) $this->getData('ean'); 83 | } 84 | 85 | 86 | /** 87 | * @return array 88 | */ 89 | public function getImages() 90 | { 91 | return (array) $this->getData('images'); 92 | } 93 | 94 | 95 | /** 96 | * @param string $source 97 | * 98 | * @return $this 99 | */ 100 | public function addImage($source) 101 | { 102 | $images = $this->getImages(); 103 | $images[] = $source; 104 | 105 | $this->setData('images', $images); 106 | 107 | return $this; 108 | } 109 | 110 | 111 | /** 112 | * @return array 113 | */ 114 | public function getSpecifications() 115 | { 116 | return (array) $this->getData('specifications'); 117 | } 118 | 119 | 120 | /** 121 | * @param string $code 122 | * @param string $value 123 | * 124 | * @return $this 125 | */ 126 | public function addSpecification($code, $value) 127 | { 128 | $data = (array) $this->getSpecifications(); 129 | $data[] = [ 130 | 'key' => $code, 131 | 'value' => $value, 132 | ]; 133 | 134 | $this->setData('specifications', $data); 135 | 136 | return $this; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Catalog/Product/Price.php: -------------------------------------------------------------------------------- 1 | setData('sku', (string) $sku); 34 | return $this; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public function getSku() 41 | { 42 | return (string) $this->getData('sku'); 43 | } 44 | 45 | /** 46 | * @param float $price 47 | * 48 | * @return $this 49 | */ 50 | public function setPrice($price) 51 | { 52 | $this->setData('price', $price); 53 | return $this; 54 | } 55 | 56 | /** 57 | * @return float 58 | */ 59 | public function getPrice() 60 | { 61 | return (float) $this->getData('price'); 62 | } 63 | 64 | /** 65 | * @param float $promotionalPrice 66 | * 67 | * @return $this 68 | */ 69 | public function setPromotionalPrice($promotionalPrice) 70 | { 71 | $this->setData('promotional_price', $promotionalPrice); 72 | return $this; 73 | } 74 | 75 | /** 76 | * @return float 77 | */ 78 | public function getPromotionalPrice() 79 | { 80 | return (float) $this->getData('promotional_price'); 81 | } 82 | 83 | /** 84 | * @return HandlerDefault|HandlerException 85 | */ 86 | public function update() 87 | { 88 | $this->validate(); 89 | 90 | /** @var \SkyHub\Api\Handler\Request\Catalog\Product\PriceHandler $handler */ 91 | $handler = $this->requestHandler(); 92 | 93 | /** @var HandlerDefault|HandlerException $response */ 94 | $response = $handler->update($this->getSku(), $this->getPrice(), $this->getPromotionalPrice()); 95 | 96 | return $response; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Catalog/Product/Stock.php: -------------------------------------------------------------------------------- 1 | setData('sku', (string) $sku); 34 | return $this; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public function getSku() 41 | { 42 | return (string) $this->getData('sku'); 43 | } 44 | 45 | /** 46 | * @param int $qty 47 | * 48 | * @return $this 49 | */ 50 | public function setQty($qty) 51 | { 52 | $this->setData('qty', $qty); 53 | return $this; 54 | } 55 | 56 | /** 57 | * @return int 58 | */ 59 | public function getQty() 60 | { 61 | return (int) $this->getData('qty'); 62 | } 63 | 64 | /** 65 | * @return HandlerDefault|HandlerException 66 | */ 67 | public function update() 68 | { 69 | $this->validate(); 70 | 71 | /** @var \SkyHub\Api\Handler\Request\Catalog\Product\StockHandler $handler */ 72 | $handler = $this->requestHandler(); 73 | 74 | /** @var HandlerDefault|HandlerException $response */ 75 | $response = $handler->update($this->getSku(), $this->getQty()); 76 | 77 | return $response; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Catalog/Product/Variation.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface\Catalog\Product; 19 | 20 | use SkyHub\Api\EntityInterface\EntityAbstract; 21 | 22 | class Variation extends EntityAbstract 23 | { 24 | 25 | use MutualMethods; 26 | 27 | 28 | /** @var array */ 29 | protected $data = []; 30 | } 31 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/EntityAbstract.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface; 19 | 20 | use SkyHub\Api; 21 | use SkyHub\Api\Helpers; 22 | 23 | abstract class EntityAbstract implements EntityInterface 24 | { 25 | 26 | use Helpers; 27 | 28 | protected $data = []; 29 | 30 | /** @var Api */ 31 | protected $api; 32 | 33 | /** @var Api\Handler\Request\HandlerAbstract */ 34 | protected $requestHandler; 35 | 36 | 37 | /** 38 | * EntityAbstract constructor. 39 | * 40 | * @param Api\Handler\Request\HandlerAbstract $handler 41 | */ 42 | public function __construct(Api\Handler\Request\HandlerAbstract $handler) 43 | { 44 | if (!empty($handler)) { 45 | $this->requestHandler = $handler; 46 | $this->api = $handler->api(); 47 | } 48 | } 49 | 50 | 51 | /** 52 | * @param string $key 53 | * @param null|mixed $default 54 | * 55 | * @return array|bool|mixed|string 56 | */ 57 | public function getData($key = null, $default = null) 58 | { 59 | if (is_null($key)) { 60 | return $this->data; 61 | } 62 | 63 | return $this->arrayExtract($this->data, $key, $default); 64 | } 65 | 66 | 67 | /** 68 | * @param string $key 69 | * @param string|array $value 70 | * 71 | * @return $this 72 | */ 73 | public function setData($key, $value) 74 | { 75 | $this->data[$key] = $value; 76 | return $this; 77 | } 78 | 79 | 80 | /** 81 | * @return array 82 | */ 83 | public function export() 84 | { 85 | return $this->getData(); 86 | } 87 | 88 | 89 | /** 90 | * @return Api 91 | */ 92 | protected function api() 93 | { 94 | return $this->api; 95 | } 96 | 97 | 98 | /** 99 | * @return \SkyHub\Api\Service\ServiceAbstract 100 | */ 101 | protected function service() 102 | { 103 | return $this->api()->service(); 104 | } 105 | 106 | 107 | /** 108 | * @return Api\Handler\Request\HandlerAbstract 109 | */ 110 | protected function requestHandler() 111 | { 112 | return $this->requestHandler; 113 | } 114 | 115 | 116 | public function validate() 117 | { 118 | return true; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/EntityInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface; 19 | 20 | interface EntityInterface 21 | { 22 | 23 | /** 24 | * @return array 25 | */ 26 | public function export(); 27 | 28 | 29 | /** 30 | * @return bool 31 | */ 32 | public function validate(); 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Getters.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface; 19 | 20 | use SkyHub\Api\EntityInterface\Catalog\Product; 21 | 22 | trait Getters 23 | { 24 | 25 | /** 26 | * @return Product 27 | */ 28 | public function productEntityInterface() 29 | { 30 | return new Product($this); 31 | } 32 | 33 | /** 34 | * @return Product\Attribute 35 | */ 36 | public function productAttributeEntityInterface() 37 | { 38 | return new Product\Attribute($this); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Questions.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface; 19 | 20 | use SkyHub\Api\Handler\Request\Sync\QuestionsHandler; 21 | 22 | class Questions extends EntityAbstract 23 | { 24 | 25 | /** 26 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 27 | */ 28 | public function questions() 29 | { 30 | /** @var QuestionsHandler $handler */ 31 | $handler = $this->requestHandler(); 32 | return $handler->questions(); 33 | } 34 | 35 | 36 | /** 37 | * @param string $questionId 38 | * 39 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 40 | */ 41 | public function showQuestion($questionId) 42 | { 43 | /** @var QuestionsHandler $handler */ 44 | $handler = $this->requestHandler(); 45 | return $handler->showQuestion($questionId); 46 | } 47 | 48 | 49 | /** 50 | * @param $questionId 51 | * 52 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 53 | */ 54 | public function deleteQuestion($questionId) 55 | { 56 | /** @var QuestionsHandler $handler */ 57 | $handler = $this->requestHandler(); 58 | return $handler->deleteQuestion($questionId); 59 | } 60 | 61 | 62 | /** 63 | * @param string $questionId 64 | * @param string $message 65 | * 66 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 67 | */ 68 | public function answerQuestion($questionId, $message) 69 | { 70 | /** @var QuestionsHandler $handler */ 71 | $handler = $this->requestHandler(); 72 | return $handler->answerQuestion($questionId, $message); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Sales/Freights.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface\Sales\Order; 19 | 20 | use SkyHub\Api\EntityInterface\EntityAbstract; 21 | use SkyHub\Api\Handler\Request\Sales\FreightsHandler; 22 | 23 | class Freights extends EntityAbstract 24 | { 25 | 26 | /** 27 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 28 | */ 29 | public function freights() 30 | { 31 | /** @var FreightsHandler $handler */ 32 | $handler = $this->requestHandler(); 33 | return $handler->freights(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Sales/Order/Queue.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface\Sales\Order; 19 | 20 | use SkyHub\Api\EntityInterface\EntityAbstract; 21 | use SkyHub\Api\Handler\Request\Sales\Order\QueueHandler; 22 | 23 | class Queue extends EntityAbstract 24 | { 25 | 26 | /** 27 | * @param $orderId 28 | * 29 | * @return $this 30 | */ 31 | public function setOrderId($orderId) 32 | { 33 | $this->setData('order_id', $orderId); 34 | return $this; 35 | } 36 | 37 | 38 | /** 39 | * @return array|bool|mixed|string 40 | */ 41 | public function getOrderId() 42 | { 43 | return $this->getData('order_id'); 44 | } 45 | 46 | 47 | /** 48 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 49 | */ 50 | public function orders() 51 | { 52 | /** @var QueueHandler $handler */ 53 | $handler = $this->requestHandler(); 54 | return $handler->orders(); 55 | } 56 | 57 | 58 | /** 59 | * @param string $orderId 60 | * 61 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 62 | */ 63 | public function delete($orderId = null) 64 | { 65 | if (empty($orderId)) { 66 | $orderId = $this->getOrderId(); 67 | } 68 | 69 | /** @var QueueHandler $handler */ 70 | $handler = $this->requestHandler(); 71 | return $handler->delete($orderId); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Sales/Order/Status.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface\Sales\Order; 19 | 20 | use SkyHub\Api\EntityInterface\EntityAbstract; 21 | use SkyHub\Api\Handler\Request\Sales\Order\StatusHandler; 22 | 23 | class Status extends EntityAbstract 24 | { 25 | 26 | /** 27 | * @param string $code 28 | * 29 | * @return $this 30 | */ 31 | public function setCode($code) 32 | { 33 | return $this->setData('code', (string) $code); 34 | } 35 | 36 | 37 | /** 38 | * @return string 39 | */ 40 | public function getCode() 41 | { 42 | return (string) $this->getData('code'); 43 | } 44 | 45 | 46 | /** 47 | * @param string $label 48 | * 49 | * @return $this 50 | */ 51 | public function setLabel($label) 52 | { 53 | return $this->setData('label', (string) $label); 54 | } 55 | 56 | 57 | /** 58 | * @return string 59 | */ 60 | public function getLabel() 61 | { 62 | return (string) $this->getData('label'); 63 | } 64 | 65 | 66 | /** 67 | * @param string $type 68 | * 69 | * @return $this 70 | */ 71 | public function setType($label) 72 | { 73 | return $this->setData('type', (string) $label); 74 | } 75 | 76 | 77 | /** 78 | * @return string 79 | */ 80 | public function getType() 81 | { 82 | return (string) $this->getData('type'); 83 | } 84 | 85 | 86 | /** 87 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 88 | */ 89 | public function statuses() 90 | { 91 | /** @var StatusHandler $handler */ 92 | $handler = $this->requestHandler(); 93 | return $handler->statuses(); 94 | } 95 | 96 | 97 | /** 98 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 99 | */ 100 | public function types() 101 | { 102 | /** @var StatusHandler $handler */ 103 | $handler = $this->requestHandler(); 104 | return $handler->types(); 105 | } 106 | 107 | 108 | /** 109 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 110 | */ 111 | public function create() 112 | { 113 | /** @var StatusHandler $handler */ 114 | $handler = $this->requestHandler(); 115 | return $handler->create($this->getCode(), $this->getLabel(), $this->getType()); 116 | } 117 | 118 | 119 | /** 120 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 121 | */ 122 | public function update() 123 | { 124 | /** @var StatusHandler $handler */ 125 | $handler = $this->requestHandler(); 126 | return $handler->update($this->getCode(), $this->getLabel(), $this->getType()); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/Api/EntityInterface/Shipment/Plp.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\EntityInterface\Shipment; 19 | 20 | use SkyHub\Api\EntityInterface\EntityAbstract; 21 | use SkyHub\Api\Handler\Request\Shipment\PlpHandler; 22 | 23 | class Plp extends EntityAbstract 24 | { 25 | 26 | /** 27 | * @param string $id 28 | * 29 | * @return $this 30 | */ 31 | public function setId($id) 32 | { 33 | $this->data['id'] = (string) $id; 34 | return $this; 35 | } 36 | 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getId() 42 | { 43 | return $this->getData('id'); 44 | } 45 | 46 | 47 | /** 48 | * @return array 49 | */ 50 | public function getOrders() 51 | { 52 | return (array) $this->getData('orders'); 53 | } 54 | 55 | 56 | /** 57 | * @param string $source 58 | * 59 | * @return $this 60 | */ 61 | public function addOrder($source) 62 | { 63 | $orders = $this->getOrders(); 64 | $orders[] = $source; 65 | 66 | $this->setData('orders', $orders); 67 | 68 | return $this; 69 | } 70 | 71 | 72 | /** 73 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 74 | */ 75 | public function plps() 76 | { 77 | /** @var PlpHandler $handler */ 78 | $handler = $this->requestHandler(); 79 | return $handler->plps(); 80 | } 81 | 82 | 83 | /** 84 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 85 | */ 86 | public function ordersReadyToGroup() 87 | { 88 | /** @var PlpHandler $handler */ 89 | $handler = $this->requestHandler(); 90 | return $handler->ordersReadyToGroup(); 91 | } 92 | 93 | 94 | /** 95 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 96 | */ 97 | public function group() 98 | { 99 | $this->validate(); 100 | 101 | /** @var \SkyHub\Api\Handler\Request\Shipment\PlpHandler $handler */ 102 | $handler = $this->requestHandler(); 103 | 104 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $response */ 105 | $response = $handler->group($this->getOrders()); 106 | 107 | return $response; 108 | } 109 | 110 | 111 | /** 112 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 113 | */ 114 | public function ungroup() 115 | { 116 | /** @var PlpHandler $handler */ 117 | $handler = $this->requestHandler(); 118 | return $handler->ungroup($this->getId()); 119 | } 120 | 121 | 122 | /** 123 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 124 | */ 125 | public function viewFile() 126 | { 127 | /** @var PlpHandler $handler */ 128 | $handler = $this->requestHandler(); 129 | return $handler->viewFile($this->getId()); 130 | } 131 | 132 | 133 | /** 134 | * @return bool 135 | */ 136 | public function validate() 137 | { 138 | return true; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/Api/Exception/JsonDataConvert.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | 19 | namespace SkyHub\Api\Exception; 20 | 21 | class JsonDataConvert extends \Exception 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Catalog/CategoryHandler.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Request\Catalog; 19 | 20 | use SkyHub\Api\EntityInterface\Catalog\Category; 21 | use SkyHub\Api\Handler\Request\HandlerAbstract; 22 | use SkyHub\Api\DataTransformer\Catalog\Category\Create as CreateTransformer; 23 | use SkyHub\Api\DataTransformer\Catalog\Category\Update as UpdateTransformer; 24 | 25 | class CategoryHandler extends HandlerAbstract 26 | { 27 | 28 | /** @var string */ 29 | protected $baseUrlPath = '/categories'; 30 | 31 | 32 | /** 33 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 34 | */ 35 | public function categories() 36 | { 37 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 38 | $responseHandler = $this->service()->get($this->baseUrlPath()); 39 | return $responseHandler; 40 | } 41 | 42 | 43 | /** 44 | * @param string $code 45 | * @param string $name 46 | * 47 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 48 | */ 49 | public function create($code, $name) 50 | { 51 | $transformer = new CreateTransformer($code, $name); 52 | $body = $transformer->output(); 53 | 54 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 55 | $responseHandler = $this->service()->post($this->baseUrlPath(), $body); 56 | 57 | return $responseHandler; 58 | } 59 | 60 | 61 | /** 62 | * @param string $code 63 | * @param string $name 64 | * 65 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 66 | */ 67 | public function update($code, $name) 68 | { 69 | $transformer = new UpdateTransformer($code, $name); 70 | $body = $transformer->output(); 71 | 72 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 73 | $responseHandler = $this->service()->put($this->baseUrlPath($code), $body); 74 | 75 | return $responseHandler; 76 | } 77 | 78 | 79 | /** 80 | * @param string $code 81 | * 82 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 83 | */ 84 | public function delete($code) 85 | { 86 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 87 | $responseHandler = $this->service()->delete($this->baseUrlPath($code)); 88 | return $responseHandler; 89 | } 90 | 91 | 92 | /** 93 | * @return Category|\SkyHub\Api\EntityInterface\Catalog\Category 94 | */ 95 | public function entityInterface() 96 | { 97 | return new Category($this); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Catalog/Product/AttributeHandler.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | class AttributeHandler extends HandlerAbstract 24 | { 25 | 26 | /** @var string */ 27 | protected $baseUrlPath = '/attributes'; 28 | 29 | 30 | /** 31 | * @param string $code 32 | * @param string $label 33 | * @param array $options 34 | * 35 | * @return HandlerInterface 36 | */ 37 | public function create($code, $label, array $options = []) 38 | { 39 | $transformer = new CreateTransformer($code, $label, $options); 40 | $body = $transformer->output(); 41 | 42 | /** @var HandlerInterface $responseHandler */ 43 | $responseHandler = $this->service()->post($this->baseUrlPath(), $body); 44 | 45 | return $responseHandler; 46 | } 47 | 48 | 49 | /** 50 | * @param string $code 51 | * @param string $label 52 | * @param array $options 53 | * 54 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 55 | */ 56 | public function update($code, $label, array $options = []) 57 | { 58 | $transformer = new UpdateTransformer($code, $label, $options); 59 | $body = $transformer->output(); 60 | 61 | /** @var HandlerInterface $responseHandler */ 62 | $responseHandler = $this->service()->put($this->baseUrlPath($code), $body); 63 | 64 | return $responseHandler; 65 | } 66 | 67 | 68 | /** 69 | * @return Attribute 70 | */ 71 | public function entityInterface() 72 | { 73 | return new Attribute($this); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Catalog/Product/PriceHandler.php: -------------------------------------------------------------------------------- 1 | output(); 49 | 50 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 51 | $responseHandler = $this->service()->put($this->baseUrlPath($sku), $body); 52 | return $responseHandler; 53 | } 54 | 55 | /** 56 | * @return Price 57 | */ 58 | public function entityInterface() 59 | { 60 | return new Price($this); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Catalog/Product/StockHandler.php: -------------------------------------------------------------------------------- 1 | output(); 42 | 43 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 44 | $responseHandler = $this->service()->put($this->baseUrlPath($sku), $body); 45 | return $responseHandler; 46 | } 47 | 48 | 49 | /** 50 | * @return Stock 51 | */ 52 | public function entityInterface() 53 | { 54 | return new Stock($this); 55 | } 56 | } -------------------------------------------------------------------------------- /src/Api/Handler/Request/Catalog/Product/VariationHandler.php: -------------------------------------------------------------------------------- 1 | 21 | */ 22 | class VariationHandler extends HandlerAbstract 23 | { 24 | 25 | /** @var string */ 26 | protected $baseUrlPath = '/variations'; 27 | 28 | 29 | /** 30 | * @param string $sku 31 | * 32 | * @return HandlerInterface 33 | */ 34 | public function get($sku) 35 | { 36 | /** @var HandlerInterface $responseHandler */ 37 | $responseHandler = $this->service()->get($this->baseUrlPath($sku)); 38 | return $responseHandler; 39 | } 40 | 41 | 42 | /** 43 | * @param string $sku 44 | * 45 | * @return HandlerInterface 46 | */ 47 | public function delete($sku) 48 | { 49 | /** @var HandlerInterface $responseHandler */ 50 | $responseHandler = $this->service()->delete($this->baseUrlPath($sku)); 51 | return $responseHandler; 52 | } 53 | 54 | 55 | /** 56 | * @param string $sku 57 | * @param string $variationSku 58 | * @param string $variationQty 59 | * @param string $variationEan 60 | * @param array $variationImages 61 | * @param array $variationSpecifications 62 | * 63 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 64 | */ 65 | public function update( 66 | $sku, 67 | $variationSku, 68 | $variationQty = null, 69 | $variationEan = null, 70 | array $variationImages = [], 71 | array $variationSpecifications = [] 72 | ) { 73 | $transformer = new Update( 74 | $variationSku, 75 | $variationQty, 76 | $variationEan, 77 | $variationImages, 78 | $variationSpecifications 79 | ); 80 | 81 | $body = $transformer->output(); 82 | 83 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 84 | $responseHandler = $this->service()->put($this->baseUrlPath($sku), $body); 85 | return $responseHandler; 86 | } 87 | 88 | 89 | /** 90 | * @return Variation 91 | */ 92 | public function entityInterface() 93 | { 94 | return new Variation($this); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Getters.php: -------------------------------------------------------------------------------- 1 | 16 | * @author Bruno Gemelli 17 | */ 18 | 19 | namespace SkyHub\Api\Handler\Request; 20 | 21 | use SkyHub\Api\Handler\Request\Catalog\CategoryHandler; 22 | use SkyHub\Api\Handler\Request\Catalog\Product\AttributeHandler; 23 | use SkyHub\Api\Handler\Request\Catalog\ProductHandler; 24 | use SkyHub\Api\Handler\Request\Sales\Order\QueueHandler; 25 | use SkyHub\Api\Handler\Request\Sales\Order\StatusHandler; 26 | use SkyHub\Api\Handler\Request\Sales\OrderHandler; 27 | use SkyHub\Api\Handler\Request\Sales\SystemHandler; 28 | use SkyHub\Api\Handler\Request\Shipment\PlpHandler; 29 | use SkyHub\Api\Handler\Request\Sync\ErrorsHandler; 30 | use SkyHub\Api\Handler\Request\Catalog\Product\VariationHandler; 31 | use SkyHub\Api\Handler\Request\Catalog\Product\StockHandler as ProductStockHandler; 32 | use SkyHub\Api\Handler\Request\Catalog\Product\PriceHandler as ProductPriceHandler; 33 | 34 | trait Getters 35 | { 36 | 37 | /** 38 | * @return AttributeHandler 39 | */ 40 | public function productAttribute() 41 | { 42 | return new AttributeHandler($this); 43 | } 44 | 45 | 46 | /** 47 | * @return ProductHandler 48 | */ 49 | public function product() 50 | { 51 | return new ProductHandler($this); 52 | } 53 | 54 | 55 | /** 56 | * @return VariationHandler 57 | */ 58 | public function productVariations() 59 | { 60 | return new VariationHandler($this); 61 | } 62 | 63 | 64 | /** 65 | * @return CategoryHandler 66 | */ 67 | public function category() 68 | { 69 | return new CategoryHandler($this); 70 | } 71 | 72 | 73 | /** 74 | * @return QueueHandler 75 | */ 76 | public function queue() 77 | { 78 | return new QueueHandler($this); 79 | } 80 | 81 | 82 | /** 83 | * @return OrderHandler 84 | */ 85 | public function order() 86 | { 87 | return new OrderHandler($this); 88 | } 89 | 90 | 91 | /** 92 | * @return StatusHandler 93 | */ 94 | public function orderStatus() 95 | { 96 | return new StatusHandler($this); 97 | } 98 | 99 | 100 | /** 101 | * @return SystemHandler 102 | */ 103 | public function saleSystems() 104 | { 105 | return new SystemHandler($this); 106 | } 107 | 108 | 109 | /** 110 | * @return PlpHandler 111 | */ 112 | public function plp() 113 | { 114 | return new PlpHandler($this); 115 | } 116 | 117 | 118 | /** 119 | * @return ErrorsHandler 120 | */ 121 | public function syncErrors() 122 | { 123 | return new ErrorsHandler($this); 124 | } 125 | 126 | /** 127 | * @return productStockHandler 128 | */ 129 | public function productStock() 130 | { 131 | return new ProductStockHandler($this); 132 | } 133 | 134 | /** 135 | * @return productPriceHandler 136 | */ 137 | public function productPrice() 138 | { 139 | return new ProductPriceHandler($this); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/HandlerAbstract.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Request; 19 | 20 | use SkyHub\Api\DataTransformer\DataTransformerInterface; 21 | use SkyHub\Api\Service\ServiceInterface; 22 | use SkyHub\ApiInterface; 23 | 24 | abstract class HandlerAbstract implements HandlerInterface 25 | { 26 | 27 | /** @var ApiInterface */ 28 | private $api; 29 | 30 | /** @var DataTransformerInterface */ 31 | protected $transformer = null; 32 | 33 | /** @var string */ 34 | protected $transformerClass = null; 35 | 36 | /** @var string */ 37 | protected $baseUrlPath = null; 38 | 39 | 40 | /** 41 | * AbstractHandler constructor. 42 | * 43 | * @param ApiInterface $api 44 | */ 45 | public function __construct(ApiInterface $api) 46 | { 47 | $this->api = $api; 48 | } 49 | 50 | 51 | /** 52 | * @return DataTransformerInterface 53 | */ 54 | protected function transformer() 55 | { 56 | if (empty($this->transformerClass)) { 57 | $this->transformer = new $this->transformerClass(); 58 | } 59 | 60 | return $this->transformer; 61 | } 62 | 63 | 64 | /** 65 | * @return ApiInterface 66 | */ 67 | public function api() 68 | { 69 | return $this->api; 70 | } 71 | 72 | 73 | /** 74 | * @return ServiceInterface 75 | */ 76 | public function service() 77 | { 78 | return $this->api->service(); 79 | } 80 | 81 | 82 | /** 83 | * @param string $suffix 84 | * @param array $query 85 | * 86 | * @return string 87 | */ 88 | protected function baseUrlPath($suffix = null, array $query = []) 89 | { 90 | /** @var string $baseUrlPath */ 91 | $baseUrlPath = $this->baseUrlPath; 92 | 93 | if (!empty($suffix)) { 94 | $suffix = ltrim($suffix, "\/"); 95 | $baseUrlPath .= '/' . trim($suffix); 96 | } 97 | 98 | if (!empty($query)) { 99 | $queryString = http_build_query($query); 100 | $baseUrlPath .= '?' . $queryString; 101 | } 102 | 103 | return $baseUrlPath; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/HandlerInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Request; 19 | 20 | use SkyHub\Api\EntityInterface\EntityInterface; 21 | 22 | interface HandlerInterface 23 | { 24 | 25 | /** 26 | * @return EntityInterface 27 | */ 28 | public function entityInterface(); 29 | } 30 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/QuestionsHandler.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Request\Sync; 19 | 20 | use SkyHub\Api\EntityInterface\Questions; 21 | use SkyHub\Api\Handler\Request\HandlerAbstract; 22 | 23 | class QuestionsHandler extends HandlerAbstract 24 | { 25 | 26 | /** @var string */ 27 | protected $baseUrlPath = '/questions'; 28 | 29 | 30 | /** 31 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 32 | */ 33 | public function questions() 34 | { 35 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 36 | $responseHandler = $this->service()->get($this->baseUrlPath()); 37 | return $responseHandler; 38 | } 39 | 40 | 41 | /** 42 | * @param string $questionId 43 | * 44 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 45 | */ 46 | public function showQuestion($questionId) 47 | { 48 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 49 | $responseHandler = $this->service()->get($this->baseUrlPath("/{$questionId}")); 50 | return $responseHandler; 51 | } 52 | 53 | 54 | /** 55 | * @param $questionId 56 | * 57 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 58 | */ 59 | public function deleteQuestion($questionId) 60 | { 61 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 62 | $responseHandler = $this->service()->delete($this->baseUrlPath("/$questionId")); 63 | return $responseHandler; 64 | } 65 | 66 | 67 | /** 68 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 69 | */ 70 | public function answerQuestion($questionId, $message) 71 | { 72 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 73 | $responseHandler = $this->service()->post($this->baseUrlPath("/{$questionId}/answer"), [$message]); 74 | return $responseHandler; 75 | } 76 | 77 | 78 | /** 79 | * @return \SkyHub\Api\EntityInterface\EntityInterface|Questions 80 | */ 81 | public function entityInterface() 82 | { 83 | return new Questions($this); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Sales/FreightsHandler.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Request\Sales; 19 | 20 | use SkyHub\Api\EntityInterface\Sales\Order\Freights; 21 | use SkyHub\Api\Handler\Request\HandlerAbstract; 22 | 23 | class FreightsHandler extends HandlerAbstract 24 | { 25 | 26 | /** @var string */ 27 | protected $baseUrlPath = '/freights'; 28 | 29 | 30 | /** 31 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 32 | */ 33 | public function freights() 34 | { 35 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 36 | $responseHandler = $this->service()->get($this->baseUrlPath()); 37 | return $responseHandler; 38 | } 39 | 40 | 41 | /** 42 | * @return \SkyHub\Api\EntityInterface\EntityInterface|Freights 43 | */ 44 | public function entityInterface() 45 | { 46 | return new Freights($this); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Sales/Order/QueueHandler.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Request\Sales\Order; 19 | 20 | use SkyHub\Api\EntityInterface\Sales\Order\Queue; 21 | use SkyHub\Api\Handler\Request\HandlerAbstract; 22 | 23 | class QueueHandler extends HandlerAbstract 24 | { 25 | 26 | /** @var string */ 27 | protected $baseUrlPath = '/queues'; 28 | 29 | 30 | /** 31 | * Retrieves and first order available in the queue in SkyHub. 32 | * 33 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 34 | */ 35 | public function orders() 36 | { 37 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 38 | $responseHandler = $this->service()->get($this->baseUrlPath('orders')); 39 | return $responseHandler; 40 | } 41 | 42 | 43 | /** 44 | * Removes an order from the integration queue. 45 | * 46 | * @param string $orderId 47 | * 48 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 49 | */ 50 | public function delete($orderId) 51 | { 52 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 53 | $responseHandler = $this->service()->delete($this->baseUrlPath("orders/{$orderId}")); 54 | return $responseHandler; 55 | } 56 | 57 | 58 | /** 59 | * @return Queue 60 | */ 61 | public function entityInterface() 62 | { 63 | return new Queue($this); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Sales/Order/StatusHandler.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Request\Sales\Order; 19 | 20 | use SkyHub\Api\DataTransformer\Sales\Order\Status\Create; 21 | use SkyHub\Api\DataTransformer\Sales\Order\Status\Update; 22 | use SkyHub\Api\EntityInterface\Sales\Order\Status; 23 | use SkyHub\Api\Handler\Request\HandlerAbstract; 24 | 25 | class StatusHandler extends HandlerAbstract 26 | { 27 | 28 | const TYPE_NEW = 'NEW'; 29 | const TYPE_CANCELLED = 'CANCELLED'; 30 | const TYPE_APPROVED = 'APPROVED'; 31 | const TYPE_SHIPPED = 'SHIPPED'; 32 | const TYPE_DELIVERED = 'DELIVERED'; 33 | const TYPE_OVERDUE = 'OVERDUE'; 34 | const TYPE_SHIPMENT_EXCEPTION = 'SHIPMENT_EXCEPTION'; 35 | 36 | 37 | /** @var string */ 38 | protected $baseUrlPath = '/statuses'; 39 | 40 | 41 | /** 42 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 43 | */ 44 | public function statuses() 45 | { 46 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 47 | $responseHandler = $this->service()->get($this->baseUrlPath()); 48 | return $responseHandler; 49 | } 50 | 51 | 52 | /** 53 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 54 | */ 55 | public function types() 56 | { 57 | $this->baseUrlPath = '/status_types'; 58 | 59 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 60 | $responseHandler = $this->service()->get($this->baseUrlPath()); 61 | return $responseHandler; 62 | } 63 | 64 | 65 | /** 66 | * @param string $code 67 | * @param string $label 68 | * @param string $type 69 | * 70 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 71 | */ 72 | public function create($code, $label, $type) 73 | { 74 | $transformer = new Create($code, $label, $type); 75 | $body = $transformer->output(); 76 | 77 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 78 | $responseHandler = $this->service()->post($this->baseUrlPath(), $body); 79 | return $responseHandler; 80 | } 81 | 82 | 83 | /** 84 | * @param string $code 85 | * @param string $label 86 | * @param string $type 87 | * 88 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 89 | */ 90 | public function update($code, $label, $type) 91 | { 92 | $transformer = new Update($code, $label, $type); 93 | $body = $transformer->output(); 94 | 95 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 96 | $responseHandler = $this->service()->put($this->baseUrlPath($code), $body); 97 | return $responseHandler; 98 | } 99 | 100 | 101 | /** 102 | * @return \SkyHub\Api\EntityInterface\EntityInterface|Status 103 | */ 104 | public function entityInterface() 105 | { 106 | return new Status($this); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/Api/Handler/Request/Sales/SystemHandler.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Request\Sales; 19 | 20 | use SkyHub\Api\Handler\Request\HandlerAbstract; 21 | 22 | class SystemHandler extends HandlerAbstract 23 | { 24 | 25 | /** @var string */ 26 | protected $baseUrlPath = '/sale_systems'; 27 | 28 | 29 | /** 30 | * @return \SkyHub\Api\Handler\Response\HandlerInterface 31 | */ 32 | public function statuses() 33 | { 34 | /** @var \SkyHub\Api\Handler\Response\HandlerInterface $responseHandler */ 35 | $responseHandler = $this->service()->get($this->baseUrlPath()); 36 | return $responseHandler; 37 | } 38 | 39 | 40 | /** 41 | * @return null 42 | */ 43 | public function entityInterface() 44 | { 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Api/Handler/Response/HandlerAbstract.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Response; 19 | 20 | abstract class HandlerAbstract implements HandlerInterface 21 | { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/Handler/Response/HandlerException.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Response; 19 | 20 | use Exception; 21 | 22 | class HandlerException extends HandlerAbstract implements HandlerInterfaceException 23 | { 24 | 25 | /** @var Exception */ 26 | protected $exception = null; 27 | 28 | 29 | /** 30 | * HandlerException constructor. 31 | * 32 | * @param Exception $exception 33 | */ 34 | public function __construct(Exception $exception) 35 | { 36 | $this->exception = $exception; 37 | } 38 | 39 | 40 | /** 41 | * @return string 42 | */ 43 | public function message() 44 | { 45 | return $this->exception->getMessage(); 46 | } 47 | 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function file() 53 | { 54 | return $this->exception->getFile(); 55 | } 56 | 57 | 58 | /** 59 | * @return int|mixed 60 | */ 61 | public function code() 62 | { 63 | return $this->exception->getCode(); 64 | } 65 | 66 | 67 | /** 68 | * @return int 69 | */ 70 | public function line() 71 | { 72 | return $this->exception->getLine(); 73 | } 74 | 75 | 76 | /** 77 | * @return string 78 | */ 79 | public function traceAsString() 80 | { 81 | return $this->exception->getTraceAsString(); 82 | } 83 | 84 | 85 | /** 86 | * @return array 87 | */ 88 | public function trace() 89 | { 90 | return $this->exception->getTrace(); 91 | } 92 | 93 | 94 | /** 95 | * @return bool 96 | */ 97 | public function success() 98 | { 99 | return false; 100 | } 101 | 102 | 103 | /** 104 | * @return bool 105 | */ 106 | public function exception() 107 | { 108 | return true; 109 | } 110 | 111 | 112 | /** 113 | * @return bool 114 | */ 115 | public function invalid() 116 | { 117 | return false; 118 | } 119 | 120 | 121 | /** 122 | * @return array 123 | */ 124 | public function export() 125 | { 126 | return [ 127 | 'message' => $this->message(), 128 | 'file' => $this->file(), 129 | 'code' => $this->code(), 130 | 'line' => $this->line(), 131 | 'trace' => $this->traceAsString(), 132 | ]; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/Api/Handler/Response/HandlerInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Response; 19 | 20 | interface HandlerInterface 21 | { 22 | 23 | /** 24 | * @return array 25 | */ 26 | public function export(); 27 | 28 | 29 | /** 30 | * @return bool 31 | */ 32 | public function success(); 33 | 34 | 35 | /** 36 | * @return bool 37 | */ 38 | public function exception(); 39 | 40 | 41 | /** 42 | * @return bool 43 | */ 44 | public function invalid(); 45 | } 46 | -------------------------------------------------------------------------------- /src/Api/Handler/Response/HandlerInterfaceException.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Response; 19 | 20 | use Exception; 21 | 22 | interface HandlerInterfaceException extends HandlerInterface 23 | { 24 | 25 | /** 26 | * HandlerInterfaceException constructor. 27 | * 28 | * @param Exception $exception 29 | */ 30 | public function __construct(Exception $exception); 31 | 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function message(); 37 | 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function file(); 43 | 44 | 45 | /** 46 | * @return int|mixed 47 | */ 48 | public function code(); 49 | 50 | 51 | /** 52 | * @return int 53 | */ 54 | public function line(); 55 | 56 | 57 | /** 58 | * @return string 59 | */ 60 | public function traceAsString(); 61 | 62 | 63 | /** 64 | * @return array 65 | */ 66 | public function trace(); 67 | } 68 | -------------------------------------------------------------------------------- /src/Api/Handler/Response/HandlerInterfaceSuccess.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Response; 19 | 20 | use GuzzleHttp\Psr7\Response; 21 | 22 | interface HandlerInterfaceSuccess extends HandlerInterface 23 | { 24 | 25 | /** 26 | * HandlerInterface constructor. 27 | * 28 | * @param Response $response 29 | */ 30 | public function __construct(Response $response); 31 | 32 | 33 | /** 34 | * @return Response 35 | */ 36 | public function httpResponse(); 37 | 38 | 39 | /** 40 | * @return mixed 41 | */ 42 | public function body(); 43 | 44 | 45 | /** 46 | * @return int|null 47 | */ 48 | public function bodySize(); 49 | 50 | 51 | /** 52 | * @return mixed 53 | */ 54 | public function headers(); 55 | 56 | 57 | /** 58 | * @return mixed 59 | */ 60 | public function statusCode(); 61 | 62 | 63 | /** 64 | * @return mixed 65 | */ 66 | public function protocolVersion(); 67 | 68 | 69 | /** 70 | * @return string 71 | */ 72 | public function reasonPhrase(); 73 | } 74 | -------------------------------------------------------------------------------- /src/Api/Handler/Response/HandlerInvalid.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Handler\Response; 19 | 20 | class HandlerInvalid extends HandlerAbstract 21 | { 22 | 23 | /** 24 | * @return bool 25 | */ 26 | public function success() 27 | { 28 | return false; 29 | } 30 | 31 | 32 | /** 33 | * @return bool 34 | */ 35 | public function exception() 36 | { 37 | return false; 38 | } 39 | 40 | 41 | /** 42 | * @return bool 43 | */ 44 | public function invalid() 45 | { 46 | return true; 47 | } 48 | 49 | 50 | /** 51 | * @return array 52 | */ 53 | public function export() 54 | { 55 | return []; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Api/Helpers.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api; 19 | 20 | trait Helpers 21 | { 22 | /** 23 | * @param string $value 24 | * @param string $char 25 | * @param float $density 26 | * 27 | * @return string 28 | */ 29 | protected function protectString($value, $char = '*', $density = 0.5) 30 | { 31 | $len = strlen($value); 32 | $protectionSize = (int) ($len * (float) $density); 33 | 34 | $sidesAmount = max((int) (($len-$protectionSize)/2), 0); 35 | 36 | $left = substr($value, 0, $sidesAmount); 37 | $right = substr($value, -$sidesAmount, $sidesAmount); 38 | $middle = str_repeat($char, $protectionSize); 39 | 40 | $value = implode([$left, $middle, $right]); 41 | 42 | return $value; 43 | } 44 | 45 | /** 46 | * @param array $data 47 | * @param string $index 48 | * @param mixed|array|bool|string $default 49 | * 50 | * @return mixed|array|bool|string 51 | */ 52 | protected function arrayExtract(array $data, $index, $default = false) 53 | { 54 | if (!$this->arrayIsNotEmpty($data, $index)) { 55 | return $default; 56 | } 57 | 58 | return $data[$index]; 59 | } 60 | 61 | /** 62 | * @param array $data 63 | * @param string $index 64 | * 65 | * @return bool 66 | */ 67 | protected function arrayIsNotEmpty(array $data, $index) 68 | { 69 | if ($this->arrayIndexExists($data, $index) && is_numeric($data[$index])) { 70 | return true; 71 | } 72 | 73 | return (bool) ($this->arrayIndexExists($data, $index)); 74 | } 75 | 76 | /** 77 | * @param array $data 78 | * @param string $index 79 | * 80 | * @return bool 81 | */ 82 | protected function arrayIndexExists(array $data, $index) 83 | { 84 | return (bool) isset($data[$index]); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Api/Log/LoggerAbstract.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log; 19 | 20 | abstract class LoggerAbstract implements LoggerInterface 21 | { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/Log/LoggerInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log; 19 | 20 | use SkyHub\Api\Log\TypeInterface\TypeRequestInterface; 21 | use SkyHub\Api\Log\TypeInterface\TypeResponseInterface; 22 | 23 | interface LoggerInterface 24 | { 25 | 26 | /** 27 | * @param TypeRequestInterface $request 28 | * 29 | * @return mixed 30 | */ 31 | public function logRequest(TypeRequestInterface $request); 32 | 33 | 34 | /** 35 | * @param TypeResponseInterface $response 36 | * 37 | * @return mixed 38 | */ 39 | public function logResponse(TypeResponseInterface $response); 40 | } 41 | -------------------------------------------------------------------------------- /src/Api/Log/TypeInterface/Request.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log\TypeInterface; 19 | 20 | class Request extends TypeAbstract implements TypeRequestInterface 21 | { 22 | 23 | /** 24 | * Request constructor. 25 | * 26 | * @param int $requestId 27 | * @param string $method 28 | * @param string $uri 29 | * @param string|array $body 30 | * @param array $headers 31 | * @param array $requestOptions 32 | * @param string $protocolVersion 33 | */ 34 | public function __construct( 35 | $requestId, 36 | $method = null, 37 | $uri = null, 38 | $body = null, 39 | array $headers = [], 40 | array $requestOptions = [], 41 | $protocolVersion = null 42 | ) { 43 | parent::__construct($requestId, $body, $headers, $protocolVersion); 44 | 45 | $this->setMethod($method) 46 | ->setUri($uri) 47 | ->setOptions($requestOptions); 48 | } 49 | 50 | 51 | /** 52 | * @param string $method 53 | * 54 | * @return $this 55 | */ 56 | public function setMethod($method = null) 57 | { 58 | $this->data['method'] = (string) $method; 59 | return $this; 60 | } 61 | 62 | 63 | /** 64 | * @param string $uri 65 | * 66 | * @return $this 67 | */ 68 | public function setUri($uri = null) 69 | { 70 | $this->data['uri'] = (string) $uri; 71 | return $this; 72 | } 73 | 74 | 75 | /** 76 | * @param array $requestOptions 77 | * 78 | * @return $this 79 | */ 80 | public function setOptions(array $requestOptions = []) 81 | { 82 | $this->data['options'] = (array) $requestOptions; 83 | return $this; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Api/Log/TypeInterface/Response.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log\TypeInterface; 19 | 20 | use SkyHub\Api\Handler\Response\HandlerInterfaceException; 21 | use SkyHub\Api\Handler\Response\HandlerInterfaceSuccess; 22 | 23 | class Response extends TypeAbstract implements TypeResponseInterface 24 | { 25 | 26 | /** 27 | * Request constructor. 28 | * 29 | * @param int $requestId 30 | * @param string|array $body 31 | * @param array $headers 32 | * @param string $statusCode 33 | * @param string $protocolVersion 34 | */ 35 | public function __construct( 36 | $requestId, 37 | $body = null, 38 | array $headers = [], 39 | $statusCode = null, 40 | $protocolVersion = null 41 | ) { 42 | parent::__construct($requestId, $body, $headers, $protocolVersion); 43 | $this->setStatusCode($statusCode); 44 | } 45 | 46 | 47 | /** 48 | * @param string $status 49 | * 50 | * @return $this 51 | */ 52 | public function setStatusCode($status = null) 53 | { 54 | $this->data['status_code'] = $status; 55 | return $this; 56 | } 57 | 58 | 59 | /** 60 | * @param HandlerInterfaceSuccess $handler 61 | * 62 | * @return $this 63 | */ 64 | public function importResponseHandler(HandlerInterfaceSuccess $handler) 65 | { 66 | $this->setCustomMessage('Success in request.'); 67 | $this->data = array_merge($this->data, $handler->export()); 68 | 69 | return $this; 70 | } 71 | 72 | 73 | /** 74 | * @param HandlerInterfaceException $handler 75 | * 76 | * @return $this 77 | */ 78 | public function importResponseExceptionHandler(HandlerInterfaceException $handler) 79 | { 80 | $this->setCustomMessage('Error in request.'); 81 | $this->data = array_merge($this->data, $handler->export()); 82 | 83 | return $this; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Api/Log/TypeInterface/ResponsePdf.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log\TypeInterface; 19 | 20 | class ResponsePdf extends Response implements TypeResponseInterface 21 | { 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function __toString() 27 | { 28 | unset($this->data['body']); 29 | return json_encode((array) $this->data); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Api/Log/TypeInterface/TypeAbstract.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log\TypeInterface; 19 | 20 | use SkyHub\Api\Exception\JsonDataConvert; 21 | 22 | abstract class TypeAbstract implements TypeInterface 23 | { 24 | 25 | /** @var array */ 26 | protected $data = []; 27 | 28 | /** 29 | * Request constructor. 30 | * 31 | * @param int $requestId 32 | * @param string|array $body 33 | * @param array $headers 34 | * @param string $httpVersion 35 | */ 36 | public function __construct($requestId, $body = null, array $headers = [], $protocolVersion = null) 37 | { 38 | $this->setRequestId($requestId) 39 | ->setBody($body) 40 | ->setHeaders($headers) 41 | ->setProtocolVersion($protocolVersion); 42 | } 43 | 44 | /** 45 | * @return string 46 | * 47 | * @throws JsonDataConvert 48 | */ 49 | public function __toString() 50 | { 51 | try { 52 | $data = json_encode((array) $this->data); 53 | } catch (\Exception $exception) { 54 | $data = ''; 55 | } 56 | 57 | return $data; 58 | } 59 | 60 | /** 61 | * @param string|array $id 62 | * 63 | * @return $this 64 | */ 65 | public function setRequestId($id = null) 66 | { 67 | $this->data['request_id'] = $id; 68 | return $this; 69 | } 70 | 71 | /** 72 | * @param string|object|array $body 73 | * 74 | * @return $this 75 | */ 76 | public function setBody($body = null) 77 | { 78 | if (is_object($body)) { 79 | $body = (string) $body; 80 | } 81 | 82 | $this->data['body'] = $body; 83 | return $this; 84 | } 85 | 86 | /** 87 | * @param string $message 88 | * 89 | * @return $this 90 | */ 91 | public function setCustomMessage($message = null) 92 | { 93 | $this->data['custom_message'] = (string) $message; 94 | return $this; 95 | } 96 | 97 | /** 98 | * @param array $headers 99 | */ 100 | public function setHeaders(array $headers = []) 101 | { 102 | $this->data['headers'] = $headers; 103 | return $this; 104 | } 105 | 106 | /** 107 | * @param string $version 108 | */ 109 | public function setProtocolVersion($version = null) 110 | { 111 | $this->data['protocol_version'] = $version; 112 | return $this; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/Api/Log/TypeInterface/TypeInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log\TypeInterface; 19 | 20 | interface TypeInterface 21 | { 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function __toString(); 27 | 28 | 29 | /** 30 | * @param string|array $id 31 | * 32 | * @return $this 33 | */ 34 | public function setRequestId($id = null); 35 | 36 | 37 | /** 38 | * @param string|array $body 39 | * 40 | * @return $this 41 | */ 42 | public function setBody($body = null); 43 | 44 | 45 | /** 46 | * @param string $message 47 | * 48 | * @return $this 49 | */ 50 | public function setCustomMessage($message = null); 51 | 52 | 53 | /** 54 | * @param array $headers 55 | * 56 | * @return $this 57 | */ 58 | public function setHeaders(array $headers = []); 59 | 60 | 61 | /** 62 | * @param string $version 63 | * 64 | * @return $this 65 | */ 66 | public function setProtocolVersion($version = null); 67 | } 68 | -------------------------------------------------------------------------------- /src/Api/Log/TypeInterface/TypeRequestInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log\TypeInterface; 19 | 20 | interface TypeRequestInterface extends TypeInterface 21 | { 22 | 23 | /** 24 | * @param string $method 25 | * 26 | * @return $this 27 | */ 28 | public function setMethod($method = null); 29 | 30 | 31 | /** 32 | * @param string $uri 33 | * 34 | * @return $this 35 | */ 36 | public function setUri($uri = null); 37 | 38 | 39 | /** 40 | * @param array $requestOptions 41 | * 42 | * @return $this 43 | */ 44 | public function setOptions(array $requestOptions = []); 45 | } 46 | -------------------------------------------------------------------------------- /src/Api/Log/TypeInterface/TypeResponseInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Log\TypeInterface; 19 | 20 | use SkyHub\Api\Handler\Response\HandlerInterfaceException; 21 | use SkyHub\Api\Handler\Response\HandlerInterfaceSuccess; 22 | 23 | interface TypeResponseInterface extends TypeInterface 24 | { 25 | /** 26 | * @param string $status 27 | * 28 | * @return $this 29 | */ 30 | public function setStatusCode($status = null); 31 | 32 | /** 33 | * @param HandlerInterfaceSuccess $handler 34 | * 35 | * @return $this 36 | */ 37 | public function importResponseHandler(HandlerInterfaceSuccess $handler); 38 | 39 | /** 40 | * @param HandlerInterfaceException $handler 41 | * 42 | * @return $this 43 | */ 44 | public function importResponseExceptionHandler(HandlerInterfaceException $handler); 45 | } 46 | -------------------------------------------------------------------------------- /src/Api/Service/ClientBuilder.php: -------------------------------------------------------------------------------- 1 | $baseUri, 23 | 'defaults' => $defaults 24 | ]); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Api/Service/ClientBuilderInterface.php: -------------------------------------------------------------------------------- 1 | headers = []; 29 | return $this; 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | public function addHeaders(array $headers = []) 36 | { 37 | foreach ($headers as $key => $value) { 38 | $this->addHeader($key, $value); 39 | } 40 | 41 | return $this; 42 | } 43 | 44 | /** 45 | * @inheritDoc 46 | */ 47 | public function addHeader(string $key, $value) 48 | { 49 | $this->headers[$key] = $value; 50 | return $this; 51 | } 52 | 53 | /** 54 | * @inheritDoc 55 | */ 56 | public function getHeader(string $key) 57 | { 58 | return $this->headers[$key]; 59 | } 60 | 61 | /** 62 | * @inheritDoc 63 | */ 64 | public function removeHeader(string $key) 65 | { 66 | unset($this->headers[$key]); 67 | return $this; 68 | } 69 | 70 | /** 71 | * @inheritDoc 72 | */ 73 | public function getHeaders() : array 74 | { 75 | return $this->headers; 76 | } 77 | 78 | /** 79 | * @inheritDoc 80 | */ 81 | public function build() : array 82 | { 83 | return $this->getHeaders(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Api/Service/HeadersBuilderInterface.php: -------------------------------------------------------------------------------- 1 | headers = $headers; 37 | $this->protectedFields = $protectedFields; 38 | 39 | foreach ($this->headers as $key => $value) { 40 | if (in_array($key, $this->protectedFields)) { 41 | $this->headers[$key] = $this->protectString($value); 42 | } 43 | } 44 | 45 | return $this; 46 | } 47 | 48 | /** 49 | * @return array 50 | */ 51 | public function export() : array 52 | { 53 | return $this->headers; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Api/Service/OptionsBuilder.php: -------------------------------------------------------------------------------- 1 | headersBuilder = new HeadersBuilder(); 27 | } 28 | 29 | /** 30 | * @inheritDoc 31 | */ 32 | public function reset() 33 | { 34 | $this->options = []; 35 | return $this; 36 | } 37 | 38 | /** 39 | * @inheritDoc 40 | */ 41 | public function getHeadersBuilder() : HeadersBuilderInterface 42 | { 43 | return $this->headersBuilder; 44 | } 45 | 46 | /** 47 | * @inheritDoc 48 | */ 49 | public function setTimeout(int $timeout) 50 | { 51 | $this->options['timeout'] = (int) $timeout; 52 | return $this; 53 | } 54 | 55 | /** 56 | * @inheritDoc 57 | */ 58 | public function setDebug(bool $flag) 59 | { 60 | $this->options['debug'] = (bool) $flag; 61 | return $this; 62 | } 63 | 64 | /** 65 | * @inheritDoc 66 | */ 67 | public function setBody($body, string $type = self::BODY_TYPE_DEFAULT) 68 | { 69 | $this->options[$type] = $body; 70 | return $this; 71 | } 72 | 73 | /** 74 | * @inheritDoc 75 | */ 76 | public function setStream(bool $flag) 77 | { 78 | $this->options['stream'] = (bool) $flag; 79 | return $this; 80 | } 81 | 82 | /** 83 | * @inheritDoc 84 | */ 85 | public function addOptions(array $options = []) 86 | { 87 | $headers = isset($options['headers']) ? $options['headers'] : []; 88 | $this->getHeadersBuilder()->addHeaders($headers); 89 | 90 | unset($options['headers']); 91 | 92 | $this->options = array_merge_recursive($this->options, $options); 93 | return $this; 94 | } 95 | 96 | /** 97 | * @inheritDoc 98 | */ 99 | public function build() : array 100 | { 101 | $this->options['headers'] = $this->getHeadersBuilder()->build(); 102 | return $this->options; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/Api/Service/OptionsBuilderInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Service; 19 | 20 | use SkyHub\Api\Handler\Response\HandlerInterfaceException; 21 | use SkyHub\Api\Handler\Response\HandlerInterfaceSuccess; 22 | 23 | class ServiceDefault extends ServiceAbstract 24 | { 25 | /** 26 | * @param string $uri 27 | * @param array|string $body 28 | * @param array $options 29 | * 30 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 31 | */ 32 | public function post(string $uri, $body = null, array $options = []) 33 | { 34 | return $this->request(self::REQUEST_METHOD_POST, $uri, $body, $options); 35 | } 36 | 37 | /** 38 | * @param string $uri 39 | * @param string $body 40 | * @param array $options 41 | * 42 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 43 | */ 44 | public function put(string $uri, $body = null, array $options = []) 45 | { 46 | return $this->request(self::REQUEST_METHOD_PUT, $uri, $body, $options); 47 | } 48 | 49 | 50 | /** 51 | * @param string $uri 52 | * @param string $body 53 | * @param array $options 54 | * 55 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 56 | */ 57 | public function patch(string $uri, $body = null, array $options = []) 58 | { 59 | return $this->request(self::REQUEST_METHOD_PATCH, $uri, $body, $options); 60 | } 61 | 62 | /** 63 | * @param string $uri 64 | * @param array $options 65 | * 66 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 67 | */ 68 | public function get(string $uri, array $options = []) 69 | { 70 | return $this->request(self::REQUEST_METHOD_GET, $uri, null, $options); 71 | } 72 | 73 | 74 | /** 75 | * @param string $uri 76 | * @param string $body 77 | * @param array $options 78 | * 79 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 80 | */ 81 | public function delete(string $uri, $body = null, array $options = []) 82 | { 83 | return $this->request(self::REQUEST_METHOD_DELETE, $uri, $body, $options); 84 | } 85 | 86 | /** 87 | * @param $uri 88 | * @param $options 89 | * 90 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 91 | */ 92 | public function head(string $uri, array $options = []) 93 | { 94 | return $this->request(self::REQUEST_METHOD_HEAD, $uri, null, $options); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Api/Service/ServiceInterface.php: -------------------------------------------------------------------------------- 1 | 16 | * @author Bruno Gemelli 17 | */ 18 | 19 | namespace SkyHub\Api\Service; 20 | 21 | use SkyHub\Api\Handler\Response\HandlerInterfaceException; 22 | use SkyHub\Api\Handler\Response\HandlerInterfaceSuccess; 23 | 24 | interface ServiceInterface 25 | { 26 | /** 27 | * @var string 28 | */ 29 | const REQUEST_METHOD_GET = 'GET'; 30 | 31 | /** 32 | * @var string 33 | */ 34 | const REQUEST_METHOD_POST = 'POST'; 35 | 36 | /** 37 | * @var string 38 | */ 39 | const REQUEST_METHOD_PUT = 'PUT'; 40 | 41 | /** 42 | * @var string 43 | */ 44 | const REQUEST_METHOD_HEAD = 'HEAD'; 45 | 46 | /** 47 | * @var string 48 | */ 49 | const REQUEST_METHOD_DELETE = 'DELETE'; 50 | 51 | /** 52 | * @var string 53 | */ 54 | const REQUEST_METHOD_PATCH = 'PATCH'; 55 | 56 | /** 57 | * @var string 58 | */ 59 | const DEFAULT_SERVICE_BASE_URI = 'https://api.skyhub.com.br'; 60 | 61 | /** 62 | * @param string $uri 63 | * @param string $body 64 | * @param array $options 65 | * 66 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 67 | */ 68 | public function post(string $uri, $body = null, array $options = []); 69 | 70 | /** 71 | * @param string $uri 72 | * @param string $body 73 | * @param array $options 74 | * 75 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 76 | */ 77 | public function put(string $uri, $body = null, array $options = []); 78 | 79 | /** 80 | * @param string $uri 81 | * @param string $body 82 | * @param array $options 83 | * 84 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 85 | */ 86 | public function patch(string $uri, $body = null, array $options = []); 87 | 88 | /** 89 | * @param string $uri 90 | * @param array $options 91 | * 92 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 93 | */ 94 | public function get(string $uri, array $options = []); 95 | 96 | /** 97 | * @param string $uri 98 | * @param string $body 99 | * @param array $options 100 | * 101 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 102 | */ 103 | public function delete(string $uri, $body = null, array $options = []); 104 | 105 | /** 106 | * @param string $uri 107 | * @param array $options 108 | * 109 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 110 | */ 111 | public function head(string $uri, array $options = []); 112 | 113 | /** 114 | * @param string $method 115 | * @param string $uri 116 | * @param string|array $body 117 | * @param array $options 118 | * 119 | * @return HandlerInterfaceException|HandlerInterfaceSuccess 120 | */ 121 | public function request(string $method, string $uri, $body = null, array $options = []); 122 | 123 | /** 124 | * @return array 125 | */ 126 | public function getHeaders() : array; 127 | 128 | /** 129 | * @param array $headers 130 | * 131 | * @return $this 132 | */ 133 | public function setHeaders(array $headers = []); 134 | } 135 | -------------------------------------------------------------------------------- /src/Api/Service/ServiceJson.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Service; 19 | 20 | /** 21 | * Class ServiceJson 22 | * 23 | * @package SkyHub\Api\Service 24 | */ 25 | class ServiceJson extends ServiceDefault 26 | { 27 | /** 28 | * @var array 29 | */ 30 | private $headers = [ 31 | 'Accept' => 'application/json', 32 | 'Content-Type' => 'application/json' 33 | ]; 34 | 35 | /** 36 | * @return $this 37 | */ 38 | protected function prepareRequestHeaders() 39 | { 40 | $this->getOptionsBuilder() 41 | ->getHeadersBuilder() 42 | ->addHeaders($this->headers); 43 | 44 | return $this; 45 | } 46 | 47 | /** 48 | * @param array $bodyData 49 | * 50 | * @return $this 51 | */ 52 | protected function prepareRequestBody($bodyData) 53 | { 54 | $this->getOptionsBuilder()->setBody($bodyData, OptionsBuilderInterface::BODY_TYPE_JSON); 55 | return $this; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Api/Service/ServiceMultipart.php: -------------------------------------------------------------------------------- 1 | 'application/json' 30 | ]; 31 | 32 | /** 33 | * @return $this 34 | */ 35 | protected function prepareRequestHeaders() 36 | { 37 | $this->getOptionsBuilder() 38 | ->getHeadersBuilder() 39 | ->addHeaders($this->headers); 40 | 41 | return $this; 42 | } 43 | 44 | /** 45 | * @param array $bodyData 46 | * 47 | * @return $this 48 | */ 49 | protected function prepareRequestBody($bodyData) 50 | { 51 | $this->getOptionsBuilder()->setBody($bodyData, OptionsBuilderInterface::BODY_TYPE_MULTIPART); 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Api/Service/ServicePdf.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub\Api\Service; 19 | 20 | use SkyHub\Api\Log\TypeInterface\ResponsePdf; 21 | 22 | /** 23 | * Class ServicePdf 24 | * 25 | * @package SkyHub\Api\Service 26 | */ 27 | class ServicePdf extends ServiceDefault 28 | { 29 | /** 30 | * @var array 31 | */ 32 | private $headers = [ 33 | 'Accept' => 'application/pdf', 34 | 'Content-Type' => 'application/json' 35 | ]; 36 | 37 | /** 38 | * @return $this 39 | */ 40 | protected function prepareRequestHeaders() 41 | { 42 | $this->getOptionsBuilder() 43 | ->setStream(true) 44 | ->getHeadersBuilder() 45 | ->addHeaders($this->headers); 46 | 47 | return $this; 48 | } 49 | 50 | /** 51 | * @param array $bodyData 52 | * @param array $options 53 | * 54 | * @return $this 55 | */ 56 | protected function prepareRequestBody($bodyData) 57 | { 58 | $this->getOptionsBuilder()->setBody($bodyData, OptionsBuilderInterface::BODY_TYPE_JSON); 59 | return $this; 60 | } 61 | 62 | 63 | /** 64 | * @return \SkyHub\Api\Log\TypeInterface\ResponsePdf 65 | */ 66 | protected function getLoggerResponse() 67 | { 68 | return new ResponsePdf($this->getRequestId()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/ApiInterface.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | namespace SkyHub; 19 | 20 | use SkyHub\Api\Service\ServiceInterface; 21 | 22 | interface ApiInterface 23 | { 24 | /** 25 | * ApiInterface constructor. 26 | * 27 | * @param string $email 28 | * @param string $apiKey 29 | * @param string|null $xAccountKey 30 | * @param string|null $baseUri 31 | * @param ServiceInterface|null $apiService 32 | */ 33 | public function __construct( 34 | string $email, 35 | string $apiKey, 36 | string $xAccountKey = null, 37 | string $baseUri = null, 38 | ServiceInterface $apiService = null 39 | ); 40 | 41 | /** 42 | * @return \SkyHub\Api\Service\ServiceInterface 43 | */ 44 | public function service(); 45 | } 46 | -------------------------------------------------------------------------------- /src/bootstrap.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | 18 | require_once __DIR__ . '/../vendor/autoload.php'; 19 | -------------------------------------------------------------------------------- /src/functions.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | class CategoryTest extends TestCase 22 | { 23 | 24 | /** 25 | * @test 26 | */ 27 | public function checkDataTransformerCatalogCategoryCreate() 28 | { 29 | $code = 'rings'; 30 | $name = 'Jewels > Rings'; 31 | 32 | $transformer = new Create($code, $name); 33 | 34 | $expected = [ 35 | 'category' => [ 36 | 'code' => $code, 37 | 'name' => $name 38 | ] 39 | ]; 40 | 41 | $this->assertEquals($expected, $transformer->output()); 42 | } 43 | 44 | /** 45 | * @test 46 | */ 47 | public function checkDataTransformerCatalogCategoryUpdate() 48 | { 49 | $code = 'rings'; 50 | $name = 'Jewels > Rings'; 51 | 52 | $transformer = new Update($code, $name); 53 | 54 | $expected = [ 55 | 'category' => [ 56 | 'name' => $name 57 | ] 58 | ]; 59 | 60 | $this->assertEquals($expected, $transformer->output()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/unit/Api/DataTransformer/Catalog/Product/AttributeTest.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | class AttributeTest extends TestCase 22 | { 23 | 24 | /** 25 | * @test 26 | */ 27 | public function checkDataTransformerCatalogProductAttributeCreate() 28 | { 29 | $code = 'rings'; 30 | $label = 'Jewels > Rings'; 31 | $options = [ 32 | 'White', 33 | 'Black', 34 | 'Brown', 35 | 'Yellow', 36 | ]; 37 | 38 | $transformer = new Create($code, $label, $options); 39 | 40 | $expected = [ 41 | 'attribute' => [ 42 | 'name' => $code, 43 | 'label' => $label, 44 | 'options' => $options 45 | ] 46 | ]; 47 | 48 | $this->assertEquals($expected, $transformer->output()); 49 | } 50 | 51 | 52 | /** 53 | * @test 54 | */ 55 | public function checkDataTransformerCatalogProductAttributeUpdate() 56 | { 57 | $code = 'rings'; 58 | $label = 'Jewels > Rings'; 59 | $options = [ 60 | 'White', 61 | 'Black', 62 | 'Brown', 63 | 'Yellow', 64 | ]; 65 | 66 | $transformer = new Update($code, $label, $options); 67 | 68 | $expected = [ 69 | 'attribute' => [ 70 | 'label' => $label, 71 | 'options' => $options 72 | ] 73 | ]; 74 | 75 | $this->assertEquals($expected, $transformer->output()); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /test/unit/Api/DataTransformer/Catalog/Product/Price/UpdateTest.php: -------------------------------------------------------------------------------- 1 | [ 34 | 'price' => $price, 35 | 'promotional_price' => $promotionalPrice 36 | ] 37 | ]; 38 | 39 | $data = new DataTransformerPrice($price, $promotionalPrice); 40 | $actual = $data->output(); 41 | $this->assertEquals($expected, $actual); 42 | } 43 | 44 | /** 45 | * @test 46 | */ 47 | public function checkDataTransformeOnlyPrice() 48 | { 49 | $price = 1.00; 50 | $expected = [ 51 | 'product' => [ 52 | 'price' => $price 53 | ] 54 | ]; 55 | 56 | $data = new DataTransformerPrice($price); 57 | $actual = $data->output(); 58 | $this->assertEquals($expected, $actual); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/unit/Api/DataTransformer/Catalog/Product/Stock/UpdateTest.php: -------------------------------------------------------------------------------- 1 | [ 33 | 'qty' => $qty 34 | ] 35 | ]; 36 | $data = new DataTransformerStock($qty); 37 | $actual = $data->output(); 38 | 39 | $this->assertEquals($expected, $actual); 40 | } 41 | } -------------------------------------------------------------------------------- /test/unit/Api/EntityInterface/Catalog/Product/AttributeTest.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | class AttributeTest extends TestCase 22 | { 23 | 24 | /** @var Api */ 25 | protected $api; 26 | 27 | /** @var Product\Attribute */ 28 | protected $attribute; 29 | 30 | 31 | protected function setUp() 32 | { 33 | $this->api = new Api('', ''); 34 | $this->attribute = $this->api->productAttribute()->entityInterface(); 35 | } 36 | 37 | 38 | /** 39 | * @test 40 | */ 41 | public function isProductAttributeEntityInterfaceCorrectInstance() 42 | { 43 | $this->assertInstanceOf(Product\Attribute::class, $this->attribute); 44 | } 45 | 46 | 47 | /** 48 | * @test 49 | */ 50 | public function productAttributeCodeSetterAndGetterCheck() 51 | { 52 | $attribute = $this->getFilledAttribute(); 53 | 54 | $this->assertInternalType('string', $attribute->getCode()); 55 | $this->assertEquals('color', $attribute->getCode()); 56 | } 57 | 58 | 59 | /** 60 | * @test 61 | */ 62 | public function productAttributeLabelSetterAndGetterCheck() 63 | { 64 | $attribute = $this->getFilledAttribute(); 65 | 66 | $this->assertInternalType('string', $attribute->getLabel()); 67 | $this->assertEquals('Color', $attribute->getLabel()); 68 | } 69 | 70 | 71 | /** 72 | * @test 73 | */ 74 | public function productAttributeOptionsSetterAndGetterCheck() 75 | { 76 | $attribute = $this->getFilledAttribute(); 77 | 78 | $expected = [ 79 | 'Black', 80 | 'White', 81 | 'Red', 82 | 'Yellow', 83 | ]; 84 | 85 | $this->assertInternalType('array', $attribute->getOptions()); 86 | $this->assertEquals($expected, $attribute->getOptions()); 87 | } 88 | 89 | 90 | /** 91 | * @test 92 | */ 93 | public function productCheckCompleteFillAndExport() 94 | { 95 | /** @var Product\Attribute $attribute */ 96 | $attribute = $this->getFilledAttribute(); 97 | 98 | $expected = [ 99 | 'attribute' => [ 100 | 'code' => 'color', 101 | 'label' => 'Color', 102 | 'options' => [ 103 | 'Black', 104 | 'White', 105 | 'Red', 106 | 'Yellow', 107 | ] 108 | ] 109 | ]; 110 | 111 | $this->assertEquals($expected, $attribute->export()); 112 | } 113 | 114 | 115 | /** 116 | * @return Product\Attribute; 117 | */ 118 | protected function getFilledAttribute() 119 | { 120 | $attribute = $this->attribute; 121 | 122 | $attribute->setCode('color') 123 | ->setLabel('Color') 124 | ->addOption('Black') 125 | ->addOption('White') 126 | ->addOption('Red') 127 | ->addOption('Yellow') 128 | ; 129 | 130 | return $attribute; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /test/unit/Api/EntityInterface/Catalog/Product/PriceTest.php: -------------------------------------------------------------------------------- 1 | 'Bar'], ''), 43 | new Response(202, ['Content-Length' => 0]), 44 | new RequestException("Error Communicating with Server", new Request('POST', 'test')) 45 | ]); 46 | 47 | $handler = HandlerStack::create($mock); 48 | $this->client = new Client(['handler' => $handler]); 49 | 50 | $this->builder = $this->createMock(ClientBuilderInterface::class); 51 | $this->builder->method('build')->willReturn($this->client); 52 | 53 | $this->service = new ServiceJson('http://www.example.com', [], [], $this->builder); 54 | 55 | $this->api = new Api('anyone@anyone.com', 'anything', null, 'https://api.skyhub.com', $this->service); 56 | $this->price = $this->api->productPrice()->entityInterface(); 57 | } 58 | 59 | /** 60 | * @test 61 | */ 62 | public function isProductPriceEntityInterfaceCorrectInstance() 63 | { 64 | $this->assertInstanceOf(Price::class, $this->price); 65 | } 66 | 67 | /** 68 | * @test 69 | * @depends isProductPriceEntityInterfaceCorrectInstance 70 | */ 71 | public function checkDataToUpdate() 72 | { 73 | $sku = 'test'; 74 | $price = 1.00; 75 | $promotionPrice = 0.90; 76 | $this->price->setSku($sku); 77 | $this->price->setPrice($price); 78 | $this->price->setPromotionalPrice($promotionPrice); 79 | 80 | $this->assertEquals($sku, $this->price->getSku()); 81 | $this->assertEquals($price, $this->price->getPrice()); 82 | $this->assertEquals($promotionPrice, $this->price->getPromotionalPrice()); 83 | return $this->price; 84 | } 85 | 86 | /** 87 | * @test 88 | * @depends checkDataToUpdate 89 | */ 90 | public function checkApiUpdate(Price $price) 91 | { 92 | $this->assertEquals( 93 | '200', 94 | $price->update()->statusCode() 95 | ); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /test/unit/Api/EntityInterface/Catalog/Product/StockTest.php: -------------------------------------------------------------------------------- 1 | 'Bar'], ''), 43 | new Response(202, ['Content-Length' => 0]), 44 | new RequestException("Error Communicating with Server", new Request('POST', 'test')) 45 | ]); 46 | 47 | $handler = HandlerStack::create($mock); 48 | $this->client = new Client(['handler' => $handler]); 49 | 50 | $this->builder = $this->createMock(ClientBuilderInterface::class); 51 | $this->builder->method('build')->willReturn($this->client); 52 | 53 | $this->service = new ServiceJson('http://www.example.com', [], [], $this->builder); 54 | 55 | $this->api = new Api('anyone@anyone.com', 'anything', null, 'https://api.skyhub.com', $this->service); 56 | $this->stock = $this->api->productStock()->entityInterface(); 57 | } 58 | 59 | /** 60 | * @test 61 | */ 62 | public function isProductStockEntityInterfaceCorrectInstance() 63 | { 64 | $this->assertInstanceOf(Stock::class, $this->stock); 65 | } 66 | 67 | /** 68 | * @test 69 | * @depends isProductStockEntityInterfaceCorrectInstance 70 | */ 71 | public function checkDataToUpdate() 72 | { 73 | $sku = 'test'; 74 | $qty = 2; 75 | 76 | $this->stock->setSku($sku); 77 | $this->stock->setQty($qty); 78 | 79 | $this->assertEquals($sku, $this->stock->getSku()); 80 | $this->assertEquals($qty, $this->stock->getQty()); 81 | return $this->stock; 82 | } 83 | 84 | /** 85 | * @test 86 | * @depends checkDataToUpdate 87 | */ 88 | public function checkApiUpdate(Stock $stock) 89 | { 90 | $this->assertEquals( 91 | '200', 92 | $stock->update()->statusCode() 93 | ); 94 | } 95 | } -------------------------------------------------------------------------------- /test/unit/Api/Handler/Sales/OrderHandlerTest.php: -------------------------------------------------------------------------------- 1 | 'Bar'], '{"orders":[]}'), 35 | new Response(202, ['Content-Length' => 0]), 36 | new RequestException("Error Communicating with Server", new Request('GET', 'test')) 37 | ]); 38 | 39 | $handler = HandlerStack::create($mock); 40 | $this->client = new Client(['handler' => $handler]); 41 | 42 | $this->builder = $this->createMock(ClientBuilderInterface::class); 43 | $this->builder->method('build')->willReturn($this->client); 44 | 45 | $this->service = new ServiceJson('http://www.example.com', [], [], $this->builder); 46 | 47 | $this->api = new Api('anyone@anyone.com', 'anything', null, 'https://api.skyhub.com', $this->service); 48 | } 49 | 50 | /** 51 | * @test 52 | */ 53 | public function orders() 54 | { 55 | $result = $this->api->order()->orders()->body(); 56 | $this->assertEquals('{"orders":[]}', $result); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/unit/Api/Service/ClientBuilderTest.php: -------------------------------------------------------------------------------- 1 | 10 52 | ]; 53 | 54 | /** 55 | * @var \SkyHub\Api\Service\ClientBuilderInterface 56 | */ 57 | private $builder; 58 | 59 | protected function setUp() 60 | { 61 | $this->baseUri = "{$this->scheme}://{$this->host}:{$this->port}/{$this->path}?$this->query"; 62 | $this->builder = new ClientBuilder(); 63 | } 64 | 65 | /** 66 | * Testing if the URI is correctly. 67 | * 68 | * @test 69 | */ 70 | public function testBuildHttpClientInstance() 71 | { 72 | $client = $this->builder->build(); 73 | $this->assertInstanceOf(\GuzzleHttp\ClientInterface::class, $client); 74 | } 75 | 76 | /** 77 | * Testing if the URI is correctly. 78 | * 79 | * @test 80 | */ 81 | public function testBuildHttpClientBaseUri() 82 | { 83 | $client = $this->builder->build($this->baseUri); 84 | 85 | /** @var \Psr\Http\Message\UriInterface $baseUri */ 86 | $baseUri = $client->getConfig('base_uri'); 87 | 88 | $this->assertInstanceOf(\Psr\Http\Message\UriInterface::class, $baseUri); 89 | $this->assertEquals($this->scheme, $baseUri->getScheme()); 90 | $this->assertEquals($this->host, $baseUri->getHost()); 91 | $this->assertEquals($this->port, $baseUri->getPort()); 92 | $this->assertEquals("/{$this->path}", $baseUri->getPath()); 93 | $this->assertEquals($this->query, $baseUri->getQuery()); 94 | } 95 | 96 | /** 97 | * Testing if the URI is correctly. 98 | * 99 | * @test 100 | */ 101 | public function testBuildHttpClientOptions() 102 | { 103 | $client = $this->builder->build($this->baseUri, $this->defaults); 104 | $this->assertEquals($this->defaults['timeout'], $client->getConfig('defaults')['timeout']); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /test/unit/Api/Service/HeadersBuilderTest.php: -------------------------------------------------------------------------------- 1 | 'application/json', 28 | 'Content-type' => 'application/json', 29 | 'Sample-user' => 'User', 30 | 'X-Account-Manager-Key' => '0a98sdfy0a98df0a9sdf', 31 | ]; 32 | 33 | protected function setUp() 34 | { 35 | $this->builder = new HeadersBuilder(); 36 | } 37 | 38 | /** 39 | * @test 40 | */ 41 | public function addHeader() 42 | { 43 | $result = $this->builder->addHeader('X-Account-Manager-Key', 'XYZ'); 44 | $this->assertEquals('XYZ', $this->builder->getHeader('X-Account-Manager-Key')); 45 | $this->assertInstanceOf(HeadersBuilderInterface::class, $result); 46 | } 47 | 48 | /** 49 | * @test 50 | */ 51 | public function setHeadersOneByTime() 52 | { 53 | foreach ($this->headers as $key => $value) { 54 | $this->builder->addHeader($key, $value); 55 | } 56 | 57 | $this->assertEquals($this->headers, $this->builder->build()); 58 | } 59 | 60 | /** 61 | * @test 62 | */ 63 | public function setHeaders() 64 | { 65 | $this->builder->addHeaders($this->headers); 66 | $this->assertEquals($this->headers, $this->builder->build()); 67 | $this->assertEquals( 68 | $this->headers['X-Account-Manager-Key'], 69 | $this->builder->getHeader('X-Account-Manager-Key') 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /test/unit/Api/Service/OptionsBuilderTest.php: -------------------------------------------------------------------------------- 1 | 'application/json', 27 | 'Content-type' => 'application/json', 28 | 'Sample-user' => 'User', 29 | 'X-Account-Manager-Key' => '0a98sdfy0a98df0a9sdf', 30 | ]; 31 | 32 | protected function setUp() 33 | { 34 | $this->builder = new OptionsBuilder(); 35 | } 36 | 37 | /** 38 | * @test 39 | */ 40 | public function setTimeout() 41 | { 42 | $this->builder->setTimeout(123); 43 | $this->assertEquals(['timeout' => 123, 'headers' => []], $this->builder->build()); 44 | } 45 | 46 | /** 47 | * @test 48 | */ 49 | public function setDebug() 50 | { 51 | $this->builder->setDebug(true); 52 | $this->assertEquals(['debug' => true, 'headers' => []], $this->builder->build()); 53 | } 54 | 55 | /** 56 | * @test 57 | */ 58 | public function setStream() 59 | { 60 | $this->builder->setStream(true); 61 | $this->assertEquals(['stream' => true, 'headers' => []], $this->builder->build()); 62 | } 63 | 64 | /** 65 | * @test 66 | */ 67 | public function setBody() 68 | { 69 | $this->builder->setBody('{"content":"Ok"}'); 70 | $this->assertEquals(['body' => '{"content":"Ok"}', 'headers' => []], $this->builder->build()); 71 | } 72 | 73 | /** 74 | * @test 75 | */ 76 | public function setAllOptionsWithHeaders() 77 | { 78 | $expected = [ 79 | 'timeout' => 123, 80 | 'debug' => true, 81 | 'stream' => true, 82 | 'body' => '{"content":"This is the result"}', 83 | 'headers' => $this->headers 84 | ]; 85 | 86 | $this->builder->setTimeout(123); 87 | $this->builder->setDebug(true); 88 | $this->builder->setStream(true); 89 | $this->builder->setBody('{"content":"This is the result"}'); 90 | $this->builder->getHeadersBuilder()->addHeaders($this->headers); 91 | 92 | $this->assertEquals($expected, $this->builder->build()); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /test/unit/Api/Service/ServiceJsonTest.php: -------------------------------------------------------------------------------- 1 | 'Bar']), 36 | new Response(202, ['Content-Length' => 0]), 37 | new RequestException("Error Communicating with Server", new Request('GET', 'test')) 38 | ]); 39 | 40 | $handler = HandlerStack::create($mock); 41 | $this->client = new Client(['handler' => $handler]); 42 | 43 | $this->builder = $this->createMock(ClientBuilderInterface::class); 44 | $this->builder->method('build')->willReturn($this->client); 45 | 46 | $this->service = new ServiceJson('http://www.example.com', [], [], $this->builder); 47 | } 48 | 49 | /** 50 | * @test 51 | */ 52 | public function get() 53 | { 54 | $result = $this->service->get('www.enom.com'); 55 | $this->assertEquals(1, 1); 56 | } 57 | 58 | /** 59 | * @test 60 | */ 61 | public function put() 62 | { 63 | $result = $this->service->put('www.enom.com'); 64 | $this->assertEquals(1, 1); 65 | } 66 | 67 | /** 68 | * @test 69 | */ 70 | public function post() 71 | { 72 | $result = $this->service->post('www.enom.com'); 73 | $this->assertEquals(1, 1); 74 | } 75 | 76 | /** 77 | * @test 78 | */ 79 | public function head() 80 | { 81 | $result = $this->service->head('www.enom.com'); 82 | $this->assertEquals(1, 1); 83 | } 84 | 85 | /** 86 | * @test 87 | */ 88 | public function patch() 89 | { 90 | $result = $this->service->patch('www.enom.com'); 91 | $this->assertEquals(1, 1); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /test/unit/Api/ServiceTest.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | class ServiceTest extends TestCase 22 | { 23 | 24 | /** 25 | * @test 26 | */ 27 | public function checkServiceHttpClientInstance() 28 | { 29 | $reflection = new ReflectionClass(Api\Service\ServiceDefault::class); 30 | 31 | /** @var \ReflectionMethod $method */ 32 | $method = $reflection->getMethod('httpClient'); 33 | $method->setAccessible(true); 34 | 35 | $httpClient = $method->invoke(new Api\Service\ServiceDefault('https://api.skyhub.com.br')); 36 | 37 | $this->assertInstanceOf(\GuzzleHttp\Client::class, $httpClient); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/unit/ApiTest.php: -------------------------------------------------------------------------------- 1 | 23 | */ 24 | class ApiTest extends TestCase 25 | { 26 | 27 | /** @var Api */ 28 | protected $api = null; 29 | 30 | /** @var string */ 31 | protected $email = 'test@e-smart.com.br'; 32 | 33 | /** @var string */ 34 | protected $apiKey = 'testApiKey'; 35 | 36 | 37 | public function setUp() 38 | { 39 | $this->api = new Api($this->email, $this->apiKey); 40 | } 41 | 42 | 43 | /** 44 | * @test 45 | */ 46 | public function getNewInstanceOfApiModel() 47 | { 48 | $this->assertInstanceOf(ApiInterface::class, $this->api); 49 | } 50 | 51 | 52 | /** 53 | * @test 54 | */ 55 | public function getServiceInstance() 56 | { 57 | $this->assertInstanceOf(Api\Service\ServiceInterface::class, $this->api->service()); 58 | } 59 | 60 | 61 | /** 62 | * @test 63 | */ 64 | public function createNewInstanceOfProductAttributeHandler() 65 | { 66 | $this->assertInstanceOf(AttributeHandler::class, $this->api->productAttribute()); 67 | } 68 | 69 | 70 | /** 71 | * @test 72 | */ 73 | public function createNewInstanceOfProductHandler() 74 | { 75 | $this->assertInstanceOf(ProductHandler::class, $this->api->product()); 76 | } 77 | 78 | 79 | /** 80 | * @test 81 | */ 82 | public function createNewInstanceOfCategoryHandler() 83 | { 84 | $this->assertInstanceOf(CategoryHandler::class, $this->api->category()); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /test/unit/Base.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | trait Base 20 | { 21 | 22 | /** @var Api */ 23 | protected $api = null; 24 | 25 | /** @var string */ 26 | protected $email = 'test@e-smart.com.br'; 27 | 28 | /** @var string */ 29 | protected $apiKey = 'testApiKey'; 30 | 31 | 32 | /** 33 | * @return Api 34 | */ 35 | protected function api() 36 | { 37 | if (empty($this->api)) { 38 | $this->api = new Api($this->email, $this->apiKey); 39 | } 40 | 41 | return $this->api; 42 | } 43 | } 44 | --------------------------------------------------------------------------------