Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Apis/Exceptions/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace Flagship\Apis\Exceptions;

class ApiException extends \Exception{
public function __construct(string $message, int $code=0){
class ApiException extends \Exception
{

public function __construct(string $message, int $code=0)
{
parent::__construct($message,$code);
}

}
4 changes: 4 additions & 0 deletions Apis/Requests/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

abstract class ApiRequest{

protected $headers = [];
protected $filters = [];
protected $url;

public function setStoreName(string $storeName){
$this->setHeader("X-Store-Name",$storeName);
return $this;
Expand Down
6 changes: 3 additions & 3 deletions Shipping/Collections/AvailableServicesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getStandardServices() : AvailableServicesCollection {
});

if($services->isEmpty()){
throw new AvailableServicesException('No services for courier - '.$courier);
throw new AvailableServicesException('No standard services available');
}

return $services;
Expand All @@ -48,7 +48,7 @@ public function getOvernightServices() : AvailableServicesCollection {
});

if($services->isEmpty()){
throw new AvailableServicesException('No services for courier - '.$courier);
throw new AvailableServicesException('No overnight services available');
}

return $services;
Expand All @@ -60,7 +60,7 @@ public function getExpressServices() : AvailableServicesCollection {
});

if($services->isEmpty()){
throw new AvailableServicesException('No services for courier - '.$courier);
throw new AvailableServicesException('No express services available');
}

return $services;
Expand Down
12 changes: 6 additions & 6 deletions Shipping/Flagship.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

class Flagship{

public function __construct(string $apiToken, string $apiUrl, string $flagshipFor='', string $version=''){
$this->apiUrl = $apiUrl;
$this->apiToken = $apiToken;
$this->flagshipFor = $flagshipFor;
$this->version = $version;
}
public function __construct(
protected string $apiToken,
protected string $apiUrl,
protected string $flagshipFor='',
protected string $version=''
){}

public function availableServicesRequest() : AvailableServicesRequest {
$availableServicesRequest = new AvailableServicesRequest($this->apiToken,$this->apiUrl,$this->flagshipFor,$this->version);
Expand Down
4 changes: 2 additions & 2 deletions Shipping/Objects/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
namespace Flagship\Shipping\Objects;

class Address{
public function __construct(\stdClass $address){
$this->address = $address;
public function __construct(public \stdClass $address)
{
}

public function getId() : int {
Expand Down
4 changes: 2 additions & 2 deletions Shipping/Objects/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class Manifest{

public function __construct(\stdClass $manifest){
$this->manifest = $manifest;
public function __construct(public \stdClass $manifest)
{
}

public function getName() : string {
Expand Down
4 changes: 2 additions & 2 deletions Shipping/Objects/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Flagship\Shipping\Objects;

class Package{
public function __construct(array $package){
$this->package = $package;
public function __construct(public array $package)
{
}
}
4 changes: 2 additions & 2 deletions Shipping/Objects/Packing.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Flagship\Shipping\Objects;

class Packing{
public function __construct(\stdClass $packing){
$this->packing = $packing;
public function __construct(public \stdClass $packing)
{
}

public function getBoxModel() : string {
Expand Down
5 changes: 3 additions & 2 deletions Shipping/Objects/Pickup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class Pickup{

public function __construct(\stdClass $pickup){
$this->pickup = $pickup;
public function __construct(
public \stdClass $pickup)
{
}

public function getId() : int {
Expand Down
3 changes: 1 addition & 2 deletions Shipping/Objects/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

class Rate
{
public function __construct( \stdClass $rate )
public function __construct(public \stdClass $rate )
{
$this->rate = $rate;
}

public function getTotal() : float
Expand Down
3 changes: 1 addition & 2 deletions Shipping/Objects/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

class Service
{
public function __construct( \stdClass $service )
public function __construct( public \stdClass $service )
{
$this->service = $service;
}

public function getCode() : string {
Expand Down
4 changes: 2 additions & 2 deletions Shipping/Objects/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class Shipment{

public function __construct(\stdclass $shipment){
$this->shipment = $shipment;
public function __construct(public \stdclass $shipment)
{
}

public function getId() : int {
Expand Down
4 changes: 2 additions & 2 deletions Shipping/Objects/TrackShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class TrackShipment {

public function __construct(?\stdClass $trackShipment){
$this->trackShipment = $trackShipment;
public function __construct(public ?\stdClass $trackShipment)
{
}

public function getCurrentStatus() : string {
Expand Down
17 changes: 11 additions & 6 deletions Shipping/Requests/AssociateShipmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
namespace Flagship\Shipping\Requests;
use Flagship\Apis\Requests\ApiRequest;
use Flagship\Shipping\Exceptions\AssociateShipmentException;
use Flagship\Apis\Exception\ApiException;
use Flagship\Apis\Exceptions\ApiException;

class AssociateShipmentRequest extends ApiRequest{
public function __construct(string $apiToken, string $baseUrl, int $manifestId, array $payload,string $flagshipFor, string $version){
protected $responseCode;
protected $apiUrl;

$this->apiToken = $apiToken;
public function __construct(
protected string $apiToken,
string $baseUrl,
int $manifestId,
protected array $payload,
protected string $flagshipFor,
protected string $version
){
$this->apiUrl = $baseUrl.'/ship/edhl/associate/'.$manifestId;
$this->payload = $payload;
$this->flagshipFor = $flagshipFor;
$this->version = $version;
}

public function execute() : bool {
Expand Down
16 changes: 11 additions & 5 deletions Shipping/Requests/AssociateToDepotRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

class AssociateToDepotRequest extends ApiRequest{

public function __construct(string $apiToken,string $baseUrl,int $manifestId,array $payload,string $flagshipFor,string $version){
$this->apiToken = $apiToken;
protected $apiUrl;
protected $responseCode;

public function __construct(
protected string $apiToken,
string $baseUrl,
int $manifestId,
protected array $payload,
protected string $flagshipFor,
protected string $version
){
$this->apiUrl = $baseUrl.'/ship/edhl/to-depot/'.$manifestId;
$this->payload = $payload;
$this->flagshipFor = $flagshipFor;
$this->version = $version;
}

public function execute() : bool {
Expand Down
18 changes: 11 additions & 7 deletions Shipping/Requests/AvailableServicesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
use Flagship\Shipping\Collections\AvailableServicesCollection;

class AvailableServicesRequest extends ApiRequest{

protected $responseCode;

public function __construct(string $token,string $baseUrl,string $flagshipFor,string $version){
$this->token = $token;
$this->url = $baseUrl.'/ship/available_services';
$this->flagshipFor = $flagshipFor;
$this->version = $version;
protected $apiUrl;

public function __construct(
protected string $apiToken,
string $baseUrl,
protected string $flagshipFor,
protected string $version
){
$this->apiUrl = $baseUrl.'/ship/available_services';
}

public function execute() : AvailableServicesCollection {
try{
$response = $this->api_request($this->url,[],$this->token,'GET',10,$this->flagshipFor,$this->version);
$response = $this->api_request($this->apiUrl,[],$this->apiToken,'GET',10,$this->flagshipFor,$this->version);
$availableServicesArray = $this->createArrayOfServices($response);
$availableServicesCollection = new AvailableServicesCollection();
$availableServicesCollection->importServices($availableServicesArray);
Expand Down
14 changes: 10 additions & 4 deletions Shipping/Requests/CancelManifestByIdRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
use Flagship\Shipping\Exceptions\CancelManifestByIdException;

class CancelManifestByIdRequest extends ApiRequest{

protected $apiUrl;
protected $responseCode;

public function __construct(string $apiToken,string $baseUrl,int $manifestId,string $flagshipFor,string $version){
$this->apiToken = $apiToken;
public function __construct(
protected string $apiToken,
protected string $baseUrl,
int $manifestId,
protected string $flagshipFor,
protected string $version
){
$this->apiUrl = $baseUrl.'/ship/edhl/'.$manifestId;
$this->flagshipFor = $flagshipFor;
$this->version = $version;
}

public function execute() : bool {
Expand Down
19 changes: 13 additions & 6 deletions Shipping/Requests/CancelPickupRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
use Flagship\Shipping\Exceptions\CancelPickupException;

class CancelPickupRequest extends ApiRequest{
public function __construct(string $baseUrl,string $token,int $id, string $flagshipFor, string $version){
$this->url = $baseUrl.'/pickups/'.$id;
$this->token = $token;
$this->flagshipFor = $flagshipFor;
$this->version = $version;

protected $apiUrl;
protected $responseCode;

public function __construct(
string $baseUrl,
protected string $apiToken,
int $id,
protected string $flagshipFor,
protected string $version
){
$this->apiUrl = $baseUrl.'/pickups/'.$id;
}

public function execute() : bool {
try{
$cancelPickupRequest = $this->api_request($this->url,[],$this->token,'DELETE',30,$this->flagshipFor,$this->version);
$cancelPickupRequest = $this->api_request($this->apiUrl,[],$this->apiToken,'DELETE',30,$this->flagshipFor,$this->version);
$this->responseCode = $cancelPickupRequest["httpcode"];
return $cancelPickupRequest["httpcode"] == 200 ? TRUE : FALSE;
}
Expand Down
18 changes: 12 additions & 6 deletions Shipping/Requests/CancelShipmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
use Flagship\Shipping\Exceptions\CancelShipmentException;

class CancelShipmentRequest extends ApiRequest{
public function __construct(string $baseUrl,string $token, int $id, string $flagshipFor, string $version){

$this->url = $baseUrl.'/ship/shipments/'.$id;
$this->token = $token;
$this->flagshipFor = $flagshipFor;
$this->version = $version;
protected $apiUrl;
protected $responseCode;

public function __construct(
protected string $baseUrl,
protected string $apiToken,
int $id,
protected string $flagshipFor,
protected string $version
){
$this->apiUrl = $baseUrl.'/ship/shipments/'.$id;
}

public function execute() : bool {
try{
$cancelShipmentRequest = $this->api_request($this->url,[],$this->token,'DELETE',0,$this->flagshipFor,$this->version);
$cancelShipmentRequest = $this->api_request($this->apiUrl,[],$this->apiToken,'DELETE',0,$this->flagshipFor,$this->version);
$this->responseCode = $cancelShipmentRequest["httpcode"];
return $cancelShipmentRequest["httpcode"] ==200 ? TRUE : FALSE;
}
Expand Down
15 changes: 11 additions & 4 deletions Shipping/Requests/ConfirmManifestByIdRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

class ConfirmManifestByIdRequest extends ApiRequest{

public function __construct(string $token,string $baseUrl,int $manifestId,string $flagshipFor,string $version){
$this->apiToken = $token;
protected $apiUrl;
protected $responseCode;

public function __construct(
protected string $apiToken,
string $baseUrl,
int $manifestId,
protected string $flagshipFor,
protected string $version
){
$this->apiUrl = $baseUrl.'/ship/edhl/close/'.$manifestId;
$this->flagshipFor = $flagshipFor;
$this->version = $version;

}

public function execute() : Manifest {
Expand Down
24 changes: 15 additions & 9 deletions Shipping/Requests/ConfirmShipmentByIdRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
use Flagship\Shipping\Exceptions\ConfirmShipmentByIdException;

class ConfirmShipmentByIdRequest extends ApiRequest{

protected $responseCode;
public function __construct(string $baseUrl, string $token, int $id, string $flagshipFor, string $version){
$this->url = $baseUrl.'/ship/'.$id.'/confirm';
$this->token = $token;
$this->flagshipFor = $flagshipFor;
$this->version = $version;
protected $apiUrl;

public function __construct(
protected string $baseUrl,
protected string $apiToken,
int $id,
protected string $flagshipFor,
protected string $version
){
$this->apiUrl = $baseUrl.'/ship/'.$id.'/confirm';
}

public function execute() : Shipment {
try{
$confirmShipmentRequest = $this->api_request($this->url,[],$this->token,'PUT',30,$this->flagshipFor,$this->version);

$confirmShipmentObject = count((array)$confirmShipmentRequest["response"]) == 0 ? new \stdClass() : $confirmShipmentRequest["response"]->content;

$confirmShipmentRequest = $this->api_request
($this->apiUrl,[],$this->apiToken,'PUT',30,$this->flagshipFor,$this->version);
$confirmShipmentObject = count((array)$confirmShipmentRequest["response"]) == 0
? new \stdClass() : $confirmShipmentRequest["response"]->content;
$confirmShipment = new Shipment($confirmShipmentObject);
$this->responseCode = $confirmShipmentRequest["httpcode"];
return $confirmShipment;
Expand Down
Loading