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 PDF data */ public function getPdfData(): string { $this->ensureDone(); return $this->pdfData; } /** * @return array Statement metadata (number, year, iban, date, filename) */ 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 HIKAASv1|null $hikaas */ $hikaas = $bpd->getLatestSupportedParameters('HIKAAS'); if ($hikaas === null) { throw new UnsupportedException('The bank does not support archive statements (HKKAA).'); } $param = $hikaas->getParameter(); // Check if PDF format is supported if ($this->format === self::FORMAT_PDF && !$param->supportsPdf()) { throw new UnsupportedException('The bank does not support PDF format for archive statements.'); } // Check if date range queries are supported if (($this->fromDate !== null || $this->toDate !== null) && !$param->canFetchByDateRange()) { throw new UnsupportedException('The bank does not support date range queries for archive statements.'); } // Use the correct HKKAA version based on HIKAAS version in BPD $hikaasVersion = $hikaas->getVersion(); // Use Kti with IBAN/BIC only (not the full account details) $kti = Kti::create($this->account->getIban(), $this->account->getBic()); if ($hikaasVersion >= 2) { return HKKAAv2::create($kti, $this->format, $this->fromDate, $this->toDate); } else { return HKKAAv1::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 HIKAA[] $responseSegments */ $responseSegments = $response->findSegments(HIKAA::class); if (empty($responseSegments)) { // No segments but also no error = empty response return; } foreach ($responseSegments as $hikaa) { // Append PDF data (for pagination) $this->pdfData .= $hikaa->getPdfData(); // Store metadata from first segment if (empty($this->statementInfo)) { $this->statementInfo = [ 'statementNumber' => $hikaa->getStatementNumber(), 'statementYear' => $hikaa->getStatementYear(), 'iban' => $hikaa->getIban(), 'creationDate' => $hikaa->getCreationDate(), 'filename' => $hikaa->getFilename(), 'format' => $hikaa->getFormat(), 'receiptCode' => $hikaa->needsReceipt() ? $hikaa->getReceiptCode() : null, ]; } } } }