added message payments in admin menu
This commit is contained in:
@@ -4,7 +4,7 @@ Plugin Name: cipf_plugin
|
||||
Plugin URI:
|
||||
Description:
|
||||
Author: hugogogo
|
||||
Version: 0.4.2.1
|
||||
Version: 0.4.3
|
||||
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/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_payment_messages.php');
|
||||
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/post_email.php');
|
||||
|
||||
include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php');
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
form#email_registration_cipf .define_email_registration {
|
||||
form .textarea {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
form#email_registration_cipf .define_email_registration textarea {
|
||||
form .textarea textarea {
|
||||
resize: vertical;
|
||||
height: 120px;
|
||||
}
|
||||
@@ -62,7 +62,7 @@
|
||||
<input type="hidden" name="action" value="<?php echo $admin_post_email_registration; ?>">
|
||||
<?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>
|
||||
<textarea id="define_email_registration_cipf" name="email"><?php echo $email_registration['email']; ?></textarea>
|
||||
</div>
|
||||
@@ -80,3 +80,24 @@
|
||||
<input type="submit" value="send"/>
|
||||
</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>
|
||||
|
||||
|
||||
@@ -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}<br><br>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...<br><br>${error}`);
|
||||
resultMessage(eval(PLGNTLS_data.paypal_message_failure));
|
||||
resultMessage(PLGNTLS_data.paypal_message_failure);
|
||||
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
81
plugins/cipf_plugin/php/admin_menu/post_payment_messages.php
Normal file
81
plugins/cipf_plugin/php/admin_menu/post_payment_messages.php
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -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');
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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 || {};
|
||||
|
||||
Reference in New Issue
Block a user