-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 84c9aa7
Showing
42 changed files
with
2,603 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all test and documentation with "export-ignore". | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Nerijus Bartoševičius | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
# DPD Api library | ||
|
||
DPD API library, to help to integrate with other systems | ||
|
||
## Official DPD docs | ||
- [DPD Amber API](https://esiunta.dpd.lt/api/) | ||
- [DPD API documentation](https://github.com/NerijusBartosevicius/dpd-api-lib/blob/main/docs/DPD-Telli-API-documentation-v1-1-3.pdf) | ||
- [DPD tracking service](https://github.com/NerijusBartosevicius/dpd-api-lib/blob/main/docs/Shipment-status-tracking-web-service.pdf) | ||
|
||
## Instalation | ||
|
||
To install via composer: | ||
|
||
```sh | ||
composer require neriba/dpd-api-lib | ||
``` | ||
|
||
## Authentication | ||
|
||
#### Environments | ||
|
||
- LT - Lithuania production (default). | ||
- LT_TEST - Lithuania sandbox. | ||
- LV - Latvia production. | ||
- LV_TEST - Latvia sandbox. | ||
- EE - Estonia production. | ||
- EE_TEST - Estonia sandbox. | ||
|
||
### Get new token | ||
|
||
`If you don't have an API key from DPD, but you have an old API credencials name and password you can generate your own API key.` | ||
|
||
```php | ||
// By default, third parameter is Lithuanian production environment | ||
$getToken = new \NeriBa\DpdApiLib\ApiTokenGenerator('USERNAME','PASSWORD','LT_TEST'); | ||
$getToken->createAuthToken('Token name'); | ||
``` | ||
|
||
#### Create instance | ||
|
||
```php | ||
$token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9....'; | ||
// By default, third parameter is Lithuanian production environment | ||
$dpd = new \NeriBa\DpdApiLib\Request($token, 'LT_TEST'); | ||
``` | ||
|
||
### Get user information | ||
|
||
```php | ||
$dpd->authMe(); | ||
``` | ||
|
||
### Get list of tokens | ||
|
||
```php | ||
$dpd->getAuthTokenSecrets(); | ||
``` | ||
|
||
### Delete existing token | ||
|
||
```php | ||
$dpd->deleteAuthTokenSecrets('99bb2035-5ed8-4547-95ca-7ffb5e79e694'); | ||
``` | ||
|
||
## Services | ||
|
||
### Get services and price for user | ||
|
||
```php | ||
// additional parameters are possible as an array e.g ['countryFrom' => 'LT', 'countryTo' => 'LT'] | ||
// Parameters list: https://esiunta.dpd.lt/api#/Services/042db4934d823e1cc21745c549f2a810 | ||
$dpd->getServices(['countryFrom' => 'LT', 'countryTo' => 'LT']); | ||
``` | ||
|
||
## Shipment | ||
|
||
### Get list of shipments | ||
|
||
```php | ||
// additional parameters are possible as an array e.g ['limit'=> 10] | ||
// Parameters list: https://esiunta.dpd.lt/api/#/Shipment/1aed3b00cafe6d7bd576b2b84b41826f | ||
$dpd->getShipments(); | ||
``` | ||
|
||
### Create simple shipment | ||
|
||
```php | ||
$senderAddress = new \NeriBa\DpdApiLib\Shipment\Package\Address(); | ||
$senderAddress | ||
->setName('Test Sender') | ||
->setPhone('62166025') | ||
->setStreet('Uosių g') | ||
->setStreetNo(24) | ||
->setCity('Kaunas') | ||
->setPostalCode('51446') | ||
->setCountry('LT'); | ||
|
||
$receiverAddress = new \NeriBa\DpdApiLib\Shipment\Package\Address(); | ||
$receiverAddress | ||
->setName('Test Receiver') | ||
->setPhone('65123456') | ||
->setStreet('Uriekstes') | ||
->setStreetNo(24) | ||
->setCity('Kaunas') | ||
->setPostalCode('51446') | ||
->setCountry('LT'); | ||
|
||
$shipment = new \NeriBa\DpdApiLib\Shipment\Shipment(); | ||
$shipment | ||
->setSenderAddress($senderAddress) | ||
->setReceiverAddress($receiverAddress) | ||
->setService((new \NeriBa\DpdApiLib\Shipment\Package\Service())->setServiceName('DPD CLASSIC')) | ||
->setParcel((new \NeriBa\DpdApiLib\Shipment\Package\Parcel())->setWeight(31)->setSize('XS')); | ||
|
||
$shipment2 = new \NeriBa\DpdApiLib\Shipment\Shipment(); | ||
$shipment2 | ||
->setSenderAddress($senderAddress) | ||
->setReceiverAddress($receiverAddress) | ||
->setService((new \NeriBa\DpdApiLib\Shipment\Package\Service())->setServiceName('DPD CLASSIC')) | ||
->setParcel((new \NeriBa\DpdApiLib\Shipment\Package\Parcel())->setWeight(10)->setSize('m')); | ||
|
||
// Max 50 shipments per request | ||
$dpd->createShipments([$shipment,$shipment2]); | ||
``` | ||
|
||
### Delete shipments | ||
|
||
```php | ||
$dpd->deleteShipments(['0fa01f06-7c56-4c5c-a33f-0eca869663f3','0fa01f06-7c56-4c5c-a33f-0eca869663f4']); | ||
``` | ||
|
||
## Labels | ||
|
||
### Create label | ||
|
||
```php | ||
$dpd->createShipmentsLabels((new \NeriBa\DpdApiLib\Shipment\Package\LabelOption())->setShipmentIds(['0fa01f06-7c56-4c5c-a33f-0eca869663f3'])); | ||
``` | ||
|
||
## Invoice | ||
|
||
### Gets invoice by uuid | ||
|
||
```php | ||
$dpd->getInvoices('0fa01f06-7c56-4c5c-a33f-0eca869663f3'); | ||
``` | ||
|
||
## Lockers | ||
|
||
### Find lockers based on given criteria | ||
|
||
```php | ||
$dpd->getLockers(['countryCode' => 'LT']); | ||
``` | ||
|
||
## Manifest | ||
|
||
### Create shipment manifest | ||
|
||
```php | ||
$dpd->createShipmentManifest((new \NeriBa\DpdApiLib\Shipment\Package\Manifest())->setShipmentIds(['0fa01f06-7c56-4c5c-a33f-0eca869663f3'])); | ||
``` | ||
|
||
### Get shipment manifest by uuid | ||
|
||
```php | ||
$dpd->getShipmentsManifestByManifest('0fa01f06-7c56-4c5c-a33f-0eca869663f3'); | ||
``` | ||
|
||
### Get shipment manifest by shipment uuid | ||
|
||
```php | ||
$dpd->getShipmentsManifestByShipment('0fa01f06-7c56-4c5c-a33f-0eca869663f3'); | ||
``` | ||
|
||
## Pickup | ||
|
||
### Create pickup | ||
|
||
```php | ||
$pickupAddress = new \NeriBa\DpdApiLib\Shipment\Package\Address(); | ||
$pickupAddress | ||
->setName('Test Sender') | ||
->setContactName('Test Sender cc') | ||
->setEmail('john.doe@email.com') | ||
->setPhone('+37062166025') | ||
->setStreet('Uosių g') | ||
->setStreetNo(24) | ||
->setCity('Kaunas') | ||
->setPostalCode('51446') | ||
->setCountry('LT'); | ||
|
||
$pickup = new \NeriBa\DpdApiLib\Pickup\Pickup(); | ||
$pickup | ||
->setPallets([(new \NeriBa\DpdApiLib\Pickup\Package\Pallet())->setWeight(150)->setCount(1)]) | ||
->setAddress($pickupAddress) | ||
->setPickupDate('2022-10-12') | ||
->setPickupTime('11:00', '15:00'); | ||
|
||
$dpd->createPickup($pickup); | ||
``` | ||
|
||
### Get pickups | ||
|
||
```php | ||
// additional parameters are possible as an array e.g ['limit'=> 10] | ||
// Parameters list: https://esiunta.dpd.lt/api/#/Pickup/50e315fc1327d9f9a55db05ef66b4b48 | ||
$dpd->getPickups(); | ||
``` | ||
|
||
### Get list of pickup timeframes | ||
|
||
```php | ||
// additional parameters are possible as an array e.g ['country' => 'LT','zip' => 51336] | ||
// Parameters list: https://esiunta.dpd.lt/api/#/Pickup%20timeframes/e092e35374638c464b1e0b3eaa7513d9 | ||
$dpd->getPickupTimeFrames(['country' => 'LT','zip' => 51336]); | ||
``` | ||
|
||
## Problem | ||
|
||
### Get a description for a problem from the knowledge base | ||
|
||
```php | ||
$dpd->getProblems(123456); | ||
``` | ||
|
||
## Tracking | ||
|
||
#### Environments | ||
|
||
- LT - Lithuania production (default). | ||
- LV - Latvia production. | ||
- EE - Estonia production. | ||
|
||
### Get tracking info by parcel numbers | ||
|
||
`NOTE: Now tracking working without authorization,although the documentation says that it is used Bearer.` | ||
|
||
```php | ||
$apiKey = ''; | ||
// By default, second parameter is Lithuanian production environment | ||
$tracking = new \NeriBa\DpdApiLib\Tracking($apiKey,'LT'); | ||
$tracking->getTracking(['05808021421108','05808021421105']); | ||
``` | ||
|
||
# License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "neriba/dpd-api-lib", | ||
"description": "DPD API library, to help to integrate with other systems", | ||
"homepage": "https://github.com/NerijusBartosevicius/dpd-api-lib", | ||
"type": "library", | ||
"version": "1.0.1", | ||
"license": "MIT", | ||
"minimum-stability": "dev", | ||
"autoload": { | ||
"psr-4": { | ||
"NeriBa\\DpdApiLib\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Nerijus Bartosevicius", | ||
"email": "nerijus.bartosevicius@gmail.com", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php" : "^8.0|^8.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "10.0.x-dev" | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" colors="true" stopOnFailure="false"> | ||
<testsuite name="DPD Api Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/** | ||
* @author: Nerijus Bartoševičius | ||
* @created: 2022-10-09 | ||
*/ | ||
|
||
namespace NeriBa\DpdApiLib; | ||
|
||
use NeriBa\DpdApiLib\Traits\EnvironmentSelector; | ||
|
||
class ApiTokenGenerator | ||
{ | ||
use EnvironmentSelector; | ||
|
||
/** | ||
* @param string $username | ||
* @param string $password | ||
* @param string $env | ||
* | ||
* @throws DpdException | ||
*/ | ||
public function __construct(private string $username, private string $password, string $env = 'LT') | ||
{ | ||
$this->chooseEnvironment($env); | ||
} | ||
|
||
/** | ||
* Gets a new token, accepts basic auth/tokens | ||
* | ||
* @param string $tokenName | ||
* @param int $ttl | ||
* | ||
* @return bool|string | ||
*/ | ||
public function createAuthToken(string $tokenName, int $ttl = 999999999): bool|string | ||
{ | ||
$curl = curl_init(); | ||
curl_setopt_array($curl, array( | ||
CURLOPT_URL => $this->apiUrl . '/auth/tokens', | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => '', | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 0, | ||
CURLOPT_FOLLOWLOCATION => true, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_CUSTOMREQUEST => 'POST', | ||
CURLOPT_POSTFIELDS => json_encode(['name' => $tokenName, 'ttl' => $ttl]), | ||
CURLOPT_HTTPHEADER => array( | ||
'Authorization: Basic ' . base64_encode($this->username . ':' . $this->password), | ||
'Content-Type: application/json' | ||
), | ||
)); | ||
|
||
$response = curl_exec($curl); | ||
$this->responseStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||
curl_close($curl); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* @author: Nerijus Bartoševičius | ||
* @created: 2022-10-09 | ||
*/ | ||
|
||
namespace NeriBa\DpdApiLib; | ||
|
||
use Exception; | ||
|
||
class DpdException extends Exception | ||
{ | ||
|
||
} |
Oops, something went wrong.