ok 1/1 : [1: at inscription - ok] * 2. to_pay . 'doit payer' -> ko 3/4 : [1: after form & new - ok], [2: after form choose paypal & expired - ok], [3: after payment failed - ok], [4: after transfert failed - ko] * 3. valid . 'carte valide' -> ko 1/2 : [1: after payment success - ok], [2: after transfert success - ko] * 4. waiting_invalid . 'en attente invalide' -> ko 3/4 : [1: after form choose transfert & expired - ok], [2: after card changes to expired & was waiting valid - ok], [3: verify at prof profil page - ok], [4: when event for expire fire - ko] * 5. waiting_valid . 'en attente valide' -> ok 1/1 : [1: after form choose transfert & not expired - ok] * 6. expired . 'carte expiree' -> ko 1/2 : [1: when prof access profil & expired - ok], [2: when event card expired fire - ko] * * [/] etat carte ('etat_carte') : * - 'Commande' -> ok 1/1 : [1: at inscription - ok] * - 'Renouvellement' -> ko 1/1 : [1: after succees payement - ok] * * [/] etat paiement ('etat_paiement') : * - 'en_cours' -> ok 1/1 : [1: start payment - ok] * - 'reussi' -> ok 1/1 : [1: after payment success - ok] * - 'echec' -> ok 1/1 : [1: after payment failure - ok] * - 'aucun' -> ok 2/2 : [1: default - ko], [2: after payment message is shown one time on profil page - ok] * * [/] type paiement ('paiement') : * - 'Paypal' -> ok 1/1 : [1: modified by diviformbuilder at form validation - ok] * - 'Virement' -> ok 1/1 : [1: modified by diviformbuilder at form validation - ok] * * [/] etat partenaire ('etat_page_partenaire') : * - 'publie' * - 'brouillon' * * [/] 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 * * */ function get_field_init_CIPF($acf_field_name, $acf_id) { Plgntls::debug_infos(); $acf_state = get_field($acf_field_name, $acf_id); if ($acf_state !== null) { return $acf_state; } /* * if get_field returns null, it means it is not initialized * - initialize it with 'temp' value * - then find it's default value, and update with it * - if no default value, update with first value * */ update_field($acf_field_name, 'temp', $acf_id); $acf_object = get_field_object($acf_field_name, $acf_id); $default = $acf_object['default_value']; if (empty($default)) { $choices = $acf_object['choices']; if (!is_array($choices)) { return false; } $default = reset($choices); } update_field($acf_field_name, $default, $acf_id); $acf_state = get_field($acf_field_name, $acf_id); return $acf_state; } /* * global 'setter' and 'izzer' for this file * */ function is_acf_state_CIPF($acf_field, $state_name, $acf_id) { Plgntls::debug_infos(); /* * when acf fields have not been initated a first time, you can't find them by name * - one solution is to use key instead * but it means knowing the key, in my case it prevents fabien to create a field himself * - another solution would be to : * try if is null, * if yes it means it was not initalize, * then initalize with any value, * find the default value, * and assign it * $acf_state = get_field($acf_field['_key'], $acf_id); */ $acf_state = get_field_init_CIPF($acf_field['_name'], $acf_id);; if ($acf_state === $acf_field[$state_name]) { return true; } return false; } function set_acf_state_CIPF($acf_field, $state_name, $acf_id) { Plgntls::debug_infos(); update_field($acf_field['_name'], $acf_field[$state_name], $acf_id); } /* * etat compte ('etat_compte') : * 1. new . 'nouveau prof' -> ok : [1: a l'inscription - ok] * 2. to_pay . 'doit payer' -> ko : [1: apres premier form - ok], [2: apres form qui suit carte expiree - ok], [3: apres paiement immediat echoue - ko], [4: apres virement echoue - ko] * 3. valid . 'carte valide' -> * 4. waiting_invalid . 'en attente invalide' -> * 5. waiting_valid . 'en attente valide' -> * 6. expired . 'carte expiree' -> * * receives the name of the state, and compare it to the current state * either use the is_acf_card_state_CIPF() function directly, * or one of the specific functions * */ function is_account_state_CIPF($state_name, $user_id = null) { Plgntls::debug_infos(); $acf_account_state = Cipf::ACF_ACCOUNT_STATE; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; return is_acf_state_CIPF($acf_account_state, $state_name, $acf_id); } function is_account_new_CIPF($user_id = null) { Plgntls::debug_infos(); return is_account_state_CIPF('new', $user_id); } function is_account_to_pay_CIPF($user_id = null) { Plgntls::debug_infos(); return is_account_state_CIPF('to_pay', $user_id); } function is_account_valid_CIPF($user_id = null) { Plgntls::debug_infos(); return is_account_state_CIPF('valid', $user_id); } function is_account_waiting_invalid_CIPF($user_id = null) { Plgntls::debug_infos(); return is_account_state_CIPF('waiting_invalid', $user_id); } function is_account_waiting_valid_CIPF($user_id = null) { Plgntls::debug_infos(); return is_account_state_CIPF('waiting_valid', $user_id); } function is_account_expired_CIPF($user_id = null) { Plgntls::debug_infos(); return is_account_state_CIPF('expired', $user_id); } // additional : check both waitings function is_account_waiting_transfert_CIPF($user_id = null) { Plgntls::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 : */ function set_account_state_CIPF($state_name, $user_id = null) { Plgntls::debug_infos(); $acf_account_state = Cipf::ACF_ACCOUNT_STATE; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; set_acf_state_CIPF($acf_account_state, $state_name, $acf_id); } function set_account_new_CIPF($user_id = null) { Plgntls::debug_infos(); set_account_state_CIPF('new', $user_id); } function set_account_to_pay_CIPF($user_id = null) { Plgntls::debug_infos(); set_account_state_CIPF('to_pay', $user_id); } function set_account_valid_CIPF($user_id = null) { Plgntls::debug_infos(); set_account_state_CIPF('valid', $user_id); } function set_account_waiting_invalid_CIPF($user_id = null) { Plgntls::debug_infos(); set_account_state_CIPF('waiting_invalid', $user_id); } function set_account_waiting_valid_CIPF($user_id = null) { Plgntls::debug_infos(); set_account_state_CIPF('waiting_valid', $user_id); } function set_account_expired_CIPF($user_id = null) { Plgntls::debug_infos(); set_account_state_CIPF('expired', $user_id); } /* * etat carte ('etat_carte') : * - 'Commande' * - 'Renouvellement' * */ function is_card_state_CIPF($state, $user_id = null) { Plgntls::debug_infos(); $acf_card_state = Cipf::ACF_CARD_STATE; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; return is_acf_state_CIPF($acf_card_state, $state, $acf_id); } function is_card_new_CIPF($user_id = null) { Plgntls::debug_infos(); return is_card_state_CIPF('new', $user_id); } function is_card_renew_CIPF($user_id = null) { Plgntls::debug_infos(); return is_card_state_CIPF('renew', $user_id); } /* * setters : */ function set_card_state_CIPF($state, $user_id = null) { Plgntls::debug_infos(); $acf_card_state = Cipf::ACF_CARD_STATE; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; set_acf_state_CIPF($acf_card_state, $state, $acf_id); } function set_card_new_CIPF($user_id = null) { Plgntls::debug_infos(); set_card_state_CIPF('new', $user_id); } function set_card_renew_CIPF($user_id = null) { Plgntls::debug_infos(); set_card_state_CIPF('renew', $user_id); } /* * etat page partenaire ('etat_page_partenaire') : * - 'Publiee' * - 'Brouillon' * */ function is_page_state_CIPF($state, $post_id = null) { Plgntls::debug_infos(); $acf_page_state = Cipf::ACF_PAGE_STATE; if (is_null($post_id)) { $post_id = get_the_ID(); } $acf_id = $post_id; return is_acf_state_CIPF($acf_page_state, $state, $acf_id); } function is_page_publish_CIPF($post_id = null) { Plgntls::debug_infos(); return is_page_state_CIPF('publish', $post_id); } function is_page_draft_CIPF($post_id = null) { Plgntls::debug_infos(); return is_page_state_CIPF('draft', $post_id); } /* * setters : */ function set_page_state_CIPF($state, $post_id = null) { Plgntls::debug_infos(); $acf_page_state = Cipf::ACF_PAGE_STATE; if (is_null($post_id)) { $post_id = get_the_ID(); } $acf_id = $post_id; set_acf_state_CIPF($acf_page_state, $state, $acf_id); } function set_page_publish_CIPF($post_id = null) { Plgntls::debug_infos(); set_page_state_CIPF('publish', $post_id); } function set_page_draft_CIPF($post_id = null) { Plgntls::debug_infos(); set_page_state_CIPF('draft', $post_id); } /* * type paiement ('paiement') : * - 'paypal'=>'Paypal' * - 'transfert'=>'Virement' * */ function is_card_method_CIPF($state, $user_id = null) { Plgntls::debug_infos(); $acf_card_payment_method = Cipf::ACF_CARD_PAYMENT_METHOD; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; return is_acf_state_CIPF($acf_card_payment_method, $state, $acf_id); } function is_payment_method_paypal_CIPF($user_id = null) { Plgntls::debug_infos(); return is_card_method_CIPF('paypal', $user_id); } function is_payment_method_transfert_CIPF($user_id = null) { Plgntls::debug_infos(); return is_card_method_CIPF('transfert', $user_id); } /* * etat paiement ('etat_paiement') : * - 'en_cours' * - 'reussi' * - 'echec' * - 'aucun' * * 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun' * */ function is_payment_state_CIPF($type, $user_id = null) { Plgntls::debug_infos(); $acf_card_payment_state = Cipf::ACF_CARD_PAYMENT_STATE; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; return is_acf_state_CIPF($acf_card_payment_state, $type, $acf_id); } function is_payment_started_CIPF($user_id = null) { Plgntls::debug_infos(); return is_payment_state_CIPF('started', $user_id); } function is_payment_success_CIPF($user_id = null) { Plgntls::debug_infos(); return is_payment_state_CIPF('success', $user_id); } function is_payment_failure_CIPF($user_id = null) { Plgntls::debug_infos(); return is_payment_state_CIPF('failure', $user_id); } function is_payment_nothing_CIPF($user_id = null) { Plgntls::debug_infos(); return is_payment_state_CIPF('nothing', $user_id); } /* * setters */ function set_payment_state_CIPF($type, $user_id = null) { Plgntls::debug_infos(); $acf_card_payment_state = Cipf::ACF_CARD_PAYMENT_STATE; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; set_acf_state_CIPF($acf_card_payment_state, $type, $acf_id); } function set_payment_started_CIPF($user_id = null) { Plgntls::debug_infos(); set_payment_state_CIPF('started', $user_id); } function set_payment_success_CIPF($user_id = null) { Plgntls::debug_infos(); set_payment_state_CIPF('success', $user_id); } function set_payment_failure_CIPF($user_id = null) { Plgntls::debug_infos(); set_payment_state_CIPF('failure', $user_id); } function set_payment_nothing_CIPF($user_id = null) { Plgntls::debug_infos(); set_payment_state_CIPF('nothing', $user_id); } /* * numero de carte * */ function set_card_number_CIPF($user_id = null) { Plgntls::debug_infos(); $acf_card_number = Cipf::ACF_CARD_NUMBER; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; $date_now = date_create('today'); $card_id = $date_now->format('Ymd') . $user_id; update_field($acf_card_number['_name'], $card_id, $acf_id); } /* * cgv * */ function reset_acf_cgv_CIPF($user_id = null) { Plgntls::debug_infos(); $acf_cgv = Cipf::ACF_PROF_CGV; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; update_field($acf_cgv['_name'], array(""), $acf_id); } /* * etat virement * */ function is_transfert_success_CIPF($user_id = null) { Plgntls::debug_infos(); $acf_transfert_state = Cipf::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 (is_null($transfert_state)) { return false; } else if (empty($transfert_state)) { return false; } else { return true; } } function reset_acf_transfert_CIPF($user_id = null) { Plgntls::debug_infos(); $acf_transfert_state = Cipf::ACF_TRANSFERT_STATE; if (is_null($user_id)) { $user_id = get_current_user_id(); } $acf_id = 'user_'.$user_id; update_field($acf_transfert_state['_name'], array(""), $acf_id); } ?>