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
This commit is contained in:
asus
2024-03-21 16:10:07 +01:00
parent 782ae1b1d8
commit 66fbbfd586
7 changed files with 115 additions and 51 deletions

View File

@@ -0,0 +1,27 @@
<?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!');
}
function partner_form_redirection_CIPF($form_id, $submit_result, $redirect_url_after_submission) {
error_log("---in partner_form_redirection_CIPF");
error_log("form_id");
error_log(json_encode($form_id));
error_log("submit_result");
error_log(json_encode($submit_result));
error_log("redirect_url_after_submission");
error_log(json_encode($redirect_url_after_submission));
}
do_action('df_before_redirect', 'partner_form_redirection_CIPF');
?>

View File

@@ -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);

View File

@@ -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

View File

@@ -0,0 +1,66 @@
<?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!');
}
/*
* if field transfert-validation is not checked, do nothing
* else
* first reset the field
* then
* if no transfert was waiting, do nothing
* when transfert is validate :
* - change card to valid
* - update date
*
*/
function handle_transfert_validation_CIPF($user_id) {
PLGNTLS_class::debug_infos();
if (false === is_transfert_success_CIPF($user_id)) {
return;
}
reset_acf_transfert_CIPF($user_id);
if (false === is_account_waiting_transfert_CIPF($user_id)) {
return;
}
set_account_valid_CIPF($user_id);
update_card_expiration_CIPF($user_id);
}
/*
* if card expire, makes some changes
*
*/
function handle_card_expire_CIPF($user_id) {
PLGNTLS_class::debug_infos();
if (false === card_date_exists_CIPF($user_id)) {
return;
}
if (false === is_card_date_expired_CIPF($user_id)) {
return;
}
if (false === is_account_expired_CIPF($user_id)) {
set_account_expired_CIPF($user_id);
}
if (is_account_waiting_valid_CIPF($user_id)) {
set_account_waiting_invalid_CIPF($user_id);
}
}
?>

View File

@@ -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

View File

@@ -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 :
*/