added message payments in admin menu

This commit is contained in:
asus
2024-03-27 17:18:14 +01:00
parent a0018c903b
commit dd0d4dfbeb
13 changed files with 229 additions and 34 deletions

View File

@@ -4,7 +4,7 @@ Plugin Name: cipf_plugin
Plugin URI: Plugin URI:
Description: Description:
Author: hugogogo Author: hugogogo
Version: 0.4.2.1 Version: 0.4.3
Author URI: Author URI:
*/ */
@@ -32,6 +32,7 @@ include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu.php');
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu_toggle.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu_toggle.php');
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/menu_content.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/menu_content.php');
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/post_paypal.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/post_paypal.php');
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/post_payment_messages.php');
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/post_email.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/post_email.php');
include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php'); include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php');

View File

@@ -15,11 +15,11 @@
width: 100%; width: 100%;
} }
form#email_registration_cipf .define_email_registration { form .textarea {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
form#email_registration_cipf .define_email_registration textarea { form .textarea textarea {
resize: vertical; resize: vertical;
height: 120px; height: 120px;
} }
@@ -62,7 +62,7 @@
<input type="hidden" name="action" value="<?php echo $admin_post_email_registration; ?>"> <input type="hidden" name="action" value="<?php echo $admin_post_email_registration; ?>">
<?php wp_nonce_field($nonce_email['_action'], $nonce_email['_name']); ?> <?php wp_nonce_field($nonce_email['_action'], $nonce_email['_name']); ?>
<div class="define_email_registration"> <div class="define_email_registration textarea">
<label for="define_email_registration_cipf">email : </label> <label for="define_email_registration_cipf">email : </label>
<textarea id="define_email_registration_cipf" name="email"><?php echo $email_registration['email']; ?></textarea> <textarea id="define_email_registration_cipf" name="email"><?php echo $email_registration['email']; ?></textarea>
</div> </div>
@@ -80,3 +80,24 @@
<input type="submit" value="send"/> <input type="submit" value="send"/>
</form> </form>
<!--
-->
<h1>messages apres paiement, avant redirection</h1>
<form id="payments_messages_cipf" method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
<input type="hidden" name="action" value="<?php echo $admin_post_payment_messages; ?>">
<?php wp_nonce_field($nonce_payment_messages['_action'], $nonce_payment_messages['_name']); ?>
<div class="define_payment_message_cipf textarea">
<label for="define_payment_message_success_cipf">paiement réussi : </label>
<textarea id="define_payment_message_success_cipf" name="message_success"><?php echo $payment_messages['success']; ?></textarea>
</div>
<div class="define_payment_message_cipf textarea">
<label for="define_payment_message_failure_cipf">paiement echec : </label>
<textarea id="define_payment_message_failure_cipf" name="message_failure"><?php echo $payment_messages['failure']; ?></textarea>
</div>
<input type="submit" value="send"/>
</form>

View File

@@ -43,15 +43,13 @@ export async function onApprove(data, actions) {
const transaction = const transaction =
orderData?.purchase_units?.[0]?.payments?.captures?.[0] || orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0]; orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
// to show a message on page console.log("Capture result",orderData);
//resultMessage(`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`); resultMessage(PLGNTLS_data.paypal_message_success);
resultMessage(eval(PLGNTLS_data.paypal_message_success));
actions.redirect(PLGNTLS_data.paypal_redirection_success); actions.redirect(PLGNTLS_data.paypal_redirection_success);
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
//resultMessage(`Sorry, your transaction could not be processed...<br><br>${error}`); resultMessage(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);
} }
} }

View File

@@ -16,7 +16,6 @@ function add_plugin_content_CIPF() {
/* /*
* paypal * paypal
* *
$option_paypal = PLGNTLS_class::OPTION_PAYPAL;
*/ */
$admin_post_paypal = PLGNTLS_class::ADMIN_POST_PAYPAL; $admin_post_paypal = PLGNTLS_class::ADMIN_POST_PAYPAL;
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL; $nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
@@ -25,12 +24,19 @@ function add_plugin_content_CIPF() {
/* /*
* registration email * registration email
* *
$option_email = PLGNTLS_class::OPTION_EMAIL;
*/ */
$admin_post_email_registration = PLGNTLS_class::ADMIN_POST_EMAIL_REGISTRATION; $admin_post_email_registration = PLGNTLS_class::ADMIN_POST_EMAIL_REGISTRATION;
$nonce_email = PLGNTLS_class::ADMIN_MENU_NONCE_EMAIL_REGISTRATION; $nonce_email = PLGNTLS_class::ADMIN_MENU_NONCE_EMAIL_REGISTRATION;
$email_registration = get_email_registration_option_CIPF(); $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(); ob_start();
include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html'); include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html');
$html = ob_get_clean(); $html = ob_get_clean();

View File

@@ -0,0 +1,81 @@
<?php
/*
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
/*
* use this hook 'admin_post_{$action}' to receive a form post
* https://developer.wordpress.org/reference/hooks/admin_post_action/
*
* add the url to the action atrtibute of form, and the value of the action in an hidden input
* <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
* <input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
*
*/
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);
}
?>

View File

@@ -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) { function set_email_registration_CIPF($email, $is_email_prof, $is_email_partner) {
PLGNTLS_class::debug_infos(); 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() { function get_email_registration_option_CIPF() {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
$option_email = PLGNTLS_class::OPTION_EMAIL; $option_email = PLGNTLS_class::OPTION_EMAIL;
delete_option($option_email['_name']);
$email_option_serialized = get_option($option_email['_name']); $email_option_serialized = get_option($option_email['_name']);
if (false === $email_option_serialized) { if (false === $email_option_serialized) {
add_option($option_email['_name'], serialize($option_email['_default']), '', 'no'); add_option($option_email['_name'], serialize($option_email['_default']), '', 'no');

View File

@@ -10,6 +10,7 @@ if (!defined('ABSPATH')) {
function set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret) { function set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret) {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
$option_paypal = PLGNTLS_class::OPTION_PAYPAL; $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'];
}
?> ?>

View File

@@ -13,6 +13,9 @@ if (!defined('ABSPATH')) {
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573 // diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
function routes_endpoints_CIPF() { function routes_endpoints_CIPF() {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
if (is_admin()) {
return;
}
$base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE; $base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
register_rest_route($base_rest_route, '/orders', array( register_rest_route($base_rest_route, '/orders', array(
'methods' => 'POST', 'methods' => 'POST',

View File

@@ -20,8 +20,8 @@ function paypal_shortcode_content_CIPF() {
$slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS; $slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS;
$slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE; $slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE;
$paypal_client_id = get_paypal_client_id_CIPF(); $paypal_client_id = get_paypal_client_id_CIPF();
$paypal_message_success = PLGNTLS_class::PAYPAL_MESSAGE_SUCCESS; $paypal_message_success = get_payment_message_success_CIPF();
$paypal_message_failure = PLGNTLS_class::PAYPAL_MESSAGE_FAILURE; $paypal_message_failure = get_payment_message_failure_CIPF();
// if (!can_pay_now_CIPF()) // if (!can_pay_now_CIPF())
// return no_payment_CIPF(); // return no_payment_CIPF();

View File

@@ -107,8 +107,8 @@ class PLGNTLS_class {
//const PAYPAL_CLIENT_ID = self::PAYPAL_HUGO_LIVE_CLIENT_ID; //const PAYPAL_CLIENT_ID = self::PAYPAL_HUGO_LIVE_CLIENT_ID;
//const PAYPAL_CLIENT_SECRET = self::PAYPAL_HUGO_LIVE_CLIENT_SECRET; //const PAYPAL_CLIENT_SECRET = self::PAYPAL_HUGO_LIVE_CLIENT_SECRET;
//const PAYPAL_API_BASE_URL = self::PAYPAL_HUGO_LIVE_API_BASE_URL; //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_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_FAILURE = 'Paiement raté, vous allez être redirigé-es vers votre espace';
// ROLES // ROLES
const ROLE_PROF = 'professeur__professeure'; const ROLE_PROF = 'professeur__professeure';
@@ -138,15 +138,28 @@ La FIPF',
'is_email_partner'=>true, '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 // ADMIN MENU
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide']; 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 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_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_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 // FORMS
const FORM_PROF_COMMANDE_ID = 'prof_commande'; const FORM_PROF_COMMANDE_ID = 'prof_commande';

View File

@@ -4,7 +4,6 @@
* *
*/ */
export function PLGNTLS_fetch(url, options = {}) { export function PLGNTLS_fetch(url, options = {}) {
console.log("inside PLGNTLS_fetch");
url = PLGNTLS_data.fetch_url + url; url = PLGNTLS_data.fetch_url + url;
options.headers = options.headers || {}; options.headers = options.headers || {};

View File

@@ -14,16 +14,32 @@ if (!defined('ABSPATH')) {
* return the result * return the result
* *
*/ */
function return_result($output) { function return_result($output, $if_empty = '') {
if (is_array($output) && count($output) === 0) {
$output = ''; /*
* if empty, apply options, or default empty string ''
*
*/
if (empty($output)) {
$output = $if_empty;
} }
/*
* if number, output a string
*
*/
if (is_numeric($output)) { if (is_numeric($output)) {
$output = (string)$output; $output = (string)$output;
} }
if (!is_string($output)) {
/*
* if not scalar, stringify output
*
*/
if (!is_scalar($output)) {
$output = json_encode($output, JSON_UNESCAPED_SLASHES); $output = json_encode($output, JSON_UNESCAPED_SLASHES);
} }
return esc_html($output); return esc_html($output);
} }
@@ -32,7 +48,7 @@ function return_result($output) {
* format the output * format the output
* if is acf, use acf default format * 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; $output_date_format = Custer::USER_INFO_DATE_FORMAT;
$is_acf = false; $is_acf = false;
@@ -75,10 +91,12 @@ function format_user_info($query, $current_user, $user_id) {
* otherwise, use the default wordpress value * otherwise, use the default wordpress value
* *
*/ */
if ($is_acf) if ($is_acf) {
$output = get_field($query, $acf_id); $output = get_field($query, $acf_id);
else }
else {
$output = $current_user->$query; $output = $current_user->$query;
}
@@ -86,8 +104,9 @@ function format_user_info($query, $current_user, $user_id) {
* try to extract a string * try to extract a string
* *
*/ */
while (is_array($output) && count($output) === 1) while (is_array($output) && count($output) === 1) {
$output = reset($output); $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);
} }

View File

@@ -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='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' * - [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' * 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) { function current_user_infos($atts) {
@@ -86,12 +87,14 @@ function current_user_infos($atts) {
$id_is = 'logged_in'; $id_is = 'logged_in';
*/ */
$id_is = 'author'; $id_is = 'author';
$if_empty = '';
/* /*
* has parameter 'id' ? * has parameter 'id' ?
* has parameter important ? * 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)) { if (is_array($atts)) {
@@ -106,6 +109,10 @@ function current_user_infos($atts) {
unset($atts[$key]); 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; $query = $atts;
else else
return ''; 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'); add_shortcode('custer_user_info', __NAMESPACE__.'\current_user_infos');