account = $account; $result->format = $format; $result->fromDate = $fromDate ? $fromDate->format('Ymd') : null; $result->toDate = $toDate ? $toDate->format('Ymd') : null; return $result; } public function __serialize(): array { return [ parent::__serialize(), $this->account, $this->format, $this->fromDate, $this->toDate, ]; } public function __unserialize(array $serialized): void { list( $parentSerialized, $this->account, $this->format, $this->fromDate, $this->toDate ) = $serialized; is_array($parentSerialized) ? parent::__unserialize($parentSerialized) : parent::unserialize($parentSerialized); } /** * @return string The raw data (MT940 text or PDF binary) */ public function getData(): string { $this->ensureDone(); return $this->data; } /** * @return array Statement metadata (number, year, iban, date, format) */ public function getStatementInfo(): array { $this->ensureDone(); return $this->statementInfo; } /** * @return bool Whether receipt confirmation is needed */ public function needsReceipt(): bool { $this->ensureDone(); return !empty($this->statementInfo['receiptCode']); } /** {@inheritdoc} */ protected function createRequest(BPD $bpd, ?UPD $upd) { /** @var HIEKASv5|null $hiekas */ $hiekas = $bpd->getLatestSupportedParameters('HIEKAS'); if ($hiekas === null) { throw new UnsupportedException('The bank does not support electronic statements (HKEKA).'); } $param = $hiekas->getParameter(); // Check if requested format is supported if ($this->format === self::FORMAT_PDF && !$param->supportsPdf()) { throw new UnsupportedException('The bank does not support PDF format for electronic statements.'); } // Use Kti (IBAN/BIC) for version 5 $kti = Kti::fromAccount($this->account); return HKEKAv5::create($kti, $this->format, $this->fromDate, $this->toDate); } /** {@inheritdoc} */ public function processResponse(Message $response) { parent::processResponse($response); // Check if no statements available if ($response->findRueckmeldung(Rueckmeldungscode::NICHT_VERFUEGBAR) !== null) { return; } /** @var HIEKA[] $responseSegments */ $responseSegments = $response->findSegments(HIEKA::class); if (empty($responseSegments)) { // No segments but also no error = empty response return; } foreach ($responseSegments as $hieka) { // Append data (for pagination) $this->data .= $hieka->getData(); // Store metadata from first segment if (empty($this->statementInfo)) { $this->statementInfo = [ 'statementNumber' => $hieka->getStatementNumber(), 'statementYear' => $hieka->getStatementYear(), 'iban' => $hieka->getIban(), 'creationDate' => $hieka->getCreationDate(), 'format' => $hieka->getFormat(), 'receiptCode' => $hieka->needsReceipt() ? $hieka->getReceiptCode() : null, ]; } } } }