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
|
||||
|
||||
Reference in New Issue
Block a user