From 4eee6970788137d299341ec404d695c2c5910b82 Mon Sep 17 00:00:00 2001 From: asus Date: Wed, 20 Mar 2024 10:10:48 +0100 Subject: [PATCH] first step in making api keys modifiable in admin : using getter and setter instead of const --- .../php/paypal/route_api_orders.php | 5 +-- .../php/paypal/route_api_orders_capture.php | 2 +- .../php/paypal/route_api_utils.php | 6 ++-- plugins/cipf_plugin/php/paypal/shortcode.php | 2 +- plugins/cipf_plugin/utils/plgntls_class.php | 36 +++++++++++++++++-- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/plugins/cipf_plugin/php/paypal/route_api_orders.php b/plugins/cipf_plugin/php/paypal/route_api_orders.php index c5991f4..095d429 100644 --- a/plugins/cipf_plugin/php/paypal/route_api_orders.php +++ b/plugins/cipf_plugin/php/paypal/route_api_orders.php @@ -91,13 +91,14 @@ function handle_orders_request_CIPF($request_data) { */ function create_order_CIPF() { PLGNTLS_class::debug_infos(); - $paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL; + $paypal_api_base_url = PLGNTLS_class::get_paypal_api_base_url(); $access_token = generate_access_token_CIPF(); $user_id = get_current_user_id(); $acf_id = 'user_' . $user_id; - $price = get_field('somme_a_regler', $acf_id); +// $price = get_field('somme_a_regler', $acf_id); + $price = 0.01; $url = $paypal_api_base_url . '/v2/checkout/orders'; $payload = array( diff --git a/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php b/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php index 631be0d..1ded001 100644 --- a/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php +++ b/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php @@ -76,7 +76,7 @@ function handle_orders_capture_request_CIPF($request) { */ function capture_order_CIPF($order_id) { PLGNTLS_class::debug_infos(); - $paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL; + $paypal_api_base_url = PLGNTLS_class::get_paypal_api_base_url(); $access_token = generate_access_token_CIPF(); $url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture'; diff --git a/plugins/cipf_plugin/php/paypal/route_api_utils.php b/plugins/cipf_plugin/php/paypal/route_api_utils.php index 19cff63..ba3b822 100644 --- a/plugins/cipf_plugin/php/paypal/route_api_utils.php +++ b/plugins/cipf_plugin/php/paypal/route_api_utils.php @@ -61,9 +61,9 @@ function handle_response_CIPF($response) { */ function generate_access_token_CIPF() { PLGNTLS_class::debug_infos(); - $paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID; - $paypal_client_secret = PLGNTLS_class::PAYPAL_CLIENT_SECRET; - $paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL; + $paypal_client_id = PLGNTLS_class::get_paypal_client_id(); + $paypal_client_secret = PLGNTLS_class::get_paypal_client_secret(); + $paypal_api_base_url = PLGNTLS_class::get_paypal_api_base_url(); /* try diff --git a/plugins/cipf_plugin/php/paypal/shortcode.php b/plugins/cipf_plugin/php/paypal/shortcode.php index 79afca9..9865f4c 100644 --- a/plugins/cipf_plugin/php/paypal/shortcode.php +++ b/plugins/cipf_plugin/php/paypal/shortcode.php @@ -19,7 +19,7 @@ function paypal_shortcode_content_CIPF() { PLGNTLS_class::debug_infos(); $slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS; $slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE; - $paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID; + $paypal_client_id = PLGNTLS_class::get_paypal_client_id(); $paypal_message_success = PLGNTLS_class::PAYPAL_MESSAGE_SUCCESS; $paypal_message_failure = PLGNTLS_class::PAYPAL_MESSAGE_FAILURE; diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index 2e8c4cb..4afc6b7 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -93,9 +93,15 @@ class PLGNTLS_class { // QUERY // PAYPAL - const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl"; - const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-"; - const PAYPAL_API_BASE_URL = "https://api-m.sandbox.paypal.com"; + const PAYPAL_SBOX_API_BASE_URL = "https://api-m.sandbox.paypal.com"; + const PAYPAL_LIVE_API_BASE_URL = "https://api-m.paypal.com"; + const PAYPAL_HUGO_SANDBOX_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl"; + const PAYPAL_HUGO_SANDBOX_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-"; + const PAYPAL_HUGO_LIVE_CLIENT_ID = "Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO"; + const PAYPAL_HUGO_LIVE_CLIENT_SECRET = "EGeGwfHGxHxsjnC-tH8W0IL4nN3_xlc3sXFRPCQOw5uUoWae3eOgghuDKMnZc5DVGTbP6yIjVJ1BaAra"; + //const PAYPAL_CLIENT_ID = self::PAYPAL_HUGO_LIVE_CLIENT_ID; + //const PAYPAL_CLIENT_SECRET = self::PAYPAL_HUGO_LIVE_CLIENT_SECRET; + //const PAYPAL_API_BASE_URL = self::PAYPAL_HUGO_LIVE_API_BASE_URL; const PAYPAL_MESSAGE_SUCCESS = '`paiement reussi`'; const PAYPAL_MESSAGE_FAILURE = '`paiement raté`'; @@ -203,6 +209,30 @@ class PLGNTLS_class { + /* + * get and set paypal options + * + */ + public static function set_paypal_client_id($client_id) { + } + public static function set_paypal_client_secret($client_secret) { + } + public static function set_paypal_api_base_url($api_url) { + } + public static function get_paypal_client_id() { + return self::PAYPAL_HUGO_LIVE_CLIENT_ID; + } + public static function get_paypal_client_secret() { + return self::PAYPAL_HUGO_LIVE_CLIENT_SECRET; + } + public static function get_paypal_api_base_url() { + /* + return self::PAYPAL_SBOX_API_BASE_URL; + */ + return self::PAYPAL_LIVE_API_BASE_URL; + } + + /*