s
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
{
|
||||
"elements":[
|
||||
|
||||
{
|
||||
"type": "SelectVariable",
|
||||
"name": "Reservate",
|
||||
"caption": "Betrag reservieren",
|
||||
"test": true
|
||||
},
|
||||
{
|
||||
"type": "SelectVariable",
|
||||
"name": "GetAmount",
|
||||
"caption": "Betrag Abziehen",
|
||||
"test": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,18 +7,16 @@ class Belevo_Bezahl_Modul extends IPSModule
|
||||
{
|
||||
// Die Standard-Create() Methode aufrufen
|
||||
parent::Create();
|
||||
$this->RegisterVariableBoolean("Reservate", "Reservate", '', false);
|
||||
$this->RegisterPropertyInteger("Reservate", 0);
|
||||
$this->RegisterPropertyInteger("GetAmount", 0);
|
||||
$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);
|
||||
$this->RegisterMessage($this->ReadPropertyInteger("Reservate"), VM_UPDATE);
|
||||
$this->RegisterMessage($this->ReadPropertyInteger("GetAmount"), VM_UPDATE);
|
||||
}
|
||||
|
||||
|
||||
public function ApplyChanges()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
@@ -26,15 +24,17 @@ class Belevo_Bezahl_Modul extends IPSModule
|
||||
|
||||
public function MessageSink($TimeStamp, $SenderID, $Message, $Data)
|
||||
{
|
||||
IPS_LogMessage("Belevo_Bezahl_Modul", "MessageSink: SenderID=$SenderID, Message=$Message");
|
||||
|
||||
switch ($SenderID) {
|
||||
case $this->GetIDForIdent("Reservate"):
|
||||
if (GetValueBoolean($this->GetIDForIdent("Reservate"))) {
|
||||
case $this->ReadPropertyInteger("Reservate"):
|
||||
if (GetValueBoolean($this->ReadPropertyInteger("Reservate"))) {
|
||||
$this->ReservateAmount(GetValueInteger($this->GetIDForIdent("ReservationAmount")));
|
||||
}
|
||||
break;
|
||||
case $this->GetIDForIdent("Get"):
|
||||
if (GetValueBoolean($this->GetIDForIdent("Get"))) {
|
||||
$this->GetAmount(GetValueInteger($this->GetIDForIdent("GetAmount")));
|
||||
case $this->ReadPropertyInteger("GetAmount"):
|
||||
if (GetValueBoolean($this->ReadPropertyInteger("GetAmount"))) {
|
||||
$this->GetAmount(GetValueInteger($this->ReadPropertyInteger("GetAmount")));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -42,56 +42,55 @@ class Belevo_Bezahl_Modul extends IPSModule
|
||||
|
||||
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
|
||||
IPS_LogMessage("Belevo_Bezahl_Modul", "ReservateAmount: amount=$amount");
|
||||
|
||||
$data = [
|
||||
"amount" => $amount,
|
||||
"currency" => "CHF", // Ersetze dies durch die gewünschte Währung
|
||||
"paymentMethod" => "creditcard" // Beispiel: Kreditkarte
|
||||
];
|
||||
// Beispiel-Logik zur Reservierung des Betrags bei Stripe
|
||||
$apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Ersetze dies durch deinen tatsächlichen API-Schlüssel
|
||||
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-type: application/json\r\nAuthorization: Bearer $apiKey\r\n",
|
||||
'method' => 'POST',
|
||||
'content' => json_encode($data),
|
||||
],
|
||||
];
|
||||
// Öffnen eines Fensters zur Eingabe der Zahlungsinformationen
|
||||
$html = '<script>
|
||||
var windowObjectReference;
|
||||
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";
|
||||
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($apiUrl, false, $context);
|
||||
function openRequestedPopup() {
|
||||
windowObjectReference = window.open("https://checkout.stripe.com/pay", "Stripe_Window", strWindowFeatures);
|
||||
}
|
||||
|
||||
if ($result === FALSE) {
|
||||
echo "Reservierung fehlgeschlagen.";
|
||||
openRequestedPopup();
|
||||
</script>';
|
||||
|
||||
SetValue(23828, $html); // Baut das HTML auf
|
||||
|
||||
// Simulierte erfolgreiche Reservierung
|
||||
$reservationSuccessful = true;
|
||||
|
||||
if ($reservationSuccessful) {
|
||||
SetValueBoolean($this->GetIDForIdent("AmountIsReserved"), true);
|
||||
IPS_LogMessage("Belevo_Bezahl_Modul", "Reservierung erfolgreich.");
|
||||
} else {
|
||||
$response = json_decode($result, true);
|
||||
if ($response['success']) {
|
||||
SetValueBoolean($this->GetIDForIdent("AmountIsReserved"), true);
|
||||
} else {
|
||||
echo "Reservierung fehlgeschlagen: " . $response['message'];
|
||||
}
|
||||
IPS_LogMessage("Belevo_Bezahl_Modul", "Reservierung fehlgeschlagen.");
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
IPS_LogMessage("Belevo_Bezahl_Modul", "GetAmount: amount=$amount");
|
||||
|
||||
// Beispiel-Logik zum Abziehen des Betrags bei Stripe
|
||||
$apiUrl = "https://api.stripe.com/v1/charges";
|
||||
$apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Ersetze dies durch deinen tatsächlichen API-Schlüssel
|
||||
|
||||
$data = [
|
||||
"amount" => $amount,
|
||||
"amount" => $amount * 100, // Betrag in Cent
|
||||
"currency" => "CHF", // Ersetze dies durch die gewünschte Währung
|
||||
"paymentMethod" => "creditcard" // Beispiel: Kreditkarte
|
||||
"source" => "tok_visa" // Beispiel: Test-Token von Stripe
|
||||
];
|
||||
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-type: application/json\r\nAuthorization: Bearer $apiKey\r\n",
|
||||
'header' => "Content-type: application/x-www-form-urlencoded\r\nAuthorization: Bearer $apiKey\r\n",
|
||||
'method' => 'POST',
|
||||
'content' => json_encode($data),
|
||||
'content' => http_build_query($data),
|
||||
],
|
||||
];
|
||||
|
||||
@@ -99,15 +98,16 @@ class Belevo_Bezahl_Modul extends IPSModule
|
||||
$result = file_get_contents($apiUrl, false, $context);
|
||||
|
||||
if ($result === FALSE) {
|
||||
echo "Abzug fehlgeschlagen.";
|
||||
IPS_LogMessage("Belevo_Bezahl_Modul", "Abzug fehlgeschlagen.");
|
||||
} else {
|
||||
$response = json_decode($result, true);
|
||||
if ($response['success']) {
|
||||
SetValueBoolean($this->GetIDForIdent("Reservate"), false);
|
||||
if (isset($response['id'])) {
|
||||
SetValueBoolean($this->ReadPropertyInteger("Reservate"), false);
|
||||
SetValueBoolean($this->GetIDForIdent("AmountIsReserved"), false);
|
||||
SetValueBoolean($this->GetIDForIdent("Get"), false);
|
||||
SetValueBoolean($this->ReadPropertyInteger("GetAmount"), false);
|
||||
IPS_LogMessage("Belevo_Bezahl_Modul", "Abzug erfolgreich.");
|
||||
} else {
|
||||
echo "Abzug fehlgeschlagen: " . $response['message'];
|
||||
IPS_LogMessage("Belevo_Bezahl_Modul", "Abzug fehlgeschlagen: " . $response['error']['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user