cipf v0.3.13 paypal credentials now from admin menu

This commit is contained in:
asus
2024-03-25 18:32:03 +01:00
parent c9f0522ecc
commit 44a5d93f77
14 changed files with 160 additions and 173 deletions

View File

@@ -4,7 +4,7 @@ Plugin Name: cipf_plugin
Plugin URI: Plugin URI:
Description: Description:
Author: hugogogo Author: hugogogo
Version: 0.3.12 Version: 0.3.13
Author URI: Author URI:
*/ */
@@ -45,6 +45,7 @@ include_once(PLGNTLS_class::root_path() . 'php/profs_handle_states.php');
include_once(PLGNTLS_class::root_path() . 'php/partners_register.php'); include_once(PLGNTLS_class::root_path() . 'php/partners_register.php');
include_once(PLGNTLS_class::root_path() . 'php/partners_page.php'); include_once(PLGNTLS_class::root_path() . 'php/partners_page.php');
include_once(PLGNTLS_class::root_path() . 'php/display_css.php'); include_once(PLGNTLS_class::root_path() . 'php/display_css.php');
include_once(PLGNTLS_class::root_path() . 'php/payments.php');

View File

@@ -14,19 +14,27 @@
<form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>"> <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
<input type="hidden" name="action" value="<?php echo $admin_post_paypal; ?>"> <input type="hidden" name="action" value="<?php echo $admin_post_paypal; ?>">
<?php wp_nonce_field($nonce_paypal['_action'], $nonce_paypal['_name']); ?> <?php wp_nonce_field($nonce_paypal['_action'], $nonce_paypal['_name']); ?>
<div class="define_paypal_credentials_cipf define_paypal_client_id_cipf"> <div class="define_paypal_credentials_cipf define_paypal_client_id_cipf">
<label for="paypal_client_id_cipf">client id : </label> <label for="paypal_client_id_cipf">client id : </label>
<input type="text" id="paypal_client_id_cipf" name="client_id" value="<?php echo $paypal_credentials['client_id']; ?>" /> <input type="text" id="paypal_client_id_cipf" name="client_id" value="<?php echo $paypal_credentials['client_id']; ?>" />
</div> </div>
<div class="define_paypal_credentials_cipf define_paypal_secret_id_cipf"> <div class="define_paypal_credentials_cipf define_paypal_secret_id_cipf">
<label for="paypal_client_secret_cipf">client secret : </label> <label for="paypal_client_secret_cipf">client secret : </label>
<input type="text" id="paypal_client_secret_cipf" name="client_secret" value="<?php echo $paypal_credentials['client_secret']; ?>" /> <input type="text" id="paypal_client_secret_cipf" name="client_secret" value="<?php echo $paypal_credentials['client_secret']; ?>" />
</div> </div>
<div class="choose_sandbox_live_cipf">
<input type="radio" id="sandbox" name="<?php echo $sandbox_live['_name']; ?>" value="<?php echo $sandbox_live['sandbox']; ?>" checked /> <div class="choose_sandbox_live_cipf choose_sandbox_cipf">
<input type="radio" id="sandbox" name="<?php echo $paypal_inputs['sandbox_or_live']; ?>" value="sandbox" <?php if ($paypal_credentials['is_sandbox'] === true) {echo 'checked';} ?> />
<label for="sandbox">sandbox</label> <label for="sandbox">sandbox</label>
<input type="radio" id="live" name="<?php echo $sandbox_live['_name']; ?>" value="<?php echo $sandbox_live['live']; ?>" /> </div>
<div class="choose_sandbox_live_cipf choose_live_cipf">
<input type="radio" id="live" name="<?php echo $paypal_inputs['sandbox_or_live']; ?>" value="live" <?php if ($paypal_credentials['is_sandbox'] === false) {echo 'checked';} ?> />
<label for="live">live</label> <label for="live">live</label>
</div> </div>
<input type="submit" value="send"/> <input type="submit" value="send"/>
</form> </form>

View File

@@ -1,5 +0,0 @@
<input type='text' id='mytext'>
<button id='mybutton'>send</button>
<input type='text' id='mytext_2'>
<button id='mybutton_2'>send</button>

View File

@@ -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();

View File

@@ -1,4 +0,0 @@
import { test_fetch } from './example_submenu.js';
test_fetch();

View File

@@ -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);
});
});

View File

@@ -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);
});
});
}

View File

@@ -15,14 +15,9 @@ function add_plugin_content_CIPF() {
$option_paypal = PLGNTLS_class::OPTION_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;
$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']); $paypal_credentials = get_paypal_options_CIPF();
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);
ob_start(); ob_start();
include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html'); include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html');
@@ -44,8 +39,6 @@ function add_plugin_content_CIPF() {
function paypal_credentials_CIPF() { function paypal_credentials_CIPF() {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL; $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']])) { if (!isset($_POST[$nonce_paypal['_name']])) {
redirect_menu_referer_CIPF($_POST); redirect_menu_referer_CIPF($_POST);
@@ -57,30 +50,7 @@ function paypal_credentials_CIPF() {
} }
// do actions here // do actions here
error_log("received form, _POST: " . json_encode($_POST)); update_paypal_credentials_CIPF($_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);
*/
redirect_menu_referer_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) { function redirect_menu_referer_CIPF($post) {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
if (!isset($post)) { if (!isset($post)) {

View File

@@ -0,0 +1,75 @@
<?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!');
}
function set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret) {
PLGNTLS_class::debug_infos();
$option_paypal = PLGNTLS_class::OPTION_PAYPAL;
$option_data = array();
$option_data['is_sandbox'] = $is_sandbox;
$option_data['client_id'] = $client_id;
$option_data['client_secret'] = $client_secret;
update_option($option_paypal['_name'], serialize($option_data), '', 'no');
}
function get_paypal_options_CIPF() {
PLGNTLS_class::debug_infos();
$option_paypal = PLGNTLS_class::OPTION_PAYPAL;
$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']);
}
return unserialize($paypal_credentials_serialized);
}
function get_paypal_client_id_CIPF() {
PLGNTLS_class::debug_infos();
$paypal_credentials = get_paypal_options_CIPF();
return $paypal_credentials['client_id'];
}
function get_paypal_client_secret_CIPF() {
PLGNTLS_class::debug_infos();
$paypal_credentials = get_paypal_options_CIPF();
return $paypal_credentials['client_secret'];
}
function get_paypal_api_base_url_CIPF() {
PLGNTLS_class::debug_infos();
$paypal_credentials = get_paypal_options_CIPF();
$paypal_base_url = '';
$is_sandbox = $paypal_credentials['is_sandbox'];
if ($is_sandbox) {
$paypal_base_url = PLGNTLS_class::PAYPAL_SBOX_API_BASE_URL;
}
else {
$paypal_base_url = PLGNTLS_class::PAYPAL_LIVE_API_BASE_URL;
}
return $paypal_base_url;
}
?>

View File

@@ -91,7 +91,7 @@ function handle_orders_request_CIPF($request_data) {
*/ */
function create_order_CIPF() { function create_order_CIPF() {
PLGNTLS_class::debug_infos(); 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; $acf_card_price_total = PLGNTLS_class::ACF_CARD_PRICE_TOTAL;
$access_token = generate_access_token_CIPF(); $access_token = generate_access_token_CIPF();

View File

@@ -76,7 +76,7 @@ function handle_orders_capture_request_CIPF($request) {
*/ */
function capture_order_CIPF($order_id) { function capture_order_CIPF($order_id) {
PLGNTLS_class::debug_infos(); 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(); $access_token = generate_access_token_CIPF();
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture'; $url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';

View File

@@ -61,9 +61,9 @@ function handle_response_CIPF($response) {
*/ */
function generate_access_token_CIPF() { function generate_access_token_CIPF() {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
$paypal_client_id = PLGNTLS_class::get_paypal_client_id(); $paypal_client_id = get_paypal_client_id_CIPF();
$paypal_client_secret = PLGNTLS_class::get_paypal_client_secret(); $paypal_client_secret = get_paypal_client_secret_CIPF();
$paypal_api_base_url = PLGNTLS_class::get_paypal_api_base_url(); $paypal_api_base_url = get_paypal_api_base_url_CIPF();
/* /*
try try

View File

@@ -19,7 +19,7 @@ function paypal_shortcode_content_CIPF() {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
$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 = PLGNTLS_class::get_paypal_client_id(); $paypal_client_id = get_paypal_client_id_CIPF();
$paypal_message_success = PLGNTLS_class::PAYPAL_MESSAGE_SUCCESS; $paypal_message_success = PLGNTLS_class::PAYPAL_MESSAGE_SUCCESS;
$paypal_message_failure = PLGNTLS_class::PAYPAL_MESSAGE_FAILURE; $paypal_message_failure = PLGNTLS_class::PAYPAL_MESSAGE_FAILURE;

View File

@@ -133,7 +133,7 @@ class PLGNTLS_class {
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_admin_menu_paypal_cipf', '_action'=>'action_admin_menu_paypal_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 // FORMS
const FORM_PROF_COMMANDE_ID = 'prof_commande'; 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;
}
/* /*