- added capacity in plugin tool to take urls
- test front end integration ok
This commit is contained in:
@@ -37,6 +37,7 @@ PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__)
|
||||
inclusions
|
||||
*/
|
||||
include_once(PLGNTLS_class::get_path() . '/php/utils/globals.php');
|
||||
include_once(PLGNTLS_class::get_path() . '/php/utils/console_log.php');
|
||||
include_once(PLGNTLS_class::get_path() . '/php/menu/example_menu.php');
|
||||
|
||||
//include_once(PLGNTLS_class::get_path() . '/php/images/image_edit_shortcode.php');
|
||||
@@ -183,6 +184,7 @@ add_action('template_redirect', 'check_paypal_request');
|
||||
|
||||
function paypal_shortcode_content()
|
||||
{
|
||||
$fipfcard_paypal = new PLGNTLS_class();
|
||||
/*
|
||||
<input type="hidden" name="custom" value="5678" />
|
||||
|
||||
@@ -203,62 +205,21 @@ function paypal_shortcode_content()
|
||||
$pp_sdk_attributes="src='$pp_sdk_src'";
|
||||
$pp_sdk_html_script="<script $pp_sdk_attributes></script>";
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<h1>old button :</h1>
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
|
||||
<input type="hidden" name="cmd" value="_s-xclick" />
|
||||
<input type="hidden" name="hosted_button_id" value="H876N9DGSCLKS" />
|
||||
<input type="hidden" name="currency_code" value="EUR" />
|
||||
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Buy Now" />
|
||||
</form>
|
||||
<h1>new button :</h1>
|
||||
<script>console.log(<?php echo json_encode($pp_sdk_attributes, JSON_HEX_TAG) ?>);</script>
|
||||
<?php echo $pp_sdk_html_script; ?>
|
||||
<div id="paypal-button-container"></div>
|
||||
<p id="result-message"></p>
|
||||
<script>
|
||||
console.log("paypal:");
|
||||
console.log(paypal);
|
||||
|
||||
paypal.Buttons({
|
||||
style: {
|
||||
layout: 'vertical',
|
||||
color: 'blue',
|
||||
shape: 'rect',
|
||||
label: 'paypal',
|
||||
},
|
||||
// Order is created on the server and the order id is returned
|
||||
createOrder() {
|
||||
return fetch("/my-server/create-paypal-order", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
// Use the "body" param to optionally pass additional order information
|
||||
// such as product SKUs and quantities
|
||||
body: JSON.stringify({
|
||||
cart: [
|
||||
{
|
||||
sku: "YOUR_PRODUCT_STOCK_KEEPING_UNIT",
|
||||
quantity: "YOUR_PRODUCT_QUANTITY",
|
||||
},
|
||||
],
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((order) => order.id);
|
||||
}
|
||||
}).render('#paypal-button-container');
|
||||
|
||||
</script>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
return $fipfcard_paypal->add_to_front(
|
||||
array(
|
||||
$pp_sdk_src,
|
||||
"js/paypal/paypal.js",
|
||||
"html/paypal/paypal.html",
|
||||
),
|
||||
compact(
|
||||
),
|
||||
);
|
||||
}
|
||||
add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content');
|
||||
|
||||
|
||||
|
||||
|
||||
//function my_custom_url_handler($query)
|
||||
//{
|
||||
// if ($_SERVER['REQUEST_METHOD'] !== 'POST' )
|
||||
|
||||
10
plugins/fipfcard_plugin/html/paypal/paypal.html
Normal file
10
plugins/fipfcard_plugin/html/paypal/paypal.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<h1>old button :</h1>
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
|
||||
<input type="hidden" name="cmd" value="_s-xclick" />
|
||||
<input type="hidden" name="hosted_button_id" value="H876N9DGSCLKS" />
|
||||
<input type="hidden" name="currency_code" value="EUR" />
|
||||
<input type="image" src="https://www.paypalobjects.com/fr_XC/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" title="PayPal, votre réflexe sécurité pour payer en ligne." alt="Acheter" />
|
||||
</form>
|
||||
<h1>new button :</h1>
|
||||
<div id="paypal-button-container"></div>
|
||||
<p id="result-message"></p>
|
||||
64
plugins/fipfcard_plugin/js/paypal/paypal.js
Normal file
64
plugins/fipfcard_plugin/js/paypal/paypal.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
paypal.Buttons({
|
||||
style: {
|
||||
layout: 'vertical',
|
||||
color: 'blue',
|
||||
shape: 'rect',
|
||||
label: 'paypal',
|
||||
},
|
||||
// Order is created on the server and the order id is returned
|
||||
createOrder() {
|
||||
return fetch("/my-server/create-paypal-order", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
// Use the "body" param to optionally pass additional order information
|
||||
// such as product SKUs and quantities
|
||||
body: JSON.stringify({
|
||||
cart: [
|
||||
{
|
||||
sku: "YOUR_PRODUCT_STOCK_KEEPING_UNIT",
|
||||
quantity: "YOUR_PRODUCT_QUANTITY",
|
||||
},
|
||||
],
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((order) => order.id);
|
||||
}
|
||||
}).render('#paypal-button-container');
|
||||
*/
|
||||
|
||||
paypal.Buttons({
|
||||
style: {
|
||||
layout: 'vertical',
|
||||
color: 'blue',
|
||||
shape: 'rect',
|
||||
label: 'paypal',
|
||||
},
|
||||
createOrder: function(data, actions) {
|
||||
// This function sets up the details of the transaction, including the amount and line item details.
|
||||
const my_order = actions.order.create({
|
||||
purchase_units: [{
|
||||
amount: {
|
||||
value: '0.01'
|
||||
}
|
||||
}]
|
||||
});
|
||||
console.log("my_order: ", my_order);
|
||||
return my_order;
|
||||
},
|
||||
onApprove: function(data, actions) {
|
||||
// This function captures the funds from the transaction.
|
||||
console.log("data: ", data);
|
||||
console.log("actions: ", actions);
|
||||
return actions.order.capture().then(function(details) {
|
||||
console.log("details: ", details);
|
||||
// This function shows a transaction success message to your buyer.
|
||||
alert('Transaction completed by ' + details.payer.name.given_name);
|
||||
});
|
||||
}
|
||||
}).render('#paypal-button-container');
|
||||
//This function displays Smart Payment Buttons on your web page.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
https://stackify.com/how-to-log-to-console-in-php/
|
||||
*/
|
||||
function console_log($output) {
|
||||
if (CONSOLE_OFF)
|
||||
if (FIPFCARD_CONSOLE_OFF)
|
||||
return;
|
||||
$json_output = json_encode($output, JSON_HEX_TAG);
|
||||
$js_code = '<script>console.log(' . $json_output . ');</script>';
|
||||
|
||||
@@ -51,26 +51,26 @@ class PLGNTLS_class
|
||||
}
|
||||
|
||||
|
||||
public function add_to_front($files_arr = null, $vars = null) {
|
||||
if (!is_null($files_arr))
|
||||
public function add_to_front($scripts_arr = null, $vars = null) {
|
||||
if (!is_null($scripts_arr))
|
||||
{
|
||||
// add ajax file at beginning of files list
|
||||
array_unshift($files_arr, "utils/plugin_ajax.js");
|
||||
array_unshift($scripts_arr, "utils/plugin_ajax.js");
|
||||
$nonce = array("ajax_nonce" => wp_create_nonce('wp-pageviews-nonce'));
|
||||
$url = array("ajax_url" => admin_url('admin-ajax.php'));
|
||||
$vars = array_merge($vars, $nonce);
|
||||
$vars = array_merge($vars, $url);
|
||||
}
|
||||
|
||||
$files = array();
|
||||
foreach($files_arr as $key => $file_name) {
|
||||
$files[] = $this->init_file($key, $file_name);
|
||||
$scripts = array();
|
||||
foreach($scripts_arr as $key => $script_name) {
|
||||
$scripts[] = $this->init_script($key, $script_name);
|
||||
}
|
||||
if (!is_null($files_arr))
|
||||
$this->add_files_to_front($files);
|
||||
if (!is_null($scripts_arr))
|
||||
$this->add_scripts_to_front($scripts);
|
||||
if (!is_null($vars))
|
||||
$this->add_vars_to_front($vars);
|
||||
return $this->create_html($files, $vars);
|
||||
return $this->create_html($scripts, $vars);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,49 +169,49 @@ class PLGNTLS_class
|
||||
* - to add ajax script and variables
|
||||
* - default to true
|
||||
*/
|
||||
private function add_files_to_front($files_arr) {
|
||||
//wp_enqueue_script(<give_it_a_name>, /url/to/file, [depends on], version, defer? );
|
||||
//wp_enqueue_style( <give_it_a_name>, /url/to/file, [depends on], version, media );
|
||||
private function add_scripts_to_front($scripts_arr) {
|
||||
//wp_enqueue_script(<give_it_a_name>, /url/to/script, [depends on], version, defer? );
|
||||
//wp_enqueue_style( <give_it_a_name>, /url/to/script, [depends on], version, media );
|
||||
|
||||
$previous_css_basename = '';
|
||||
$previous_js_basename = '';
|
||||
foreach ($files_arr as $file) {
|
||||
if ($file->ext === "js") {
|
||||
foreach ($scripts_arr as $script) {
|
||||
if (in_array($script->ext, array("js", "url"))) {
|
||||
if (is_null($this->_first_script))
|
||||
$this->_first_script = $file->handle;
|
||||
$depends_on = $this->check_dependencies($file, $previous_js_basename);
|
||||
$this->_first_script = $script->handle;
|
||||
$depends_on = $this->check_dependencies($script, $previous_js_basename);
|
||||
if ($depends_on !== null)
|
||||
wp_enqueue_script( $file->handle, $file->url, $depends_on, $file->version, true);
|
||||
$previous_js_basename = $file->handle;
|
||||
wp_enqueue_script( $script->handle, $script->url, $depends_on, $script->version, true);
|
||||
$previous_js_basename = $script->handle;
|
||||
}
|
||||
else if ($file->ext === "css") {
|
||||
$depends_on = $this->check_dependencies($file, $previous_css_basename);
|
||||
else if ($script->ext === "css") {
|
||||
$depends_on = $this->check_dependencies($script, $previous_css_basename);
|
||||
if ($depends_on !== null)
|
||||
wp_enqueue_style( $file->handle, $file->url, $depends_on, $file->version, '');
|
||||
$previous_css_basename = $file->handle;
|
||||
wp_enqueue_style( $script->handle, $script->url, $depends_on, $script->version, '');
|
||||
$previous_css_basename = $script->handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
private function check_dependencies(&$file, $previous_basename)
|
||||
private function check_dependencies(&$script, $previous_basename)
|
||||
{
|
||||
if ($file->ext === "js")
|
||||
if (in_array($script->ext, array("js", "url")))
|
||||
{
|
||||
global $wp_scripts;
|
||||
$already_enqueued = array_search($file->handle, $wp_scripts->queue);
|
||||
$already_enqueued = array_search($script->handle, $wp_scripts->queue);
|
||||
if ($already_enqueued !== false)
|
||||
return null;
|
||||
}
|
||||
else if ($file->ext === "css")
|
||||
else if ($script->ext === "css")
|
||||
{
|
||||
global $wp_styles;
|
||||
$already_enqueued = array_search($file->handle, $wp_styles->queue);
|
||||
$already_enqueued = array_search($script->handle, $wp_styles->queue);
|
||||
if ($already_enqueued !== false)
|
||||
return null;
|
||||
}
|
||||
|
||||
$depends_on = array();
|
||||
if (isset($file->depends) && $file->depends !== '')
|
||||
$depends_on[] = $file->depends;
|
||||
if (isset($script->depends) && $script->depends !== '')
|
||||
$depends_on[] = $script->depends;
|
||||
if (isset($previous_basename) && $previous_basename !== '')
|
||||
$depends_on[] = $previous_basename;
|
||||
|
||||
@@ -233,25 +233,40 @@ class PLGNTLS_class
|
||||
* - version : used to avoid browser caching
|
||||
* - depends : string if depends on a handle, or ''
|
||||
*/
|
||||
private function init_file($key, $file_name) {
|
||||
$file = (object)[];
|
||||
private function init_script($key, $script_name) {
|
||||
$script = (object)[];
|
||||
|
||||
$file->ext = pathinfo($file_name, PATHINFO_EXTENSION);
|
||||
if (! in_array($file->ext, array("js", "css", "html")))
|
||||
if(filter_var($script_name, FILTER_VALIDATE_URL))
|
||||
$script->ext = "url";
|
||||
else
|
||||
$script->ext = pathinfo($script_name, PATHINFO_EXTENSION);
|
||||
if (! in_array($script->ext, array("js", "css", "html", "url")))
|
||||
return null;
|
||||
|
||||
$file->basename = pathinfo($file_name, PATHINFO_BASENAME);
|
||||
$file->handle = "PLGNTLS_" . str_replace(".", "_", $file->basename);
|
||||
if ($script->ext === "url")
|
||||
$script->basename = parse_url($script_name, PHP_URL_HOST);
|
||||
else
|
||||
$script->basename = pathinfo($script_name, PATHINFO_BASENAME);
|
||||
$script->handle = "PLGNTLS_" . str_replace(".", "_", $script->basename);
|
||||
console_log("script->handle:");
|
||||
console_log($script->handle);
|
||||
|
||||
$file->url = $this->get_url().$file_name;
|
||||
$file->path = $this->get_path().$file_name;
|
||||
$file->version = date("ymd-Gis", filemtime($file->path));
|
||||
if ($script->ext === "url") {
|
||||
$script->url = $script_name;
|
||||
$script->path = null;
|
||||
$script->version = null;
|
||||
}
|
||||
else {
|
||||
$script->url = $this->get_url().$script_name;
|
||||
$script->path = $this->get_path().$script_name;
|
||||
$script->version = date("ymd-Gis", filemtime($script->path));
|
||||
}
|
||||
|
||||
$file->depends = '';
|
||||
$script->depends = '';
|
||||
if (is_string($key))
|
||||
$file->depends = $key;
|
||||
$script->depends = $key;
|
||||
|
||||
return $file;
|
||||
return $script;
|
||||
}
|
||||
|
||||
|
||||
|
||||
2
private
2
private
Submodule private updated: 31a5126c32...42499ed5b4
Reference in New Issue
Block a user