From 0717a7d9e4eb09de05eb5ba352e0fd5ee6ac6af0 Mon Sep 17 00:00:00 2001 From: asus Date: Wed, 20 Mar 2024 11:42:22 +0100 Subject: [PATCH] v 0.3.10 admin can validate payment from front --- plugins/cipf_plugin/cipf_plugin.php | 4 +- .../cipf_plugin/php/paypal/payment_page.php | 2 +- ...profs_form.php => profs_form_commande.php} | 16 ++++---- plugins/cipf_plugin/php/profs_profil.php | 35 ++++++++++++++++- plugins/cipf_plugin/php/profs_states.php | 38 ++++++++++++++++++- plugins/cipf_plugin/utils/plgntls_class.php | 13 +++++-- 6 files changed, 92 insertions(+), 16 deletions(-) rename plugins/cipf_plugin/php/{profs_form.php => profs_form_commande.php} (85%) diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index 998e328..bb9f32d 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -27,8 +27,8 @@ include_once( plugin_dir_path(__FILE__) . '/utils/plgntls_class.php'); /* * general inclusions -*/ // utils : +*/ include_once(PLGNTLS_class::root_path() . 'php/utils/globals.php'); include_once(PLGNTLS_class::root_path() . 'utils/console_log.php'); @@ -41,7 +41,7 @@ include_once(PLGNTLS_class::root_path() . '/php/hide_admin.php'); //include_once(PLGNTLS_class::root_path() . '/php/menus.php'); include_once(PLGNTLS_class::root_path() . 'php/redirections.php'); include_once(PLGNTLS_class::root_path() . 'php/profs_profil.php'); -include_once(PLGNTLS_class::root_path() . 'php/profs_form.php'); +include_once(PLGNTLS_class::root_path() . 'php/profs_form_commande.php'); include_once(PLGNTLS_class::root_path() . 'php/profs_dates.php'); include_once(PLGNTLS_class::root_path() . 'php/profs_states.php'); include_once(PLGNTLS_class::root_path() . 'php/partners_register.php'); diff --git a/plugins/cipf_plugin/php/paypal/payment_page.php b/plugins/cipf_plugin/php/paypal/payment_page.php index 3934d81..a7c2f71 100644 --- a/plugins/cipf_plugin/php/paypal/payment_page.php +++ b/plugins/cipf_plugin/php/paypal/payment_page.php @@ -46,7 +46,7 @@ function payment_page_redirects_CIPF() { $role_prof = PLGNTLS_class::ROLE_PROF; // don't redirect if it is the divi builder mode - if (et_fb_is_enabled) { + if (et_fb_is_enabled()) { return; } // check the slug diff --git a/plugins/cipf_plugin/php/profs_form.php b/plugins/cipf_plugin/php/profs_form_commande.php similarity index 85% rename from plugins/cipf_plugin/php/profs_form.php rename to plugins/cipf_plugin/php/profs_form_commande.php index 9758dd4..d2f541b 100644 --- a/plugins/cipf_plugin/php/profs_form.php +++ b/plugins/cipf_plugin/php/profs_form_commande.php @@ -12,15 +12,17 @@ if (!defined('ABSPATH')) { /* -* actions after prof form is validated +* actions after prof form commande is validated * */ -function prof_after_form_CIPF($form_id, $post_array, $form_type) { +function prof_after_form_commande_CIPF($form_id, $post_array, $form_type) { PLGNTLS_class::debug_infos(); $acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE; -error_log('form_id: '.json_encode($form_id)); -error_log('post_array: '.json_encode($post_array)); -error_log('form_type: '.json_encode($form_type)); + $form_prof_commande_id = PLGNTLS_class::FORM_PROF_COMMANDE_ID; + + if ($form_prof_commande_id !== $form_id) { + return; + } //$user_id = get_current_user_id(); $user_id = $post_array['ID']; @@ -58,7 +60,7 @@ error_log('form_type: '.json_encode($form_type)); } } } -add_action('df_after_process', 'prof_after_form_CIPF', 10, 3); +add_action('df_after_process', 'prof_after_form_commande_CIPF', 10, 3); @@ -73,7 +75,7 @@ function prof_form_restrictions_CIPF(){ $role_prof = PLGNTLS_class::ROLE_PROF; // don't redirect if it is the divi builder mode - if (et_fb_is_enabled) { + if (et_fb_is_enabled()) { return; } if (!is_page($slug_renew_card)) { diff --git a/plugins/cipf_plugin/php/profs_profil.php b/plugins/cipf_plugin/php/profs_profil.php index 2f06740..a8c8350 100644 --- a/plugins/cipf_plugin/php/profs_profil.php +++ b/plugins/cipf_plugin/php/profs_profil.php @@ -10,6 +10,39 @@ if (!defined('ABSPATH')) { + + +/* +* actions after prof form transfert validation is processed +* +*/ +function prof_after_form_transfert_validation_CIPF($form_id, $post_array, $form_type) { + PLGNTLS_class::debug_infos(); + $acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE; + $form_prof_transfert_id = PLGNTLS_class::FORM_PROF_TRANSFERT_ID; + + if ($form_prof_transfert_id !== $form_id) { + return; + } + + //$user_id = get_current_user_id(); + $user_id = $post_array['ID']; + + + /* + * when transfert is validate, change card to valid + * + */ + if (is_transfert_success_CIPF($user_id)) { + set_account_valid_CIPF($user_id); + } +} +add_action('df_after_process', 'prof_after_form_transfert_validation_CIPF', 10, 3); + + + + + /* * early checks on profil page * @@ -60,7 +93,7 @@ function prof_profil_redirects_CIPF() { if (!is_author()) return; // don't redirect if it is the divi builder mode - if (et_fb_is_enabled) { + if (et_fb_is_enabled()) { return; } diff --git a/plugins/cipf_plugin/php/profs_states.php b/plugins/cipf_plugin/php/profs_states.php index 4596621..6674fe6 100644 --- a/plugins/cipf_plugin/php/profs_states.php +++ b/plugins/cipf_plugin/php/profs_states.php @@ -38,8 +38,9 @@ if (!defined('ABSPATH')) { * * [/] numero de carte ('numero_de_la_carte') -> ok 1/1 : [1: after payment & card is 'commande' - ok] * -* [ ] cgv +* [/] cgv * +* [/] etat_virement -> ko 0/2 : [1: at form validation - ko], [2: check on profil page - ko] * */ @@ -357,4 +358,39 @@ function reset_acf_cgv_CIPF($user_id = null) { + +/* +* etat virement +* +*/ +function is_transfert_success_CIPF($user_id = null) { + PLGNTLS_class::debug_infos(); + $acf_transfert_state = PLGNTLS_class::ACF_TRANSFERT_STATE; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $acf_id = 'user_'.$user_id; + $transfert_state = get_field($acf_transfert_state['_name'], $acf_id); + + /* + * before first use : returns null + * if checked : returns value + * if unchecked : returns empty + */ + if (empty($transfert_state)) { + return false; + } + if (is_null($transfert_state)) { + return false; + } + if (reset($transfert_state) === $acf_transfert_state['success']) { + return true; + } + return false; +} + + + + ?> diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index 4afc6b7..a0946ca 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -71,6 +71,7 @@ class PLGNTLS_class { const ACF_CARD_EXPIRATION = ['_name'=>'fin_de_validite']; // date picker const ACF_CARD_PAYMENT_STATE = ['_name'=>'etat_paiement', 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun']; // radio button const ACF_ACCOUNT_STATE = ['_name'=>'etat_compte', 'new'=>'nouveau prof', 'to_pay'=>'doit payer', 'valid'=>'carte valide', 'waiting_invalid'=>'en attente invalide', 'waiting_valid'=>'en attente valide', 'expired'=>'carte expiree']; + const ACF_TRANSFERT_STATE = ['_name'=>'etat_virement', 'success'=>'virement validé']; // META const META_PAYEMENT_STATUS = 'cipf_payement_status'; @@ -116,16 +117,20 @@ class PLGNTLS_class { // OPTIONS const OPTION_PARTNER_SLUG = ['_name'=>'cipf_partner_slug', 'true'=>'true', 'false'=>'false']; + // MENU + const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide']; + const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide']; + + // FORMS + const FORM_PROF_COMMANDE_ID = 'prof_commande'; + const FORM_PROF_TRANSFERT_ID = 'prof_valide_virement'; + // OTHER const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days') const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php) const ADMIN_VALIDATE_PROF_FIELD = 'admin_activate_prof_cipf'; // for admin_modif_prof.php - // MENU - const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide']; - const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide']; - private static $_DEBUG_INFOS = false; private static $_plugin_dir_path;