|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Ypmn; |
| 6 | + |
| 7 | +use DateTimeZone; |
| 8 | + |
| 9 | +class Receiver implements \JsonSerializable |
| 10 | +{ |
| 11 | + private string $sku; |
| 12 | + private string $bic; |
| 13 | + private string $correspondentAccount; |
| 14 | + private string $account; |
| 15 | + private string $name; |
| 16 | + private string $inn; |
| 17 | + private string $kpp; |
| 18 | + private string $purpose; |
| 19 | + private string $personalAccount; |
| 20 | + private string $period; |
| 21 | + |
| 22 | + public function __construct( |
| 23 | + string $sku, |
| 24 | + string $bic, |
| 25 | + string $correspondentAccount, |
| 26 | + string $account, |
| 27 | + string $name, |
| 28 | + string $inn, |
| 29 | + string $kpp, |
| 30 | + string $purpose, |
| 31 | + string $personalAccount, |
| 32 | + string $period |
| 33 | + ) { |
| 34 | + $this->sku = $sku; |
| 35 | + $this->bic = $bic; |
| 36 | + $this->correspondentAccount = $correspondentAccount; |
| 37 | + $this->account = $account; |
| 38 | + $this->name = $name; |
| 39 | + $this->inn = $inn; |
| 40 | + $this->kpp = $kpp; |
| 41 | + $this->purpose = $purpose; |
| 42 | + $this->personalAccount = $personalAccount; |
| 43 | + |
| 44 | + if (preg_match('~^(0[1-9]|1[0-2])\/\d{4}$~', $period)) { |
| 45 | + throw new PaymentException('Аргумент period имеет неверный формат'); |
| 46 | + } |
| 47 | + |
| 48 | + $this->period = $period; |
| 49 | + } |
| 50 | + |
| 51 | + public function toArray(): array |
| 52 | + { |
| 53 | + return [ |
| 54 | + 'sku' => $this->sku, |
| 55 | + 'bic' => $this->bic, |
| 56 | + 'correspondentAccount' => $this->correspondentAccount, |
| 57 | + 'account' => $this->account, |
| 58 | + 'name' => $this->name, |
| 59 | + 'inn' => $this->inn, |
| 60 | + 'kpp' => $this->kpp, |
| 61 | + 'purpose' => $this->purpose, |
| 62 | + 'personalAccount' => $this->personalAccount, |
| 63 | + 'period' => $this->period |
| 64 | + ]; |
| 65 | + } |
| 66 | + |
| 67 | + public function jsonSerialize() |
| 68 | + { |
| 69 | + return $this->toArray(); |
| 70 | + } |
| 71 | +} |
0 commit comments