feat: per method debug setting in BPN API client

This commit is contained in:
Björn Fromme
2025-03-23 10:40:03 +01:00
parent 882a7185bc
commit 7f83e16a48
+12 -8
View File
@@ -104,8 +104,12 @@ class ApiClient
* @throws ApiClientException * @throws ApiClientException
* @throws ResponseParserException * @throws ResponseParserException
*/ */
public function updatePersonalData(string $email, string $password, PersonalData $personalData): Notification|PersonalData public function updatePersonalData(
{ string $email,
string $password,
PersonalData $personalData,
bool $debug
): Notification|PersonalData {
$data = [ $data = [
'user' => $this->config['bpn_username'], 'user' => $this->config['bpn_username'],
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_CUSTOMER_DATA), 'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_CUSTOMER_DATA),
@@ -117,7 +121,7 @@ class ApiClient
'adressdaten' => $personalData->toPayload(), 'adressdaten' => $personalData->toPayload(),
]; ];
return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data); return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data, $debug);
} }
/** /**
@@ -180,7 +184,7 @@ class ApiClient
* @throws ApiClientException * @throws ApiClientException
* @throws ResponseParserException * @throws ResponseParserException
*/ */
public function updateBooking(BookingData $formData): Notification|BookingUpdate public function updateBooking(BookingData $formData, bool $debug = false): Notification|BookingUpdate
{ {
$payload = (new BookingDataProcessor())->createUpdateRequestPayload($formData); $payload = (new BookingDataProcessor())->createUpdateRequestPayload($formData);
@@ -192,7 +196,7 @@ class ApiClient
...$payload, ...$payload,
]; ];
return $this->sendRequest(static::TYPE_BOOKING_UPDATE, $data); return $this->sendRequest(static::TYPE_BOOKING_UPDATE, $data, $debug);
} }
/** /**
@@ -284,7 +288,7 @@ class ApiClient
* @throws ApiClientException * @throws ApiClientException
* @throws ResponseParserException * @throws ResponseParserException
*/ */
private function sendRequest(string $type, array $data): mixed private function sendRequest(string $type, array $data, bool $debug = false): mixed
{ {
$requestId = date(DATE_ATOM).uniqid(); $requestId = date(DATE_ATOM).uniqid();
@@ -300,7 +304,7 @@ class ApiClient
'requestId' => $requestId, 'requestId' => $requestId,
]); ]);
if (true === $this->config['debug']) { if (true === $debug || true === $this->config['debug']) {
$this->dumpXmlToFile('request', $requestId, $body); $this->dumpXmlToFile('request', $requestId, $body);
} }
@@ -316,7 +320,7 @@ class ApiClient
// message length (10 bytes) is prepended to actual message // message length (10 bytes) is prepended to actual message
$xml = substr($response, 10); $xml = substr($response, 10);
if (true === $this->config['debug']) { if (true === $debug || true === $this->config['debug']) {
$this->dumpXmlToFile('response', $requestId, $xml); $this->dumpXmlToFile('response', $requestId, $xml);
} }