diff --git a/plugins/fipfcard_plugin/fipfcard_plugin.php b/plugins/fipfcard_plugin/fipfcard_plugin.php
index b3d25e5..3efe43a 100644
--- a/plugins/fipfcard_plugin/fipfcard_plugin.php
+++ b/plugins/fipfcard_plugin/fipfcard_plugin.php
@@ -32,14 +32,11 @@ plugin dir root
include_once( plugin_dir_path(__FILE__) . '/utils/plugin_tools.php');
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
-/*
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-inclusions
-*/
+/**
+ * general 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/paypal/paypal.php');
//include_once(PLGNTLS_class::get_path() . '/php/images/image_edit_shortcode.php');
//include_once(PLGNTLS_class::get_path() . '/php/images/image-edit.php');
@@ -49,75 +46,17 @@ include_once(PLGNTLS_class::get_path() . '/php/paypal/paypal.php');
-/*
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-plugin shortcode
-*/
-function fipfcard_main_shortcode()
-{
-
-
- $fipfcard_tools = new PLGNTLS_class();
+/**
+ * test the class PLGNTLS
+ */
+add_shortcode('fipfcard_plugin', 'fipfcard_test_class_tools');
- $myvar_1 = "I am one";
- $myvar_2 = "I am two";
-
- $names = ["hugo", "camille"];
- $ages = ["13", "34", "56"];
-
-$data = wp_get_current_user();
-$data = $data->data;
-$data = $data->user_email;
-//error_log("data->data");
-//error_log($data);
-//delete_post_meta(get_the_ID(), "_data_user_email");
-//delete_post_meta(get_the_ID(), "_data");
-//add_post_meta(get_the_ID(), "data_user_email", $data);
-
- $post_metadata = get_metadata( 'post', get_the_ID() );
- $post_meta = get_post_meta( get_the_ID() );
-
- $user_metadata = get_metadata( 'user', get_current_user_id() );
- $user_meta = get_user_meta( get_current_user_id() );
- $acf_get_fields = get_fields( get_the_ID() );
- $user_data = get_userdata( get_current_user_id() );
- $current_user = wp_get_current_user();
- $user_email = get_field('user_email', 'MarieM');
-
-
- return $fipfcard_tools->add_to_front
- (
- array
- (
- "css/example_style.css",
- "js/example_init.js",
- "js/example_script2.js",
- "js/example_script3.js",
- "html/example_index.html",
- "html/example_index2.html",
- ),
- compact
- (
- "myvar_1",
- "myvar_2",
- "post_metadata",
- "post_meta",
- "user_metadata",
- "user_meta",
- "acf_get_fields",
- "user_data",
- "current_user",
- "user_email",
- "names",
- "ages",
- )
- );
-
-}
-add_shortcode('fipfcard_plugin', 'fipfcard_main_shortcode');
+/**
+ *
+ */
function custom_frontend_posting_form() {
$my_image = the_field('image_ratio');
error_log("my_image");
@@ -163,59 +102,15 @@ add_shortcode('custom_frontend_posting_form', 'custom_frontend_posting_form');
-/*
-function check_paypal_request()
-{
- error_log("----");
- if (is_page('test_paypal_payment'))
- error_log("on test_paypal_payment");
- else if (is_page('test_paypal_ok'))
- error_log("on test_paypal_ok");
- else if (is_page('test_paypal_infos'))
- error_log("on test_paypal_infos");
- else
- return;
- error_log("_GET");
- error_log(json_encode($_GET));
- error_log("_POST");
- error_log(json_encode($_POST));
-// error_log("_COOKIE");
-// error_log(json_encode($_COOKIE));
-}
-add_action('template_redirect', 'check_paypal_request');
-*/
-function paypal_shortcode_content()
-{
- $fipfcard_paypal = new PLGNTLS_class();
-/*
-
-*/
-
- $pp_sdk_currency = "EUR";
- $pp_sdk_debug = "true";
- $pp_sdk_base_url="https://sandbox.paypal.com";
- $pp_sdk_base_url="https://www.paypal.com";
-// $pp_sdk_client_token="abc123xyz==";
- $pp_sdk_src="$pp_sdk_base_url/sdk/js?client-id=" . PAYPAL_CLIENT_ID . "¤cy=$pp_sdk_currency&debug=$pp_sdk_debug";
- $pp_sdk_src="$pp_sdk_base_url/sdk/js?client-id=" . PAYPAL_CLIENT_ID ;
-// $pp_sdk_attributes="src='$pp_sdk_src' data-client-token='$pp_sdk_client_token'";
-// $pp_sdk_attributes="src='$pp_sdk_src'";
-// $pp_sdk_html_script="";
-
- return $fipfcard_paypal->add_to_front(
- array(
- $pp_sdk_src,
- "js/paypal/paypal.js",
- "html/paypal/paypal.html",
- ),
- );
-}
+/**
+ * call to paypal_shortcode_content()
+ */
+include_once(PLGNTLS_class::get_path() . '/php/paypal/paypal.php');
add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content');
-
//function my_custom_url_handler($query)
//{
// if ($_SERVER['REQUEST_METHOD'] !== 'POST' )
@@ -386,7 +281,6 @@ function my_custom_url_handler($query)
* - https://stackoverflow.com/questions/19802492/check-if-current-user-is-administrator-in-wordpress
* - https://developer.wordpress.org/reference/functions/current_user_can/
*/
-add_action ('df_before_process', 'PLGNTLS_my_custom_df_form_handler', 10, 3);
function PLGNTLS_my_custom_df_form_handler($form_id, $post_array, $form_type)
{
error_log("in my_custom_df_form_handler");
@@ -397,6 +291,7 @@ function PLGNTLS_my_custom_df_form_handler($form_id, $post_array, $form_type)
error_log("form_type");
error_log($form_type);
}
+add_action ('df_before_process', 'PLGNTLS_my_custom_df_form_handler', 10, 3);
@@ -451,6 +346,7 @@ function handle_acf_form_submission($post_id)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
menu plugin
*/
+include_once(PLGNTLS_class::get_path() . '/php/menu/example_menu.php');
function fipfcard_plugin_menu()
{
add_menu_page
diff --git a/plugins/fipfcard_plugin/php/paypal/paypal.php b/plugins/fipfcard_plugin/php/paypal/paypal.php
index 2b53fb2..bd75f55 100644
--- a/plugins/fipfcard_plugin/php/paypal/paypal.php
+++ b/plugins/fipfcard_plugin/php/paypal/paypal.php
@@ -1,168 +1,60 @@
cart;
- error_log( "cart" );
- error_log( json_encode( $cart ) );
- create_order($cart);
- wp_send_json_success(
+
+
+function paypal_shortcode_content()
+{
+ $fipfcard_paypal = new PLGNTLS_class();
+/*
+
+*/
+
+ $pp_sdk_currency = "EUR";
+ $pp_sdk_debug = "true";
+ $pp_sdk_base_url="https://sandbox.paypal.com";
+ $pp_sdk_base_url="https://www.paypal.com";
+// $pp_sdk_client_token="abc123xyz==";
+ $pp_sdk_src="$pp_sdk_base_url/sdk/js?client-id=" . PAYPAL_CLIENT_ID . "¤cy=$pp_sdk_currency&debug=$pp_sdk_debug";
+ $pp_sdk_src="$pp_sdk_base_url/sdk/js?client-id=" . PAYPAL_CLIENT_ID ;
+// $pp_sdk_attributes="src='$pp_sdk_src' data-client-token='$pp_sdk_client_token'";
+// $pp_sdk_attributes="src='$pp_sdk_src'";
+// $pp_sdk_html_script="";
+
+ return $fipfcard_paypal->add_to_front(
array(
- 'from paypal_order',
- "data_received" => $data_received,
+ $pp_sdk_src,
+ "js/paypal/paypal.js",
+ "html/paypal/paypal.html",
),
- 200
);
}
-add_action( 'wp_ajax_paypal_orders', 'fipfcard_paypal_order' );
-
-
-
-
-
-
-/**
- * Generate an OAuth 2.0 access token for authenticating with PayPal REST APIs.
- * @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
- * @see https://developer.paypal.com/api/rest/authentication/
- */
-function generate_access_token( )
-{
- $base = "https://api-m.sandbox.paypal.com";
-
- try {
- if ( !PAYPAL_CLIENT_ID || !PAYPAL_CLIENT_SECRET ) {
- throw new Error( "MISSING_API_CREDENTIALS" );
- }
- $credentials = PAYPAL_CLIENT_ID . ":" . PAYPAL_CLIENT_SECRET;
- $auth = base64_encode($credentials);
-
- $url = $base . '/v1/oauth2/token';
- $body = http_build_query(array('grant_type' => 'client_credentials'));
- // Initialize curl
- $ch = curl_init();
- // Set curl options
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Authorization: Basic ' . $auth,
- ));
- // Execute curl and get the response
- $data_json = curl_exec($ch);
-
- if ( $data_json === false)
- throw new Error('cURL error: ' . curl_error($ch));
- // Close curl
- curl_close($ch);
-
- $data = json_decode($data_json);
-
- return $data->access_token;
- }
- catch (Throwable $error) {
- error_log("Failed to generate Access Token:");
- error_log($error->getMessage());
- }
-};
-/*
-*/
-
-
-
-/**
- * Create an order to start the transaction.
- * @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
- */
-
-function create_order( $cart )
-{
-
- // use the cart information passed from the front-end to calculate the purchase unit details
-
- $access_token = generate_access_token();
- error_log("access_token:");
- error_log($access_token);
-
-/*
-
-
- const url = `${base}/v2/checkout/orders`;
-
- const payload = {
-
- intent: "CAPTURE",
-
- purchase_units: [
-
- {
-
- amount: {
-
- currency_code: "USD",
-
- value: "100.00",
-
- },
-
- },
-
- ],
-
- };
-
-
-
- const response = await fetch(url, {
-
- headers: {
-
- "Content-Type": "application/json",
-
- Authorization: `Bearer ${accessToken}`,
-
- // Uncomment one of these to force an error for negative testing (in sandbox mode only). Documentation:
-
- // https://developer.paypal.com/tools/sandbox/negative-testing/request-headers/
-
- // "PayPal-Mock-Response": '{"mock_application_codes": "MISSING_REQUIRED_PARAMETER"}'
-
- // "PayPal-Mock-Response": '{"mock_application_codes": "PERMISSION_DENIED"}'
-
- // "PayPal-Mock-Response": '{"mock_application_codes": "INTERNAL_SERVER_ERROR"}'
-
- },
-
- method: "POST",
-
- body: JSON.stringify(payload),
-
- });
-
-
-
- return handleResponse(response);
-
-*/
-};
-
?>
diff --git a/plugins/fipfcard_plugin/php/paypal/route_api_orders.php b/plugins/fipfcard_plugin/php/paypal/route_api_orders.php
new file mode 100644
index 0000000..326abe3
--- /dev/null
+++ b/plugins/fipfcard_plugin/php/paypal/route_api_orders.php
@@ -0,0 +1,166 @@
+cart;
+ error_log( "cart" );
+ error_log( json_encode( $cart ) );
+ create_order($cart);
+
+ wp_send_json_success(
+ array(
+ 'from paypal_order',
+ "data_received" => $data_received,
+ ),
+ 200
+ );
+}
+add_action( 'wp_ajax_paypal_orders', 'fipfcard_paypal_order' );
+
+
+
+
+
+
+/**
+ * Generate an OAuth 2.0 access token for authenticating with PayPal REST APIs.
+ * @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
+ * @see https://developer.paypal.com/api/rest/authentication/
+ */
+function generate_access_token( )
+{
+ $base = "https://api-m.sandbox.paypal.com";
+
+ try {
+ if ( !PAYPAL_CLIENT_ID || !PAYPAL_CLIENT_SECRET ) {
+ throw new Error( "MISSING_API_CREDENTIALS" );
+ }
+ $credentials = PAYPAL_CLIENT_ID . ":" . PAYPAL_CLIENT_SECRET;
+ $auth = base64_encode($credentials);
+
+ $url = $base . '/v1/oauth2/token';
+ $body = http_build_query(array('grant_type' => 'client_credentials'));
+ // Initialize curl
+ $ch = curl_init();
+ // Set curl options
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'Authorization: Basic ' . $auth,
+ ));
+ // Execute curl and get the response
+ $data_json = curl_exec($ch);
+
+ if ( $data_json === false)
+ throw new Error('cURL error: ' . curl_error($ch));
+ // Close curl
+ curl_close($ch);
+
+ $data = json_decode($data_json);
+
+ return $data->access_token;
+ }
+ catch (Throwable $error) {
+ error_log("Failed to generate Access Token:");
+ error_log($error->getMessage());
+ }
+};
+/*
+*/
+
+
+
+/**
+ * Create an order to start the transaction.
+ * @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
+ */
+
+function create_order( $cart )
+{
+
+ // use the cart information passed from the front-end to calculate the purchase unit details
+
+ $access_token = generate_access_token();
+ error_log("access_token:");
+ error_log($access_token);
+
+/*
+
+
+ const url = `${base}/v2/checkout/orders`;
+
+ const payload = {
+
+ intent: "CAPTURE",
+
+ purchase_units: [
+
+ {
+
+ amount: {
+
+ currency_code: "USD",
+
+ value: "100.00",
+
+ },
+
+ },
+
+ ],
+
+ };
+
+
+
+ const response = await fetch(url, {
+
+ headers: {
+
+ "Content-Type": "application/json",
+
+ Authorization: `Bearer ${accessToken}`,
+
+ // Uncomment one of these to force an error for negative testing (in sandbox mode only). Documentation:
+
+ // https://developer.paypal.com/tools/sandbox/negative-testing/request-headers/
+
+ // "PayPal-Mock-Response": '{"mock_application_codes": "MISSING_REQUIRED_PARAMETER"}'
+
+ // "PayPal-Mock-Response": '{"mock_application_codes": "PERMISSION_DENIED"}'
+
+ // "PayPal-Mock-Response": '{"mock_application_codes": "INTERNAL_SERVER_ERROR"}'
+
+ },
+
+ method: "POST",
+
+ body: JSON.stringify(payload),
+
+ });
+
+
+
+ return handleResponse(response);
+
+*/
+};
+
+?>
diff --git a/plugins/fipfcard_plugin/php/test_class_tools.php b/plugins/fipfcard_plugin/php/test_class_tools.php
new file mode 100644
index 0000000..1ede0ff
--- /dev/null
+++ b/plugins/fipfcard_plugin/php/test_class_tools.php
@@ -0,0 +1,67 @@
+data;
+$data = $data->user_email;
+//error_log("data->data");
+//error_log($data);
+//delete_post_meta(get_the_ID(), "_data_user_email");
+//delete_post_meta(get_the_ID(), "_data");
+//add_post_meta(get_the_ID(), "data_user_email", $data);
+
+ $post_metadata = get_metadata( 'post', get_the_ID() );
+ $post_meta = get_post_meta( get_the_ID() );
+
+ $user_metadata = get_metadata( 'user', get_current_user_id() );
+ $user_meta = get_user_meta( get_current_user_id() );
+ $acf_get_fields = get_fields( get_the_ID() );
+ $user_data = get_userdata( get_current_user_id() );
+ $current_user = wp_get_current_user();
+ $user_email = get_field('user_email', 'MarieM');
+
+
+ return $fipfcard_tools->add_to_front
+ (
+ array
+ (
+ "css/example_style.css",
+ "js/example_init.js",
+ "js/example_script2.js",
+ "js/example_script3.js",
+ "html/example_index.html",
+ "html/example_index2.html",
+ ),
+ compact
+ (
+ "myvar_1",
+ "myvar_2",
+ "post_metadata",
+ "post_meta",
+ "user_metadata",
+ "user_meta",
+ "acf_get_fields",
+ "user_data",
+ "current_user",
+ "user_email",
+ "names",
+ "ages",
+ )
+ );
+
+}
+
+
+?>