-
-
Save axelerator/504bd989443b4628ce7035d0b9daf6e6 to your computer and use it in GitHub Desktop.
Kunde, Ansprechpartner und Aufgaben für Neukunden anlegen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function api_call($resource, $postData, $query_str) { | |
#$SERVER="http://vertriebstool.dev:3000/api/v2"; | |
$SERVER="https://skyline-web.de/api/v2"; | |
$url = "${SERVER}/${resource}?${query_str}"; | |
$ch = curl_init($url); | |
curl_setopt_array($ch, array( | |
CURLOPT_POST => TRUE, | |
CURLOPT_HTTPHEADER => array( | |
'Accept: application/json', | |
'Content-Type: application/json' | |
), | |
CURLOPT_POSTFIELDS => json_encode($postData), | |
CURLOPT_RETURNTRANSFER => true | |
) | |
); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
return $response; | |
} | |
function create_skyline_customer ($user_login, $first_name, $last_name, $email) { | |
# app key and app token ensure that a user can grant the right to consume our api | |
# on a per app basis so that we could block an app that misbehaves. key and token | |
# can be constants in your code | |
$APP_KEY= <WERT_AUS_DENZUGANGSDATEN>; | |
$APP_TOKEN=<WERT_AUS_DENZUGANGSDATEN>; | |
# user credentials for the api. have to be taken from | |
# $SERVER/configuration/apps (we need a help text in the setup process) | |
# we display it there as KEY:TOKEN, so maybe a combined input would be | |
# the best and you split key and token by the colon. | |
$USER_KEY=<WERT_AUS_DENZUGANGSDATEN>; | |
$USER_TOKEN=<WERT_AUS_DENZUGANGSDATEN>; | |
$CUSTOMER_STATE_ID=<WERT_AUS_DENZUGANGSDATEN>; | |
# api requests require a signature which is invalidated after a given time. | |
$VALID_UNTIL = time() + 240; # 240 seconds from now | |
# signature is calculated by hashing with SHA2 | |
$source = "${USER_TOKEN}:${APP_TOKEN}:${VALID_UNTIL}"; | |
$signature=hash('sha256',$source ); | |
# authorization params are sent as get params | |
$requestParams = array( | |
'user' => $USER_KEY, | |
'app' => $APP_KEY, | |
'validuntil' => $VALID_UNTIL, | |
'signature' => $signature | |
); | |
$credentials = http_build_query($requestParams); | |
# CUSTOMER | |
$postData = array( | |
'name' => $user_login, | |
'customer_state_id' => $CUSTOMER_STATE_ID, | |
); | |
$response = api_call('customers', $postData, $credentials); | |
$customer = json_decode($response, true); | |
# EMPLOYEE | |
$postData = array( | |
'first_name' => $first_name, | |
'last_name' => $last_name, | |
'email' => $email, | |
'company_id' => $customer['id'], | |
'company_type' => 'Customer' | |
); | |
api_call('employees', $postData, $credentials); | |
# TASK | |
$postData = array( | |
'text' => 'Onlineregistrierung bearbeiten', | |
'taskable_type' => 'Customer', | |
'taskable_id' => $customer['id'], | |
'due_at' => date("c", time() + (24*60*60)*7) | |
); | |
api_call('tasks', $postData, $credentials); | |
} | |
$t = '' . time(); | |
create_skyline_customer('Max Muster' . $t, "Max", "Muster", "mm-${t}@example.org"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment