diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..634e92b --- /dev/null +++ b/LICENCE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Online Identity & Solutions B.V. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..881eb16 --- /dev/null +++ b/README.MD @@ -0,0 +1,67 @@ +# Laravel Channable API connector + +## About +This package creates a wrapper around [onlineidentity/channable](https://github.com/onlineidentity/channable/) for ease of use in the [Laravel framework](https://laravel.com). + +## Installation + +`composer require onlineidentity/laravel-channable` + +(Optional) Publish the config file with `php artisan vendor:publish --tag=channable` + +Set your .env variables +```dotenv +CHANNABLE_API_TOKEN='{API_TOKEN}' +CHANNABLE_COMPANY_ID={COMPANY_ID} +CHANNABLE_PROJECT_ID={PROJECT_ID} #default, swappable after initialization +``` + +## Usage + +````php +#Examples + +# app()->make(); + +$channable = app()->make('channable'); + +//Get all orders +$channable->orders()->allOrders(); + +$order_id = 12345678; +$channable->orders()->shipment($order_id, [ + 'tracking_code' => '3S1234567890', + 'transporter' => 'POSTNL', + 'order_item_ids' => [ + 1, + 2 + ] +]); + +//Get all returns with queryParameters +$channable->returns()->allReturns(['limit' => 2, 'last_modified_after' => '2022-01-01']); + +//update returns status +$return_id = 12345678; +$status_accepted = \OnlineIdentity\Enums\ReturnsType::ACCEPTED; +$channable->returns()->updateReturnStatus($return_id, $status_accepted); + +# Using the facade + +//get all orders +$orders = \OnlineIdentity\LaravelChannable\Facades\Channable::orders()->allOrders(); + +//change project id +\OnlineIdentity\LaravelChannable\Facades\Channable::setProjectId(123456); + +\OnlineIdentity\LaravelChannable\Facades\Channable::orders()->shipment($order_id, [ + 'tracking_code' => '3S1234567890', + 'transporter' => 'POSTNL', + 'order_item_ids' => [ + 1, + 2 + ]); + +```` +For more details and options visit the offical channable docs https://api.channable.com/v1/docs + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..16aeacd --- /dev/null +++ b/composer.json @@ -0,0 +1,36 @@ +{ + "name": "onlineidentity/laravel-channable", + "description": "Laravel wrapper for OnlineIdentity Channable API connector", + "type": "library", + "keywords": ["api","channable","connector","laravel"], + "license": "MIT", + "authors": [ + { + "name": "Bryan Schreuder", + "email": "bryan@onlineidentity.nl" + }, + { + "name": "Joeri Aben", + "email": "joeri@onlineidentity.nl" + } + ], + "require": { + "php": "^8.1", + "onlineidentity/channable": "dev-master", + "illuminate/support": "^6|^7|^8|^9|^10" + }, + "autoload": { + "psr-4": { + "OnlineIdentity\\LaravelChannable\\": "src/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "laravel": { + "providers": [ + "OnlineIdentity\\LaravelChannable\\ChannableServiceProvider" + ] + } + } +} diff --git a/config/channable.php b/config/channable.php new file mode 100644 index 0000000..4a2d263 --- /dev/null +++ b/config/channable.php @@ -0,0 +1,9 @@ + env('CHANNABLE_API_TOKEN'), + 'company_id' => env('CHANNABLE_COMPANY_ID'), + 'project_id' => env('CHANNABLE_PROJECT_ID'), + 'base_url' => env('CHANNABLE_BASE_URL', 'https://api.channable.com'), + 'version' => env('CHANNABLE_VERSION', 'v1') + ]; \ No newline at end of file diff --git a/src/ChannableServiceProvider.php b/src/ChannableServiceProvider.php new file mode 100644 index 0000000..4afcea0 --- /dev/null +++ b/src/ChannableServiceProvider.php @@ -0,0 +1,47 @@ +mergeConfigFrom( + __DIR__ . '/../config/channable.php', 'channable' + ); + + $this->app->bind('channable', function ($app) { + + $config = new ChannableConfig( + api_token: config('channable.api_token'), + company_id: config('channable.company_id'), + project_id: config('channable.project_id'), + version: config('channable.version'), + base_url: config('channable.base_url') + ); + + return new Channable($config); + }); + } + + public function boot(): void + { + $this->publishes([ + __DIR__ . "/config" => config_path() + ], 'channable'); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return ['channable']; + } +} \ No newline at end of file diff --git a/src/Facade/Channable.php b/src/Facade/Channable.php new file mode 100644 index 0000000..2607aef --- /dev/null +++ b/src/Facade/Channable.php @@ -0,0 +1,25 @@ + env('CHANNABLE_API_TOKEN'), + 'company_id' => env('CHANNABLE_COMPANY_ID'), + 'project_id' => env('CHANNABLE_PROJECT_ID'), + 'base_url' => env('CHANNABLE_BASE_URL', 'https://api.channable.com'), + 'version' => env('CHANNABLE_VERSION', 'v1') + ]; \ No newline at end of file