From 7027c1839137bc5706d3ccd001876a259381eba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=A4fliger?= Date: Tue, 28 Jan 2025 14:43:42 +0100 Subject: [PATCH] =?UTF-8?q?Bezahlmodul=20zum=20testen=20eingef=C3=BChgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Belevo_Bezahl_Modul/README.md | 67 +++++++++++++++++++ Belevo_Bezahl_Modul/form.json | 5 ++ Belevo_Bezahl_Modul/module.json | 12 ++++ Belevo_Bezahl_Modul/module.php | 112 ++++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 Belevo_Bezahl_Modul/README.md create mode 100644 Belevo_Bezahl_Modul/form.json create mode 100644 Belevo_Bezahl_Modul/module.json create mode 100644 Belevo_Bezahl_Modul/module.php diff --git a/Belevo_Bezahl_Modul/README.md b/Belevo_Bezahl_Modul/README.md new file mode 100644 index 0000000..b059e3a --- /dev/null +++ b/Belevo_Bezahl_Modul/README.md @@ -0,0 +1,67 @@ +# Manager_1 +Beschreibung des Moduls. + +### Inhaltsverzeichnis + +1. [Funktionsumfang](#1-funktionsumfang) +2. [Voraussetzungen](#2-voraussetzungen) +3. [Software-Installation](#3-software-installation) +4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon) +5. [Statusvariablen und Profile](#5-statusvariablen-und-profile) +6. [WebFront](#6-webfront) +7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz) + +### 1. Funktionsumfang + +* + +### 2. Voraussetzungen + +- IP-Symcon ab Version 7.1 + +### 3. Software-Installation + +* Über den Module Store das 'Manager_1'-Modul installieren. +* Alternativ über das Module Control folgende URL hinzufügen + +### 4. Einrichten der Instanzen in IP-Symcon + + Unter 'Instanz hinzufügen' kann das 'Manager_1'-Modul mithilfe des Schnellfilters gefunden werden. + - Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen) + +__Konfigurationsseite__: + +Name | Beschreibung +-------- | ------------------ + | + | + +### 5. Statusvariablen und Profile + +Die Statusvariablen/Kategorien werden automatisch angelegt. Das Löschen einzelner kann zu Fehlfunktionen führen. + +#### Statusvariablen + +Name | Typ | Beschreibung +------ | ------- | ------------ + | | + | | + +#### Profile + +Name | Typ +------ | ------- + | + | + +### 6. WebFront + +Die Funktionalität, die das Modul im WebFront bietet. + +### 7. PHP-Befehlsreferenz + +`boolean GEF_BeispielFunktion(integer $InstanzID);` +Erklärung der Funktion. + +Beispiel: +`GEF_BeispielFunktion(12345);` \ No newline at end of file diff --git a/Belevo_Bezahl_Modul/form.json b/Belevo_Bezahl_Modul/form.json new file mode 100644 index 0000000..55397d9 --- /dev/null +++ b/Belevo_Bezahl_Modul/form.json @@ -0,0 +1,5 @@ +{ + "elements":[ + + ] + } \ No newline at end of file diff --git a/Belevo_Bezahl_Modul/module.json b/Belevo_Bezahl_Modul/module.json new file mode 100644 index 0000000..80bb7ae --- /dev/null +++ b/Belevo_Bezahl_Modul/module.json @@ -0,0 +1,12 @@ +{ + "id": "{466A36DA-3C90-06E8-1D57-161D921B45EE}", + "name": "Belevo_Bezahl_Modul", + "type": 3, + "vendor": "Belevo AG", + "aliases": [], + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "GEF", + "url": "" +} \ No newline at end of file diff --git a/Belevo_Bezahl_Modul/module.php b/Belevo_Bezahl_Modul/module.php new file mode 100644 index 0000000..c11fd49 --- /dev/null +++ b/Belevo_Bezahl_Modul/module.php @@ -0,0 +1,112 @@ +class Belevo_Bezahl_Modul extends IPSModule +{ + public function Create() + { + // Die Standard-Create() Methode aufrufen + parent::Create(); + $this->RegisterVariableBoolean("Reservate", "Reservate", '', false); + $this->RegisterVariableInteger("ReservationAmount", "ReservationAmount", '', 0); + $this->RegisterVariableBoolean("AmountIsReserved", "AmountIsReserved", '', false); + $this->RegisterVariableBoolean("Get", "Get", '', false); + $this->RegisterVariableInteger("GetAmount", "GetAmount", '', 0); + + // Event-Handler registrieren + $this->RegisterMessage($this->GetIDForIdent("Reservate"), VM_UPDATE); + $this->RegisterMessage($this->GetIDForIdent("Get"), VM_UPDATE); + } + + + public function ApplyChanges() + { + parent::ApplyChanges(); + } + + public function MessageSink($TimeStamp, $SenderID, $Message, $Data) + { + switch ($SenderID) { + case $this->GetIDForIdent("Reservate"): + if (GetValueBoolean($this->GetIDForIdent("Reservate"))) { + $this->ReservateAmount(GetValueInteger($this->GetIDForIdent("ReservationAmount"))); + } + break; + case $this->GetIDForIdent("Get"): + if (GetValueBoolean($this->GetIDForIdent("Get"))) { + $this->GetAmount(GetValueInteger($this->GetIDForIdent("GetAmount"))); + } + break; + } + } + + public function ReservateAmount($amount) + { + // Beispiel-Logik zur Reservierung des Betrags bei Wallee + $apiUrl = "https://api.wallee.com/transaction/create"; + $apiKey = "DEIN_API_KEY"; // Ersetze dies durch deinen tatsächlichen API-Schlüssel + + $data = [ + "amount" => $amount, + "currency" => "CHF", // Ersetze dies durch die gewünschte Währung + "paymentMethod" => "creditcard" // Beispiel: Kreditkarte + ]; + + $options = [ + 'http' => [ + 'header' => "Content-type: application/json\r\nAuthorization: Bearer $apiKey\r\n", + 'method' => 'POST', + 'content' => json_encode($data), + ], + ]; + + $context = stream_context_create($options); + $result = file_get_contents($apiUrl, false, $context); + + if ($result === FALSE) { + echo "Reservierung fehlgeschlagen."; + } else { + $response = json_decode($result, true); + if ($response['success']) { + SetValueBoolean($this->GetIDForIdent("AmountIsReserved"), true); + } else { + echo "Reservierung fehlgeschlagen: " . $response['message']; + } + } + } + + public function GetAmount($amount) + { + // Beispiel-Logik zum Abziehen des Betrags bei Wallee + $apiUrl = "https://api.wallee.com/transaction/charge"; + $apiKey = "DEIN_API_KEY"; // Ersetze dies durch deinen tatsächlichen API-Schlüssel + + $data = [ + "amount" => $amount, + "currency" => "CHF", // Ersetze dies durch die gewünschte Währung + "paymentMethod" => "creditcard" // Beispiel: Kreditkarte + ]; + + $options = [ + 'http' => [ + 'header' => "Content-type: application/json\r\nAuthorization: Bearer $apiKey\r\n", + 'method' => 'POST', + 'content' => json_encode($data), + ], + ]; + + $context = stream_context_create($options); + $result = file_get_contents($apiUrl, false, $context); + + if ($result === FALSE) { + echo "Abzug fehlgeschlagen."; + } else { + $response = json_decode($result, true); + if ($response['success']) { + SetValueBoolean($this->GetIDForIdent("Reservate"), false); + SetValueBoolean($this->GetIDForIdent("AmountIsReserved"), false); + SetValueBoolean($this->GetIDForIdent("Get"), false); + } else { + echo "Abzug fehlgeschlagen: " . $response['message']; + } + } + } +} +?> \ No newline at end of file