|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Class NetworkToken |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Paytrail\SDK\Model\Token; |
| 8 | + |
| 9 | +use Paytrail\SDK\Exception\ValidationException; |
| 10 | +use Paytrail\SDK\Util\ObjectPropertyConverter; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class NetworkToken |
| 14 | + * |
| 15 | + * The NetworkToken class defiens additional details the network token. |
| 16 | + * |
| 17 | + * @package Paytrail\SDK\Model\Token |
| 18 | + */ |
| 19 | +class NetworkToken implements \JsonSerializable |
| 20 | +{ |
| 21 | + use ObjectPropertyConverter; |
| 22 | + |
| 23 | + /** @var string $type */ |
| 24 | + protected $type; |
| 25 | + |
| 26 | + /** @var string $partialPan */ |
| 27 | + protected $partialPan; |
| 28 | + |
| 29 | + /** @var string $expireYear */ |
| 30 | + protected $expireYear; |
| 31 | + |
| 32 | + /** @var string $expireMonth */ |
| 33 | + protected $expireMonth; |
| 34 | + |
| 35 | + /** @var string $imageUrl */ |
| 36 | + protected $imageUrl; |
| 37 | + |
| 38 | + /** @var string $paymentAccountReference */ |
| 39 | + protected $paymentAccountReference; |
| 40 | + |
| 41 | + /** |
| 42 | + * Validate email |
| 43 | + * |
| 44 | + * @throws ValidationException |
| 45 | + */ |
| 46 | + public function validate() |
| 47 | + { |
| 48 | + $props = $this->convertObjectVarsToSnake(); |
| 49 | + |
| 50 | + if (empty($props['type'])) { |
| 51 | + throw new ValidationException('Type is empty'); |
| 52 | + } |
| 53 | + |
| 54 | + if (empty($props['partial_pan'])) { |
| 55 | + throw new ValidationException('Partial pan is empty'); |
| 56 | + } |
| 57 | + |
| 58 | + if (empty($props['expire_year'])) { |
| 59 | + throw new ValidationException('Expire year is empty'); |
| 60 | + } |
| 61 | + |
| 62 | + if (empty($props['expire_month'])) { |
| 63 | + throw new ValidationException('Expire month is empty'); |
| 64 | + } |
| 65 | + |
| 66 | + return true; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @param string $type |
| 71 | + * @return NetworkToken |
| 72 | + */ |
| 73 | + public function setType(string $type): NetworkToken |
| 74 | + { |
| 75 | + $this->type = $type; |
| 76 | + |
| 77 | + return $this; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @return string |
| 82 | + */ |
| 83 | + public function getType(): string |
| 84 | + { |
| 85 | + return $this->type; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @param string $partialPan |
| 90 | + * @return NetworkToken |
| 91 | + */ |
| 92 | + public function setPartialPan(string $partialPan): NetworkToken |
| 93 | + { |
| 94 | + $this->partialPan = $partialPan; |
| 95 | + |
| 96 | + return $this; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * @return string |
| 101 | + */ |
| 102 | + public function getPartialPan(): string |
| 103 | + { |
| 104 | + return $this->partialPan; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * @param string $expireYear |
| 109 | + * @return NetworkToken |
| 110 | + */ |
| 111 | + public function setExpireYear(string $expireYear): NetworkToken |
| 112 | + { |
| 113 | + $this->expireYear = $expireYear; |
| 114 | + |
| 115 | + return $this; |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * @return string |
| 120 | + */ |
| 121 | + public function getExpireYear(): string |
| 122 | + { |
| 123 | + return $this->expireYear; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @param string $expireMonth |
| 128 | + * @return NetworkToken |
| 129 | + */ |
| 130 | + public function setExpireMonth(string $expireMonth): NetworkToken |
| 131 | + { |
| 132 | + $this->expireMonth = $expireMonth; |
| 133 | + |
| 134 | + return $this; |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * @return string |
| 139 | + */ |
| 140 | + public function getExpireMonth(): string |
| 141 | + { |
| 142 | + return $this->expireMonth; |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * @param string|null $imageUrl |
| 147 | + * @return NetworkToken |
| 148 | + */ |
| 149 | + public function setImageUrl(?string $imageUrl): NetworkToken |
| 150 | + { |
| 151 | + $this->imageUrl = $imageUrl; |
| 152 | + |
| 153 | + return $this; |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * @return string |
| 158 | + */ |
| 159 | + public function getImageUrl(): ?string |
| 160 | + { |
| 161 | + return $this->imageUrl; |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * @param string|null $paymentAccountReference |
| 166 | + * @return NetworkToken |
| 167 | + */ |
| 168 | + public function setPaymentAccountReference(?string $paymentAccountReference): NetworkToken |
| 169 | + { |
| 170 | + $this->paymentAccountReference = $paymentAccountReference; |
| 171 | + |
| 172 | + return $this; |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * @return string |
| 177 | + */ |
| 178 | + public function getPaymentAccountReference(): ?string |
| 179 | + { |
| 180 | + return $this->paymentAccountReference; |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Implements the json serialize method and |
| 185 | + * return all object variables including |
| 186 | + * private/protected properties. |
| 187 | + */ |
| 188 | + public function jsonSerialize(): array |
| 189 | + { |
| 190 | + return array_filter($this->convertObjectVarsToSnake(), function ($item) { |
| 191 | + return $item !== null; |
| 192 | + }); |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * @param \stdClass $networkToken |
| 197 | + * @return NetworkToken |
| 198 | + */ |
| 199 | + public function loadFromStdClass(\stdClass $networkToken): NetworkToken |
| 200 | + { |
| 201 | + $this->setType($networkToken->type); |
| 202 | + $this->setPartialPan($networkToken->partial_pan); |
| 203 | + $this->setExpireYear($networkToken->expire_year); |
| 204 | + $this->setExpireMonth($networkToken->expire_month); |
| 205 | + $this->setImageUrl($networkToken->image_url); |
| 206 | + $this->setPaymentAccountReference($networkToken->payment_account_reference ?? null); |
| 207 | + |
| 208 | + |
| 209 | + return $this; |
| 210 | + } |
| 211 | +} |
0 commit comments