336 lines
10 KiB
PHP
336 lines
10 KiB
PHP
<?php
|
|
|
|
/*
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* [/] etat compte ('etat_compte') :
|
|
* 1. new . 'nouveau prof' -> 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' -> ok 1/1 : [1: after form choose transfert & expired - ok]
|
|
* 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 virement ('etat_virement') :
|
|
* - 'en attente' -> ko 0/1 : [1: after form validation $ virement checked - ok]
|
|
* - 'reçu' -> ko 0/1 : [1: after admin change it from front - ko]
|
|
*
|
|
* [ ] 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]
|
|
* - '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]
|
|
*
|
|
* [/] numero de carte ('numero_de_la_carte') -> ok 1/1 : [1: after payment & card is 'commande' - ok]
|
|
*
|
|
*/
|
|
|
|
|
|
|
|
function get_field_init_CIPF($acf_field, $acf_id) {
|
|
$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'], 'temps', $acf_id);
|
|
$acf_object = get_field_object($acf_field['_name'], $acf_id);
|
|
$default = $acf_object['default_value'];
|
|
if (empty($default)) {
|
|
$choices = $acf_object['choices'];
|
|
$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($user_id = null, $acf_field, $state_name) {
|
|
PLGNTLS_class::debug_infos();
|
|
|
|
if (is_null($user_id)) {
|
|
$user_id = get_current_user_id();
|
|
}
|
|
$acf_id = 'user_'.$user_id;
|
|
|
|
/*
|
|
* 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, $acf_id);;
|
|
|
|
if ($acf_state === $acf_field[$state_name]) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
function set_acf_state_CIPF($user_id = null, $acf_field, $state_name) {
|
|
PLGNTLS_class::debug_infos();
|
|
|
|
if (is_null($user_id)) {
|
|
$user_id = get_current_user_id();
|
|
}
|
|
$acf_id = 'user_'.$user_id;
|
|
|
|
update_field($acf_field['_key'], $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($user_id = null, $state_name) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
|
|
return is_acf_state_CIPF($user_id, $acf_account_state, $state_name);
|
|
}
|
|
function is_account_new_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_account_state_CIPF($user_id, 'new');
|
|
}
|
|
function is_account_to_pay_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_account_state_CIPF($user_id, 'to_pay');
|
|
}
|
|
function is_account_valid_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_account_state_CIPF($user_id, 'valid');
|
|
}
|
|
function is_account_waiting_invalid_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_account_state_CIPF($user_id, 'waiting_invalid');
|
|
}
|
|
function is_account_waiting_valid_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_account_state_CIPF($user_id, 'waiting_valid');
|
|
}
|
|
function is_account_expired_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_account_state_CIPF($user_id, 'expired');
|
|
}
|
|
/*
|
|
* setters :
|
|
*/
|
|
function set_account_state_CIPF($user_id = null, $state_name) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
|
|
set_acf_state_CIPF($user_id, $acf_account_state, $state_name);
|
|
}
|
|
function set_account_new_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_account_state_CIPF($user_id, 'new');
|
|
}
|
|
function set_account_to_pay_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_account_state_CIPF($user_id, 'to_pay');
|
|
}
|
|
function set_account_valid_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_account_state_CIPF($user_id, 'valid');
|
|
}
|
|
function set_account_waiting_invalid_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_account_state_CIPF($user_id, 'waiting_invalid');
|
|
}
|
|
function set_account_waiting_valid_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_account_state_CIPF($user_id, 'waiting_valid');
|
|
}
|
|
function set_account_expired_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_account_state_CIPF($user_id, 'expired');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
* etat carte ('etat_carte') :
|
|
* - 'Commande'
|
|
* - 'Renouvellement'
|
|
*
|
|
*/
|
|
function is_card_new_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
|
return is_acf_state_CIPF($user_id, $acf_card_state, 'new');
|
|
}
|
|
function is_card_renew_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
|
return is_acf_state_CIPF($user_id, $acf_card_state, 'renew');
|
|
}
|
|
function set_card_new_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
|
set_acf_state_CIPF($user_id, $acf_card_state, 'new');
|
|
}
|
|
function set_card_renew_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
|
set_acf_state_CIPF($user_id, $acf_card_state, 'renew');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
* type paiement ('paiement') :
|
|
* - 'paypal'=>'Paypal'
|
|
* - 'transfert'=>'Virement'
|
|
*
|
|
*/
|
|
function is_payment_method_paypal_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
|
return is_acf_state_CIPF($user_id, $acf_card_payment_method, 'paypal');
|
|
}
|
|
function is_payment_method_transfert_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
|
return is_acf_state_CIPF($user_id, $acf_card_payment_method, 'transfert');
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
* etat paiement ('etat_paiement') :
|
|
* - 'en_cours'
|
|
* - 'reussi'
|
|
* - 'echec'
|
|
* - 'aucun'
|
|
*
|
|
* 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun'
|
|
*
|
|
*/
|
|
function is_payment_state_CIPF($user_id = null, $type) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_payment_state = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
|
return is_acf_state_CIPF($user_id, $acf_card_payment_state, $type);
|
|
}
|
|
function is_payment_started_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_payment_state_CIPF($user_id, 'started');
|
|
}
|
|
function is_payment_success_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_payment_state_CIPF($user_id, 'success');
|
|
}
|
|
function is_payment_failure_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_payment_state_CIPF($user_id, 'failure');
|
|
}
|
|
function is_payment_nothing_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
return is_payment_state_CIPF($user_id, 'nothing');
|
|
}
|
|
/*
|
|
* setters
|
|
*/
|
|
function set_payment_state_CIPF($user_id = null, $type) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_payment_state = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
|
set_acf_state_CIPF($user_id, $acf_card_payment_state, $type);
|
|
}
|
|
function set_payment_started_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_payment_state_CIPF($user_id, 'started');
|
|
}
|
|
function set_payment_success_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_payment_state_CIPF($user_id, 'success');
|
|
}
|
|
function set_payment_failure_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_payment_state_CIPF($user_id, 'failure');
|
|
}
|
|
function set_payment_nothing_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
set_payment_state_CIPF($user_id, 'nothing');
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
*
|
|
*/
|
|
function set_card_number_CIPF($user_id = null) {
|
|
PLGNTLS_class::debug_infos();
|
|
$acf_card_number = PLGNTLS_class::ACF_CARD_NUMBER;
|
|
|
|
if (is_null($user_id)) {
|
|
$user_id = get_current_user_id();
|
|
}
|
|
|
|
$date_now = date_create('today');
|
|
$card_id = $date_now->format('Ymd') . $user_id;
|
|
update_field($acf_card_number['_key'], $card_id, $acf_id);
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|