+
+
diff --git a/plugins/cipf_plugin/js/paypal/on_approve.js b/plugins/cipf_plugin/js/paypal/on_approve.js
index 639bd6c..78da796 100644
--- a/plugins/cipf_plugin/js/paypal/on_approve.js
+++ b/plugins/cipf_plugin/js/paypal/on_approve.js
@@ -43,15 +43,13 @@ export async function onApprove(data, actions) {
const transaction =
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
- // to show a message on page
- //resultMessage(`Transaction ${transaction.status}: ${transaction.id}
See console for all available details`);
- resultMessage(eval(PLGNTLS_data.paypal_message_success));
+ console.log("Capture result",orderData);
+ resultMessage(PLGNTLS_data.paypal_message_success);
actions.redirect(PLGNTLS_data.paypal_redirection_success);
}
} catch (error) {
console.error(error);
- //resultMessage(`Sorry, your transaction could not be processed...
${error}`);
- resultMessage(eval(PLGNTLS_data.paypal_message_failure));
+ resultMessage(PLGNTLS_data.paypal_message_failure);
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
}
}
diff --git a/plugins/cipf_plugin/php/admin_menu/menu_content.php b/plugins/cipf_plugin/php/admin_menu/menu_content.php
index 8a3822a..d2b5789 100644
--- a/plugins/cipf_plugin/php/admin_menu/menu_content.php
+++ b/plugins/cipf_plugin/php/admin_menu/menu_content.php
@@ -16,7 +16,6 @@ function add_plugin_content_CIPF() {
/*
* paypal
*
- $option_paypal = PLGNTLS_class::OPTION_PAYPAL;
*/
$admin_post_paypal = PLGNTLS_class::ADMIN_POST_PAYPAL;
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
@@ -25,12 +24,19 @@ function add_plugin_content_CIPF() {
/*
* registration email
*
- $option_email = PLGNTLS_class::OPTION_EMAIL;
*/
$admin_post_email_registration = PLGNTLS_class::ADMIN_POST_EMAIL_REGISTRATION;
$nonce_email = PLGNTLS_class::ADMIN_MENU_NONCE_EMAIL_REGISTRATION;
$email_registration = get_email_registration_option_CIPF();
+ /*
+ * registration email
+ *
+ */
+ $admin_post_payment_messages = PLGNTLS_class::ADMIN_POST_PAYMENT_MESSAGES;
+ $nonce_payment_messages = PLGNTLS_class::ADMIN_MENU_NONCE_PAYMENT_MESSAGES;
+ $payment_messages = get_payment_messages_option_CIPF();
+
ob_start();
include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html');
$html = ob_get_clean();
diff --git a/plugins/cipf_plugin/php/admin_menu/post_payment_messages.php b/plugins/cipf_plugin/php/admin_menu/post_payment_messages.php
new file mode 100644
index 0000000..4b6f835
--- /dev/null
+++ b/plugins/cipf_plugin/php/admin_menu/post_payment_messages.php
@@ -0,0 +1,81 @@
+">
+*
+*
+*/
+function change_payment_messages_CIPF() {
+ PLGNTLS_class::debug_infos();
+ $nonce_payment_messages = PLGNTLS_class::ADMIN_MENU_NONCE_PAYMENT_MESSAGES;
+
+ if (!isset($_POST[$nonce_payment_messages['_name']])) {
+ redirect_menu_referer_CIPF($_POST);
+ exit;
+ }
+ if (!wp_verify_nonce($_POST[$nonce_payment_messages['_name']], $nonce_payment_messages['_action'])) {
+ redirect_menu_referer_CIPF($_POST);
+ exit;
+ }
+
+ // do actions here
+ update_payment_messages_option_CIPF($_POST);
+
+ redirect_menu_referer_CIPF($_POST);
+}
+add_action('admin_post_'.PLGNTLS_class::ADMIN_POST_PAYMENT_MESSAGES, 'change_payment_messages_CIPF');
+
+
+
+
+
+function update_payment_messages_option_CIPF($post) {
+ PLGNTLS_class::debug_infos();
+
+error_log("post: " . json_encode($post));
+
+ /*
+ * success
+ * failure
+ *
+ */
+ $success = '';
+ $failure = '';
+ if (!isset($post['message_success'])) {
+ return;
+ }
+ if (!isset($post['message_failure'])) {
+ return;
+ }
+ $success = $post['message_success'];
+ $failure = $post['message_failure'];
+
+
+ /*
+ * update the option with new values
+ *
+ */
+ set_payment_messages_option_CIPF($success, $failure);
+}
+
+
+
+
+
+?>
diff --git a/plugins/cipf_plugin/php/email_registration.php b/plugins/cipf_plugin/php/email_registration.php
index ddabda3..43e1530 100644
--- a/plugins/cipf_plugin/php/email_registration.php
+++ b/plugins/cipf_plugin/php/email_registration.php
@@ -58,7 +58,10 @@ add_filter('wp_new_user_notification_email', 'filter_regitration_email_CIPF', 21
-
+/*
+* OPTIONS
+*
+*/
function set_email_registration_CIPF($email, $is_email_prof, $is_email_partner) {
PLGNTLS_class::debug_infos();
@@ -73,14 +76,10 @@ function set_email_registration_CIPF($email, $is_email_prof, $is_email_partner)
}
-
-
-
function get_email_registration_option_CIPF() {
PLGNTLS_class::debug_infos();
$option_email = PLGNTLS_class::OPTION_EMAIL;
- delete_option($option_email['_name']);
$email_option_serialized = get_option($option_email['_name']);
if (false === $email_option_serialized) {
add_option($option_email['_name'], serialize($option_email['_default']), '', 'no');
diff --git a/plugins/cipf_plugin/php/payments.php b/plugins/cipf_plugin/php/payments.php
index ae2cf3b..8f6b11e 100644
--- a/plugins/cipf_plugin/php/payments.php
+++ b/plugins/cipf_plugin/php/payments.php
@@ -10,6 +10,7 @@ if (!defined('ABSPATH')) {
+
function set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret) {
PLGNTLS_class::debug_infos();
$option_paypal = PLGNTLS_class::OPTION_PAYPAL;
@@ -72,4 +73,46 @@ function get_paypal_api_base_url_CIPF() {
+/*
+* OPTIONS MESSAGES PAIMENT
+*
+*/
+
+function set_payment_messages_option_CIPF($success, $failure) {
+ PLGNTLS_class::debug_infos();
+ $option_payment = PLGNTLS_class::OPTION_PAYMENT;
+
+ $option_data = array();
+ $option_data['success'] = $success;
+ $option_data['failure'] = $failure;
+
+ update_option($option_payment['_name'], serialize($option_data), '', 'no');
+}
+
+function get_payment_messages_option_CIPF() {
+ PLGNTLS_class::debug_infos();
+ $option_payment = PLGNTLS_class::OPTION_PAYMENT;
+
+ $payment_option_serialized = get_option($option_payment['_name']);
+ if (false === $payment_option_serialized) {
+ add_option($option_payment['_name'], serialize($option_payment['_default']), '', 'no');
+ $payment_option_serialized = get_option($option_payment['_name']);
+ }
+
+ return unserialize($payment_option_serialized);
+}
+
+function get_payment_message_success_CIPF() {
+ PLGNTLS_class::debug_infos();
+ $payment_option = get_payment_messages_option_CIPF();
+ return $payment_option['success'];
+}
+
+function get_payment_message_failure_CIPF() {
+ PLGNTLS_class::debug_infos();
+ $payment_option = get_payment_messages_option_CIPF();
+ return $payment_option['failure'];
+}
+
+
?>
diff --git a/plugins/cipf_plugin/php/paypal/routes.php b/plugins/cipf_plugin/php/paypal/routes.php
index 5c523b9..2154ef3 100644
--- a/plugins/cipf_plugin/php/paypal/routes.php
+++ b/plugins/cipf_plugin/php/paypal/routes.php
@@ -13,6 +13,9 @@ if (!defined('ABSPATH')) {
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
function routes_endpoints_CIPF() {
PLGNTLS_class::debug_infos();
+ if (is_admin()) {
+ return;
+ }
$base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
register_rest_route($base_rest_route, '/orders', array(
'methods' => 'POST',
diff --git a/plugins/cipf_plugin/php/paypal/shortcode.php b/plugins/cipf_plugin/php/paypal/shortcode.php
index 2bf309c..62e6090 100644
--- a/plugins/cipf_plugin/php/paypal/shortcode.php
+++ b/plugins/cipf_plugin/php/paypal/shortcode.php
@@ -20,8 +20,8 @@ function paypal_shortcode_content_CIPF() {
$slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS;
$slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE;
$paypal_client_id = get_paypal_client_id_CIPF();
- $paypal_message_success = PLGNTLS_class::PAYPAL_MESSAGE_SUCCESS;
- $paypal_message_failure = PLGNTLS_class::PAYPAL_MESSAGE_FAILURE;
+ $paypal_message_success = get_payment_message_success_CIPF();
+ $paypal_message_failure = get_payment_message_failure_CIPF();
// if (!can_pay_now_CIPF())
// return no_payment_CIPF();
diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php
index 9d6f52f..79a12ab 100644
--- a/plugins/cipf_plugin/utils/plgntls_class.php
+++ b/plugins/cipf_plugin/utils/plgntls_class.php
@@ -107,8 +107,8 @@ class PLGNTLS_class {
//const PAYPAL_CLIENT_ID = self::PAYPAL_HUGO_LIVE_CLIENT_ID;
//const PAYPAL_CLIENT_SECRET = self::PAYPAL_HUGO_LIVE_CLIENT_SECRET;
//const PAYPAL_API_BASE_URL = self::PAYPAL_HUGO_LIVE_API_BASE_URL;
- const PAYPAL_MESSAGE_SUCCESS = '`Paiement reussi, vous allez être redirigé-es vers votre espace`';
- const PAYPAL_MESSAGE_FAILURE = '`Paiement raté, vous allez être redirigé-es vers votre espace`';
+ const PAYPAL_MESSAGE_SUCCESS = 'Paiement reussi, vous allez être redirigé-es vers votre espace';
+ const PAYPAL_MESSAGE_FAILURE = 'Paiement raté, vous allez être redirigé-es vers votre espace';
// ROLES
const ROLE_PROF = 'professeur__professeure';
@@ -138,15 +138,28 @@ La FIPF',
'is_email_partner'=>true,
],
];
+ const OPTION_PAYMENT = [
+ '_name'=>'cipf_payment_messages',
+ '_default'=>[
+ 'success'=>
+'Paiement réussi,
+vous allez être redirigés vers votre espace',
+ 'failure'=>
+'Paiement échoué,
+vous allez être redirigés vers votre espace',
+ ],
+ ];
// ADMIN MENU
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide'];
- const ADMIN_POST_PAYPAL = 'paypal_credentials_CIPF';
+ const ADMIN_POST_PAYPAL = 'paypal_credentials_CIPF';
const ADMIN_MENU_NONCE_PAYPAL = ['_name'=>'nonce_paypal_cipf', '_action'=>'action_admin_menu_paypal_cipf'];
- const ADMIN_POST_EMAIL_REGISTRATION = 'email_registration_message_CIPF';
+ const ADMIN_POST_EMAIL_REGISTRATION = 'email_registration_message_CIPF';
const ADMIN_MENU_NONCE_EMAIL_REGISTRATION = ['_name'=>'nonce_email_cipf', '_action'=>'action_admin_menu_email_registration_cipf'];
+ const ADMIN_POST_PAYMENT_MESSAGES = 'payment_messages_CIPF';
+ const ADMIN_MENU_NONCE_PAYMENT_MESSAGES = ['_name'=>'nonce_payment_cipf', '_action'=>'action_admin_menu_payment_messages_cipf'];
// FORMS
const FORM_PROF_COMMANDE_ID = 'prof_commande';
diff --git a/plugins/cipf_plugin/utils/plgntls_fetch.js b/plugins/cipf_plugin/utils/plgntls_fetch.js
index 6854404..adfbe06 100644
--- a/plugins/cipf_plugin/utils/plgntls_fetch.js
+++ b/plugins/cipf_plugin/utils/plgntls_fetch.js
@@ -4,7 +4,6 @@
*
*/
export function PLGNTLS_fetch(url, options = {}) {
- console.log("inside PLGNTLS_fetch");
url = PLGNTLS_data.fetch_url + url;
options.headers = options.headers || {};
diff --git a/plugins/custer/format_user_infos.php b/plugins/custer/format_user_infos.php
index 1480613..b05caea 100644
--- a/plugins/custer/format_user_infos.php
+++ b/plugins/custer/format_user_infos.php
@@ -14,16 +14,32 @@ if (!defined('ABSPATH')) {
* return the result
*
*/
-function return_result($output) {
- if (is_array($output) && count($output) === 0) {
- $output = '';
+function return_result($output, $if_empty = '') {
+
+ /*
+ * if empty, apply options, or default empty string ''
+ *
+ */
+ if (empty($output)) {
+ $output = $if_empty;
}
+
+ /*
+ * if number, output a string
+ *
+ */
if (is_numeric($output)) {
$output = (string)$output;
}
- if (!is_string($output)) {
+
+ /*
+ * if not scalar, stringify output
+ *
+ */
+ if (!is_scalar($output)) {
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
}
+
return esc_html($output);
}
@@ -32,7 +48,7 @@ function return_result($output) {
* format the output
* if is acf, use acf default format
*/
-function format_user_info($query, $current_user, $user_id) {
+function format_user_info($query, $current_user, $user_id, $if_empty = '') {
$output_date_format = Custer::USER_INFO_DATE_FORMAT;
$is_acf = false;
@@ -75,10 +91,12 @@ function format_user_info($query, $current_user, $user_id) {
* otherwise, use the default wordpress value
*
*/
- if ($is_acf)
+ if ($is_acf) {
$output = get_field($query, $acf_id);
- else
+ }
+ else {
$output = $current_user->$query;
+ }
@@ -86,8 +104,9 @@ function format_user_info($query, $current_user, $user_id) {
* try to extract a string
*
*/
- while (is_array($output) && count($output) === 1)
+ while (is_array($output) && count($output) === 1) {
$output = reset($output);
+ }
@@ -110,7 +129,12 @@ function format_user_info($query, $current_user, $user_id) {
}
}
- return \CUSTER\return_result($output);
+
+ /*
+ * check options to format the result
+ *
+ */
+ return \CUSTER\return_result($output, $if_empty);
}
diff --git a/plugins/custer/user_infos.php b/plugins/custer/user_infos.php
index e648b3b..909ad02 100644
--- a/plugins/custer/user_infos.php
+++ b/plugins/custer/user_infos.php
@@ -72,6 +72,7 @@ function output_list_front($array, $current_user, $user_id) {
* - [custer_user_info user_email id='author'] -> display the email of the creator of the page/post
* - [custer_user_info user_email id='logged_in' important] -> display the email of the connected user, even if surrounded by shortcode 'custer_change_id'
* important keyword has no effect if id='author'
+* - [custer_user_info user_email if_empty="value"] -> display 'value' if the user_email is empty or does not exist
*
*/
function current_user_infos($atts) {
@@ -86,12 +87,14 @@ function current_user_infos($atts) {
$id_is = 'logged_in';
*/
$id_is = 'author';
+ $if_empty = '';
/*
* has parameter 'id' ?
* has parameter important ?
- * if yes, removes them from $atts
+ * has parameter if_empty ?
+ * if yes, handle them and removes them from $atts
*
*/
if (is_array($atts)) {
@@ -106,6 +109,10 @@ function current_user_infos($atts) {
unset($atts[$key]);
}
}
+ if (isset($atts['if_empty'])) {
+ $if_empty = $atts['if_empty'];
+ unset($atts['if_empty']);
+ }
}
@@ -175,7 +182,7 @@ function current_user_infos($atts) {
$query = $atts;
else
return '';
- return \CUSTER\format_user_info($query, $current_user, $user_id);
+ return \CUSTER\format_user_info($query, $current_user, $user_id, $if_empty);
}
add_shortcode('custer_user_info', __NAMESPACE__.'\current_user_infos');