From a2e37cf62175f95b48bef1bfb24718e97dbd1c63 Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 9 Apr 2024 22:33:34 +0200 Subject: [PATCH] schedult card expiration --- plugins/cipf_plugin/php/_actions_payments.php | 1 - .../php/_actions_scheduled_events.php | 58 ++++++------------- .../php/paypal/update_user_payment.php | 4 ++ .../cipf_plugin/php/profs_handle_states.php | 32 ++++++++++ 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/plugins/cipf_plugin/php/_actions_payments.php b/plugins/cipf_plugin/php/_actions_payments.php index 139130c..483a12a 100644 --- a/plugins/cipf_plugin/php/_actions_payments.php +++ b/plugins/cipf_plugin/php/_actions_payments.php @@ -97,7 +97,6 @@ function is_paypal_force_1_cent_CIPF() { Plgntls::debug_infos(); $paypal_options = get_paypal_options_CIPF(); -error_log("paypal_options: " . json_encode($paypal_options)); return $paypal_options['force_1_cent']; } diff --git a/plugins/cipf_plugin/php/_actions_scheduled_events.php b/plugins/cipf_plugin/php/_actions_scheduled_events.php index bfbe5e9..bb63157 100644 --- a/plugins/cipf_plugin/php/_actions_scheduled_events.php +++ b/plugins/cipf_plugin/php/_actions_scheduled_events.php @@ -58,7 +58,7 @@ function schedule_delete_orderid_CIPF($order_id, $user_id) { $duration_order_id = Cipf::DURATION_OLD_ORDER_ID; $delay = strtotime($duration_order_id); - wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($order_id, $user_id)); + wp_schedule_single_event($delay, 'CIPF_orderid_deletion_event', array($order_id, $user_id)); } function delete_order_id_later_CIPF($order_id, $user_id) { Plgntls::debug_infos(); @@ -71,7 +71,7 @@ function delete_order_id_later_CIPF($order_id, $user_id) { } reset_acf_order_id_CIPF($user_id); } -add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 10, 2); +add_action('CIPF_orderid_deletion_event', 'delete_order_id_later_CIPF', 10, 2); @@ -91,37 +91,9 @@ function schedule_prof_account_deletion_CIPF($user_id) { } $date_limit->modify($duration_deletion); $delay = $date_limit->getTimestamp(); - wp_schedule_single_event($delay, 'schedule_event_prof_account_deletion_CIPF', array($user_id)); + wp_schedule_single_event($delay, 'CIPF_schedule_event_prof_account_deletion', array($user_id)); } -/* -* this function will delete the account if the deletion date is expired -* it is called both by e scheduled event, and every time a prof go on its page -* -*/ -function handle_prof_account_deletion_CIPF($user_id) { - Plgntls::debug_infos(); - - /* - * check if account still exists - * - */ - if (false === get_user_by('id', $user_id)) { - return; - } - - /* - * check if account should be deleted - * - */ - if (!is_prof_account_deletion_date_exceeded_CIPF($user_id)) { - return; - } - - send_emails_CIPF('account_deleted', $user_id); - include_once(ABSPATH.'wp-admin/includes/user.php'); - wp_delete_user($user_id); -} -add_action('schedule_event_prof_account_deletion_CIPF', 'handle_prof_account_deletion_CIPF'); +add_action('CIPF_schedule_event_prof_account_deletion', 'handle_prof_account_deletion_CIPF'); @@ -129,16 +101,20 @@ add_action('schedule_event_prof_account_deletion_CIPF', 'handle_prof_account_del /* * 3. prof, deactivate card at expiration time, also email * -function schedule__CIPF($user_id) { - Plgntls::debug_infos(); - $delay = strtotime('+3 days'); - wp_schedule_single_event($delay, 'scedule_event_CIPF', array($user_id)); -} -function event_CIPF($user_id) { - Plgntls::debug_infos(); -} -add_action('schedule_event_CIPF', 'event_CIPF', 10, 2); */ +function schedule_deactivate_expired_card_CIPF($user_id) { + Plgntls::debug_infos(); + $duration_validity = Cipf::DURATION_CARD_VALIDITY; + + $date_limit = get_card_date_expiration_CIPF($user_id); + if (false === $date_limit) { + return; + } + $date_limit->modify('+1 day'); + $delay = $date_limit->getTimestamp(); + wp_schedule_single_event($delay, 'CIPF_schedule_event_deactivate_expired_card', array($user_id)); +} +add_action('CIPF_schedule_event_deactivate_expired_card', 'handle_card_expire_CIPF'); diff --git a/plugins/cipf_plugin/php/paypal/update_user_payment.php b/plugins/cipf_plugin/php/paypal/update_user_payment.php index c4a2903..91364d5 100644 --- a/plugins/cipf_plugin/php/paypal/update_user_payment.php +++ b/plugins/cipf_plugin/php/paypal/update_user_payment.php @@ -169,9 +169,13 @@ function success_payment_for_user_CIPF($user_id, $order_id) { /* * else + * order is important for some + * -> first update date, then schedul events * */ update_card_date_expiration_CIPF($user_id); + schedule_deactivate_expired_card_CIPF($user_id); + schedule_prof_account_deletion_CIPF($user_id); if (is_card_new_CIPF($user_id)) { set_card_number_CIPF($user_id); diff --git a/plugins/cipf_plugin/php/profs_handle_states.php b/plugins/cipf_plugin/php/profs_handle_states.php index 6614437..68a9f90 100644 --- a/plugins/cipf_plugin/php/profs_handle_states.php +++ b/plugins/cipf_plugin/php/profs_handle_states.php @@ -85,4 +85,36 @@ function handle_card_expire_CIPF($user_id) { +/* +* this function will delete the account if the deletion date is expired +* it is called both by e scheduled event, and every time a prof go on its page +* +*/ +function handle_prof_account_deletion_CIPF($user_id) { + Plgntls::debug_infos(); + + /* + * check if account still exists + * + */ + if (false === get_user_by('id', $user_id)) { + return; + } + + /* + * check if account should be deleted + * + */ + if (!is_prof_account_deletion_date_exceeded_CIPF($user_id)) { + return; + } + + send_emails_CIPF('account_deleted', $user_id); + include_once(ABSPATH.'wp-admin/includes/user.php'); + wp_delete_user($user_id); +} + + + + ?>