clarity-tech / laravel-ezyslips
Laravel ezyslips package
Requires
- php: >=7.3.0
- illuminate/support: ^7.0|^8.0|^9.0|10.0
- psr/http-message: ^1.0
Suggests
- guzzlehttp/guzzle: Must Required to use the HTTP Client.
This package is auto-updated.
Last update: 2024-10-22 15:05:13 UTC
README
Laravel Ezyslips is a simple package which helps to build robust integration into Ezyslips.
Installation
Add package to composer.json
composer require clarity-tech/laravel-ezyslips
Laravel 5.5+
Package auto discovery will take care of setting up the alias and facade for you
Laravel 5.4 <
Add the service provider to config/app.php in the providers array.
<?php 'providers' => [ ... ClarityTech\Ezyslips\EzyslipsServiceProvider::class, ],
Setup alias for the Facade
<?php 'aliases' => [ ... 'Ezyslips' => ClarityTech\Ezyslips\Facades\Ezyslips::class, ],
Set credendials
in your .env
file set these values from your app
EZYSLIPS_EMAIL=your-email
EZYSLIPS_LICENSE_KEY=your-license-key
Optional Configuration (Publishing)
Laravel Ezyslips requires you to set email and license key configuration. You will need to publish configs assets
`php artisan vendor:publish --tag=ezyslips-config`
This will create a ezyslips.php file in the config directory.
'key' => env("EZYSLIPS_EMAIL", null),
'secret' => env("EZYSLIPS_LICENSE_KEY", null)
Usage
Just set the env and use the Ezyslips facade or resolve it in the container
use ClarityTech\Ezyslips\Facades\Ezyslips; return Ezyslips::api()->order->create( $attributes );
Controller Example
If you prefer to use dependency injection over facades like me, then you can inject the Class:
use Illuminate\Http\Request; use ClarityTech\Ezyslips\Ezyslips; class Foo { protected $ezyslips; public function __construct(Ezyslips $ezyslips) { $this->ezyslips = $ezyslips; } /* * returns a single order */ public function getOrder(Request $request) { $orders = $this->ezyslips ->order->fetch(['orderid' => 40586]); } /* * returns the array of orders */ public function getOrder(Request $request) { $orders = $this->ezyslips ->order->all(['status' => 'A']); } /* * Advanced use case call the api directly * with specifying the prefix * returns the raw responses */ public function getOrder(Request $request) { $orders = $this->ezyslips ->get('getorders'); } }
Miscellaneous
To get Response headers
Ezyslips::getHeaders();
To get specific header
Ezyslips::getHeader("Content-Type");
Check if header exist
if(Ezyslips::hasHeader("Content-Type")){ echo "Yes header exist"; }
To get response status code or status message
Ezyslips::getStatusCode(); // 200 Ezyslips::getReasonPhrase(); // ok