0f0a0322edf035353b8405eae542cf7be9a699bc
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

1) <?php
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

2) require_once('api.php');
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

3) 
4) function suche_kunde($name, $number) {
5)         global $content;
6)         if (! $number) {
7)             return NULL;
8)         }
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

9)         $ret = api_call('GET', 'customerContacts/search/'.format_number_api($number));
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 9 months ago

10)         if ($ret['status_code'] >= 400) {
11)             foreach ($ret['data']['validation_errors'] as $item) {
12)                 $_SESSION['warning'][] = $item['message'];
13)             }
14)             return null;
15)         }
16)         $ret = $ret['data'];
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

17)         if (count($ret) > 0) {
18)             $name = strtolower($name);
19)             foreach ($ret as $item) {
20)                 $cust = $item['customer'];
21)                 if ($name == strtolower($cust['lastname']) ||
22)                     $name == strtolower($cust['firstname']) ||
Bernd Wurst Erlaube nachname vorname

Bernd Wurst authored 9 months ago

23)                     $name == strtolower($cust['firstname'] .' '. $cust['lastname']) ||
24)                     $name == strtolower($cust['lastname'] .' '. $cust['firstname'])
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

25)                     ) {
26)                     return $cust;
27)                 }
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

28)             }
29)         }
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

30)         return null;
31) 
32)         /*
33)         $kundenliste = json_decode(file_get_contents('../kunden.json'), TRUE);
34)         foreach ($kundenliste as $k) {
35)                 foreach ($k['kontakt'] as $kon) {
36)                         if ($kon['wert'] == $number) {
37)                                 return $k;
38)                         }
39)                 }
40)         }
41)         */
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

42) }
43) 
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

44) function erstelle_kunde($daten) {
45)     $json = [
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 9 months ago

46)         "firstname" => $daten['fname'] ?: null,
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

47)         "lastname" => $daten['lname'],
48)         "phone" => format_number_api($daten['phone']),
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 9 months ago

49)         "street" => $daten['address'] ?: null,
50)         "zip" => $daten['zip'] ?: null,
51)         "city" => $daten['city'] ?: null,
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

52)         "contacts" => []];
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 9 months ago

53)     $filename = '../data/'.date('Y').'/neukunde-'.time().'.json';
54)     @file_put_contents($filename, json_encode($json));
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

55)     $ret = api_call('POST', 'customers', $json);
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 9 months ago

56)     if ($ret['status_code'] >= 400) {
57)         foreach ($ret['data']['validation_errors'] as $item) {
Bernd Wurst Fange ungültige Telefonnumm...

Bernd Wurst authored 9 months ago

58)             $_SESSION['warnings'][] = $item['key'].': '.$item['message'];
Bernd Wurst API-Aufrufe über Guzzle um...

Bernd Wurst authored 9 months ago

59)         }
60)         return null;
61)     }
62)     $ret = $ret['data'];
Bernd Wurst Neue API 2023

Bernd Wurst authored 9 months ago

63)     if (isset($ret['id'])) {
64)         return $ret['id'];
65)     } else {
66)         return null;
67)     }
68) }