no message

This commit is contained in:
dh
2025-01-28 16:53:50 +01:00
parent d57e97a68e
commit 2c32f46cc3
2 changed files with 91 additions and 87 deletions
+90 -86
View File
@@ -21,101 +21,105 @@ class Belevo_Bezahl_Modul extends IPSModule
{ {
$apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Test-API-Schlüssel $apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Test-API-Schlüssel
$html = "<html> $html = "<html lang='en'>
<head> <head>
<script> <meta charset='UTF-8'>
const stripeScript = document.createElement('script'); <meta name='viewport' content='width=device-width, initial-scale=1.0'>
stripeScript.src = 'https://js.stripe.com/v3/'; <title>Google Pay mit Stripe</title>
stripeScript.onload = function() { <!-- Stripe.js -->
console.log('Stripe.js loaded successfully'); <script src='https://js.stripe.com/v3/'></script>
initializeStripe(); <!-- Google Pay API -->
}; <script src='https://pay.google.com/gp/p/js/pay.js' async></script>
stripeScript.onerror = function() { </head>
console.error('Failed to load Stripe.js'); <body>
}; <h1>Google Pay Integration mit Stripe</h1>
document.head.appendChild(stripeScript); <button id='google-pay-button'>Mit Google Pay bezahlen</button>
function initializeStripe() { <script>
const stripe = Stripe('$apiKey'); // Stripe initialisieren
const elements = stripe.elements(); const stripe = Stripe('pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm'); // Ersetze mit deinem Stripe-Publishable-Key
const paymentRequest = stripe.paymentRequest({ const googlePayButton = document.getElementById('google-pay-button');
country: 'CH',
currency: 'chf', // Google Pay-Konfiguration
total: { const googlePayConfig = {
label: 'Reservation Amount', apiVersion: 2,
amount: 1000, apiVersionMinor: 0,
allowedPaymentMethods: [
{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['VISA', 'MASTERCARD'],
}, },
requestPayerName: true, tokenizationSpecification: {
requestPayerEmail: true, type: 'PAYMENT_GATEWAY',
requestPayerPhone: true, 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) { const result = await response.json();
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 prButton = elements.create('paymentRequestButton', { if (result.clientSecret) {
paymentRequest: paymentRequest, // Zahlung mit Stripe abschließen
}); const stripeResult = await stripe.confirmCardPayment(result.clientSecret);
paymentRequest.canMakePayment().then(function(result) { if (stripeResult.error) {
if (result) { alert('Zahlung fehlgeschlagen: ' + stripeResult.error.message);
prButton.mount('#payment-request-button'); } else if (stripeResult.paymentIntent && stripeResult.paymentIntent.status === 'succeeded') {
} else { alert('Zahlung erfolgreich abgeschlossen!');
document.getElementById('payment-request-button').style.display = 'none';
} }
}); } else {
alert('Ein Fehler ist im Backend aufgetreten.');
document.getElementById('reservate-button').addEventListener('click', function() { }
document.getElementById('payment-request-button').style.display = 'block'; } catch (error) {
}); console.error('Fehler bei der Zahlung:', error);
alert('Ein Fehler ist aufgetreten: ' + error.message);
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.');
}
};
});
} }
</script> });
</head> </script>
<body> </body>
<h1>Stripe Payment Request API Integration</h1> </html>";
<button id=\"reservate-button\">Reservate</button>
<button id=\"get-amount-button\">Get Amount</button>
<div id=\"payment-request-button\"></div>
</body>
</html>";
SetValue($this->ReadPropertyInteger("HTMLBox"), $html); SetValue($this->ReadPropertyInteger("HTMLBox"), $html);
} }
+1 -1
View File
@@ -6,7 +6,7 @@
"compatibility": { "compatibility": {
"version": "7.1" "version": "7.1"
}, },
"version": "1.025", "version": "1.026",
"build": 0, "build": 0,
"date": 0 "date": 0
} }