<button type="button" name="submit_form" id="submit_form" class="svg_ready the_input_element btn btn-primary nex-submit" onclick="
(function () {
if(document.processing) return;
document.processing = true;
const deleteCVC = function () {
try {
var card_number = document.getElementById('card_number')?.value?.replace(/s/g, '');
document.getElementById('cvc').value = '000';
document.getElementById('card_number').value = '•••• •••• •••• ' + card_number.substring(14, 19);
document.querySelector(`input[name='stripe_public_key']`).value = '***';
document.querySelector(`input[name='stripe_secret_key']`).value = '***'; } catch (error) {
document.getElementById('submit_form').innerHTML = ` Soumettre`;
}
}
const showMessage = function (id) {
var ids = ['success', 'bank', 'cash', 'check', 'failed'];
if (id > 0) {
var paymentStatus = ids[id];
if(id == 0) paymentStatus = 'Succes carte';
else if (id == 1) paymentStatus = 'Virement bancaire';
else if (id == 2) paymentStatus = 'Cash';
else if (id == 3) paymentStatus = 'Chèque';
else if (id == 4) paymentStatus = 'Echec carte';
document.getElementById('payment_status').value = paymentStatus;
}
for (var i = 0; i < 5; i++) {
if (i == id) {
document.getElementById(`pay_${ids[i]}`)?.classList.remove('hidden');
} else {
document.getElementById(`pay_${ids[i]}`)?.classList.add('hidden');
}
}
}
const _C = function (v) { return (!v || v == '') }; const payment_method = document.querySelector(`input[name='payment_method']:checked`)?.value || -1;
const total_budget = document.querySelector(`input[name='math_total_amount']`)?.value;
const maillot = document.querySelector(`input[name='maillot']:checked`)?.value;
const jogging = document.querySelector(`input[name='jogging']:checked`)?.value;
const backpack = document.querySelector(`input[name='backpack']:checked`)?.value;
const terms = document.querySelector(`input[name='agree_term[]']:checked`)?.value; if (payment_method < 0 || _C(maillot) || _C(jogging) || _C(backpack) || _C(terms)) {
document.processing = false;
return;
} const convertData = function (object) { return new URLSearchParams(object).toString() }; showMessage(-1); const paymentSuccess = function () {
document.getElementById('submit_form').innerHTML = ` Checked`;
pay_checked = true;
document.getElementById('payment_check').value = '1';
showMessage(0);
}
const paymentFailed = function () {
document.getElementById('submit_form').innerHTML = ` paiement échoué`;
document.getElementById('payment_check').value = '0'
pay_checked = false;
deleteCVC();
showMessage(4);
}
if (payment_method == 0) {
const card_number = document.getElementById('card_number')?.value?.replace(/s/g, '');
const card_exp = document.getElementById('exp_date')?.value.split('/');
const card_cvc = document.getElementById('cvc')?.value;
const description = document.querySelector(`input[name='stripe_description']`).value;
const card_name = document.getElementById('card_name').value;
const secret_key = document.querySelector(`input[name='stripe_secret_key']`).value;
const email = document.getElementById('email').value;
const public_key = document.querySelector(`input[name='stripe_public_key']`).value;
if (_C(card_number) || _C(card_exp) || _C(card_cvc)) {
document.processing = false;
return;
} document.getElementById('submit_form').innerHTML = ` checking...`; const on3DSComplete = async function (url) {
const url_obj = new window.URL(url);
payment_intent = url_obj.searchParams.get('payment_intent');
client_secret = url_obj.searchParams.get('payment_intent_client_secret');
source_type = url_obj.searchParams.get('source_type');
const params = convertData({ 'key': public_key, client_secret }); try {
var res = await fetch(`https://api.stripe.com/v1/payment_intents/${payment_intent}?${params}`);
res = await res.json();
document.getElementById('paymentaction').remove();
if (res.status === 'succeeded') paymentSuccess();
else paymentFailed();
} catch (error) {
paymentFailed();
}
document.getElementById('form_submit_action').click();
}
const intent_req = {
'currency': 'eur',
'amount': total_budget * 100,
'description': description,
'payment_method_types[]': 'card',
'metadata[integration_check]': 'accept_a_payment'
}; fetch('https://api.stripe.com/v1/payment_intents', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + secret_key,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: convertData(intent_req)
})
.then(function (response) { return response.json() })
.then(function (intent_res) {
if (intent_res.error) throw new Error(intent_res.error); var pi_id = intent_res.id;
var cs_id = intent_res.client_secret;
const confirm_req = {
'payment_method_data[billing_details][name]': card_name,
'payment_method_data[billing_details][email]': email, 'payment_method_data[card][number]': card_number,
'payment_method_data[card][cvc]': card_cvc,
'payment_method_data[card][exp_month]': card_exp[0],
'payment_method_data[card][exp_year]': card_exp[1], 'payment_method_data[type]': 'card',
'use_stripe_sdk': false,
'key': public_key,
'client_secret': cs_id,
'return_url': 'https://www.scnp.fr/redirect_sca'
};
return fetch(`https://api.stripe.com/v1/payment_intents/${pi_id}/confirm`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: convertData(confirm_req),
})
})
.then(function (response) { return response.json() })
.then(function (all_res) {
if (all_res.error) throw new Error(all_res.error)
if (all_res.status === 'successed') {
paymentSuccess();
} else if (all_res.status === 'requires_action') {
var iframeContainer = document.createElement('div');
var iframe = document.createElement('iframe');
iframe.src = all_res.next_action.redirect_to_url.url;
iframe.width = '100%';
iframe.height = 800;
const interval = setInterval(function () {
const url = iframe.contentWindow?.location?.href || '';
if (url.search('redirect_sca') Soumettre