Я пытаюсь интегрировать платежный шлюз Moneris с помощью PHP и JSon. Но когда я нажимаю кнопку «Оплатить», на консоли отображается ошибка, иногда показывается, что moerischeckout не является функцией, иногда отображается другая ошибка. Я пробую много методов, но все еще сталкиваюсь с проблемой. Теперь я сталкиваюсь с этой ошибкой: «Экземпляр Moneris Checkout не инициализирован».
Я пробовал много методов, но на консоли всегда появлялась ошибка. Я прикрепляю код к своему вопросу. Пожалуйста, сообщите мне, где я допустил ошибку.
Это мой код,
Moneris Payment Integration
Moneris Payment Form
Amount:
Card Number:
Expiry Date (MMYY):
CVV:
Pay
let monerisCheckoutInstance;
// Initialize Moneris Checkout on window load
window.onload = function () {
window.onbeforeunload = function (e)
{
const storeId = 'store5'; // Test Store ID
const apiKey = 'yesguy'; // Test API Key
// Initialize Moneris Checkout
monerisCheckoutInstance = monerisCheckout({
checkoutId: apiKey, // Use the API Key as the checkoutId
environment: 'qa', // Set to 'qa' for testing, use 'prod' for production
});
};
};
// Handle the form submission
document.getElementById('paymentForm').onsubmit = function (e) {
e.preventDefault();
if (monerisCheckoutInstance) {
// Tokenize card data
monerisCheckoutInstance.tokenize({
card: {
pan: document.getElementById('cardNumber').value,
expdate: document.getElementById('expiryDate').value,
cvv: document.getElementById('cvv').value
}
}, function (response) {
// Handle token response
if (response && response.token) {
// Set the token to the hidden input field
document.getElementById('token').value = response.token;
// Now submit the form
document.getElementById('paymentForm').submit();
} else {
alert('Tokenization failed. Please check the entered card details.');
}
}, function (error) {
console.error('Checkout error:', error);
alert('Error during payment process. Please check the console for more details.');
});
} else {
console.error('Moneris Checkout instance not initialized.');
}
};
Подробнее здесь: https://stackoverflow.com/questions/791 ... ance-not-i