101 lines
2.7 KiB
PHP
101 lines
2.7 KiB
PHP
<?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!');
|
|
}
|
|
|
|
|
|
include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_orders.php');
|
|
include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_orders_capture.php');
|
|
|
|
|
|
|
|
/*
|
|
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="<script $pp_sdk_attributes></script>";
|
|
|
|
$added_to_front = $fipfcard_paypal->add_to_front(
|
|
array(
|
|
$pp_sdk_src,
|
|
"js/paypal/paypal.js",
|
|
"html/paypal/paypal.html",
|
|
),
|
|
);
|
|
|
|
return $added_to_front;
|
|
}
|
|
|
|
|
|
/**
|
|
* the js file paypal.js needs to be imported as a module to use import
|
|
* @see https://developer.wordpress.org/reference/hooks/script_loader_tag/
|
|
*/
|
|
add_filter( 'script_loader_tag', 'add_id_to_script', 10, 3 );
|
|
function add_id_to_script( $tag, $handle, $src ) {
|
|
if ( $handle === 'PLGNTLS_paypal_js' ) {
|
|
$tag = '<script type="module" src="' . esc_url( $src ) . '" ></script>';
|
|
}
|
|
return $tag;
|
|
}
|
|
|
|
|
|
// handling routes and endpoints
|
|
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
|
function fipf_routes_endpoints()
|
|
{
|
|
$base_rest_route = "fipf_plugin/api/v1";
|
|
register_rest_route($base_rest_route, '/orders', array(
|
|
'methods' => 'POST',
|
|
'callback' => 'handle_orders_request',
|
|
));
|
|
// https://local_fipfcard_plugin.com/wp-json/fipf_plugin/api/v1/orders/21T129305J264761D/capture
|
|
register_rest_route($base_rest_route, '/orders/(?P<orderID>[a-zA-Z0-9]+)/capture', array(
|
|
'methods' => 'POST',
|
|
'callback' => 'handle_orders_capture_request',
|
|
));
|
|
};
|
|
add_action('rest_api_init', 'fipf_routes_endpoints');
|
|
|
|
|
|
|
|
?>
|