Merge branch 'fronkdev' into 'master'

creating Snopp Order from Order (OrderProduct with oaid or preroder_id)

See merge request fronk/thetool!2047
This commit is contained in:
Frank Schubert
2026-01-26 12:58:46 +00:00
7 changed files with 338 additions and 47 deletions

View File

@@ -1,36 +0,0 @@
<?php
/**
* Represents the SNOPP API.
*/
class SNOPP {
/**
* SNOPP constructor.
*/
public function __construct() {}
/**
* Search for support tickets using the SNOPP API.
* @return array - The search results.
*/
function getSNOPPTickets(): array {
$SNOPP_API_URL = SNOPP_API_URL;
$SNOPP_API_KEY = SNOPP_API_KEY;
$ctx_opts = [
'http' => [
'method' => 'GET',
'header' => "X-Api-Key: $SNOPP_API_KEY\r\n",
]
];
$snopp_output = file_get_contents("$SNOPP_API_URL/ticket/find?provider_id=all&status=open", false, stream_context_create($ctx_opts));
$ticket_obj = json_decode($snopp_output);
$tickets = $ticket_obj->result->tickets;
return $tickets;
}
}
?>

111
lib/Snoppapi/Snoppapi.php Normal file
View File

@@ -0,0 +1,111 @@
<?php
/**
* Represents the SNOPP API.
*/
class Snoppapi {
private $log;
private $baseurl;
private $apikey;
public function __construct($baseurl, $apikey) {
$this->baseurl = $baseurl;
$this->apikey = $apikey;
$this->log = mfLoghandler::singleton();
}
public function searchAddress(Array $address_data) {
$street = trim($address_data['street']);
$zip = trim($address_data['zip']);
$city = trim($address_data['city']);
$ctx_opts = [
'http' => [
'method' => 'GET',
'ignore_errors' => true,
'header' => [
"Accept: application/json",
"X-Api-Key: {$this->apikey}",
]
]
];
$getHomesEp = $this->baseurl.SNOPP_API_EP_GET_HOMES;
//$url = $getHomesEp."?".$qs;
$url = $getHomesEp;
$ctx = stream_context_create($ctx_opts);
$this->log->debug(__METHOD__.": Getting SNOPP homes: $url");
$response = file_get_contents($url, false, $ctx);
//var_dump($response);exit;
if($response === false) {
$this->log->error("Fehler beim Homes abfragen in SNOPP");
return false;
}
$resp_data = json_decode($response);
$homes = $resp_data->result->homes;
$results = [];
foreach($homes as $home) {
if(trim($home->street) == $street
&& trim($home->zip) == $zip
&& trim($home->city) == $city
) {
$results[] = $home;
}
}
return $results;
}
public function submitOrder(Array $order_data) {
$data = [];
foreach(["oan_id", "execution_date", "product_id", "name", "street", "zip", "city"] as $field) {
if(!array_key_exists($field, $order_data) || !$order_data[$field]) {
$this->log->error(__METHOD__.": Mandatory field '$field' missing");
return false;
}
$data[$field] = $order_data[$field];
}
foreach(["phone", "mobile", "email"] as $field) {
if(array_key_exists($field, $order_data) && $order_data[$field]) {
$data[$field] = $order_data[$field];
}
}
$ctx_opts = [
'http' => [
'method' => 'POST',
'content' => json_encode($data),
'ignore_errors' => true,
'header' => [
"Accept: application/json",
"Content-type: application/json",
"X-Api-Key: {$this->apikey}",
]
]
];
$url = $this->baseurl.SNOPP_API_EP_SUBMIT_ORDER;
$ctx = stream_context_create($ctx_opts);
$this->log->debug(__METHOD__.": Ordering Snopp product: $url\n".print_r($data, true));
$response = file_get_contents($url, false, $ctx);
$this->log->debug(__METHOD__.": ".print_r($response, true));
if($response === false) {
$this->log->error("Fehler beim Bestellen in SNOPP ".print_r($response, true));
return false;
}
$resp_data = json_decode($response);
return $resp_data;
}
}