feat: request replay command for bpn api

This commit is contained in:
Björn Fromme
2025-12-06 15:02:13 +01:00
parent 696800aafd
commit 2b3a8f1c69
3 changed files with 221 additions and 0 deletions
+76
View File
@@ -468,6 +468,82 @@ class ApiClient
return $this->sendRequest(static::TYPE_PROMO_VOUCHER, $data);
}
/**
* Sends raw XML to the BPN API with key regeneration.
*
* Parses the XML to extract the request type, regenerates the authentication key
* with the current date, and sends the request. Returns the raw XML response.
*
* @param string $xml The raw XML request body
* @param bool $debug Enable debug mode (XML dumps)
*
* @return string The raw XML response
*
* @throws ApiClientException If the request fails or XML is invalid
*/
public function sendRawXml(string $xml, bool $debug = false): string
{
$requestId = date(DATE_ATOM).uniqid();
$doc = new \DOMDocument();
if (false === @$doc->loadXML($xml)) {
throw new ApiClientException('Invalid XML provided');
}
$satzNode = $doc->getElementsByTagName('satz')->item(0);
if (null === $satzNode) {
throw new ApiClientException('Missing <satz> element in XML');
}
$type = $satzNode->getAttribute('typ');
if ('' === $type) {
throw new ApiClientException('Missing typ attribute on <satz> element');
}
$keyNode = $doc->getElementsByTagName('key')->item(0);
if (null === $keyNode) {
throw new ApiClientException('Missing <key> element in XML');
}
$newKey = $this->createKey(
$this->config['bpn_username'],
$this->config['bpn_password'],
$type
);
$keyNode->nodeValue = $newKey;
$body = $doc->saveXML();
$this->logger->info('Sending raw XML request to BPN API', [
'requestId' => $requestId,
'type' => $type,
]);
if (true === $debug || true === $this->config['debug']) {
$this->dumpXmlToFile('request', $requestId, $body);
}
$socket = $this->connect(
$this->config['bpn_api_ip'],
$this->config['bpn_api_port'],
$this->config['max_retries'],
$this->config['connection_timeout'],
$this->config['stream_timeout'],
$this->config['total_timeout']
);
$this->send($socket, $body, $this->config['total_timeout']);
$response = $this->receive($socket, $this->config['total_timeout']);
$this->disconnect($socket);
$responseXml = substr($response, 10);
if (true === $debug || true === $this->config['debug']) {
$this->dumpXmlToFile('response', $requestId, $responseXml);
}
return $responseXml;
}
/**
* @throws ApiClientException
*/