Skip to content

Commit b5c1b3d

Browse files
committed
temp: fieldlab, rebase later
1 parent 6bfaccd commit b5c1b3d

2 files changed

Lines changed: 31 additions & 24 deletions

File tree

src/PrefillGravityForms/Controllers/BaseController.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ protected function getCurlHeaders(string $doelBinding = ''): array
287287
return array_filter($headers);
288288
}
289289

290-
protected function handleCurl(array $args, string $transientKey): array
290+
protected function handleCurl(array $args, string $transientKey, array $locationBsnInResponse = []): array
291291
{
292292
try {
293293
/**
@@ -333,7 +333,7 @@ protected function handleCurl(array $args, string $transientKey): array
333333
throw new Exception(sprintf('%s', $decoded['detail'] ?? ($decoded['Error Details'] ?? 'Request failed, error unknown')), is_int($httpStatus) ? $httpStatus : 500);
334334
}
335335

336-
$this->handleTransient($response, $transientKey);
336+
$this->handleTransient($response, $transientKey, $locationBsnInResponse);
337337

338338
return $response;
339339
} catch (Exception $e) {
@@ -346,34 +346,16 @@ protected function handleCurl(array $args, string $transientKey): array
346346
}
347347
}
348348

349-
/**
350-
* Extracts the burgerservicenummer (BSN) from the API response.
351-
*/
352-
protected function extractBSN(array $response): string
353-
{
354-
if (! isset($response['burgerservicenummer'])) {
355-
throw new Exception('Burgerservicenummer not found in response.', 404);
356-
}
357-
358-
$bsn = $response['burgerservicenummer'];
359-
360-
if (! is_numeric($bsn)) {
361-
throw new Exception('Invalid burgerservicenummer format, value is not numeric.', 500);
362-
}
363-
364-
return (string) $bsn;
365-
}
366-
367349
/**
368350
* Validates whether the necessary conditions are met before setting the transient.
369351
*
370352
* Ensures that:
371353
* - A valid BSN (burgerservicenummer) is present in the response.
372354
* - The transient key derived from that BSN matches the one generated from the current session.
373355
*/
374-
protected function handleTransient(array $response, string $transientKey): void
356+
protected function handleTransient(array $response, string $transientKey, array $locationBsnInResponse = []): void
375357
{
376-
$responseBSN = $this->extractBSN($response);
358+
$responseBSN = $this->extractBSN($response, $locationBsnInResponse);
377359

378360
if ('' === $responseBSN) {
379361
throw new Exception('No burgerservicenummer found in the response.', 404);
@@ -393,6 +375,29 @@ protected function handleTransient(array $response, string $transientKey): void
393375
}
394376
}
395377

378+
/**
379+
* Extracts the burgerservicenummer (BSN) from the API response.
380+
*/
381+
protected function extractBSN(array $response, array $locationBsnInResponse = []): string
382+
{
383+
if ([] !== $locationBsnInResponse) {
384+
$response = $this->explodeDotNotationValue(implode('.', $locationBsnInResponse), $response);
385+
$bsn = $response;
386+
} else {
387+
if (! isset($response['burgerservicenummer'])) {
388+
throw new Exception('Burgerservicenummer not found in response.', 404);
389+
}
390+
391+
$bsn = $response['burgerservicenummer'];
392+
}
393+
394+
if ('' === $bsn || ! is_numeric($bsn)) {
395+
throw new Exception('Invalid burgerservicenummer format, value is not numeric.', 500);
396+
}
397+
398+
return (string) $bsn;
399+
}
400+
396401
protected function timeoutOptionCURL(): int
397402
{
398403
$timeout = apply_filters('owc_prefill_gravity_forms_curl_timeout', 10);

src/PrefillGravityForms/Controllers/PinkRoccadeV2Controller.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function fetchApiResponse(array $preparedData, string $bsn, string $do
8787
$message = sprintf('%s: %s', $message, $apiResponse['message']);
8888
}
8989

90-
$this->logException(new Exception($message, (int) ($response['status'] ?? 500)));
90+
$this->logException(new Exception($message, (int) ($apiResponse['status'] ?? 500)));
9191

9292
return [];
9393
}
@@ -112,7 +112,9 @@ protected function request(array $data, string $bsn, string $doelBinding, string
112112
],
113113
];
114114

115-
return $this->handleCurl($curlArgs, CacheService::formatTransientKey($bsn));
115+
$locationBsnInResponse = ['personen.0.burgerservicenummer'];
116+
117+
return $this->handleCurl($curlArgs, CacheService::formatTransientKey($bsn), $locationBsnInResponse);
116118
}
117119

118120
protected function getDefaultCurlArgs(): array

0 commit comments

Comments
 (0)