|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/** |
| 3 | + * Copyright © MultiSafepay, Inc. All rights reserved. |
| 4 | + * See DISCLAIMER.md for disclaimer details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace MultiSafepay\Api\Terminals; |
| 8 | + |
| 9 | +use MultiSafepay\Api\Base\ResponseBody; |
| 10 | +use MultiSafepay\Exception\InvalidDataInitializationException; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class Terminal |
| 14 | + * |
| 15 | + * Represents a POS terminal as returned by the API. |
| 16 | + * The exact fields may evolve; use getData() for forward compatibility. |
| 17 | + */ |
| 18 | +class Terminal extends ResponseBody |
| 19 | +{ |
| 20 | + public const ID_KEY = 'id'; |
| 21 | + public const PROVIDER_KEY = 'provider'; |
| 22 | + public const NAME_KEY = 'name'; |
| 23 | + public const CODE_KEY = 'code'; |
| 24 | + public const CREATED_KEY = 'created'; |
| 25 | + public const LAST_UPDATED_KEY = 'last_updated'; |
| 26 | + public const MANUFACTURER_ID_KEY = 'manufacturer_id'; |
| 27 | + public const SERIAL_NUMBER_KEY = 'serial_number'; |
| 28 | + public const ACTIVE_KEY = 'active'; |
| 29 | + public const GROUP_ID_KEY = 'group_id'; |
| 30 | + public const COUNTRY_KEY = 'country'; |
| 31 | + |
| 32 | + /** |
| 33 | + * Terminal constructor. |
| 34 | + * |
| 35 | + * @param array $data |
| 36 | + * @throws InvalidDataInitializationException |
| 37 | + */ |
| 38 | + public function __construct(array $data = []) |
| 39 | + { |
| 40 | + $this->validate($data); |
| 41 | + parent::__construct($data); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Validate required fields |
| 46 | + * |
| 47 | + * @param array $data |
| 48 | + * @return void |
| 49 | + * @throws InvalidDataInitializationException |
| 50 | + */ |
| 51 | + private function validate(array $data): void |
| 52 | + { |
| 53 | + if (empty($data[self::ID_KEY])) { |
| 54 | + throw new InvalidDataInitializationException('Missing required field: ID'); |
| 55 | + } |
| 56 | + |
| 57 | + if (empty($data[self::PROVIDER_KEY])) { |
| 58 | + throw new InvalidDataInitializationException('Missing required field: Provider'); |
| 59 | + } |
| 60 | + |
| 61 | + if (empty($data[self::NAME_KEY])) { |
| 62 | + throw new InvalidDataInitializationException('Missing required field: Name'); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Get the terminal ID |
| 68 | + * |
| 69 | + * @return string |
| 70 | + */ |
| 71 | + public function getId(): string |
| 72 | + { |
| 73 | + return (string)$this->get(self::ID_KEY); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Get the terminal provider |
| 78 | + * |
| 79 | + * @return string |
| 80 | + */ |
| 81 | + public function getProvider(): string |
| 82 | + { |
| 83 | + return (string)$this->get(self::PROVIDER_KEY); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Get the terminal name |
| 88 | + * |
| 89 | + * @return string |
| 90 | + */ |
| 91 | + public function getName(): string |
| 92 | + { |
| 93 | + return (string)$this->get(self::NAME_KEY); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Get the terminal code |
| 98 | + * |
| 99 | + * @return string|null |
| 100 | + */ |
| 101 | + public function getCode(): ?string |
| 102 | + { |
| 103 | + $code = $this->get(self::CODE_KEY); |
| 104 | + return $code !== null ? (string)$code : null; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Get the terminal creation date |
| 109 | + * |
| 110 | + * @return string|null |
| 111 | + */ |
| 112 | + public function getCreated(): ?string |
| 113 | + { |
| 114 | + $created = $this->get(self::CREATED_KEY); |
| 115 | + return $created !== null ? (string)$created : null; |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Get the terminal last updated date |
| 120 | + * |
| 121 | + * @return string|null |
| 122 | + */ |
| 123 | + public function getLastUpdated(): ?string |
| 124 | + { |
| 125 | + $lastUpdated = $this->get(self::LAST_UPDATED_KEY); |
| 126 | + return $lastUpdated !== null ? (string)$lastUpdated : null; |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Get the terminal manufacturer ID |
| 131 | + * |
| 132 | + * @return string|null |
| 133 | + */ |
| 134 | + public function getManufacturerId(): ?string |
| 135 | + { |
| 136 | + $manufacturerId = $this->get(self::MANUFACTURER_ID_KEY); |
| 137 | + return $manufacturerId !== null ? (string)$manufacturerId : null; |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Get the terminal serial number |
| 142 | + * |
| 143 | + * @return string|null |
| 144 | + */ |
| 145 | + public function getSerialNumber(): ?string |
| 146 | + { |
| 147 | + $serialNumber = $this->get(self::SERIAL_NUMBER_KEY); |
| 148 | + return $serialNumber !== null ? (string)$serialNumber : null; |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Check if the terminal is active |
| 153 | + * |
| 154 | + * @return bool |
| 155 | + */ |
| 156 | + public function isActive(): bool |
| 157 | + { |
| 158 | + return (bool)$this->get(self::ACTIVE_KEY); |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Get the terminal group ID |
| 163 | + * |
| 164 | + * @return int|null |
| 165 | + */ |
| 166 | + public function getGroupId(): ?int |
| 167 | + { |
| 168 | + $groupId = $this->get(self::GROUP_ID_KEY); |
| 169 | + return $groupId !== null ? (int)$groupId : null; |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * Get the terminal country code |
| 174 | + * |
| 175 | + * @return string|null |
| 176 | + */ |
| 177 | + public function getCountry(): ?string |
| 178 | + { |
| 179 | + $country = $this->get(self::COUNTRY_KEY); |
| 180 | + return $country !== null ? (string)$country : null; |
| 181 | + } |
| 182 | +} |
0 commit comments