-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcreatePackagesWithService.php
99 lines (80 loc) · 3 KB
/
createPackagesWithService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php declare(strict_types = 1);
require __DIR__.'/vendor/autoload.php';
use Salamek\PplMyApi\Api;
use Salamek\PplMyApi\Model\Package;
use Salamek\PplMyApi\Model\Recipient;
use Salamek\PplMyApi\Enum\Country;
use Salamek\PplMyApi\Enum\Depo;
use Salamek\PplMyApi\Model\CityRouting;
use Salamek\PplMyApi\Enum\Product;
use Salamek\PplMyApi\Model\PackageService;
use Salamek\PplMyApi\Enum\PackageService as PackageServiceEnum;
/**
* Creates package/s on PPL MyApi (sends Package object to PPL) with Service provided
*/
/**
*
It may happen that PPL support staff requires you to omit the ISender while you send the package (not pallet) data. In that case you just use null:
While sending pallet data, Sender is required.
*/
$username = 'my_api_username';
$password = 'my_api_password';
$customerId = 'my_api_customer_id';
$pplMyApi = new Api($username, $password, $customerId);
$country = Country::CZ;
$city = 'Olomouc';
$street = 'My Address';
$zipCode = '77900';
$recipient = new Recipient($city, 'Adam Schubert', $street, $zipCode, '[email protected]', '+420123456789', 'https://www.salamek.cz', $country, 'My Compamy a.s.');
$packageNumber = '40950000114';
$cityRoutingResponse = $pplMyApi->getCitiesRouting($country, null, $zipCode, $street);
//Get first routing from the response and test (response can contain more records, not 100% sure how this works...)
if (is_array($cityRoutingResponse)) {
$cityRoutingResponse = $cityRoutingResponse[0];
}
if (!isset($cityRoutingResponse->RouteCode) || !isset($cityRoutingResponse->DepoCode) || !isset($cityRoutingResponse->Highlighted)) {
throw new Exception('Štítek PPL se nepodařilo vytisknout, chybí Routing, pravděpodobně neplatná adresa!');
}
$cityRouting = new CityRouting(
$cityRoutingResponse->RouteCode,
$cityRoutingResponse->DepoCode,
$cityRoutingResponse->Highlighted
);
$package = new Package(
$packageNumber,
Product::PPL_PARCEL_CZ_PRIVATE,
'Testovaci balik se sluzbou',
$recipient,
$cityRouting,
null,
Depo::CODE_09,
null,
null,
[],
[
new PackageService(PackageServiceEnum::ANOTHER_DELIVERY_ATTEMPT), // Service attempt another delivery when first fails
new PackageService(PackageServiceEnum::AGE_CHECK_18_UP) // Service check that $recipient is 18+ on delivery
]
);
// Or you can use setter if you dont want to put all those nulls and [] stuff in constructor like this
/*
$package = new Package(
$packageNumber,
Product::PPL_PARCEL_CZ_PRIVATE,
'Testovaci balik se sluzbou',
$recipient,
$cityRouting,
);
$package->setPackageServices([
new PackageService(PackageServiceEnum::ANOTHER_DELIVERY_ATTEMPT), // Service attempt another delivery when first fails
new PackageService(PackageServiceEnum::AGE_CHECK_18_UP) // Service check that $recipient is 18+ on delivery
]);
*/
try
{
$pplMyApi->createPackages([$package]);
}
catch (\Exception $e)
{
echo $e->getMessage() . PHP_EOL;
}