| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
namespace MyparcelNL\Sdk\src\Helper; |
| 4 |
|
| 5 |
class TrackTraceUrl |
| 6 |
{ |
| 7 |
const CONSUMER_PORTAL_BASE_URL = "https://myparcel.me/track-trace/"; |
| 8 |
|
| 9 |
/** |
| 10 |
* Creates a Track & Trace URL to myparcel.me from given barcode, postalCode and optional countryCode. Trims |
| 11 |
* spaces from postal code and only adds country code to the url if it's added. |
| 12 |
* |
| 13 |
* @param string $barcode |
| 14 |
* @param string $postalCode |
| 15 |
* @param string|null $countryCode |
| 16 |
* |
| 17 |
* @return string |
| 18 |
*/ |
| 19 |
public static function create( |
| 20 |
string $barcode, |
| 21 |
string $postalCode, |
| 22 |
?string $countryCode = null |
| 23 |
): string { |
| 24 |
$postalCode = str_replace(' ', '', $postalCode); |
| 25 |
|
| 26 |
$url = self::CONSUMER_PORTAL_BASE_URL . "$barcode/$postalCode"; |
| 27 |
|
| 28 |
if ($countryCode) { |
| 29 |
$url .= "/$countryCode"; |
| 30 |
} |
| 31 |
|
| 32 |
return $url; |
| 33 |
} |
| 34 |
} |
| 35 |
|