|
|
|
|
@@ -28,38 +28,20 @@ if (!defined('ABSPATH')) {
|
|
|
|
|
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
|
|
|
|
* ['aaaaaa'] - $del_ret === false
|
|
|
|
|
*
|
|
|
|
|
* order status : https://developer.paypal.com/docs/api/orders/v2/#orders_capture!c=201&path=status&t=response
|
|
|
|
|
* CREATED
|
|
|
|
|
* SAVED
|
|
|
|
|
* APPROVED ?
|
|
|
|
|
* VOIDED
|
|
|
|
|
* - COMPLETED
|
|
|
|
|
* PAYER_ACTION_REQUIRED
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function update_user_payment_FIPF($message, $step)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
function update_user_payment_FIPF($message, $step) {
|
|
|
|
|
$order_id = $message->id;
|
|
|
|
|
$user_id = get_current_user_id();
|
|
|
|
|
/*
|
|
|
|
|
order status : https://developer.paypal.com/docs/api/orders/v2/#orders_capture!c=201&path=status&t=response
|
|
|
|
|
CREATED
|
|
|
|
|
SAVED
|
|
|
|
|
APPROVED ?
|
|
|
|
|
VOIDED
|
|
|
|
|
- COMPLETED
|
|
|
|
|
PAYER_ACTION_REQUIRED
|
|
|
|
|
*/
|
|
|
|
|
$status = $message->status;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//error_log("--- in update_user_payment, step :");
|
|
|
|
|
//error_log($step);
|
|
|
|
|
////error_log("message :");
|
|
|
|
|
////error_log(json_encode($message));
|
|
|
|
|
//error_log("order_id :");
|
|
|
|
|
//error_log($order_id);
|
|
|
|
|
//error_log("status :");
|
|
|
|
|
//error_log($status);
|
|
|
|
|
//$user_meta_order_id = get_user_meta($user_id, 'fipf_order_id');
|
|
|
|
|
//error_log("user_meta->fipf_order_id :");
|
|
|
|
|
//error_log(json_encode($user_meta_order_id));
|
|
|
|
|
//error_log("... update user");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// addind order_id to fipf_order_id meta field
|
|
|
|
|
// it can duplicate, it's not a problem : delete_user_meta will delete all
|
|
|
|
|
add_user_meta($user_id, 'fipf_order_id', $order_id);
|
|
|
|
|
@@ -73,12 +55,6 @@ function update_user_payment_FIPF($message, $step)
|
|
|
|
|
// proceed to validate payment for user
|
|
|
|
|
validate_payment_for_user_FIPF($user_id_to_update, $order_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//$user_meta_order_id = get_user_meta($user_id, 'fipf_order_id');
|
|
|
|
|
//error_log("user_meta->fipf_order_id :");
|
|
|
|
|
//error_log(json_encode($user_meta_order_id));
|
|
|
|
|
//error_log("--- out update_user_payment");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -99,23 +75,27 @@ function update_user_payment_FIPF($message, $step)
|
|
|
|
|
*
|
|
|
|
|
* acf uses 'Y-m-d H:i:s' format :
|
|
|
|
|
* -> https://www.advancedcustomfields.com/resources/date-time-picker/
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function validate_payment_for_user_FIPF($user_id, $order_id) {
|
|
|
|
|
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
|
|
|
|
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
|
|
|
|
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
|
|
|
|
|
|
|
|
|
|
error_log("---");
|
|
|
|
|
$acf_date_format = 'Y-m-d H:i:s';
|
|
|
|
|
$acf_id = 'user_'.$user_id;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* update card validity to true
|
|
|
|
|
update_field(CARD_IS_VALID, true, $acf_id);
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
update_field($acf_card_state, 'Renouvellement', $acf_id);
|
|
|
|
|
|
|
|
|
|
$date_now = date($acf_date_format);
|
|
|
|
|
$date_now = date_create('today');
|
|
|
|
|
/*
|
|
|
|
|
* update purchase date to now
|
|
|
|
|
*
|
|
|
|
|
update_field(CARD_DATE_PURCHASE, $date_now, $acf_id);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@@ -123,34 +103,42 @@ function validate_payment_for_user_FIPF($user_id, $order_id) {
|
|
|
|
|
* get current date limit
|
|
|
|
|
* if no date, use now
|
|
|
|
|
* if paste date, use now
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
$current_date_limit = get_field($acf_card_expiration, $acf_id);
|
|
|
|
|
// output is in format 'dd/mm/yyyy' which is not understood by php dates functions
|
|
|
|
|
// so i clean it
|
|
|
|
|
// -> not a reliable solution, someone can change the ouput format in dashboard
|
|
|
|
|
$current_date_limit = str_replace('/', '-', $current_date_limit);
|
|
|
|
|
$current_date_limit_object = get_field_object($acf_card_expiration, $acf_id);
|
|
|
|
|
|
|
|
|
|
if ($current_date_limit === null) {
|
|
|
|
|
if ($current_date_limit_object === false) {
|
|
|
|
|
error_log("current_date_limit_object === false");
|
|
|
|
|
$current_date_limit = $date_now;
|
|
|
|
|
}
|
|
|
|
|
else if (empty($current_date_limit_object['value'])) {
|
|
|
|
|
error_log("empty current_date_limit_object['value']");
|
|
|
|
|
$current_date_limit = $date_now;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
error_log("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)
|
|
|
|
|
$comp_current_date_limit = date_create($current_date_limit);
|
|
|
|
|
$comp_date_now = date_create($date_now);
|
|
|
|
|
$date_is_in_past = date_diff($comp_date_now, $comp_current_date_limit)->format("%R%a") < 0;
|
|
|
|
|
$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
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
$time_plus_one_year = strtotime('+1 year', strtotime($current_date_limit));
|
|
|
|
|
$new_date_limit = date('Y-m-d H:i:s', $time_plus_one_year);
|
|
|
|
|
update_field($acf_card_expiration, $new_date_limit, $acf_id);
|
|
|
|
|
error_log("current_date_limit");
|
|
|
|
|
error_log($current_date_limit);
|
|
|
|
|
$date_plus_one_year = $current_date_limit->add(date_interval_create_from_date_string('+'.$card_duration));;
|
|
|
|
|
update_field($acf_card_expiration, $date_plus_one_year->format($acf_date_format), $acf_id);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -160,23 +148,25 @@ function validate_payment_for_user_FIPF($user_id, $order_id) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* add a schedule event to delete this order_id
|
|
|
|
|
* after 3 days ?
|
|
|
|
|
* time() + 60 = one minute from now
|
|
|
|
|
* time() + MINUTE_IN_SECONDS = one minute from now
|
|
|
|
|
* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants
|
|
|
|
|
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* add a schedule event to delete this order_id
|
|
|
|
|
* after 3 days ?
|
|
|
|
|
* time() + 60 = one minute from now
|
|
|
|
|
* time() + MINUTE_IN_SECONDS = one minute from now
|
|
|
|
|
* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants
|
|
|
|
|
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function schedule_delete_orderid_FIPF($user_id, $order_id)
|
|
|
|
|
{
|
|
|
|
|
$delay = time() + MINUTE_IN_SECONDS;
|
|
|
|
|
wp_schedule_single_event($delay, 'orderid_deletion_event_FIPF', array($user_id, $order_id));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* action hook for the scheduled event
|
|
|
|
|
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* action hook for the scheduled event
|
|
|
|
|
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function delete_order_id_later_FIPF($user_id, $order_id)
|
|
|
|
|
{
|
|
|
|
|
error_log("delete order_id[$order_id] from user_id[$user_id]");
|
|
|
|
|
@@ -189,10 +179,11 @@ add_action('orderid_deletion_event_FIPF', 'delete_order_id_later_FIPF', 5, 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return mixed num - user_id
|
|
|
|
|
* bool false - if no match found
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* @return mixed num - user_id
|
|
|
|
|
* bool false - if no match found
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function delete_order_id_on_success_FIPF($current_user_id, $order_id)
|
|
|
|
|
{
|
|
|
|
|
$del_ret = delete_user_meta($current_user_id, 'fipf_order_id', $order_id);
|
|
|
|
|
|