better file organisation
This commit is contained in:
@@ -32,14 +32,11 @@ plugin dir root
|
|||||||
include_once( plugin_dir_path(__FILE__) . '/utils/plugin_tools.php');
|
include_once( plugin_dir_path(__FILE__) . '/utils/plugin_tools.php');
|
||||||
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
* general inclusions
|
||||||
inclusions
|
|
||||||
*/
|
*/
|
||||||
include_once(PLGNTLS_class::get_path() . '/php/utils/globals.php');
|
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/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_shortcode.php');
|
||||||
//include_once(PLGNTLS_class::get_path() . '/php/images/image-edit.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');
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
* test the class PLGNTLS
|
||||||
plugin shortcode
|
|
||||||
*/
|
*/
|
||||||
function fipfcard_main_shortcode()
|
add_shortcode('fipfcard_plugin', 'fipfcard_test_class_tools');
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
$fipfcard_tools = new PLGNTLS_class();
|
|
||||||
|
|
||||||
|
|
||||||
$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() {
|
function custom_frontend_posting_form() {
|
||||||
$my_image = the_field('image_ratio');
|
$my_image = the_field('image_ratio');
|
||||||
error_log("my_image");
|
error_log("my_image");
|
||||||
@@ -163,59 +102,15 @@ add_shortcode('custom_frontend_posting_form', 'custom_frontend_posting_form');
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
function check_paypal_request()
|
/**
|
||||||
{
|
* call to paypal_shortcode_content()
|
||||||
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');
|
|
||||||
*/
|
*/
|
||||||
|
include_once(PLGNTLS_class::get_path() . '/php/paypal/paypal.php');
|
||||||
function paypal_shortcode_content()
|
|
||||||
{
|
|
||||||
$fipfcard_paypal = new PLGNTLS_class();
|
|
||||||
/*
|
|
||||||
<input type="hidden" name="custom" value="5678" />
|
|
||||||
*/
|
|
||||||
|
|
||||||
$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="<script $pp_sdk_attributes></script>";
|
|
||||||
|
|
||||||
return $fipfcard_paypal->add_to_front(
|
|
||||||
array(
|
|
||||||
$pp_sdk_src,
|
|
||||||
"js/paypal/paypal.js",
|
|
||||||
"html/paypal/paypal.html",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content');
|
add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//function my_custom_url_handler($query)
|
//function my_custom_url_handler($query)
|
||||||
//{
|
//{
|
||||||
// if ($_SERVER['REQUEST_METHOD'] !== 'POST' )
|
// 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://stackoverflow.com/questions/19802492/check-if-current-user-is-administrator-in-wordpress
|
||||||
* - https://developer.wordpress.org/reference/functions/current_user_can/
|
* - 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)
|
function PLGNTLS_my_custom_df_form_handler($form_id, $post_array, $form_type)
|
||||||
{
|
{
|
||||||
error_log("in my_custom_df_form_handler");
|
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");
|
||||||
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
|
menu plugin
|
||||||
*/
|
*/
|
||||||
|
include_once(PLGNTLS_class::get_path() . '/php/menu/example_menu.php');
|
||||||
function fipfcard_plugin_menu()
|
function fipfcard_plugin_menu()
|
||||||
{
|
{
|
||||||
add_menu_page
|
add_menu_page
|
||||||
|
|||||||
@@ -1,168 +1,60 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_orders.php');
|
||||||
/**
|
|
||||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
/*
|
||||||
*/
|
function check_paypal_request()
|
||||||
function fipfcard_paypal_order()
|
|
||||||
{
|
{
|
||||||
// json decode from JSON.stringify : https://stackoverflow.com/q/15986235/9497573
|
error_log("----");
|
||||||
$data_received = json_decode( html_entity_decode( stripslashes( $_POST['data'] ) ) );
|
if (is_page('test_paypal_payment'))
|
||||||
// error_log( "data_received" );
|
error_log("on test_paypal_payment");
|
||||||
// error_log( json_encode( $data_received ) );
|
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');
|
||||||
|
*/
|
||||||
|
|
||||||
// use the cart information passed from the front-end to calculate the order amount detals
|
|
||||||
$cart = $data_received->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();
|
||||||
|
/*
|
||||||
|
<input type="hidden" name="custom" value="5678" />
|
||||||
|
*/
|
||||||
|
|
||||||
|
$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="<script $pp_sdk_attributes></script>";
|
||||||
|
|
||||||
|
return $fipfcard_paypal->add_to_front(
|
||||||
array(
|
array(
|
||||||
'from paypal_order',
|
$pp_sdk_src,
|
||||||
"data_received" => $data_received,
|
"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);
|
|
||||||
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
166
plugins/fipfcard_plugin/php/paypal/route_api_orders.php
Normal file
166
plugins/fipfcard_plugin/php/paypal/route_api_orders.php
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function fipfcard_paypal_order()
|
||||||
|
{
|
||||||
|
// json decode from JSON.stringify : https://stackoverflow.com/q/15986235/9497573
|
||||||
|
$data_received = json_decode( html_entity_decode( stripslashes( $_POST['data'] ) ) );
|
||||||
|
// error_log( "data_received" );
|
||||||
|
// error_log( json_encode( $data_received ) );
|
||||||
|
|
||||||
|
// use the cart information passed from the front-end to calculate the order amount detals
|
||||||
|
$cart = $data_received->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);
|
||||||
|
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
?>
|
||||||
67
plugins/fipfcard_plugin/php/test_class_tools.php
Normal file
67
plugins/fipfcard_plugin/php/test_class_tools.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function fipfcard_test_class_tools()
|
||||||
|
{
|
||||||
|
|
||||||
|
$fipfcard_tools = new PLGNTLS_class();
|
||||||
|
|
||||||
|
|
||||||
|
$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",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user