Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

01envios/logistics-sdk

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

01envios/logistics-sdk - npm Package Compare versions

Comparing version
v1.0-beta
to
dev-master
+5
mnek84-01envios-sdk-6871fd5/.gitignore
vendor
composer.lock
.idea
Thumbs.db
.DS_Store
{
"name": "rimoldlogistica/logistics-sdk",
"description": "Logistica SDK",
"type": "library",
"homepage": "https://app.rimoldlogistica.com",
"license": "MIT",
"prefer-stable": true,
"minimum-stability": "dev",
"keywords": [
"php",
"sdk",
"rest",
"api"
],
"authors": [
{
"name": "maximiliano",
"email": "mnek84@gmail.com"
}
],
"require": {
"php": ">=7.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.2.1",
"tightenco/collect": "^8.34"
},
"autoload": {
"psr-4": { "RimoldSDK\\" : "src/" }
},
"require-dev": {
"phpunit/phpunit": "9"
}
}
# RIMOLD LOGISTICA SDK
[![Latest Stable Version](https://img.shields.io/packagist/v/intrasistema/logsdk.svg?style=flat-square)](https://packagist.org/packages/rimoldlogistica/logistics-sdk)
[![Total Downloads](https://img.shields.io/packagist/dt/intrasistema/logsdk.svg?style=flat-square)](https://packagist.org/packages/rimoldlogistica/logistics-sdk)
Librareria para la gestión de Logistica de Rimold-Logistica
Para crear tu cuenta ir a https://app.rimoldlogistica.com
## Instalación
### Composer
```
$ composer require rimoldlogistica/logistics-sdk
```
```json
{
"require": {
"rimoldlogistica/logistics-sdk": "dev-master"
}
}
```
>Ver la carpeta examples.
<?php
namespace RimoldSDK;
use \Exception;
/**
* ApiException Class Doc Comment
*
* @category Class
* @package Meli
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class ApiException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*
* @var mixed
*/
protected $responseBody;
/**
* The HTTP header of the server response.
*
* @var string[]|null
*/
protected $responseHeaders;
/**
* The deserialized response object
*
* @var $responseObject;
*/
protected $responseObject;
/**
* Constructor
*
* @param string $message Error message
* @param int $code HTTP status code
* @param string[]|null $responseHeaders HTTP response header
* @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string
*/
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
{
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
/**
* Gets the HTTP response header
*
* @return string[]|null HTTP response header
*/
public function getResponseHeaders()
{
return $this->responseHeaders;
}
/**
* Gets the HTTP body of the server response either as Json or string
*
* @return mixed HTTP body of the server response either as \stdClass or string
*/
public function getResponseBody()
{
return $this->responseBody;
}
/**
* Sets the deseralized response object (during deserialization)
*
* @param mixed $obj Deserialized response object
*
* @return void
*/
public function setResponseObject($obj)
{
$this->responseObject = $obj;
}
/**
* Gets the deseralized response object (during deserialization)
*
* @return mixed the deserialized response object
*/
public function getResponseObject()
{
return $this->responseObject;
}
}
<?php
namespace RimoldSDK;
class Auth
{
}
<?php
namespace RimoldSDK;
use \Exception;
/**
* ApiException Class Doc Comment
*
* @category Class
* @package Meli
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class AuthException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*
* @var mixed
*/
protected $responseBody;
/**
* The HTTP header of the server response.
*
* @var string[]|null
*/
protected $responseHeaders;
/**
* The deserialized response object
*
* @var $responseObject;
*/
protected $responseObject;
/**
* Constructor
*
* @param string $message Error message
* @param int $code HTTP status code
* @param string[]|null $responseHeaders HTTP response header
* @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string
*/
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
{
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
/**
* Gets the HTTP response header
*
* @return string[]|null HTTP response header
*/
public function getResponseHeaders()
{
return $this->responseHeaders;
}
/**
* Gets the HTTP body of the server response either as Json or string
*
* @return mixed HTTP body of the server response either as \stdClass or string
*/
public function getResponseBody()
{
return $this->responseBody;
}
/**
* Sets the deseralized response object (during deserialization)
*
* @param mixed $obj Deserialized response object
*
* @return void
*/
public function setResponseObject($obj)
{
$this->responseObject = $obj;
}
/**
* Gets the deseralized response object (during deserialization)
*
* @return mixed the deserialized response object
*/
public function getResponseObject()
{
return $this->responseObject;
}
}
<?php
include '../../vendor/autoload.php';
$sdk = new RimoldSDK\Logistica();
$sdk->setToken("666");
try {
$shipment = new \RimoldSDK\Shipment($sdk);
$shipment->addBulk(1, 1, 1, 1);
$shipment
->setCountry("ARGENTINA")
->setProvince("BUENOS AIRES")
->setLocality("SAN ANTONIO DE PADUA")
->setAddressType("RESIDENTIAL")
->setAddress("GAONA 1584")
->setAddressComments("PAREDON NEGRO")
->setZipcode("1718")
->setCoords("","")
->setReceiver("XXX EMMANUELLI")
->setReceiverEmail("pepe@pepe.com")
->setReceiverMobile("")
->setExternalReference(\RimoldSDK\Shipment::EXTERNAL_TYPE_ML,"1234")
->setIsCollect(1)
->setLogisticTypeId(1)
->setServiceTypeId(1);
$createdShipment = $shipment
->create();
print "Tracking Number: ".($createdShipment->getTrackingNumber());
dd($createdShipment);
} catch (\RimoldSDK\ValidationFailedException $e) {
foreach($e->getErrorBag() as $error)
{
print $error[0].chr(13).chr(10);
}
} catch (\RimoldSDK\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \EnviosSDK\Logistica();
$sdk->setToken("666");
try {
//$createdShipment = $sdk->getShipment("2619872706");
$createdShipment = $sdk->getShipmentByExternal("meli","1234");
print $createdShipment->current_status['name'];
foreach($createdShipment->history as $history)
{
print "ESTADOS: ".$history['name_displayed'];
}
//$createdShipment->makeLabelPrinted();
$createdShipment->fullfiled();
dd($createdShipment->history);
} catch (\EnviosSDK\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \EnviosSDK\Logistica();
$sdk->setToken("2835754040");
try {
$tracking = 114626706437;
// Información de un Tracking
$info = $sdk->get("driver/settlements",[
'from'=>'2021-05-12',
'to'=>'2021-05-13',
'zones'=>'0',
'driver'=>'21',
'status'=>[1,2,3]
]);
$info = $sdk->put("shipments/288741353957",[
"client_id"=> 2,
"status"=>18,
"comment"=>"Prueba de cambio!"
]);
var_dump($info['history']);
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \EnviosSDK\Logistica();
$sdk->setToken("2835754040");
try {
$shipping = $sdk->get("shipping",['iqr'=>true,'shipping'=>"40559180982"]);
$tracking = $shipping['tracking_number'];
$info = $sdk->put("shipments/".$tracking,['status'=>10,'client_id'=>0,'comment'=>'']);
die("cambiado correctamente");
} catch (\EnviosSDK\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \EnviosSDK\Logistica();
$sdk->setToken("666");
try {
#$user = $sdk->me();
#print "Usuario Logoneado: ".$user->name;
$drivers = $sdk->getDrivers();
foreach ($drivers as $driver)
{
dd($driver['name']);
}
} catch (\EnviosSDK\AuthException $e) {
die("Fallo al autenticar");
} catch (\EnviosSDK\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \EnviosSDK\Logistica();
$sdk->setToken("2835754040");
try {
$tracking = 114626706437;
// Información de un Tracking
$info = $sdk->get("shipping",['shipping'=>'114626706437','history'=>1,'order'=>'LATEST']);
print $info['owner_fullname'];
var_dump($info['history']);
} catch (\EnviosSDK\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../vendor/autoload.php';
$sdk = new \RimoldSDK\Logistica();
$sdk->setToken("2835754040");
try {
$shipmentHistory = $sdk->traceShipment(34794766800);
if ($shipmentHistory)
{
foreach($shipmentHistory as $info)
{
echo "Status:".$info['status']." - ".( ($info['status_info'])?$info['status_info']['name']:'Unknown' ).chr(13).chr(10);
}
}
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
namespace RimoldSDK;
use RimoldSDK\Responses\ShipmentResponse;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Tightenco\Collect\Support\Collection;
class Logistica
{
#const API = 'https://app.rimoldlogistica.com/api/';
const API = 'http://01envios.local/api/';
private $token;
private function getClient()
{
$handler = HandlerStack::create();
$extraParams = [
'Authorization'=>'Bearer '.$this->token
];
$handler->push(Middleware::mapRequest(function (RequestInterface $request) use ($extraParams) {
$uri = $request->getUri();
$headers = $request->getHeaders();
$headers['Authorization'] = $extraParams['Authorization'];
return new Request(
$request->getMethod(),
$uri,
$headers,
$request->getBody(),
$request->getProtocolVersion()
);
}));
return new Client([
'base_uri' => self::API,
'handler' => $handler,
'exceptions' => false,
]);
}
private function getResponse(ResponseInterface $response)
{
$body = $response->getBody()->getContents();
$data = json_decode((string) $body,true);
//var_dump($data);
if ($response->getStatusCode()==200)
{
if (!isset($data['status']))
{
throw new ApiException("Bad Response");
}
if ($data['status']==1)
{
if (isset($data['data']))
{
if (count($data['data']) == count($data['data'], COUNT_RECURSIVE))
{
return Collection::make([$data['data']]);
}else{
return Collection::make($data['data']);
}
}else{
return true;
}
}else{
if ($data['error']=="VALIDATION_FAILED")
{
throw new ValidationFailedException($data['error'],$data['errors']);
}else{
throw new ApiException($data['error']);
}
}
}else{
if ($response->getStatusCode()==401)
{
throw new AuthException($data['error']);
}else{
if (isset($data['errors']))
throw new ApiException($data['message'],1,null,$response->getBody());
throw new AuthException(($data['error'] ?? $response->getBody()));
}
}
}
/**
* @param $search
* @param $page
* @param $perPage
* @return false|mixed
* @throws ApiException
*/
public function getDrivers($search=null,$page=null,$perPage=null)
{
$params = [];
if ($search)
$params['search'] = $search;
if ($page)
{
$params['page'] = $page;
$params['limit'] = ($perPage)?$perPage:10;
}
return $this->get("driver",$params);
}
public function findShipping($trackingNumber)
{
$client = $this->getClient();
$response = $client->get('driver', [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
]);
if ($response->getStatusCode()==200)
{
$body = $response->getBody();
$data = json_decode((string) $body,true);
if ($data['status']==1)
{
return $data['data'];
}else{
throw new ApiException($data['error']);
}
}else{
return false;
}
}
public function setToken(string $string)
{
$this->token = $string;
}
/**
* @param $tracking
* @return mixed
* @throws ApiException
*/
public function traceShipment($tracking)
{
$client = $this->getClient();
$response = $client->get('shipments/'.$tracking.'/history', [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
]);
return $this->getResponse($response);
}
/**
* @param $ep
* @param null $params
* @return mixed
* @throws ApiException
*/
public function get($ep,$params=null)
{
$client = $this->getClient();
$defaultData = [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
];
if ($params)
$defaultData['query'] = $params;
$response = $client->get($ep, $defaultData);
return $this->getResponse($response);
}
/**
* @param $ep
* @param null $params
* @return mixed
* @throws ApiException
*/
public function post($ep,$params=null)
{
$client = $this->getClient();
$defaultData = [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
];
if ($params)
$defaultData['query'] = $params;
$response = $client->post($ep, $defaultData);
return $this->getResponse($response);
}
/**
* @param $ep
* @param null $params
* @return mixed
* @throws ApiException
*/
public function put($ep,$params=null)
{
$client = $this->getClient();
$defaultData = [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
];
if ($params)
$defaultData['query'] = $params;
$response = $client->put($ep, $defaultData);
return $this->getResponse($response);
}
public function getShippingList($tracking=null, $driver=null, $statuses=null,$from=null,$to=null, $paginated=null, $page=null,$clientId=null,$orderBy="id",$orderType='ASC')
{
return $this->get("shipments",[
'search'=>$tracking,
'client_id'=>$clientId,
'driver'=>$driver,
'statuses'=>$statuses,
'from'=>$from,
'to'=>$to,
'limit'=>$paginated,
'page'=>$page,
'orderby'=>$orderBy,
'ordertype'=>$orderType,
]);
}
public function getToken()
{
return $this->token;
}
public function me()
{
$userCollection = $this->get('user');
return ((object)$userCollection->first());
}
/**
* @param $shipment
* @return ShipmentResponse
* @throws ApiException
*/
public function createShipment($shipment)
{
return ShipmentResponse::createFromRequest($this,$this->post("shipment",$shipment));
}
/**
* @param $shipment
* @return ShipmentResponse
* @throws ApiException
*/
public function getShipment($tracking)
{
return ShipmentResponse::createFromRequest($this,$this->get("shipment/".$tracking));
}
public function getShipmentByExternal($type,$val): ShipmentResponse
{
return ShipmentResponse::createFromRequest($this,$this->get("shipmentx/".$type."/".$val));
}
}
<?php
namespace RimoldSDK\Responses;
use RimoldSDK\Logistica;
class ShipmentResponse
{
private $shipment;
/**
* @var Logistica
*/
private $sdk;
/**
* @param $shipment
*/
public function __construct($shipment,$sdk)
{
$this->sdk = $sdk;
$this->shipment = $shipment;
}
public static function createFromRequest($sdk,$post)
{
return new self($post,$sdk);
}
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}else{
if (isset($this->shipment[$property])){
return $this->shipment[$property];
}
}
}
public function getTrackingNumber()
{
return $this->tracking;
}
public function makeLabelPrinted()
{
$this->shipment = $this->sdk->post("shipment/".$this->_id."/status/201");
}
public function fullfiled()
{
$this->shipment = $this->sdk->post("shipment/".$this->_id."/status/202");
}
}
<?php
namespace RimoldSDK;
use RimoldSDK\Responses\ShipmentResponse;
class Shipment
{
const EXTERNAL_TYPE_TIENDANUBE = "Tienda Nube";
const EXTERNAL_TYPE_LOCAL = "RIMOLD";
const EXTERNAL_TYPE_ML = "MercadoLibre";
private $bulks;
private $sdk;
private $shipment;
/**
* @param Logistica $sdk
*/
public function __construct(Logistica $sdk)
{
$this->sdk = $sdk;
}
/**
* @param string $service_type_id
*/
public function setServiceTypeId(string $service_type_id): Shipment
{
$this->shipment['service_type_id'] = $service_type_id;
return $this;
}
/**
* @param string $receiver
*/
public function setReceiver(string $receiver): Shipment
{
$this->shipment['receiver'] = $receiver;
return $this;
}
/**
* @param string $auth_fullname
*/
public function setAuthFullname(string $auth_fullname): Shipment
{
$this->shipment['auth_fullname'] = $auth_fullname;
return $this;
}
/**
* @param string $logistic_type_id
*/
public function setLogisticTypeId(string $logistic_type_id): Shipment
{
$this->shipment['logistic_type_id'] = $logistic_type_id;
return $this;
}
/**
* @param string $address_type
* @return Shipment
*/
public function setAddressType($address_type): Shipment
{
$this->shipment['address_type'] = $address_type;
return $this;
}
/**
* @param string $delivery_time
* @return Shipment
*/
public function setDeliveryTime(string $delivery_time): Shipment
{
$this->shipment['delivery_time'] = $delivery_time;
return $this;
}
/**
* @param string $address
* @return Shipment
*/
public function setAddress(string $address): Shipment
{
$this->shipment['address'] = $address;
return $this;
}
/**
* @param $comments
* @return Shipment
*/
public function setAddressComments($comments): Shipment
{
if (!$comments)
$comments = "";
$this->shipment['comments'] = $comments;
return $this;
}
/**
* @param $locality
* @return Shipment
*/
public function setLocality($locality): Shipment
{
if(!$locality)
$locality="";
$this->shipment['locality'] = $locality;
return $this;
}
/**
* @param $province
* @return Shipment
*/
public function setProvince($province): Shipment
{
if (!$province)
$province = "";
$this->shipment['province'] = $province;
return $this;
}
/**
* @param $country
* @return Shipment
*/
public function setCountry($country): Shipment
{
if (!$country)
$country = "";
$this->shipment['country'] = $country;
return $this;
}
/**
* @param $zipcode
* @return Shipment
*/
public function setZipcode($zipcode): Shipment
{
if (!$zipcode)
$zipcode = "";
$this->shipment['zipcode'] = $zipcode;
return $this;
}
/**
* @param $latitude
* @param $longitude
* @return Shipment
*/
public function setCoords($latitude,$longitude): Shipment
{
$this->shipment['coords'] = [
'lat'=>floatval($latitude),
'lng'=>floatval($longitude)
];
return $this;
}
/**
* @param integer $total_bulk
* @return Shipment
*/
public function setTotalBulk(int $total_bulk): Shipment
{
$this->shipment['total_bulk'] = $total_bulk;
return $this;
}
/**
* @param int $tall
* @param int $width
* @param int $height
* @param int $weight
* @return Shipment
*/
public function addBulk(int $tall,$width,$height,$weight): Shipment
{
$this->bulks[] = [
'tall'=>$tall,
'width'=>$width,
'height'=>$height,
'weight'=>$weight
];
return $this;
}
/**
* @param bool $is_collect
* @return Shipment
*/
public function setIsCollect(bool $is_collect): Shipment
{
$this->shipment['is_collect'] = $is_collect;
return $this;
}
/**
* @param string $external_type
* @return Shipment
*/
public function setExternalReference(string $type,string $value): Shipment
{
$this->shipment['external_type'] = $type;
$this->shipment['external_value'] = $value;
return $this;
}
/**
* @return ShipmentResponse
* @throws \Exception
*/
public function create()
{
$this->shipment['bulk'] = $this->bulks;
$this->setTotalBulk(sizeof($this->bulks));
return $this->sdk->createShipment($this->shipment);
}
/**
* @return Shipment
*/
public function getShipment(): Shipment
{
return $this->shipment;
}
/**
* @param $email
* @return Shipment
*/
public function setReceiverEmail(string $email)
{
$this->shipment['receiver_email'] = $email;
return $this;
}
/**
* @param string $mobile
* @return Shipment
*/
public function setReceiverMobile(string $mobile)
{
$this->shipment['receiver_mobile'] = $mobile;
return $this;
}
}
<?php
include '../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("2835754040");
try {
$drivers = $sdk->getDrivers();
if ($drivers)
{
foreach($drivers as $driver)
{
echo "Driver:#".$driver['fullname'];
}
}
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
namespace LogisticaSdk\tests;
use LogisticaSdk\Logistica;
use PHPUnit\Framework\TestCase;
class ConnectionTest extends TestCase
{
public function testConnection()
{
$sdk = new Logistica();
$sdk->setToken("1234");
$this->assertSame("1234",$sdk->getToken());
}
}
<?php
namespace RimoldSDK;
use \Exception;
/**
* ApiException Class Doc Comment
*
* @category Class
* @package Meli
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class ValidationFailedException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*
* @var mixed
*/
protected $responseBody;
/**
* The HTTP header of the server response.
*
* @var string[]|null
*/
protected $responseHeaders;
/**
* The deserialized response object
*
* @var $responseObject;
*/
protected $responseObject;
private $bag;
/**
* Constructor
*
* @param string $message Error message
* @param int $code HTTP status code
* @param string[]|null $responseHeaders HTTP response header
* @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string
*/
public function __construct($message = "", $bag=[] ,$code = 0, $responseHeaders = [], $responseBody = null)
{
$this->bag = $bag;
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
public function getErrorBag()
{
return $this->bag;
}
/**
* Gets the HTTP response header
*
* @return string[]|null HTTP response header
*/
public function getResponseHeaders()
{
return $this->responseHeaders;
}
/**
* Gets the HTTP body of the server response either as Json or string
*
* @return mixed HTTP body of the server response either as \stdClass or string
*/
public function getResponseBody()
{
return $this->responseBody;
}
/**
* Sets the deseralized response object (during deserialization)
*
* @param mixed $obj Deserialized response object
*
* @return void
*/
public function setResponseObject($obj)
{
$this->responseObject = $obj;
}
/**
* Gets the deseralized response object (during deserialization)
*
* @return mixed the deserialized response object
*/
public function getResponseObject()
{
return $this->responseObject;
}
}
-5
vendor
composer.lock
.idea
Thumbs.db
.DS_Store
{
"name": "01envios/logistics-sdk",
"description": "Logistica SDK",
"type": "library",
"homepage": "https://app.01envios.com",
"license": "MIT",
"prefer-stable": true,
"minimum-stability": "dev",
"keywords": [
"intrasistema",
"php",
"sdk",
"rest",
"api"
],
"authors": [
{
"name": "maximiliano",
"email": "mnek84@gmail.com"
}
],
"require": {
"php": ">=7.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.2.1",
"tightenco/collect": "^8.34"
},
"autoload": {
"psr-4": { "LogisticaSdk\\" : "src/" }
},
"require-dev": {
"phpunit/phpunit": "9"
}
}
# 01ENVIOS SDK
[![Latest Stable Version](https://img.shields.io/packagist/v/intrasistema/logsdk.svg?style=flat-square)](https://packagist.org/packages/01envios/logistics-sdk)
[![Total Downloads](https://img.shields.io/packagist/dt/intrasistema/logsdk.svg?style=flat-square)](https://packagist.org/packages/01envios/logistics-sdk)
Librareria para la gestión de Logistica de 01envios
## Instalación
### Composer
```
$ composer require 01envios/logistics-sdk
```
```json
{
"require": {
"01envios/logistics-sdk": "dev-master"
}
}
```
>Ver la carpeta examples.
<?php
namespace LogisticaSdk;
use \Exception;
/**
* ApiException Class Doc Comment
*
* @category Class
* @package Meli
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class ApiException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*
* @var mixed
*/
protected $responseBody;
/**
* The HTTP header of the server response.
*
* @var string[]|null
*/
protected $responseHeaders;
/**
* The deserialized response object
*
* @var $responseObject;
*/
protected $responseObject;
/**
* Constructor
*
* @param string $message Error message
* @param int $code HTTP status code
* @param string[]|null $responseHeaders HTTP response header
* @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string
*/
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
{
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
/**
* Gets the HTTP response header
*
* @return string[]|null HTTP response header
*/
public function getResponseHeaders()
{
return $this->responseHeaders;
}
/**
* Gets the HTTP body of the server response either as Json or string
*
* @return mixed HTTP body of the server response either as \stdClass or string
*/
public function getResponseBody()
{
return $this->responseBody;
}
/**
* Sets the deseralized response object (during deserialization)
*
* @param mixed $obj Deserialized response object
*
* @return void
*/
public function setResponseObject($obj)
{
$this->responseObject = $obj;
}
/**
* Gets the deseralized response object (during deserialization)
*
* @return mixed the deserialized response object
*/
public function getResponseObject()
{
return $this->responseObject;
}
}
<?php
namespace LogisticaSdk;
class Auth
{
}
<?php
namespace LogisticaSdk;
use \Exception;
/**
* ApiException Class Doc Comment
*
* @category Class
* @package Meli
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class AuthException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*
* @var mixed
*/
protected $responseBody;
/**
* The HTTP header of the server response.
*
* @var string[]|null
*/
protected $responseHeaders;
/**
* The deserialized response object
*
* @var $responseObject;
*/
protected $responseObject;
/**
* Constructor
*
* @param string $message Error message
* @param int $code HTTP status code
* @param string[]|null $responseHeaders HTTP response header
* @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string
*/
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
{
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
/**
* Gets the HTTP response header
*
* @return string[]|null HTTP response header
*/
public function getResponseHeaders()
{
return $this->responseHeaders;
}
/**
* Gets the HTTP body of the server response either as Json or string
*
* @return mixed HTTP body of the server response either as \stdClass or string
*/
public function getResponseBody()
{
return $this->responseBody;
}
/**
* Sets the deseralized response object (during deserialization)
*
* @param mixed $obj Deserialized response object
*
* @return void
*/
public function setResponseObject($obj)
{
$this->responseObject = $obj;
}
/**
* Gets the deseralized response object (during deserialization)
*
* @return mixed the deserialized response object
*/
public function getResponseObject()
{
return $this->responseObject;
}
}
<?php
include '../../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("666");
try {
$info = [
"external_type" => "ML",
"external_value" => "1002",
"client_id" => 2,
"country" => "Argentina",
"province" => "BS AS",
"locality" => "Padua",
"address_type" => "RESIDENCIAL",
"address" => "gaona 1584",
"zipcode" => 1425,
"bulk" => [
[
"sku_id" => null,
"weight" => 10000,
"height" => 20,
"width" => 20,
"tall" => 20
]
],
"comments" => "",
"coords_lat" => "-59.23330",
"coords_lng" => "-59.23400",
"owner_fullname" => "MAxi",
"auth_fullname" => "",
"delivery_time" => "9:00",
"email" => "mnek84@gmail.com",
"mobile" => "123",
"is_collect" => 1,
"logistic_type" => 1,
"service_type" => 1,
"warehouse_origin" => 1
];
$shipment = new \LogisticaSdk\Shipment($sdk);
$shipment->addBulk(1, 1, 1, 1);
$shipment
->setCountry("ARGENTINA")
->setProvince("BUENOS AIRES")
->setLocality("MERLO")
->setAddressType("RESIDENTIAL")
->setAddress("GAONA 1584")
->setAddressComments("PAREDON NEGRO")
->setZipcode("1718")
->setCoords("","")
->setOwnerFullname("SAMANTA EMMANUELLI")
->setAuthFullname("SAMANTA EMMANUELLI")
->setDeliveryTime("9 a 18")
->setEmail("")
->setPhone("")
->setExternalReference("meli","1234")
->setIsCollect(1)
->setLogisticTypeId(1)
->setServiceTypeId(1);
$createdShipment = $shipment->setWarehouseOriginId(1)->create();
print "Tracking Number: ".($createdShipment->getTrackingNumber());
foreach($createdShipment->history as $history)
{
dd($history);
}
} catch (\LogisticaSdk\ValidationFailedException $e) {
foreach($e->getErrorBag() as $error)
{
print $error[0].chr(13).chr(10);
}
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("666");
try {
$createdShipment = $sdk->getShipment("2619872706");
print $createdShipment->current_status['name'];
foreach($createdShipment->history as $history)
{
print "ESTADOS: ".$history['name'];
}
//$createdShipment->makeLabelPrinted();
$createdShipment->fullfiled();
dd($createdShipment->history);
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("2835754040");
try {
$tracking = 114626706437;
// Información de un Tracking
$info = $sdk->get("driver/settlements",[
'from'=>'2021-05-12',
'to'=>'2021-05-13',
'zones'=>'0',
'driver'=>'21',
'status'=>[1,2,3]
]);
$info = $sdk->put("shipments/288741353957",[
"client_id"=> 2,
"status"=>18,
"comment"=>"Prueba de cambio!"
]);
var_dump($info['history']);
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("2835754040");
try {
$shipping = $sdk->get("shipping",['iqr'=>true,'shipping'=>"40559180982"]);
$tracking = $shipping['tracking_number'];
$info = $sdk->put("shipments/".$tracking,['status'=>10,'client_id'=>0,'comment'=>'']);
die("cambiado correctamente");
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("666");
try {
#$user = $sdk->me();
#print "Usuario Logoneado: ".$user->name;
$drivers = $sdk->getDrivers();
foreach ($drivers as $driver)
{
dd($driver['name']);
}
} catch (\LogisticaSdk\AuthException $e) {
die("Fallo al autenticar");
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("2835754040");
try {
$tracking = 114626706437;
// Información de un Tracking
$info = $sdk->get("shipping",['shipping'=>'114626706437','history'=>1,'order'=>'LATEST']);
print $info['owner_fullname'];
var_dump($info['history']);
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
include '../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("2835754040");
try {
$shipmentHistory = $sdk->traceShipment(34794766800);
if ($shipmentHistory)
{
foreach($shipmentHistory as $info)
{
echo "Status:".$info['status']." - ".( ($info['status_info'])?$info['status_info']['name']:'Unknown' ).chr(13).chr(10);
}
}
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
namespace LogisticaSdk;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request;
use LogisticaSdk\Responses\ShipmentResponse;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Tightenco\Collect\Support\Collection;
class Logistica
{
#const API = 'https://logistics-api.intrasistema.com/v1/';
const API = 'http://01envios.local/api/';
private $token;
private function getClient()
{
$handler = HandlerStack::create();
$extraParams = [
'Authorization'=>'Bearer '.$this->token
];
$handler->push(Middleware::mapRequest(function (RequestInterface $request) use ($extraParams) {
$uri = $request->getUri();
$headers = $request->getHeaders();
$headers['Authorization'] = $extraParams['Authorization'];
return new Request(
$request->getMethod(),
$uri,
$headers,
$request->getBody(),
$request->getProtocolVersion()
);
}));
return new Client([
'base_uri' => self::API,
'handler' => $handler,
'exceptions' => false,
]);
}
private function getResponse(ResponseInterface $response)
{
$body = $response->getBody()->getContents();
$data = json_decode((string) $body,true);
//var_dump($data);
if ($response->getStatusCode()==200)
{
if (!isset($data['status']))
{
throw new ApiException("Bad Response");
}
if ($data['status']==1)
{
if (isset($data['data']))
{
if (count($data['data']) == count($data['data'], COUNT_RECURSIVE))
{
return Collection::make([$data['data']]);
}else{
return Collection::make($data['data']);
}
}else{
return true;
}
}else{
if ($data['error']=="VALIDATION_FAILED")
{
throw new ValidationFailedException($data['error'],$data['errors']);
}else{
throw new ApiException($data['error']);
}
}
}else{
if ($response->getStatusCode()==401)
{
throw new AuthException($data['error']);
}else{
throw new ApiException($data['error']);
}
}
}
/**
* @param $search
* @param $page
* @param $perPage
* @return false|mixed
* @throws ApiException
*/
public function getDrivers($search=null,$page=null,$perPage=null)
{
$params = [];
if ($search)
$params['search'] = $search;
if ($page)
{
$params['page'] = $page;
$params['limit'] = ($perPage)?$perPage:10;
}
return $this->get("driver",$params);
}
public function findShipping($trackingNumber)
{
$client = $this->getClient();
$response = $client->get('driver', [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
]);
if ($response->getStatusCode()==200)
{
$body = $response->getBody();
$data = json_decode((string) $body,true);
if ($data['status']==1)
{
return $data['data'];
}else{
throw new ApiException($data['error']);
}
}else{
return false;
}
}
public function setToken(string $string)
{
$this->token = $string;
}
/**
* @param $tracking
* @return mixed
* @throws ApiException
*/
public function traceShipment($tracking)
{
$client = $this->getClient();
$response = $client->get('shipments/'.$tracking.'/history', [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
]);
return $this->getResponse($response);
}
/**
* @param $ep
* @param null $params
* @return mixed
* @throws ApiException
*/
public function get($ep,$params=null)
{
$client = $this->getClient();
$defaultData = [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
];
if ($params)
$defaultData['query'] = $params;
$response = $client->get($ep, $defaultData);
return $this->getResponse($response);
}
/**
* @param $ep
* @param null $params
* @return mixed
* @throws ApiException
*/
public function post($ep,$params=null)
{
$client = $this->getClient();
$defaultData = [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
];
if ($params)
$defaultData['query'] = $params;
$response = $client->post($ep, $defaultData);
return $this->getResponse($response);
}
/**
* @param $ep
* @param null $params
* @return mixed
* @throws ApiException
*/
public function put($ep,$params=null)
{
$client = $this->getClient();
$defaultData = [
'debug' => FALSE,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
];
if ($params)
$defaultData['query'] = $params;
$response = $client->put($ep, $defaultData);
return $this->getResponse($response);
}
public function getShippingList($tracking=null, $driver=null, $statuses=null,$from=null,$to=null, $paginated=null, $page=null,$clientId=null,$orderBy="id",$orderType='ASC')
{
return $this->get("shipments",[
'search'=>$tracking,
'client_id'=>$clientId,
'driver'=>$driver,
'statuses'=>$statuses,
'from'=>$from,
'to'=>$to,
'limit'=>$paginated,
'page'=>$page,
'orderby'=>$orderBy,
'ordertype'=>$orderType,
]);
}
public function getToken()
{
return $this->token;
}
public function me()
{
$userCollection = $this->get('user');
return ((object)$userCollection->first());
}
/**
* @param $shipment
* @return ShipmentResponse
* @throws ApiException
*/
public function createShipment($shipment)
{
return ShipmentResponse::createFromRequest($this,$this->post("shipment",$shipment));
}
/**
* @param $shipment
* @return ShipmentResponse
* @throws ApiException
*/
public function getShipment($tracking)
{
return ShipmentResponse::createFromRequest($this,$this->get("shipment/".$tracking));
}
}
<?php
namespace LogisticaSdk\Responses;
use LogisticaSdk\Logistica;
class ShipmentResponse
{
private $shipment;
/**
* @var Logistica
*/
private $sdk;
/**
* @param $shipment
*/
public function __construct($shipment,$sdk)
{
$this->sdk = $sdk;
$this->shipment = $shipment;
}
public static function createFromRequest($sdk,$post)
{
return new self($post,$sdk);
}
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}else{
if (isset($this->shipment[$property])){
return $this->shipment[$property];
}
}
}
public function getTrackingNumber()
{
return $this->tracking;
}
public function makeLabelPrinted()
{
$this->shipment = $this->sdk->post("shipment/".$this->_id."/status/201");
}
public function fullfiled()
{
$this->shipment = $this->sdk->post("shipment/".$this->_id."/status/202");
}
}
<?php
namespace LogisticaSdk;
use LogisticaSdk\Responses\ShipmentResponse;
class Shipment
{
private $bulks;
private $sdk;
private $shipment;
/**
* @param Logistica $sdk
*/
public function __construct(Logistica $sdk)
{
$this->sdk = $sdk;
}
/**
* @param string $service_type_id
*/
public function setServiceTypeId(string $service_type_id): Shipment
{
$this->shipment['service_type_id'] = $service_type_id;
return $this;
}
/**
* @param string $owner_fullname
*/
public function setOwnerFullname(string $owner_fullname): Shipment
{
$this->shipment['owner_fullname'] = $owner_fullname;
return $this;
}
/**
* @param string $auth_fullname
*/
public function setAuthFullname(string $auth_fullname): Shipment
{
$this->shipment['auth_fullname'] = $auth_fullname;
return $this;
}
/**
* @param string $logistic_type_id
*/
public function setLogisticTypeId(string $logistic_type_id): Shipment
{
$this->shipment['logistic_type_id'] = $logistic_type_id;
return $this;
}
/**
* @param string $email
*/
public function setEmail(string $email): Shipment
{
$this->shipment['email'] = $email;
return $this;
}
/**
* @param string $address_type
* @return Shipment
*/
public function setAddressType($address_type): Shipment
{
$this->shipment['address_type'] = $address_type;
return $this;
}
/**
* @param string $delivery_time
* @return Shipment
*/
public function setDeliveryTime(string $delivery_time): Shipment
{
$this->shipment['delivery_time'] = $delivery_time;
return $this;
}
/**
* @param string $address
* @return Shipment
*/
public function setAddress(string $address): Shipment
{
$this->shipment['address'] = $address;
return $this;
}
/**
* @param $address_comments
* @return Shipment
*/
public function setAddressComments($address_comments): Shipment
{
if (!$address_comments)
$address_comments = "";
$this->shipment['address_comments'] = $address_comments;
return $this;
}
/**
* @param $locality
* @return Shipment
*/
public function setLocality($locality): Shipment
{
if(!$locality)
$locality="";
$this->shipment['locality'] = $locality;
return $this;
}
/**
* @param $province
* @return Shipment
*/
public function setProvince($province): Shipment
{
if (!$province)
$province = "";
$this->shipment['province'] = $province;
return $this;
}
/**
* @param $country
* @return Shipment
*/
public function setCountry($country): Shipment
{
if (!$country)
$country = "";
$this->shipment['country'] = $country;
return $this;
}
/**
* @param $zipcode
* @return Shipment
*/
public function setZipcode($zipcode): Shipment
{
if (!$zipcode)
$zipcode = "";
$this->shipment['zipcode'] = $zipcode;
return $this;
}
/**
* @param $latitude
* @param $longitude
* @return Shipment
*/
public function setCoords($latitude,$longitude): Shipment
{
$this->shipment['coords'] = [
'lat'=>floatval($latitude),
'lng'=>floatval($longitude)
];
return $this;
}
/**
* @param $phone
* @return Shipment
*/
public function setPhone($phone): Shipment
{
if (!$phone)
$phone = "";
$this->shipment['phone'] = $phone;
return $this;
}
/**
* @param integer $total_bulk
* @return Shipment
*/
public function setTotalBulk(int $total_bulk): Shipment
{
$this->shipment['total_bulk'] = $total_bulk;
return $this;
}
/**
* @param int $tall
* @param int $width
* @param int $height
* @param int $weight
* @return Shipment
*/
public function addBulk(int $tall,$width,$height,$weight): Shipment
{
$this->bulks[] = [
'tall'=>$tall,
'width'=>$width,
'height'=>$height,
'weight'=>$weight
];
return $this;
}
/**
* @param string $warehouse_origin_id
* @return Shipment
*/
public function setWarehouseOriginId(string $warehouse_origin_id): Shipment
{
$this->shipment['warehouse_origin_id'] = $warehouse_origin_id;
return $this;
}
/**
* @param bool $is_collect
* @return Shipment
*/
public function setIsCollect(bool $is_collect): Shipment
{
$this->shipment['is_collect'] = $is_collect;
return $this;
}
/**
* @param string $external_type
* @return Shipment
*/
public function setExternalReference(string $type,string $value): Shipment
{
$this->shipment['external_type'] = $type;
$this->shipment['external_value'] = $value;
return $this;
}
/**
* @return ShipmentResponse
* @throws \Exception
*/
public function create()
{
$this->shipment['bulk'] = $this->bulks;
$this->setTotalBulk(sizeof($this->bulks));
return $this->sdk->createShipment($this->shipment);
}
/**
* @return Shipment
*/
public function getShipment(): Shipment
{
return $this->shipment;
}
}
<?php
include '../vendor/autoload.php';
$sdk = new \LogisticaSdk\Logistica();
$sdk->setToken("2835754040");
try {
$drivers = $sdk->getDrivers();
if ($drivers)
{
foreach($drivers as $driver)
{
echo "Driver:#".$driver['fullname'];
}
}
} catch (\LogisticaSdk\ApiException $e) {
die($e->getMessage());
} catch (\Exception $e) {
die($e->getMessage());
}
<?php
namespace LogisticaSdk\tests;
use LogisticaSdk\Logistica;
use PHPUnit\Framework\TestCase;
class ConnectionTest extends TestCase
{
public function testConnection()
{
$sdk = new Logistica();
$sdk->setToken("1234");
$this->assertSame("1234",$sdk->getToken());
}
}
<?php
namespace LogisticaSdk;
use \Exception;
/**
* ApiException Class Doc Comment
*
* @category Class
* @package Meli
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class ValidationFailedException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*
* @var mixed
*/
protected $responseBody;
/**
* The HTTP header of the server response.
*
* @var string[]|null
*/
protected $responseHeaders;
/**
* The deserialized response object
*
* @var $responseObject;
*/
protected $responseObject;
private $bag;
/**
* Constructor
*
* @param string $message Error message
* @param int $code HTTP status code
* @param string[]|null $responseHeaders HTTP response header
* @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string
*/
public function __construct($message = "", $bag=[] ,$code = 0, $responseHeaders = [], $responseBody = null)
{
$this->bag = $bag;
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
public function getErrorBag()
{
return $this->bag;
}
/**
* Gets the HTTP response header
*
* @return string[]|null HTTP response header
*/
public function getResponseHeaders()
{
return $this->responseHeaders;
}
/**
* Gets the HTTP body of the server response either as Json or string
*
* @return mixed HTTP body of the server response either as \stdClass or string
*/
public function getResponseBody()
{
return $this->responseBody;
}
/**
* Sets the deseralized response object (during deserialization)
*
* @param mixed $obj Deserialized response object
*
* @return void
*/
public function setResponseObject($obj)
{
$this->responseObject = $obj;
}
/**
* Gets the deseralized response object (during deserialization)
*
* @return mixed the deserialized response object
*/
public function getResponseObject()
{
return $this->responseObject;
}
}