no message
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
.bar-container {
|
||||
width: 100%;
|
||||
background-color: #eee;
|
||||
border-radius: 5px;
|
||||
overflow: hidden;
|
||||
height: 20px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.bar {
|
||||
height: 100%;
|
||||
float: left;
|
||||
}
|
||||
.bar-cons { background-color: #4CAF50; }
|
||||
.bar-feed { background-color: #8BC34A; }
|
||||
.bar-pv { background-color: #FF9800; }
|
||||
.bar-grid { background-color: #FF5722; }
|
||||
.value-label {
|
||||
font-size: 0.9em;
|
||||
margin: 4px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="value-label" id="prodLabel"></div>
|
||||
<div class="bar-container">
|
||||
<div class="bar bar-cons" id="barCons"></div>
|
||||
<div class="bar bar-feed" id="barFeed"></div>
|
||||
</div>
|
||||
|
||||
<div class="value-label" id="consLabel"></div>
|
||||
<div class="bar-container">
|
||||
<div class="bar bar-pv" id="barPV"></div>
|
||||
<div class="bar bar-grid" id="barGrid"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Daten in die Balken und Beschriftungen einfüllen
|
||||
function Apply(data) {
|
||||
document.getElementById('prodLabel').innerText =
|
||||
"Produktion: " + data.value.prod + " kWh";
|
||||
document.getElementById('barCons').style.width = data.prodCons + "%";
|
||||
document.getElementById('barFeed').style.width = data.prodFeed + "%";
|
||||
|
||||
document.getElementById('consLabel').innerText =
|
||||
"Verbrauch: " + data.value.cons + " kWh";
|
||||
document.getElementById('barPV').style.width = data.consPV + "%";
|
||||
document.getElementById('barGrid').style.width = data.consGrid + "%";
|
||||
}
|
||||
|
||||
// HTML-SDK: hier kommen die Nachrichten vom Modul an
|
||||
function handleMessage(msg) {
|
||||
if (msg) {
|
||||
Apply(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// beim Laden gleich initial Daten anfordern
|
||||
requestAction('update', true);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,126 +1,126 @@
|
||||
<?php
|
||||
class Belevo_Bezahl_Modul extends IPSModule
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class Belevo_PV_Visu extends IPSModule
|
||||
{
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
$this->RegisterPropertyInteger("Reservate", 0);
|
||||
$this->RegisterPropertyInteger("GetAmount", 0);
|
||||
$this->RegisterPropertyInteger("HTMLBox", 0);
|
||||
$this->RegisterVariableInteger("ReservationAmount", "ReservationAmount", '', 0);
|
||||
$this->RegisterVariableBoolean("AmountIsReserved", "AmountIsReserved", '', false);
|
||||
// vier Properties, in denen später die vier Zähler-Variablen gewählt werden
|
||||
$this->RegisterPropertyInteger('VarProduction', 0);
|
||||
$this->RegisterPropertyInteger('VarConsumption', 0);
|
||||
$this->RegisterPropertyInteger('VarFeedIn', 0);
|
||||
$this->RegisterPropertyInteger('VarGrid', 0);
|
||||
// HTML-SDK aktivieren
|
||||
$this->SetVisualizationType(3);
|
||||
}
|
||||
|
||||
public function ApplyChanges()
|
||||
public function GetConfigurationForm(): string
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
$this->SetHTMLContent();
|
||||
}
|
||||
|
||||
private function SetHTMLContent()
|
||||
{
|
||||
$apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Test-API-Schlüssel
|
||||
|
||||
$html = "<html lang='en'>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>Google Pay mit Stripe</title>
|
||||
<!-- Stripe.js -->
|
||||
<script src='https://js.stripe.com/v3/'></script>
|
||||
<!-- Google Pay API -->
|
||||
<script src='https://pay.google.com/gp/p/js/pay.js' async></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Google Pay Integration mit Stripe</h1>
|
||||
<button id='google-pay-button'>Mit Google Pay bezahlen</button>
|
||||
|
||||
<script>
|
||||
// Stripe initialisieren
|
||||
const stripe = Stripe('pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm'); // Ersetze mit deinem Stripe-Publishable-Key
|
||||
|
||||
const googlePayButton = document.getElementById('google-pay-button');
|
||||
|
||||
// Google Pay-Konfiguration
|
||||
const googlePayConfig = {
|
||||
apiVersion: 2,
|
||||
apiVersionMinor: 0,
|
||||
allowedPaymentMethods: [
|
||||
{
|
||||
type: 'CARD',
|
||||
parameters: {
|
||||
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
|
||||
allowedCardNetworks: ['VISA', 'MASTERCARD'],
|
||||
},
|
||||
tokenizationSpecification: {
|
||||
type: 'PAYMENT_GATEWAY',
|
||||
parameters: {
|
||||
gateway: 'stripe',
|
||||
'stripe:version': '2020-08-27',
|
||||
'stripe:publishableKey': 'pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm', // Ersetze hier ebenfalls
|
||||
},
|
||||
},
|
||||
},
|
||||
return json_encode([
|
||||
'elements' => [
|
||||
[
|
||||
'type' => 'SelectVariable',
|
||||
'name' => 'VarProduction',
|
||||
'caption' => 'Produktion (kWh)'
|
||||
],
|
||||
[
|
||||
'type' => 'SelectVariable',
|
||||
'name' => 'VarConsumption',
|
||||
'caption' => 'Verbrauch (kWh)'
|
||||
],
|
||||
[
|
||||
'type' => 'SelectVariable',
|
||||
'name' => 'VarFeedIn',
|
||||
'caption' => 'Einspeisung (kWh)'
|
||||
],
|
||||
[
|
||||
'type' => 'SelectVariable',
|
||||
'name' => 'VarGrid',
|
||||
'caption' => 'Bezug Netz (kWh)'
|
||||
]
|
||||
],
|
||||
merchantInfo: {
|
||||
merchantId: 'TEST', // Für Testumgebungen
|
||||
merchantName: 'Dein Unternehmen',
|
||||
},
|
||||
transactionInfo: {
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: '100.00', // Betrag in CHF
|
||||
currencyCode: 'CHF',
|
||||
},
|
||||
};
|
||||
|
||||
// Eventlistener für den Google Pay-Button
|
||||
googlePayButton.addEventListener('click', async () => {
|
||||
try {
|
||||
const googlePayClient = new google.payments.api.PaymentsClient({ environment: 'TEST' });
|
||||
|
||||
// Prüfen, ob Google Pay verfügbar ist
|
||||
const isReadyToPay = await googlePayClient.isReadyToPay(googlePayConfig);
|
||||
if (!isReadyToPay.result) {
|
||||
alert('Google Pay ist auf diesem Gerät nicht verfügbar.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Google Pay PaymentData abrufen
|
||||
const paymentData = await googlePayClient.loadPaymentData(googlePayConfig);
|
||||
|
||||
// Token aus dem PaymentData extrahieren
|
||||
const paymentToken = paymentData.paymentMethodData.tokenizationData.token;
|
||||
|
||||
// Token an das Backend senden
|
||||
const response = await fetch('/path-to-your-backend.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token: paymentToken }),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.clientSecret) {
|
||||
// Zahlung mit Stripe abschließen
|
||||
const stripeResult = await stripe.confirmCardPayment(result.clientSecret);
|
||||
|
||||
if (stripeResult.error) {
|
||||
alert('Zahlung fehlgeschlagen: ' + stripeResult.error.message);
|
||||
} else if (stripeResult.paymentIntent && stripeResult.paymentIntent.status === 'succeeded') {
|
||||
alert('Zahlung erfolgreich abgeschlossen!');
|
||||
}
|
||||
} else {
|
||||
alert('Ein Fehler ist im Backend aufgetreten.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fehler bei der Zahlung:', error);
|
||||
alert('Ein Fehler ist aufgetreten: ' + error.message);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>";
|
||||
|
||||
SetValue($this->ReadPropertyInteger("HTMLBox"), $html);
|
||||
'actions' => []
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird automatisch aufgerufen, wenn die Visu die Tile anfordert
|
||||
*/
|
||||
public function GetVisualizationTile(int $InstanceID): string
|
||||
{
|
||||
$file = __DIR__ . '/module.html';
|
||||
if (!file_exists($file)) {
|
||||
return '';
|
||||
}
|
||||
// Übersetzungen einbinden
|
||||
return $this->Translate(file_get_contents($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* JS-requestAction ruft das auf, um frische Daten anzufordern
|
||||
*/
|
||||
public function RequestAction(string $Ident, $Value): void
|
||||
{
|
||||
if ($Ident === 'update') {
|
||||
$this->Update();
|
||||
} else {
|
||||
throw new Exception('Unknown Ident');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet die Tages-Summen und sendet sie an die Visu
|
||||
*/
|
||||
private function Update(): void
|
||||
{
|
||||
$start = strtotime('today 00:00');
|
||||
$end = time();
|
||||
$prod = $this->GetDailyTotal($this->ReadPropertyInteger('VarProduction'), $start, $end);
|
||||
$cons = $this->GetDailyTotal($this->ReadPropertyInteger('VarConsumption'), $start, $end);
|
||||
$feed = $this->GetDailyTotal($this->ReadPropertyInteger('VarFeedIn'), $start, $end);
|
||||
$grid = $this->GetDailyTotal($this->ReadPropertyInteger('VarGrid'), $start, $end);
|
||||
|
||||
// Quoten berechnen
|
||||
$prodCons = $prod > 0 ? ($cons / $prod) * 100 : 0;
|
||||
$prodFeed = $prod > 0 ? ($feed / $prod) * 100 : 0;
|
||||
$consPV = $cons > 0 ? (min($cons, $prod) / $cons) * 100 : 0;
|
||||
$consGrid = $cons > 0 ? ($grid / $cons) * 100 : 0;
|
||||
|
||||
$data = [
|
||||
'prodCons' => round($prodCons, 2),
|
||||
'prodFeed' => round($prodFeed, 2),
|
||||
'consPV' => round($consPV, 2),
|
||||
'consGrid' => round($consGrid, 2),
|
||||
'value' => [
|
||||
'prod' => round($prod, 2),
|
||||
'cons' => round($cons, 2),
|
||||
'feed' => round($feed, 2),
|
||||
'grid' => round($grid, 2)
|
||||
]
|
||||
];
|
||||
$this->UpdateVisualizationTile($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruft den Tages-Gesamtwert aus dem Archiv ab (tägliche Aggregation)
|
||||
*/
|
||||
private function GetDailyTotal(int $varID, int $start, int $end): float
|
||||
{
|
||||
if ($varID <= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
// Erste Archive-Instanz finden
|
||||
$archives = IPS_GetInstanceListByModuleID('{43192F11-5B02-4B5D-9B53-8B4DBD4769E9}');
|
||||
if (empty($archives)) {
|
||||
return 0.0;
|
||||
}
|
||||
$archiveID = $archives[0];
|
||||
// AC_GetAggregatedValues( InstanzID, VarID, AggregationLevel(1=Täglich), Start, Ende, Limit=1 )
|
||||
$values = AC_GetAggregatedValues($archiveID, $varID, 1, $start, $end, 1);
|
||||
if (empty($values)) {
|
||||
return 0.0;
|
||||
}
|
||||
// Bei Counter-Variablen enthält 'Avg' die Summe der Deltas
|
||||
return (float)$values[0]['Avg'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user