-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathServicePoints.php
More file actions
65 lines (49 loc) · 1.49 KB
/
ServicePoints.php
File metadata and controls
65 lines (49 loc) · 1.49 KB
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
<?php
namespace Mvdnbrk\DhlParcel\Endpoints;
use Illuminate\Support\Collection;
use Mvdnbrk\DhlParcel\Resources\ServicePoint as ServicePointResource;
use Mvdnbrk\DhlParcel\Support\Str;
class ServicePoints extends BaseEndpoint
{
/** @var string */
public $postal_code;
/** @var string */
public $housenumber;
/** @var string */
public $country = 'NL';
public function get(array $filters = []): Collection
{
$response = $this->performApiCall(
'GET',
'parcel-shop-locations/'.$this->country.$this->buildQueryString($this->getFilters($filters))
);
$collection = new Collection();
collect($response)->each(function ($item) use ($collection) {
$collection->push(new ServicePointResource($item));
});
return $collection;
}
protected function getFilters(array $filters): array
{
return array_merge([
'zipCode' => $this->postal_code,
'houseNumber' => $this->housenumber,
'showUnavailable' => 'false',
], $filters);
}
public function setHousenumber(string $value): self
{
$this->housenumber = $value;
return $this;
}
public function setPostalCode(string $value): self
{
$this->postal_code = preg_replace('/\s+/', '', Str::upper($value));
return $this;
}
public function setCountry(string $value): self
{
$this->country = $value;
return $this;
}
}