Version 2.0.0 Beta
This commit is contained in:
126
Belevo_Bezahl_Modul/module.php
Normal file
126
Belevo_Bezahl_Modul/module.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
class Belevo_Bezahl_Modul 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);
|
||||
}
|
||||
|
||||
public function ApplyChanges()
|
||||
{
|
||||
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
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user