- renew state : removed

- payment state : in acf
This commit is contained in:
asus
2024-03-10 14:51:47 +01:00
parent b457ed119e
commit 9ee35b23bc
5 changed files with 8 additions and 72 deletions

View File

@@ -36,7 +36,6 @@ if (!defined('ABSPATH')) {
*/
function update_user_pre_order_CIPF($message) {
PLGNTLS_class::debug_infos();
//$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
@@ -60,8 +59,6 @@ function update_user_pre_order_CIPF($message) {
* - 'failure' -> at capture failure (on author page, it means failure, then make it empty)
* - 'nothing' -> output nothing on author page
*
delete_user_meta($user_id, $meta_payement_status);
add_user_meta($user_id, $meta_payement_status, 'started');
*/
update_field($acf_payment_status['_name'], $acf_payment_status['started'], $acf_id);
}
@@ -134,10 +131,8 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
$acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
$prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
//$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
@@ -156,71 +151,18 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
* - 'failure' -> at capture failure (on author page, it means failure, then mark it 'nothing')
* - 'nothing' -> output nothing on author page
*
update_user_meta($user_id, $meta_payement_status, 'failure');
*/
update_field($acf_payment_status['_name'], $acf_payment_status['failure'], $acf_id);
/*
* acf uses 'Y-m-d H:i:s' format : https://www.advancedcustomfields.com/resources/date-time-picker/
*
*/
$acf_date_format = 'Y-m-d H:i:s';
$acf_id = 'user_'.$user_id;
$date_now = date_create('today');
/*
* update purchase date to now
*
update_field(CARD_DATE_PURCHASE, $date_now, $acf_id);
*/
/*
* get current date limit
* if no date, use now
* if paste date, use now
*
*/
$current_date_limit_object = get_field_object($acf_card_expiration['_name'], $acf_id);
if ($current_date_limit_object === false) {
$current_date_limit = $date_now;
}
else if (empty($current_date_limit_object['value'])) {
$current_date_limit = $date_now;
}
else
{
$current_date_limit_string = $current_date_limit_object['value'];
$current_format_field = $current_date_limit_object['return_format'];
// compare 2 dates : https://stackoverflow.com/q/8722806/9497573
// also I dont use strtotime to compare 2 ints,
// because i don't know if it will fail one day (2000 bug alike)
$current_date_limit = date_create_from_format($current_format_field, $current_date_limit_string);
$date_diff = date_diff($date_now, $current_date_limit);
$date_is_in_past = $date_diff->format('%R%a') < 0;
if ($date_is_in_past)
$current_date_limit = $date_now;
}
/*
* update date limit validity to add 1 year
*
*/
$date_plus_one_year = $current_date_limit->add(date_interval_create_from_date_string('+'.$card_duration));
update_field($acf_card_expiration['_name'], $date_plus_one_year->format($acf_date_format), $acf_id);
/*
* change user profil :
* - to active
* - card state is renewal
* - cannot renew
*
*/
update_field($prof_is_activ['_name'], $prof_is_activ['activ'], $acf_id);
update_field($acf_card_state['_name'], $acf_card_state['renew'], $acf_id);
//update_field($acf_prof_can_renew['_name'], $acf_prof_can_renew['cannot'] , $acf_id);
}
@@ -232,10 +174,9 @@ function validate_payment_for_user_CIPF($user_id, $order_id) {
PLGNTLS_class::debug_infos();
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
$acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
// $acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
$prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
//$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
@@ -250,7 +191,6 @@ function validate_payment_for_user_CIPF($user_id, $order_id) {
/*
* change payement status to success
*
update_user_meta($user_id, $meta_payement_status, 'success');
*/
update_field($acf_payment_status['_name'], $acf_payment_status['success'], $acf_id);