From 66fbbfd586c9cfa6c759d8d23a2f9ff2cef4ce8a Mon Sep 17 00:00:00 2001 From: asus Date: Thu, 21 Mar 2024 16:10:07 +0100 Subject: [PATCH] small improvements in handling prof states : - card date validation now uses direct card duration, not a parameter - checker for both types of transfert valid and invalid - mv checks for transfert and date expiration in specific functions --- plugins/cipf_plugin/cipf_plugin.php | 2 + plugins/cipf_plugin/php/partners_form.php | 27 ++++++++ .../php/paypal/update_user_payment.php | 5 +- plugins/cipf_plugin/php/profs_dates.php | 3 +- .../cipf_plugin/php/profs_handle_states.php | 66 +++++++++++++++++++ plugins/cipf_plugin/php/profs_profil.php | 45 ++----------- plugins/cipf_plugin/php/profs_states.php | 18 +++-- 7 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 plugins/cipf_plugin/php/partners_form.php create mode 100644 plugins/cipf_plugin/php/profs_handle_states.php diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index fe44ebf..376dcc3 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -44,8 +44,10 @@ include_once(PLGNTLS_class::root_path() . 'php/profs_profil.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/profs_handle_states.php'); include_once(PLGNTLS_class::root_path() . 'php/partners_register.php'); include_once(PLGNTLS_class::root_path() . 'php/partners_page.php'); +//include_once(PLGNTLS_class::root_path() . 'php/partners_form.php'); include_once(PLGNTLS_class::root_path() . 'php/display_css.php'); diff --git a/plugins/cipf_plugin/php/partners_form.php b/plugins/cipf_plugin/php/partners_form.php new file mode 100644 index 0000000..44cd9c9 --- /dev/null +++ b/plugins/cipf_plugin/php/partners_form.php @@ -0,0 +1,27 @@ + diff --git a/plugins/cipf_plugin/php/paypal/update_user_payment.php b/plugins/cipf_plugin/php/paypal/update_user_payment.php index 5c86263..0ce936a 100644 --- a/plugins/cipf_plugin/php/paypal/update_user_payment.php +++ b/plugins/cipf_plugin/php/paypal/update_user_payment.php @@ -150,11 +150,8 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) { */ function success_payment_for_user_CIPF($user_id, $order_id) { PLGNTLS_class::debug_infos(); - - $card_duration = PLGNTLS_class::CARD_VALIDITY_TIME; $meta_order_id = PLGNTLS_class::META_ORDER_ID; - $acf_id = 'user_'.$user_id; @@ -165,7 +162,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) { delete_user_meta($user_id, $meta_order_id, $order_id); - update_card_expiration_CIPF($user_id, $card_duration); + update_card_expiration_CIPF($user_id); if (is_card_new_CIPF()) { set_card_number_CIPF($user_id); diff --git a/plugins/cipf_plugin/php/profs_dates.php b/plugins/cipf_plugin/php/profs_dates.php index 5460a92..7bd1512 100644 --- a/plugins/cipf_plugin/php/profs_dates.php +++ b/plugins/cipf_plugin/php/profs_dates.php @@ -167,9 +167,10 @@ function card_date_exists_CIPF($user_id = null) { * card_duration is expected in a string format : https://www.php.net/manual/en/class.dateinterval.php * */ -function update_card_expiration_CIPF($user_id = null, $card_duration = '0') { +function update_card_expiration_CIPF($user_id = null) { PLGNTLS_class::debug_infos(); $acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION; + $card_duration = PLGNTLS_class::CARD_VALIDITY_TIME; /* * define acf id and acf date format diff --git a/plugins/cipf_plugin/php/profs_handle_states.php b/plugins/cipf_plugin/php/profs_handle_states.php new file mode 100644 index 0000000..cd853d2 --- /dev/null +++ b/plugins/cipf_plugin/php/profs_handle_states.php @@ -0,0 +1,66 @@ + diff --git a/plugins/cipf_plugin/php/profs_profil.php b/plugins/cipf_plugin/php/profs_profil.php index e0334d6..0b2fa7d 100644 --- a/plugins/cipf_plugin/php/profs_profil.php +++ b/plugins/cipf_plugin/php/profs_profil.php @@ -11,7 +11,6 @@ if (!defined('ABSPATH')) { - /* * actions after prof form transfert validation is processed * @@ -28,29 +27,8 @@ function prof_after_form_transfert_validation_CIPF($form_id, $post_array, $form_ //$user_id = get_current_user_id(); $user_id = $post_array['ID']; - - /* - * check if transfert was waiting, if no stop here - * when transfert is validate, - * - change card to valid - * - and reset the field - * - */ - $is_transfert = false; - if (is_account_waiting_valid_CIPF($user_id)) { - $is_transfert = true; - } - else if (is_account_waiting_invalid_CIPF($user_id)) { - $is_transfert = true; - } - if ($is_transfert === false) { - reset_acf_transfert_CIPF($user_id); - return; - } - if (is_transfert_success_CIPF($user_id)) { - set_account_valid_CIPF($user_id); - reset_acf_transfert_CIPF($user_id); - } + // the check is not really connected to the form, it check the acf value, whatever the form value is, the form validation is just a trigger for this check + handle_transfert_validation_CIPF($user_id); } add_action('df_after_process', 'prof_after_form_transfert_validation_CIPF', 10, 3); @@ -72,22 +50,8 @@ function prof_profil_check_CIPF() { // the way to find the id of the author of an author_page $author_id = get_queried_object_id(); - - /* - * in case event didn't fire, change account to expire here - * also check for waiting transfert : valid -> invalid - * - */ - if (card_date_exists_CIPF($author_id)) { - if (is_card_date_expired_CIPF($author_id)) { - if (!is_account_expired_CIPF($author_id)) { - set_account_expired_CIPF($author_id); - } - if (is_account_waiting_valid_CIPF($author_id)) { - set_account_waiting_invalid_CIPF($author_id); - } - } - } + // in case event didn't fire, handle card_expiration + handle_card_expire_CIPF($author_id); } add_action('wp', 'prof_profil_check_CIPF', 11); @@ -113,7 +77,6 @@ function prof_profil_redirects_CIPF() { } - /* * check multiple user roles * https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083 diff --git a/plugins/cipf_plugin/php/profs_states.php b/plugins/cipf_plugin/php/profs_states.php index 3e4f911..9411bb6 100644 --- a/plugins/cipf_plugin/php/profs_states.php +++ b/plugins/cipf_plugin/php/profs_states.php @@ -22,10 +22,6 @@ if (!defined('ABSPATH')) { * - 'Commande' -> ok 1/1 : [1: at inscription - ok] * - 'Renouvellement' -> ko 1/1 : [1: after succees payement - ok] * -* [ ] activation du compte ('compte-actif') : -* - 'Actif' -> equivalent a etat compte [3] carte valide -* - 'Inactif' -> equivalent a etat compte [2] doit payer -* * [/] etat paiement ('etat_paiement') : * - 'en_cours' -> ok 1/1 : [1: start payment - ok] * - 'reussi' -> ok 1/1 : [1: after payment success - ok] @@ -38,9 +34,10 @@ if (!defined('ABSPATH')) { * * [/] numero de carte ('numero_de_la_carte') -> ok 1/1 : [1: after payment & card is 'commande' - ok] * +* [/] etat_virement -> ko 2/3 : [1: at form validation - ok], [2: check on profil page - ko], [3: when transfert is started, reset - ok]] +* * [/] cgv * -* [/] etat_virement -> ko 2/3 : [1: at form validation - ok], [2: check on profil page - ko], [3: when transfert is started, reset - ok]] * */ @@ -167,6 +164,17 @@ function is_account_expired_CIPF($user_id = null) { PLGNTLS_class::debug_infos(); return is_account_state_CIPF('expired', $user_id); } +// additional : check both waitings +function is_account_waiting_transfert_CIPF($user_id = null) { + PLGNTLS_class::debug_infos(); + if (is_account_waiting_valid_CIPF($user_id)) { + return true; + } + if (is_account_waiting_invalid_CIPF($user_id)) { + return true; + } + return false; +} /* * setters : */