@@ -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 );
0 commit comments