| Server IP : 188.114.96.2 / Your IP : 104.23.243.200 Web Server : Apache/2.4.59 (Debian) System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : edlftp ( 1002) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/nicolasj/www/sms.formationlangues.be/assets/frontend/js/ |
Upload File : |
function init_cart_payment(stripe_api_public, stripe_client_secret, redirect_url) {
const stripe = Stripe(stripe_api_public);
let elements;
initialize();
document.querySelector("#payment-form").addEventListener("submit", handleSubmit);
// Fetches a payment intent and captures the client secret
async function initialize() {
elements = stripe.elements({clientSecret: stripe_client_secret});
const paymentElementOptions = {
layout: "accordion",
};
const paymentElement = elements.create("payment", paymentElementOptions);
paymentElement.mount("#payment-element");
}
async function handleSubmit(e) {
e.preventDefault();
// Check if the customer have filled user informations
const filled_customer = await is_fullfilled_customer();
if (!filled_customer) {
showMessage('Les coordonnées du responsable ne sont pas entière remplies.');
return;
}
setLoading(true);
const {error} = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: redirect_url,
},
});
if (error.type === "card_error" || error.type === "validation_error") {
showMessage(error.message);
} else {
showMessage("An unexpected error occurred.");
}
setLoading(false);
}
async function is_fullfilled_customer() {
const response = await fetch('/customers/fullfilled_status');
const status = await response.json();
return status.fullfilled === true
}
function showMessage(messageText) {
const messageContainer = document.querySelector("#payment-message");
messageContainer.classList.remove("d-none");
messageContainer.textContent = messageText;
}
// Show a spinner on payment submission
function setLoading(isLoading) {
if (isLoading) {
// Disable the button and show a spinner
document.querySelector("#submit").disabled = true;
document.querySelector("#spinner").classList.remove("d-none");
document.querySelector("#button-text").classList.add("d-none");
} else {
document.querySelector("#submit").disabled = false;
document.querySelector("#spinner").classList.add("d-none");
document.querySelector("#button-text").classList.remove("d-none");
}
}
}