-
+
+
+ />
-
+
+
+
+ />
+
+
diff --git a/plugins/cipf_plugin/html/menu/example_menu.html b/plugins/cipf_plugin/html/menu/example_menu.html
deleted file mode 100644
index c1f683e..0000000
--- a/plugins/cipf_plugin/html/menu/example_menu.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/plugins/cipf_plugin/js/admin_prevent_submit.js b/plugins/cipf_plugin/js/admin_prevent_submit.js
deleted file mode 100644
index d05b4dd..0000000
--- a/plugins/cipf_plugin/js/admin_prevent_submit.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
-
-cipf_admin_activate_prof_form
-*/
-
-function admin_activate_form_submit_prevent_CIPF() {
- let form_activate_prof = document.querySelector('#cipf_admin_activate_prof_form form');
- console.log("form:");
- console.log(form_activate_prof);
- if (form_activate_prof === null)
- return;
-
- function handle_form(event) {
- event.preventDefault();
- let form_data = new FormData(event.target);
- for (var pair of form_data.entries()) {
- console.log(pair[0]+ ': ' + pair[1]);
- }
- }
-
- form_activate_prof.addEventListener('submit', handle_form);
-}
-admin_activate_form_submit_prevent_CIPF();
-
diff --git a/plugins/cipf_plugin/js/menu/example_menu.js b/plugins/cipf_plugin/js/menu/example_menu.js
deleted file mode 100644
index e3d5d13..0000000
--- a/plugins/cipf_plugin/js/menu/example_menu.js
+++ /dev/null
@@ -1,4 +0,0 @@
-
-import { test_fetch } from './example_submenu.js';
-
-test_fetch();
diff --git a/plugins/cipf_plugin/js/menu/example_menu_2.js b/plugins/cipf_plugin/js/menu/example_menu_2.js
deleted file mode 100644
index 7d26d32..0000000
--- a/plugins/cipf_plugin/js/menu/example_menu_2.js
+++ /dev/null
@@ -1,29 +0,0 @@
-
-const inputElement2 = document.getElementById('mytext_2');
-const sendButton2 = document.getElementById('mybutton_2');
-
-sendButton2.addEventListener('click', () => {
- let inputValue = inputElement2.value;
- inputValue = {
- key1: 'value1',
- key2: 'value2'
- };
- inputValue = JSON.stringify(inputValue);
- console.log("inputValue:");
- console.log(inputValue);
- PLGNTLS_fetch('/plgntls/get_data', {
- method: "POST",
- })
- //PLGNTLS_fetch('get_data', {body: {inputValue}})
- .then((response) => response.json())
- .then((data) => {
- console.log("dataaa: ");
- console.log(data);
- })
- .catch((error) => {
- console.log("error: ");
- console.log(error);
- });
-});
-
-
diff --git a/plugins/cipf_plugin/js/menu/example_submenu.js b/plugins/cipf_plugin/js/menu/example_submenu.js
deleted file mode 100644
index b12cf4f..0000000
--- a/plugins/cipf_plugin/js/menu/example_submenu.js
+++ /dev/null
@@ -1,33 +0,0 @@
-
-import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
-
-export function test_fetch() {
- const inputElement = document.getElementById('mytext');
- const sendButton = document.getElementById('mybutton');
-
- sendButton.addEventListener('click', () => {
- let inputValue = inputElement.value;
- inputValue = {
- key1: 'value1',
- key2: 'value2'
- };
- inputValue = JSON.stringify(inputValue);
- console.log("inputValue:");
- console.log(inputValue);
- PLGNTLS_fetch('/plgntls/get_data', {
- method: "POST",
- })
- //PLGNTLS_fetch('get_data', {body: {inputValue}})
- .then((response) => response.json())
- .then((data) => {
- console.log("dataaa: ");
- console.log(data);
- })
- .catch((error) => {
- console.log("error: ");
- console.log(error);
- });
- });
-}
-
-
diff --git a/plugins/cipf_plugin/php/admin_menu/menu_content.php b/plugins/cipf_plugin/php/admin_menu/menu_content.php
index ca9116b..1e90033 100644
--- a/plugins/cipf_plugin/php/admin_menu/menu_content.php
+++ b/plugins/cipf_plugin/php/admin_menu/menu_content.php
@@ -15,14 +15,9 @@ function add_plugin_content_CIPF() {
$option_paypal = PLGNTLS_class::OPTION_PAYPAL;
$admin_post_paypal = PLGNTLS_class::ADMIN_POST_PAYPAL;
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
- $sandbox_live = PLGNTLS_class::ADMIN_MENU_PAYPAL_SANDBOX_LIVE;
+ $paypal_inputs = PLGNTLS_class::ADMIN_MENU_PAYPAL_INPUTS;
- $paypal_credentials_serialized = get_option($option_paypal['_name']);
- if (false === $paypal_credentials_serialized) {
- add_option($option_paypal['_name'], serialize($option_paypal['_default']), '', 'no');
- $paypal_credentials_serialized = get_option($option_paypal['_name']);
- }
- $paypal_credentials = unserialize($paypal_credentials_serialized);
+ $paypal_credentials = get_paypal_options_CIPF();
ob_start();
include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html');
@@ -44,8 +39,6 @@ function add_plugin_content_CIPF() {
function paypal_credentials_CIPF() {
PLGNTLS_class::debug_infos();
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
- $sandbox_live = PLGNTLS_class::ADMIN_MENU_PAYPAL_SANDBOX_LIVE;
- $option_paypal = PLGNTLS_class::OPTION_PAYPAL;
if (!isset($_POST[$nonce_paypal['_name']])) {
redirect_menu_referer_CIPF($_POST);
@@ -57,30 +50,7 @@ function paypal_credentials_CIPF() {
}
// do actions here
- error_log("received form, _POST: " . json_encode($_POST));
- $is_sandbox = false;
- if ($_POST[$sandbox_live['_name']] === $sandbox_live['sandbox']) {
- $is_sandbox = true;
- }
- error_log("is sandbox: " . json_encode($is_sandbox));
-
- /*
- const OPTION_PAYPAL = [
- '_name'=>'cipf_paypal_credentials',
- '_default' => [
- 'is_sandbox' =>true,
- 'client_id' =>PAYPAL_HUGO_SBOX_CLIENT_ID,
- 'client_secret'=>PAYPAL_HUGO_SBOX_CLIENT_SECRET,
- ],
- ];
- $paypal_credentials_option = get_option($option_paypal['_name']);
- if (false === $paypal_credentials_option) {
- add_option($option_paypal['_name'], serialize($option_paypal['_default']), '', 'no');
- }
- $patches_option = unserialize($raw_patches_option);
- $serialize_patches_option = serialize($patches_option);
- update_option(self::$_patches['_name'], $serialize_patches_option);
- */
+ update_paypal_credentials_CIPF($_POST);
redirect_menu_referer_CIPF($_POST);
}
@@ -89,6 +59,68 @@ add_action('admin_post_'.PLGNTLS_class::ADMIN_POST_PAYPAL, 'paypal_credentials_C
+
+function update_paypal_credentials_CIPF($post) {
+ PLGNTLS_class::debug_infos();
+ $paypal_inputs = PLGNTLS_class::ADMIN_MENU_PAYPAL_INPUTS;
+ $option_paypal = PLGNTLS_class::OPTION_PAYPAL;
+
+ error_log("received form, _POST: " . json_encode($post));
+
+ /*
+ * is sandbox or live ?
+ *
+ */
+ $is_sandbox = false;
+ if (!isset($post[$paypal_inputs['sandbox_or_live']])) {
+ return;
+ }
+ if ($post[$paypal_inputs['sandbox_or_live']] === 'sandbox') {
+ $is_sandbox = true;
+ }
+ else if ($post[$paypal_inputs['sandbox_or_live']] === 'live') {
+ $is_sandbox = false;
+ }
+ else {
+ return;
+ }
+
+
+ /*
+ * client id
+ *
+ */
+ $client_id = '';
+ if (!isset($post[$paypal_inputs['client_id']])) {
+ return;
+ }
+ else {
+ $client_id = $post[$paypal_inputs['client_id']];
+ }
+
+
+ /*
+ * client secret
+ *
+ */
+ $client_secret = '';
+ if (!isset($post[$paypal_inputs['client_secret']])) {
+ return;
+ }
+ else {
+ $client_secret = $post[$paypal_inputs['client_secret']];
+ }
+
+
+ /*
+ * update the option with new credentials
+ *
+ */
+ set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret);
+}
+
+
+
function redirect_menu_referer_CIPF($post) {
PLGNTLS_class::debug_infos();
if (!isset($post)) {
diff --git a/plugins/cipf_plugin/php/payments.php b/plugins/cipf_plugin/php/payments.php
new file mode 100644
index 0000000..ae2cf3b
--- /dev/null
+++ b/plugins/cipf_plugin/php/payments.php
@@ -0,0 +1,75 @@
+
diff --git a/plugins/cipf_plugin/php/paypal/route_api_orders.php b/plugins/cipf_plugin/php/paypal/route_api_orders.php
index e363bb8..c25c764 100644
--- a/plugins/cipf_plugin/php/paypal/route_api_orders.php
+++ b/plugins/cipf_plugin/php/paypal/route_api_orders.php
@@ -91,7 +91,7 @@ function handle_orders_request_CIPF($request_data) {
*/
function create_order_CIPF() {
PLGNTLS_class::debug_infos();
- $paypal_api_base_url = PLGNTLS_class::get_paypal_api_base_url();
+ $paypal_api_base_url = get_paypal_api_base_url_CIPF();
$acf_card_price_total = PLGNTLS_class::ACF_CARD_PRICE_TOTAL;
$access_token = generate_access_token_CIPF();
diff --git a/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php b/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php
index 1ded001..8a8d6bc 100644
--- a/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php
+++ b/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php
@@ -76,7 +76,7 @@ function handle_orders_capture_request_CIPF($request) {
*/
function capture_order_CIPF($order_id) {
PLGNTLS_class::debug_infos();
- $paypal_api_base_url = PLGNTLS_class::get_paypal_api_base_url();
+ $paypal_api_base_url = get_paypal_api_base_url_CIPF();
$access_token = generate_access_token_CIPF();
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';
diff --git a/plugins/cipf_plugin/php/paypal/route_api_utils.php b/plugins/cipf_plugin/php/paypal/route_api_utils.php
index ba3b822..de96c7e 100644
--- a/plugins/cipf_plugin/php/paypal/route_api_utils.php
+++ b/plugins/cipf_plugin/php/paypal/route_api_utils.php
@@ -61,9 +61,9 @@ function handle_response_CIPF($response) {
*/
function generate_access_token_CIPF() {
PLGNTLS_class::debug_infos();
- $paypal_client_id = PLGNTLS_class::get_paypal_client_id();
- $paypal_client_secret = PLGNTLS_class::get_paypal_client_secret();
- $paypal_api_base_url = PLGNTLS_class::get_paypal_api_base_url();
+ $paypal_client_id = get_paypal_client_id_CIPF();
+ $paypal_client_secret = get_paypal_client_secret_CIPF();
+ $paypal_api_base_url = get_paypal_api_base_url_CIPF();
/*
try
diff --git a/plugins/cipf_plugin/php/paypal/shortcode.php b/plugins/cipf_plugin/php/paypal/shortcode.php
index 9865f4c..2bf309c 100644
--- a/plugins/cipf_plugin/php/paypal/shortcode.php
+++ b/plugins/cipf_plugin/php/paypal/shortcode.php
@@ -19,7 +19,7 @@ function paypal_shortcode_content_CIPF() {
PLGNTLS_class::debug_infos();
$slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS;
$slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE;
- $paypal_client_id = PLGNTLS_class::get_paypal_client_id();
+ $paypal_client_id = get_paypal_client_id_CIPF();
$paypal_message_success = PLGNTLS_class::PAYPAL_MESSAGE_SUCCESS;
$paypal_message_failure = PLGNTLS_class::PAYPAL_MESSAGE_FAILURE;
diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php
index c3678d2..6bd7a05 100644
--- a/plugins/cipf_plugin/utils/plgntls_class.php
+++ b/plugins/cipf_plugin/utils/plgntls_class.php
@@ -133,7 +133,7 @@ class PLGNTLS_class {
const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide'];
const ADMIN_POST_PAYPAL = 'paypal_credentials_CIPF';
const ADMIN_MENU_NONCE_PAYPAL = ['_name'=>'nonce_admin_menu_paypal_cipf', '_action'=>'action_admin_menu_paypal_cipf'];
- const ADMIN_MENU_PAYPAL_SANDBOX_LIVE = ['_name'=>'sandbox_live', 'sandbox'=>'sandbox', 'live'=>'live'];
+ const ADMIN_MENU_PAYPAL_INPUTS = ['sandbox_or_live' => 'sandbox_or_live', 'client_id' => 'client_id', 'client_secret' =>'client_secret'];
// FORMS
const FORM_PROF_COMMANDE_ID = 'prof_commande';
@@ -229,40 +229,6 @@ class PLGNTLS_class {
- /*
- * get and set paypal options
- *
- */
- public static function set_paypal_client_id($client_id) {
- }
- public static function set_paypal_client_secret($client_secret) {
- }
- public static function set_paypal_api_base_url($api_url) {
- }
- public static function get_paypal_client_id() {
- /*
- return self::PAYPAL_HUGO_LIVE_CLIENT_ID;
- return self::PAYPAL_DIEGO_SBOX_CLIENT_ID;
- return self::PAYPAL_DIEGO_LIVE_CLIENT_ID;
- */
- return self::PAYPAL_HUGO_SBOX_CLIENT_ID;
- }
- public static function get_paypal_client_secret() {
- /*
- return self::PAYPAL_HUGO_LIVE_CLIENT_SECRET;
- return self::PAYPAL_DIEGO_SBOX_CLIENT_SECRET;
- return self::PAYPAL_DIEGO_LIVE_CLIENT_SECRET;
- */
- return self::PAYPAL_HUGO_SBOX_CLIENT_SECRET;
- }
- public static function get_paypal_api_base_url() {
- /*
- return self::PAYPAL_LIVE_API_BASE_URL;
- */
- return self::PAYPAL_SBOX_API_BASE_URL;
- }
-
-
/*