This commit is contained in:
2025-01-28 15:27:44 +01:00
parent 8a61df2346
commit 4c0e144aa9
2 changed files with 49 additions and 25 deletions

View File

@@ -48,35 +48,60 @@ class Belevo_Bezahl_Modul extends IPSModule
{
IPS_LogMessage("Belevo_Bezahl_Modul", "ReservateAmount: amount=$amount");
// Beispiel-Logik zur Reservierung des Betrags bei Stripe
// Beispiel-Logik zur Reservierung des Betrags bei Stripe mit Google Pay
$apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Test-API-Schlüssel
// Öffnen eines Fensters zur Eingabe der Zahlungsinformationen über Google Pay
$html = '<script src="https://js.stripe.com/v3/"></script>
<script>
var stripe = Stripe("' . $apiKey . '");
var elements = stripe.elements();
var paymentRequest = stripe.paymentRequest({
country: "CH",
currency: "chf",
total: {
label: "Reservation Amount",
amount: ' . ($amount * 100) . ',
},
requestPayerName: true,
requestPayerEmail: true,
});
// Öffnen eines Fensters zur Eingabe der Zahlungsinformationen
$html = '<script>
var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";
var prButton = elements.create("paymentRequestButton", {
paymentRequest: paymentRequest,
});
function openRequestedPopup() {
windowObjectReference = window.open("https://checkout.stripe.com/pay", "Stripe_Window", strWindowFeatures);
}
paymentRequest.canMakePayment().then(function(result) {
if (result) {
prButton.mount("#payment-request-button");
} else {
document.getElementById("payment-request-button").style.display = "none";
}
});
openRequestedPopup();
</script>';
paymentRequest.on("token", function(ev) {
// Send the token to your server to charge it!
fetch("/charges", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({token: ev.token.id}),
}).then(function(response) {
if (response.ok) {
ev.complete("success");
SetValueBoolean(' . $this->GetIDForIdent("AmountIsReserved") . ', true);
IPS_LogMessage("Belevo_Bezahl_Modul", "Reservierung erfolgreich.");
} else {
ev.complete("fail");
IPS_LogMessage("Belevo_Bezahl_Modul", "Reservierung fehlgeschlagen.");
}
});
});
</script>
<div id="payment-request-button"></div>';
SetValue($this->ReadPropertyInteger("Reservate"), $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 {
IPS_LogMessage("Belevo_Bezahl_Modul", "Reservierung fehlgeschlagen.");
}
}
public function GetAmount($amount)
@@ -85,8 +110,7 @@ class Belevo_Bezahl_Modul extends IPSModule
// Beispiel-Logik zum Abziehen des Betrags bei Stripe
$apiUrl = "https://api.stripe.com/v1/charges";
$apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm";
$apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Test-API-Schlüssel
$data = [
"amount" => $amount * 100, // Betrag in Cent

View File

@@ -6,7 +6,7 @@
"compatibility": {
"version": "7.1"
},
"version": "1.007",
"version": "1.008",
"build": 0,
"date": 0
}