- improved payement paypal for date and other things
This commit is contained in:
@@ -51,7 +51,7 @@ export async function onApprove(data, actions) {
|
|||||||
orderData,
|
orderData,
|
||||||
JSON.stringify(orderData, null, 2),
|
JSON.stringify(orderData, null, 2),
|
||||||
);
|
);
|
||||||
actions.redirect(PLGNTLS_data.paypal_redirection_success);
|
//actions.redirect(PLGNTLS_data.paypal_redirection_success);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("payment ok but error on traitment afterwards : ", error);
|
console.error("payment ok but error on traitment afterwards : ", error);
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ export async function onApprove(data, actions) {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
//resultMessage(`Sorry, your transaction could not be processed...<br><br>${error}`);
|
//resultMessage(`Sorry, your transaction could not be processed...<br><br>${error}`);
|
||||||
resultMessage(eval(PLGNTLS_data.paypal_message_failure));
|
resultMessage(eval(PLGNTLS_data.paypal_message_failure));
|
||||||
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
|
//actions.redirect(PLGNTLS_data.paypal_redirection_failure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function handle_orders_request_FIPF($request_data) {
|
|||||||
if ($can_pay['success'] === false)
|
if ($can_pay['success'] === false)
|
||||||
throw new Exception($can_pay['message']);
|
throw new Exception($can_pay['message']);
|
||||||
error_log("can_pay:");
|
error_log("can_pay:");
|
||||||
error_log($can_pay);
|
error_log(json_encode($can_pay));
|
||||||
|
|
||||||
// Process the order and get the response
|
// Process the order and get the response
|
||||||
//$order_response = create_order_FIPF($cart);
|
//$order_response = create_order_FIPF($cart);
|
||||||
|
|||||||
@@ -28,38 +28,20 @@ if (!defined('ABSPATH')) {
|
|||||||
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||||
* ['aaaaaa'] - $del_ret === false
|
* ['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;
|
$order_id = $message->id;
|
||||||
$user_id = get_current_user_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;
|
$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
|
// addind order_id to fipf_order_id meta field
|
||||||
// it can duplicate, it's not a problem : delete_user_meta will delete all
|
// it can duplicate, it's not a problem : delete_user_meta will delete all
|
||||||
add_user_meta($user_id, 'fipf_order_id', $order_id);
|
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
|
// proceed to validate payment for user
|
||||||
validate_payment_for_user_FIPF($user_id_to_update, $order_id);
|
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 :
|
* acf uses 'Y-m-d H:i:s' format :
|
||||||
* -> https://www.advancedcustomfields.com/resources/date-time-picker/
|
* -> https://www.advancedcustomfields.com/resources/date-time-picker/
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
function validate_payment_for_user_FIPF($user_id, $order_id) {
|
function validate_payment_for_user_FIPF($user_id, $order_id) {
|
||||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
$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_date_format = 'Y-m-d H:i:s';
|
||||||
$acf_id = 'user_'.$user_id;
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* update card validity to true
|
* update card validity to true
|
||||||
update_field(CARD_IS_VALID, true, $acf_id);
|
*
|
||||||
*/
|
*/
|
||||||
update_field($acf_card_state, 'Renouvellement', $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 purchase date to now
|
||||||
|
*
|
||||||
update_field(CARD_DATE_PURCHASE, $date_now, $acf_id);
|
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
|
* get current date limit
|
||||||
* if no date, use now
|
* if no date, use now
|
||||||
* if paste date, use now
|
* if paste date, use now
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
$current_date_limit = get_field($acf_card_expiration, $acf_id);
|
$current_date_limit_object = get_field_object($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);
|
|
||||||
|
|
||||||
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;
|
$current_date_limit = $date_now;
|
||||||
}
|
}
|
||||||
else
|
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
|
// compare 2 dates : https://stackoverflow.com/q/8722806/9497573
|
||||||
// also I dont use strtotime to compare 2 ints,
|
// also I dont use strtotime to compare 2 ints,
|
||||||
// because i don't know if it will fail one day (2000 bug alike)
|
// because i don't know if it will fail one day (2000 bug alike)
|
||||||
$comp_current_date_limit = date_create($current_date_limit);
|
$current_date_limit = date_create_from_format($current_format_field, $current_date_limit_string);
|
||||||
$comp_date_now = date_create($date_now);
|
$date_diff = date_diff($date_now, $current_date_limit);
|
||||||
$date_is_in_past = date_diff($comp_date_now, $comp_current_date_limit)->format("%R%a") < 0;
|
$date_is_in_past = $date_diff->format('%R%a') < 0;
|
||||||
|
|
||||||
if ($date_is_in_past)
|
if ($date_is_in_past)
|
||||||
$current_date_limit = $date_now;
|
$current_date_limit = $date_now;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* update date limit validity to add 1 year
|
* update date limit validity to add 1 year
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
$time_plus_one_year = strtotime('+1 year', strtotime($current_date_limit));
|
error_log("current_date_limit");
|
||||||
$new_date_limit = date('Y-m-d H:i:s', $time_plus_one_year);
|
error_log($current_date_limit);
|
||||||
update_field($acf_card_expiration, $new_date_limit, $acf_id);
|
$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,22 +148,24 @@ function validate_payment_for_user_FIPF($user_id, $order_id) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* add a schedule event to delete this order_id
|
* add a schedule event to delete this order_id
|
||||||
* after 3 days ?
|
* after 3 days ?
|
||||||
* time() + 60 = one minute from now
|
* time() + 60 = one minute from now
|
||||||
* time() + MINUTE_IN_SECONDS = one minute from now
|
* time() + MINUTE_IN_SECONDS = one minute from now
|
||||||
* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants
|
* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants
|
||||||
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
function schedule_delete_orderid_FIPF($user_id, $order_id)
|
function schedule_delete_orderid_FIPF($user_id, $order_id)
|
||||||
{
|
{
|
||||||
$delay = time() + MINUTE_IN_SECONDS;
|
$delay = time() + MINUTE_IN_SECONDS;
|
||||||
wp_schedule_single_event($delay, 'orderid_deletion_event_FIPF', array($user_id, $order_id));
|
wp_schedule_single_event($delay, 'orderid_deletion_event_FIPF', array($user_id, $order_id));
|
||||||
}
|
}
|
||||||
/**
|
/*
|
||||||
* action hook for the scheduled event
|
* action hook for the scheduled event
|
||||||
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
function delete_order_id_later_FIPF($user_id, $order_id)
|
function delete_order_id_later_FIPF($user_id, $order_id)
|
||||||
{
|
{
|
||||||
@@ -189,9 +179,10 @@ add_action('orderid_deletion_event_FIPF', 'delete_order_id_later_FIPF', 5, 2);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @return mixed num - user_id
|
* @return mixed num - user_id
|
||||||
* bool false - if no match found
|
* bool false - if no match found
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
function delete_order_id_on_success_FIPF($current_user_id, $order_id)
|
function delete_order_id_on_success_FIPF($current_user_id, $order_id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ function can_pay_now_CIPF() {
|
|||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
$acf_id = 'user_' . $user_id;
|
$acf_id = 'user_' . $user_id;
|
||||||
|
|
||||||
|
error_log("etat_carte:");
|
||||||
|
error_log(json_encode(get_field_object($acf_card_state, $acf_id)));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check if payment is virement or immediat
|
* check if payment is virement or immediat
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ function output_list_front_CIPF($array) {
|
|||||||
function current_user_infos_CIPF($atts) {
|
function current_user_infos_CIPF($atts) {
|
||||||
if (!is_user_logged_in())
|
if (!is_user_logged_in())
|
||||||
return ;
|
return ;
|
||||||
error_log("----");
|
|
||||||
|
|
||||||
$current_user = wp_get_current_user();
|
$current_user = wp_get_current_user();
|
||||||
$current_user_infos = $current_user->data;
|
$current_user_infos = $current_user->data;
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ class PLGNTLS_class
|
|||||||
const ACF_CARD_PRICE_DELIVERY = 'livraison';
|
const ACF_CARD_PRICE_DELIVERY = 'livraison';
|
||||||
const ACF_CARD_PRICE_TOTAL = 'somme_a_regler';
|
const ACF_CARD_PRICE_TOTAL = 'somme_a_regler';
|
||||||
const ACF_CARD_EXPIRATION = 'fin_de_validite';
|
const ACF_CARD_EXPIRATION = 'fin_de_validite';
|
||||||
const CARD_RENEW_PERIOD = 31; // number of days before expiration when renew card start to be possible
|
const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible
|
||||||
|
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
|
||||||
|
|
||||||
private static $_root_path;
|
private static $_root_path;
|
||||||
private static $_root_url;
|
private static $_root_url;
|
||||||
|
|||||||
2
private
2
private
Submodule private updated: c04d227649...c4950c3dcd
Reference in New Issue
Block a user