updates acf fields const values in class to avoid errors
This commit is contained in:
@@ -51,6 +51,8 @@ function handle_orders_request_CIPF($request_data) {
|
||||
//function create_order_CIPF($cart)
|
||||
function create_order_CIPF()
|
||||
{
|
||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||
|
||||
// use the cart information passed from the front-end to calculate the purchase unit details
|
||||
|
||||
$access_token = generate_access_token_CIPF();
|
||||
@@ -59,7 +61,7 @@ function create_order_CIPF()
|
||||
$acf_id = 'user_' . $user_id;
|
||||
$price = get_field('somme_a_regler', $acf_id);
|
||||
|
||||
$url = PAYPAL_API_BASE_URL . '/v2/checkout/orders';
|
||||
$url = $paypal_api_base_url . '/v2/checkout/orders';
|
||||
$payload = array(
|
||||
'intent' => "CAPTURE",
|
||||
'note' => 'ERRPYO005',
|
||||
|
||||
@@ -17,7 +17,7 @@ function handle_orders_capture_request_CIPF($request) {
|
||||
// Implement captureOrder function logic here
|
||||
// Make sure you implement captureOrder function similar to the Node.js code
|
||||
|
||||
$response_data = capture_order_CIPF($order_id);
|
||||
$response_data = capture_order_cipf($order_id);
|
||||
$http_status_code = $response_data['http_status_code'];
|
||||
$json_response = $response_data['json_response'];
|
||||
|
||||
@@ -35,9 +35,10 @@ function handle_orders_capture_request_CIPF($request) {
|
||||
* Capture payment for the created order to complete the transaction.
|
||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||
*/
|
||||
function capture_order_CIPF($orderID) {
|
||||
function capture_order_CIPF($order_id) {
|
||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||
$access_token = generate_access_token_CIPF();
|
||||
$url = PAYPAL_API_BASE_URL . '/v2/checkout/orders/' . $orderID . '/capture';
|
||||
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';
|
||||
|
||||
$headers = array(
|
||||
"Content-Type: application/json",
|
||||
|
||||
@@ -38,6 +38,8 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function update_user_payment_CIPF($message, $step) {
|
||||
$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
|
||||
|
||||
$order_id = $message->id;
|
||||
$user_id = get_current_user_id();
|
||||
$status = $message->status;
|
||||
@@ -55,15 +57,15 @@ function update_user_payment_CIPF($message, $step) {
|
||||
* - '' -> no message to output | on author page (after set to empty on author page)
|
||||
*
|
||||
*/
|
||||
delete_user_meta($user_id, 'cipf_payement_status');
|
||||
add_user_meta($user_id, 'cipf_payement_status', 'started');
|
||||
delete_user_meta($user_id, $meta_payement_status);
|
||||
add_user_meta($user_id, $meta_payement_status, 'started');
|
||||
|
||||
// if transaction is COMPLETED, then delete order_id and update user
|
||||
if ($status === 'COMPLETED') {
|
||||
// find the user containing the order_id and delete this order_id
|
||||
$user_id_to_update = delete_order_id_on_success_CIPF($user_id, $order_id);
|
||||
// change payement status to success
|
||||
update_user_meta($user_id_to_update, 'cipf_payement_status', 'success');
|
||||
update_user_meta($user_id_to_update, $meta_payement_status, 'success');
|
||||
// proceed to validate payment for user
|
||||
validate_payment_for_user_CIPF($user_id_to_update, $order_id);
|
||||
}
|
||||
@@ -92,18 +94,13 @@ function update_user_payment_CIPF($message, $step) {
|
||||
function validate_payment_for_user_CIPF($user_id, $order_id) {
|
||||
$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;
|
||||
|
||||
$acf_date_format = 'Y-m-d H:i:s';
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
/*
|
||||
* update card validity to true
|
||||
*
|
||||
*/
|
||||
update_field($acf_card_state, 'Renouvellement', $acf_id);
|
||||
|
||||
$date_now = date_create('today');
|
||||
/*
|
||||
* update purchase date to now
|
||||
@@ -151,10 +148,12 @@ function validate_payment_for_user_CIPF($user_id, $order_id) {
|
||||
* change user profil :
|
||||
* - to active
|
||||
* - card state is renewal
|
||||
* - cannot renew
|
||||
*
|
||||
*/
|
||||
update_field($prof_is_activ, 'Actif', $acf_id);
|
||||
update_field($acf_card_state, 'Renouvellement', $acf_id);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
* default true
|
||||
*/
|
||||
function can_pay_now_CIPF() {
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
$acf_card_price_choice = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||
$acf_card_price_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||
@@ -23,7 +22,7 @@ function can_pay_now_CIPF() {
|
||||
/*
|
||||
* check if payment is virement or immediat
|
||||
*
|
||||
$payement = get_field($acf_card_payment_method, $acf_id);
|
||||
$payement = get_field($acf_card_payment_method['_name'], $acf_id);
|
||||
if (strtolower($payement) === 'virement') {
|
||||
return false;
|
||||
}
|
||||
@@ -35,8 +34,8 @@ function can_pay_now_CIPF() {
|
||||
* in case it was changed from admin pannel
|
||||
*
|
||||
*/
|
||||
$tarif = (int)get_field($acf_card_price_choice, $acf_id);
|
||||
$livraison = (int)get_field($acf_card_price_delivery, $acf_id);
|
||||
$tarif = (int)get_field($acf_card_price_choice['_name'], $acf_id);
|
||||
$livraison = (int)get_field($acf_card_price_delivery['_name'], $acf_id);
|
||||
$price = $tarif + $livraison;
|
||||
update_field($acf_card_price_total, $price, $acf_id);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ function handle_prof_is_activ_CIPF($author_id) {
|
||||
* if prof is activ, do nothing more
|
||||
*
|
||||
*/
|
||||
$is_activ = get_field($acf_prof_is_activ, $acf_id);
|
||||
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
||||
if ($is_activ === 'Actif')
|
||||
return;
|
||||
|
||||
@@ -51,7 +51,7 @@ function handle_prof_is_activ_CIPF($author_id) {
|
||||
|
||||
|
||||
/*
|
||||
* check meta field 'cipf_payement_status'
|
||||
* check meta field META_PAYEMENT_STATUS
|
||||
* if field value is 'success'
|
||||
* - hide block 'failure'
|
||||
* - and update field to '', so it will not show next time
|
||||
@@ -68,13 +68,15 @@ function handle_prof_is_activ_CIPF($author_id) {
|
||||
*
|
||||
*/
|
||||
function show_prof_paiement_messages_CIPF($user_id) {
|
||||
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||
$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
|
||||
|
||||
/*
|
||||
* if prof is inactive, do nothing more
|
||||
*
|
||||
*/
|
||||
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||
$acf_id = 'user_' . $user_id;
|
||||
$is_activ = get_field($acf_prof_is_activ, $acf_id);
|
||||
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
||||
if (is_null($is_activ) || empty($is_activ))
|
||||
return;
|
||||
if ($is_activ === 'Inactif')
|
||||
@@ -82,8 +84,7 @@ function show_prof_paiement_messages_CIPF($user_id) {
|
||||
|
||||
$cipf_prof_payement = new PLGNTLS_class();
|
||||
|
||||
$payement_status2 = get_user_meta($user_id, 'cipf_payement_status');
|
||||
$payement_status = get_user_meta($user_id, 'cipf_payement_status', true);
|
||||
$payement_status = get_user_meta($user_id, $meta_payement_status, true);
|
||||
if ($payement_status === 'success') {
|
||||
$cipf_prof_payement->add_to_front(array(
|
||||
array( 'css' => '#cipf_prof_paiement_reussi {display: block;}' )
|
||||
@@ -95,7 +96,7 @@ function show_prof_paiement_messages_CIPF($user_id) {
|
||||
));
|
||||
}
|
||||
|
||||
update_user_meta($user_id, 'cipf_payement_status', '');
|
||||
update_user_meta($user_id, $meta_payement_status, '');
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
/*
|
||||
* at registration, add role 'partenaire' when page url has path 'creation-du-compte-partenaire'
|
||||
*
|
||||
*/
|
||||
function add_partenaires_PLGNTLS($customer_data){
|
||||
$current_url = $_SERVER['HTTP_REFERER']; // not reliable to use referer, TODO: find another solution
|
||||
|
||||
@@ -26,10 +26,10 @@ function reset_some_fields_CIPF() {
|
||||
$acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
update_field($acf_cgv , array(""), 'user_'.$user_id);
|
||||
update_field($acf_payement, array(""), 'user_'.$user_id);
|
||||
update_field($acf_delivery, array(""), 'user_'.$user_id);
|
||||
update_field($acf_price , array(""), 'user_'.$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);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,14 +37,21 @@ function reset_some_fields_CIPF() {
|
||||
|
||||
|
||||
/*
|
||||
* prevent users to fill the renew form if
|
||||
* they are not prof and logged in,
|
||||
* and if their card is not in renewable state
|
||||
* except admins and editor
|
||||
* on renew page :
|
||||
* - check restrictions
|
||||
* - change some acf fields (if access granted)
|
||||
*
|
||||
* prevent users to fill the renew form if :
|
||||
* - they are not prof and logged in,
|
||||
* - and if their card is not in renewable state
|
||||
* - except admins and editor
|
||||
*
|
||||
*/
|
||||
function renew_page_restrictions_CIPF(){
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
$acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
|
||||
|
||||
if (!is_page($slug_renew_card))
|
||||
return;
|
||||
|
||||
@@ -54,30 +61,36 @@ function renew_page_restrictions_CIPF(){
|
||||
|
||||
$base_url = home_url();
|
||||
$current_user_id = get_current_user_id();
|
||||
/*
|
||||
if (current_user_can('professeur__professeure')) {
|
||||
$user_page = get_author_posts_url($current_user_id);
|
||||
wp_redirect($user_page, 301);
|
||||
}
|
||||
else if (current_user_can('partenaire')) {
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
'author' => $current_user_id,
|
||||
'posts_per_page' => 1,
|
||||
);
|
||||
$posts = get_posts($args);
|
||||
if (empty($posts))
|
||||
$redirect_url = $base_url;
|
||||
else {
|
||||
$query = reset($posts);
|
||||
$post_id = $query->ID;
|
||||
$redirect_url = get_permalink($query->ID);
|
||||
}
|
||||
wp_redirect($redirect_url, 301);
|
||||
}
|
||||
exit;
|
||||
*/
|
||||
$current_user = wp_get_current_user();
|
||||
$acf_id = 'user_'.$current_user_id;
|
||||
|
||||
|
||||
/*
|
||||
* check multiple user roles
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
*
|
||||
*/
|
||||
$allowed_roles = array('administrator', 'editor', 'professeur__professeure');
|
||||
if (!array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
|
||||
/*
|
||||
* if prof, check card state
|
||||
*
|
||||
*/
|
||||
if (current_user_can('professeur__professeure')) {
|
||||
$can_renew = get_field($acf_prof_can_renew, $acf_id);
|
||||
if ($can_renew === false) {
|
||||
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
||||
wp_redirect($redirect_url, 301);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if prof can renew its card, reset some form fields before
|
||||
*
|
||||
*/
|
||||
reset_some_fields_CIPF();
|
||||
}
|
||||
add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
||||
@@ -88,8 +101,13 @@ add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
||||
|
||||
|
||||
/*
|
||||
* on the renew card page for prof
|
||||
* output the right message, depending of the status of the card
|
||||
* 'renouveler' or 'commander'
|
||||
*
|
||||
* #cipf_prof_carte_commande -> default display: block;
|
||||
* #cipf_prof_carte_renouvellement -> default display: none;
|
||||
*
|
||||
*/
|
||||
function renew_page_filter_message_CIPF(){
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
@@ -103,7 +121,7 @@ function renew_page_filter_message_CIPF(){
|
||||
|
||||
$cipf_renew = new PLGNTLS_class();
|
||||
|
||||
$card_state = get_field($acf_card_state, $acf_id);
|
||||
$card_state = get_field($acf_card_state['_name'], $acf_id);
|
||||
error_log("card_state");
|
||||
error_log($card_state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user