get_ongoing_credit_token(); } if (empty($token)) { wp_redirect(home_url()); exit; } get_header(); //try to load the model $post = $_POST; if (empty($post)) { $post = array('credit-direct-token' => $token); } if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit_step4.php')) { $currentCredit = $model->getCredit($token); $type_credit_selected = ''; $coBorrower = $model->getCoBorrower($currentCredit); $borrower = $model->getBorrower($currentCredit); if(isset($currentCredit->sel_credit) && !empty($currentCredit->sel_credit)) { $type_credit_selected = $currentCredit->sel_credit; } if(isset($_POST['type_credit_selected']) && !empty($_POST['type_credit_selected']) || isset($_POST['sub_loan_type']) && !empty($_POST['sub_loan_type'])) $type_credit_selected = isset($_POST['sub_loan_type']) ? $_POST['sub_loan_type'] : $_POST['type_credit_selected']; if(empty($type_credit_selected)) { $type_credit_selected = $currentCredit->type_credit; } if (is_object($currentCredit)) { // Sauvegarder l'étape 3 seulement si on vient du formulaire POST if (!empty($_POST)) { // Validation Turnstile si configuré if (\libraries\TurnstileValidator::isConfigured()) { $turnstileToken = isset($_POST['cf-turnstile-response']) ? $_POST['cf-turnstile-response'] : ''; $turnstileValidator = new \libraries\TurnstileValidator(); $turnstileResult = $turnstileValidator->validateForDisplay($turnstileToken, $_SERVER['REMOTE_ADDR'] ?? null); if (!$turnstileResult['valid']) { $turnstile_error = $turnstileResult['message']; } } // Ne traiter le formulaire que si Turnstile est valide (ou non configuré) if (!isset($turnstile_error)) { $model->save_step_3($post, $currentCredit); } } //try to load the view if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step4.php')) { include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step4.php'); } } else { // Si le crédit n'existe pas, rediriger vers la page d'accueil wp_redirect(home_url()); exit; } } get_footer();