|
28 | 28 | if (0 !== strpos($action, 'international') && 0 !== strpos($action, 'dutchAddress')) |
29 | 29 | throw new Exception('This example only supports calls to international or dutchAddress methods'); |
30 | 30 |
|
31 | | - if ($action == 'internationalAutocomplete' || $action == 'internationalGetDetails') |
32 | | - $parts []= 'MY_SESSION_ID'; |
| 31 | + // Use the session header if it was specified already (the Postcode.nl js library will generate one automatically, for example) |
| 32 | + // Fall back to a place holder identifier. Don't use a fixed identifier for production environments, please read: |
| 33 | + // https://api.postcode.nl/documentation/international/v1/Autocomplete/autocomplete |
| 34 | + $sessionHeaderKey = 'HTTP_' . str_replace('-', '_', strtoupper(PostcodeNl\Api\Client::SESSION_HEADER_KEY)); |
| 35 | + $sessionId = $_SERVER[$sessionHeaderKey] ?? 'MY_SESSION_ID'; |
33 | 36 |
|
34 | 37 | $client = new PostcodeNl\Api\Client(API_KEY, API_SECRET, PLATFORM); |
35 | | - print json_encode(call_user_func_array([$client, $action], $parts)); |
| 38 | + |
| 39 | + switch ($action) |
| 40 | + { |
| 41 | + case 'internationalAutocomplete': |
| 42 | + $response = $client->internationalAutocomplete($parts[0], $parts[1], $sessionId, $parts[2] ?? null); |
| 43 | + break; |
| 44 | + case 'internationalGetDetails': |
| 45 | + $response = $client->internationalGetDetails($parts[0], $sessionId); |
| 46 | + break; |
| 47 | + default: |
| 48 | + $response = call_user_func_array([$client, $action], $parts); |
| 49 | + break; |
| 50 | + } |
| 51 | + |
| 52 | + print json_encode($response); |
36 | 53 | } |
37 | 54 | catch (Exception $e) |
38 | 55 | { |
|
0 commit comments