added dates functions for prof card
This commit is contained in:
@@ -101,7 +101,7 @@ function update_user_post_capture_CIPF($message) {
|
||||
throw new HttpException('cannot find user with this order_id', 502);
|
||||
if ($status === 'COMPLETED') {
|
||||
// proceed to validate payment for user
|
||||
validate_payment_for_user_CIPF($user_id_to_update, $order_id);
|
||||
success_payment_for_user_CIPF($user_id_to_update, $order_id);
|
||||
}
|
||||
else if ($status === 'PENDING') {
|
||||
// i don't know what to do yet, maybe make more checks and output a message to contact diego ?
|
||||
@@ -173,7 +173,7 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
|
||||
* things to do when a payment is a success
|
||||
*
|
||||
*/
|
||||
function validate_payment_for_user_CIPF($user_id, $order_id) {
|
||||
function success_payment_for_user_CIPF($user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
@@ -191,58 +191,27 @@ function validate_payment_for_user_CIPF($user_id, $order_id) {
|
||||
$acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* acf uses 'Y-m-d H:i:s' format : https://www.advancedcustomfields.com/resources/date-time-picker/
|
||||
*
|
||||
*/
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
|
||||
/*
|
||||
* remove the order_id from user meta
|
||||
*
|
||||
*/
|
||||
delete_user_meta($user_id, $meta_order_id, $order_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');
|
||||
|
||||
/*
|
||||
* 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);
|
||||
update_card_expiration_CIPF($user_id, $card_duration);
|
||||
|
||||
|
||||
/*
|
||||
* - if card status is command, create card id
|
||||
|
||||
165
plugins/cipf_plugin/php/profs_dates.php
Normal file
165
plugins/cipf_plugin/php/profs_dates.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* returns the date limit as a DateTime object
|
||||
* or false if not set
|
||||
*
|
||||
*/
|
||||
function get_date_limit_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||
|
||||
/*
|
||||
* define ids
|
||||
*
|
||||
*/
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
/*
|
||||
* get acf date field
|
||||
*
|
||||
*/
|
||||
$date_now = date_create('today');
|
||||
$current_date_limit_object = get_field_object($acf_card_expiration['_name'], $acf_id);
|
||||
if ($current_date_limit_object === false) {
|
||||
return false;
|
||||
}
|
||||
else if (empty($current_date_limit_object['value'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* create date object from acf date
|
||||
*
|
||||
*/
|
||||
$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 (2000y bug style)
|
||||
$current_date_limit = date_create_from_format($current_format_field, $current_date_limit_string);
|
||||
if ($current_date_limit === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the date object
|
||||
*
|
||||
*/
|
||||
return $current_date_limit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* returns the diff in days between today and the expiration date of the card
|
||||
* returns false if the expiration date field is empty
|
||||
*
|
||||
*/
|
||||
function card_date_diff_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
/*
|
||||
* get date limit as DateTime object
|
||||
*
|
||||
*/
|
||||
$current_date_limit = get_date_limit_CIPF();
|
||||
if ($current_date_limit === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns diff in days
|
||||
*
|
||||
*/
|
||||
$date_diff = date_diff($date_now, $current_date_limit);
|
||||
return (int)$date_diff->format('%R%a');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* returns true if date is in paste or is empty
|
||||
*
|
||||
*/
|
||||
function is_card_date_expired_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
/*
|
||||
* define user_id
|
||||
*
|
||||
*/
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
|
||||
/*
|
||||
* check if expired
|
||||
*
|
||||
*/
|
||||
$date_diff = card_date_diff_CIPF($user_id);
|
||||
if ($date_diff === false) {
|
||||
return true;
|
||||
}
|
||||
else if ($date_diff < 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function update_card_expiration_CIPF($user_id = null, $card_duration = '0') {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||
|
||||
/*
|
||||
* define acf id and acf date format
|
||||
*
|
||||
*/
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
$acf_date_format = 'Y-m-d H:i:s';
|
||||
|
||||
/*
|
||||
* get date limit as DateTime object
|
||||
*
|
||||
*/
|
||||
$current_date_limit = get_date_limit_CIPF();
|
||||
if ($current_date_limit === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -12,9 +12,7 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
/*
|
||||
* when form is validated
|
||||
* - reset some fields
|
||||
* - change account state
|
||||
* actions after prof form is validated
|
||||
*
|
||||
*/
|
||||
function prof_form_reset_fields_CIPF($form_id, $post_array, $form_type) {
|
||||
@@ -25,10 +23,23 @@ function prof_form_reset_fields_CIPF($form_id, $post_array, $form_type) {
|
||||
$user_id = get_current_user_id();
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
|
||||
/*
|
||||
* reset cgv
|
||||
*
|
||||
*/
|
||||
update_field($acf_cgv['_name'], array(""), $acf_id);
|
||||
update_field($acf_account_state['_name'], $acf_account_state['to_pay'], $acf_id);
|
||||
|
||||
|
||||
/*
|
||||
* if new prof, change status to 'to pay'
|
||||
*
|
||||
*/
|
||||
$is_new = get_field($acf_account_state['_name'], $acf_id);
|
||||
if ($is_new === $acf_account_state['new']) {
|
||||
update_field($acf_account_state['_name'], $acf_account_state['to_pay'], $acf_id);
|
||||
}
|
||||
}
|
||||
//add_action('df_before_process', 'prof_form_reset_fields_CIPF', 10, 3);
|
||||
add_action('df_after_process', 'prof_form_reset_fields_CIPF', 10, 3);
|
||||
|
||||
|
||||
@@ -36,44 +47,6 @@ add_action('df_after_process', 'prof_form_reset_fields_CIPF', 10, 3);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* NOT USEFUL ANYMORE :
|
||||
* it was to fix pbms in formbuilder with calculation field
|
||||
* but I made 2 better fixes (css and js)
|
||||
*
|
||||
* reset some fields for the form to buy the card
|
||||
* - cgv
|
||||
* - paiement
|
||||
* - livraison
|
||||
* - tarif
|
||||
* this action is called after redirection hook
|
||||
*
|
||||
*/
|
||||
//function reset_some_fields_CIPF() {
|
||||
// PLGNTLS_class::debug_infos();
|
||||
// $slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
// $acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
||||
// $acf_payement = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
// $acf_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||
// $acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||
//
|
||||
// if (!is_page($slug_renew_card))
|
||||
// return;
|
||||
//
|
||||
// $user_id = get_current_user_id();
|
||||
// update_field($acf_cgv['_name'] , array(""), 'user_'.$user_id);
|
||||
// update_field($acf_payement['_name'], array(""), 'user_'.$user_id);
|
||||
// update_field($acf_delivery['_name'], array(""), 'user_'.$user_id);
|
||||
// update_field($acf_price['_name'] , array(""), 'user_'.$user_id);
|
||||
//}
|
||||
//add_action('wp', 'reset_some_fields_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* on renew page :
|
||||
* - check restrictions
|
||||
@@ -85,7 +58,7 @@ add_action('df_after_process', 'prof_form_reset_fields_CIPF', 10, 3);
|
||||
* - except admins and editor
|
||||
*
|
||||
*/
|
||||
function renew_page_restrictions_CIPF(){
|
||||
function prof_form_restrictions_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
@@ -142,7 +115,7 @@ function renew_page_restrictions_CIPF(){
|
||||
}
|
||||
*/
|
||||
}
|
||||
add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
||||
add_action('template_redirect', 'prof_form_restrictions_CIPF');
|
||||
|
||||
|
||||
|
||||
@@ -150,6 +123,8 @@ add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
||||
|
||||
|
||||
/*
|
||||
* enqueue scripts on page prof
|
||||
*
|
||||
* on the renew card page for prof
|
||||
* output the right message, depending of the status of the card
|
||||
* 'renouveler' or 'commander'
|
||||
|
||||
Reference in New Issue
Block a user