diff --git a/plugins/fipfcard_plugin/fipfcard_plugin.php b/plugins/fipfcard_plugin/fipfcard_plugin.php
index aaeb684..6154d57 100644
--- a/plugins/fipfcard_plugin/fipfcard_plugin.php
+++ b/plugins/fipfcard_plugin/fipfcard_plugin.php
@@ -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();
/*
@@ -203,62 +205,21 @@ function paypal_shortcode_content()
$pp_sdk_attributes="src='$pp_sdk_src'";
$pp_sdk_html_script="";
- ob_start();
- ?>
-
old button :
-
- new button :
-
-
-
-
-
- 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' )
diff --git a/plugins/fipfcard_plugin/html/paypal/paypal.html b/plugins/fipfcard_plugin/html/paypal/paypal.html
new file mode 100644
index 0000000..cec290b
--- /dev/null
+++ b/plugins/fipfcard_plugin/html/paypal/paypal.html
@@ -0,0 +1,10 @@
+old button :
+
+new button :
+
+
diff --git a/plugins/fipfcard_plugin/js/paypal/paypal.js b/plugins/fipfcard_plugin/js/paypal/paypal.js
new file mode 100644
index 0000000..6caf1bf
--- /dev/null
+++ b/plugins/fipfcard_plugin/js/paypal/paypal.js
@@ -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.
+
diff --git a/plugins/fipfcard_plugin/php/utils/console_log.php b/plugins/fipfcard_plugin/php/utils/console_log.php
index f45ca58..151aab6 100644
--- a/plugins/fipfcard_plugin/php/utils/console_log.php
+++ b/plugins/fipfcard_plugin/php/utils/console_log.php
@@ -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 = '';
diff --git a/plugins/fipfcard_plugin/utils/plugin_tools.php b/plugins/fipfcard_plugin/utils/plugin_tools.php
index e3a8ad8..9a0f95d 100644
--- a/plugins/fipfcard_plugin/utils/plugin_tools.php
+++ b/plugins/fipfcard_plugin/utils/plugin_tools.php
@@ -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(, /url/to/file, [depends on], version, defer? );
- //wp_enqueue_style( , /url/to/file, [depends on], version, media );
+ private function add_scripts_to_front($scripts_arr) {
+ //wp_enqueue_script(, /url/to/script, [depends on], version, defer? );
+ //wp_enqueue_style( , /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;
}
diff --git a/private b/private
index 31a5126..42499ed 160000
--- a/private
+++ b/private
@@ -1 +1 @@
-Subproject commit 31a5126c329070383711db495ee15457f08e3159
+Subproject commit 42499ed5b473b3a849c7f26d9152f295ee9b239c