no message

This commit is contained in:
2025-01-28 16:53:50 +01:00
parent d57e97a68e
commit 2c32f46cc3
2 changed files with 91 additions and 87 deletions

View File

@@ -21,101 +21,105 @@ class Belevo_Bezahl_Modul extends IPSModule
{
$apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Test-API-Schlüssel
$html = "<html>
<head>
<script>
const stripeScript = document.createElement('script');
stripeScript.src = 'https://js.stripe.com/v3/';
stripeScript.onload = function() {
console.log('Stripe.js loaded successfully');
initializeStripe();
};
stripeScript.onerror = function() {
console.error('Failed to load Stripe.js');
};
document.head.appendChild(stripeScript);
$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>
function initializeStripe() {
const stripe = Stripe('$apiKey');
const elements = stripe.elements();
<script>
// Stripe initialisieren
const stripe = Stripe('pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm'); // Ersetze mit deinem Stripe-Publishable-Key
const paymentRequest = stripe.paymentRequest({
country: 'CH',
currency: 'chf',
total: {
label: 'Reservation Amount',
amount: 1000,
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'],
},
requestPayerName: true,
requestPayerEmail: true,
requestPayerPhone: true,
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 }),
});
paymentRequest.on('paymentmethod', function(ev) {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/api/');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
'jsonrpc': '2.0',
'method': 'SetValue',
'params': ['AmountIsReserved', true],
'id': 0
}));
xhr.onload = function() {
if (xhr.status === 200) {
ev.complete('success');
console.log('Reservierung erfolgreich.');
} else {
ev.complete('fail');
console.log('Reservierung fehlgeschlagen.');
}
};
});
const result = await response.json();
const prButton = elements.create('paymentRequestButton', {
paymentRequest: paymentRequest,
});
if (result.clientSecret) {
// Zahlung mit Stripe abschließen
const stripeResult = await stripe.confirmCardPayment(result.clientSecret);
paymentRequest.canMakePayment().then(function(result) {
if (result) {
prButton.mount('#payment-request-button');
} else {
document.getElementById('payment-request-button').style.display = 'none';
if (stripeResult.error) {
alert('Zahlung fehlgeschlagen: ' + stripeResult.error.message);
} else if (stripeResult.paymentIntent && stripeResult.paymentIntent.status === 'succeeded') {
alert('Zahlung erfolgreich abgeschlossen!');
}
});
document.getElementById('reservate-button').addEventListener('click', function() {
document.getElementById('payment-request-button').style.display = 'block';
});
document.getElementById('get-amount-button').addEventListener('click', function() {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/api/');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
'jsonrpc': '2.0',
'method': 'SetValue',
'params': ['AmountIsReserved', false],
'id': 0
}));
xhr.onload = function() {
if (xhr.status === 200) {
console.log('Abzug erfolgreich.');
} else {
console.log('Abzug fehlgeschlagen.');
}
};
});
} 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>
</head>
<body>
<h1>Stripe Payment Request API Integration</h1>
<button id=\"reservate-button\">Reservate</button>
<button id=\"get-amount-button\">Get Amount</button>
<div id=\"payment-request-button\"></div>
</body>
</html>";
});
</script>
</body>
</html>";
SetValue($this->ReadPropertyInteger("HTMLBox"), $html);
}

View File

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