Skip to content
Draft
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ FedEx Rest API documentation https://developer.fedex.com/api/en-us/get-started.h
- [ ] Postal Code Validation API
- [x] Rate Quotes API
- [ ] Service Availability API
- [ ] Freight LTL API
- [ ] Rate Freight LTL ([docs](https://developer.fedex.com/api/en-us/catalog/ltl-freight/v1/docs.html#operation/Freight%20RateQuote))
- [ ] Ship Freight LTL ([docs](https://developer.fedex.com/api/en-us/catalog/ltl-freight/v1/docs.html#operation/Freight%20Shipment))
- [X] Check Freight LTL Pickup Availability ([docs](https://developer.fedex.com/api/en-us/catalog/ltl-freight/v1/docs.html#operation/Check%20Freight%20Pickup%20Availability))
- [X] Create Freight LTL Pickup ([docs](https://developer.fedex.com/api/en-us/catalog/ltl-freight/v1/docs.html#operation/Create%20Freight%20Pickup))
- [x] Cancel Freight LTL Pickup ([docs](https://developer.fedex.com/api/en-us/catalog/ltl-freight/v1/docs.html#operation/Cancel%20Freight%20Pickup))

### Other
- [x] [oAuth authorization](#authorization)
Expand Down
148 changes: 148 additions & 0 deletions src/FedexRest/Services/FreightLTL/CancelFreightLTLPickup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

namespace FedexRest\Services\FreightLTL;

use FedexRest\Services\AbstractRequest;
use FedexRest\Services\FreightLTL\Exceptions\MissingReasonException;
use FedexRest\Services\FreightLTL\Exceptions\MissingContactNameException;
use FedexRest\Services\FreightLTL\Exceptions\MissingAssociatedAccountNumberException;
use FedexRest\Services\FreightLTL\Exceptions\MissingPickupConfirmationCodeException;

class CancelFreightLTLPickup extends AbstractRequest
{
protected string $associatedAccountNumber = '';
protected string $pickupConfirmationCode = '';
protected ?string $remarks = null;
protected string $reason = '';
protected string $contactName = '';
protected ?string $scheduledDate = null;

public function setApiEndpoint(): string
{
return '/pickup/v1/freight/pickups/cancel/';
}

/**
* @param string $associatedAccountNumber
* @return $this
*/
public function setAssociatedAccountNumber(string $associatedAccountNumber): CancelFreightLTLPickup
{
$this->associatedAccountNumber = $associatedAccountNumber;
return $this;
}

/**
* @param string $pickupConfirmationNumber
* @return $this
*/
public function setPickupConfirmationCode(string $pickupConfirmationCode): CancelFreightLTLPickup
{
$this->pickupConfirmationCode = $pickupConfirmationCode;
return $this;
}

/**
* @param string $remarks
* @return $this
*/
public function setRemarks(string $remarks): CancelFreightLTLPickup
{
$this->remarks = $remarks;
return $this;
}

/**
* @param string $reason
* @return $this
*/
public function setReason(string $reason): CancelFreightLTLPickup
{
$this->reason = $reason;
return $this;
}

/**
* @param string $contactName
* @return $this
*/
public function setContactName(string $contactName): CancelFreightLTLPickup
{
$this->contactName = $contactName;
return $this;
}

/**
* @param string $scheduledDate
* @return $this
*/
public function setScheduledDate(string $scheduledDate): CancelFreightLTLPickup
{
$this->scheduledDate = $scheduledDate;
return $this;
}

public function prepare(): array
{
$data = [
'associatedAccountNumber' => [
'value' => $this->associatedAccountNumber
],
'pickupConfirmationCode' => $this->pickupConfirmationCode,
'reason' => $this->reason,
'contactName' => $this->contactName,
];

if(!empty($this->remarks)){
$data['remarks'] = $this->remarks;
}

if(!empty($this->scheduledDate)){
$data['scheduledDate'] = $this->scheduledDate;
}

return $data;
}

/**
* @throws MissingAssociatedAccountNumberException
* @throws MissingPickupConfirmationCodeException
* @throws MissingReasonException
* @throws MissingContactNameException
* @throws GuzzleException
*/
public function request()
{
parent::request();

if(empty($this->associatedAccountNumber)){
throw new MissingAssociatedAccountNumberException('Associated Account Number is required.');
}

if(empty($this->pickupConfirmationCode)){
throw new MissingPickupConfirmationCodeException('Pickup Confirmation Number is required.');
}

if(empty($this->reason)){
throw new MissingReasonException('Reason is required.');
}

if(empty($this->contactName)){
throw new MissingContactNameException('Contact Name is required.');
}


try {
$query = $this->http_client->put($this->getApiUri($this->api_endpoint), [
'json' => $this->prepare(),
'http_errors' => false,
]);
return ($this->raw === true) ? $query : json_decode($query->getBody()->getContents());
} catch (\Exception $e) {
return $e->getMessage();
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
<?php

namespace FedexRest\Services\FreightLTL;

use FedexRest\Entity\Weight;
use FedexRest\Entity\Address;
use FedexRest\Entity\Dimensions;
use FedexRest\Services\AbstractRequest;
use FedexRest\Services\FreightLTL\Entity\FreightDirectDetail;
use FedexRest\Services\FreightLTL\Exceptions\MissingFreightPickupDetailException;

class CheckFreightLTLPickupAvailability extends AbstractRequest
{
protected ?Address $pickupAddress = null;
protected ?string $packageReadyTime = null;
protected ?string $customerCloseTime = null;
protected ?string $serviceType = null;
protected ?Weight $weight = null;
protected ?string $packagingType = null;
protected ?Dimensions $dimensions = null;
protected ?string $freightGuaranteeTime = null;
protected ?FreightDirectDetail $freightDirectDetail = null;
protected ?array $specialServiceTypes = null;
protected ?string $dispatchDate = null;
protected ?int $numberOfBusinessDays = null;

public function setApiEndpoint(): string
{
return '/pickup/v1/freight/pickups/availabilities';
}

/**
* @param Address|null $pickupAddress
* @return CheckFreightLTLPickupAvailability
*/
public function setPickupAddress(?Address $pickupAddress): CheckFreightLTLPickupAvailability
{
$this->pickupAddress = $pickupAddress;
return $this;
}

/**
* @param string|null $packageReadyTime
* @return CheckFreightLTLPickupAvailability
*/
public function setPackageReadyTime(?string $packageReadyTime): CheckFreightLTLPickupAvailability
{
$this->packageReadyTime = $packageReadyTime;
return $this;
}

/**
* @param string|null $customerCloseTime
* @return CheckFreightLTLPickupAvailability
*/
public function setCustomerCloseTime(?string $customerCloseTime): CheckFreightLTLPickupAvailability
{
$this->customerCloseTime = $customerCloseTime;
return $this;
}

/**
* @param string|null $ServiceType
* @return CheckFreightLTLPickupAvailability
*/
public function setServiceType(?string $serviceType): CheckFreightLTLPickupAvailability
{
$this->serviceType = $serviceType;
return $this;
}

/**
* @param Weight|null $weight
* @return CheckFreightLTLPickupAvailability
*/
public function setWeight(?Weight $weight): CheckFreightLTLPickupAvailability
{
$this->weight = $weight;
return $this;
}

/**
* @param string|null $packagingType
* @return CheckFreightLTLPickupAvailability
*/
public function setPackagingType(?string $packagingType): CheckFreightLTLPickupAvailability
{
$this->packagingType = $packagingType;
return $this;
}

/**
* @param Dimensions|null $dimensions
* @return CheckFreightLTLPickupAvailability
*/
public function setDimensions(?Dimensions $dimensions): CheckFreightLTLPickupAvailability
{
$this->dimensions = $dimensions;
return $this;
}

/**
* @param string|null $freightGuaranteeTime
* @return CheckFreightLTLPickupAvailability
*/
public function setFreightGuaranteeTime(?string $freightGuaranteeTime): CheckFreightLTLPickupAvailability
{
$this->freightGuaranteeTime = $freightGuaranteeTime;
return $this;
}

/**
* @param FreightDirectDetail|null $freightDirectDetail
* @return CheckFreightLTLPickupAvailability
*/
public function setFreightDirectDetail(?FreightDirectDetail $freightDirectDetail): CheckFreightLTLPickupAvailability
{
$this->freightDirectDetail = $freightDirectDetail;
return $this;
}

/**
* @param array|null $specialServiceTypes
* @return CheckFreightLTLPickupAvailability
*/
public function setSpecialServiceTypes(?string ...$specialServiceTypes): CheckFreightLTLPickupAvailability
{
$this->specialServiceTypes = $specialServiceTypes;
return $this;
}

/**
* @param string|null $dispatchDate
* @return CheckFreightLTLPickupAvailability
*/
public function setDispatchDate(?string $dispatchDate): CheckFreightLTLPickupAvailability
{
$this->dispatchDate = $dispatchDate;
return $this;
}

/**
* @param int|null $numberOfBusinessDays
* @return CheckFreightLTLPickupAvailability
*/
public function setNumberOfBusinessDays(?int $numberOfBusinessDays): CheckFreightLTLPickupAvailability
{
$this->numberOfBusinessDays = $numberOfBusinessDays;
return $this;
}


public function prepare(): array
{
$data = [];

if (!empty($this->pickupAddress)) {
$data['pickupAddress'] = $this->pickupAddress->prepare();
}

if (!empty($this->packageReadyTime)) {
$data['packageReadyTime'] = $this->packageReadyTime;
}

if (!empty($this->customerCloseTime)) {
$data['customerCloseTime'] = $this->customerCloseTime;
}

if (!empty($this->serviceType) || !empty($this->weight) || !empty($this->packagingType) || !empty($this->dimensions)) {
$data['shipmentAttributes'] = [];

if (!empty($this->serviceType)) {
$data['shipmentAttributes']['serviceType'] = $this->serviceType;
}

if (!empty($this->weight)) {
$data['shipmentAttributes']['weight'] = $this->weight->prepare();
}

if (!empty($this->packagingType)) {
$data['shipmentAttributes']['packagingType'] = $this->packagingType;
}

if (!empty($this->dimensions)) {
$data['shipmentAttributes']['dimensions'] = $this->dimensions->prepare();
}
}

if (!empty($this->freightGuaranteeTime) || !empty($this->freightDirectDetail) || !empty($this->specialServiceTypes)) {
$data['freightPickupSpecialServiceDetail'] = [];
$data['freightPickupSpecialServiceDetail']['shipmentSpecialServicesRequested'] = [];

if (!empty($this->freightGuaranteeTime)) {
$data['freightPickupSpecialServiceDetail']['shipmentSpecialServicesRequested']['freightGuaranteeDetail'] = ['time'=>$this->freightGuaranteeTime];
}

if (!empty($this->freightDirectDetail)) {
$data['freightPickupSpecialServiceDetail']['shipmentSpecialServicesRequested']['freightDirectDetail'] = $this->freightDirectDetail->prepare();
}

if (!empty($this->specialServiceTypes)) {
$data['freightPickupSpecialServiceDetail']['shipmentSpecialServicesRequested']['specialServiceTypes'] = $this->specialServiceTypes;
}
}

if (!empty($this->dispatchDate)) {
$data['dispatchDate'] = $this->dispatchDate;
}

if (!empty($this->numberOfBusinessDays)) {
$data['numberOfBusinessDays'] = $this->numberOfBusinessDays;
}

return $data;
}


public function request()
{
parent::request();

if (empty($this->pickupAddress)) {
throw new MissingFreightPickupDetailException('Pickup Address is required.');
}

try {
$query = $this->http_client->post($this->getApiUri($this->api_endpoint), [
'json' => $this->prepare(),
'http_errors' => FALSE,
]);
return ($this->raw === true) ? $query : json_decode($query->getBody()->getContents());
} catch (\Exception $e) {
return $e->getMessage();
}
}
}
Loading
Loading