-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
- />
-
+ />
+
- />
-
+ />
+
+
+
+
+ />
+
diff --git a/plugins/cipf_plugin/php/_actions_payments.php b/plugins/cipf_plugin/php/_actions_payments.php
index d3327ef..452c9cd 100644
--- a/plugins/cipf_plugin/php/_actions_payments.php
+++ b/plugins/cipf_plugin/php/_actions_payments.php
@@ -54,12 +54,30 @@ function get_paypal_options_CIPF() {
function get_paypal_client_id_CIPF() {
Plgntls::debug_infos();
$paypal_credentials = get_paypal_options_CIPF();
- return $paypal_credentials['client_id'];
+ $is_sandbox = $paypal_credentials['is_sandbox'];
+
+ $client_id = '';
+ if ($is_sandbox) {
+ $client_id = $paypal_credentials['sandbox_client_id'];
+ }
+ else {
+ $client_id = $paypal_credentials['live_client_id'];
+ }
+ return $client_id;
}
function get_paypal_client_secret_CIPF() {
Plgntls::debug_infos();
$paypal_credentials = get_paypal_options_CIPF();
- return $paypal_credentials['client_secret'];
+ $is_sandbox = $paypal_credentials['is_sandbox'];
+
+ $client_secret = '';
+ if ($is_sandbox) {
+ $client_secret = $paypal_credentials['sandbox_client_secret'];
+ }
+ else {
+ $client_secret = $paypal_credentials['live_client_secret'];
+ }
+ return $client_secret;
}
function get_paypal_api_base_url_CIPF() {
Plgntls::debug_infos();
@@ -75,7 +93,31 @@ function get_paypal_api_base_url_CIPF() {
}
return $paypal_base_url;
}
+function is_paypal_force_1_cent_CIPF() {
+ Plgntls::debug_infos();
+ $paypal_options = get_paypal_options_CIPF();
+error_log("paypal_options: " . json_encode($paypal_options));
+ return $paypal_options['force_1_cent'];
+}
+
+
+
+function get_paypal_price_CIPF($user_id = null) {
+ Plgntls::debug_infos();
+
+ if (is_null($user_id)) {
+ $user_id = get_current_user_id();
+ }
+
+ if (is_paypal_force_1_cent_CIPF($user_id)) {
+ $price = "0.01";
+ }
+ else {
+ $price = get_card_price_CIPF($user_id);
+ }
+ return $price;
+}
diff --git a/plugins/cipf_plugin/php/_utils_acf_fields.php b/plugins/cipf_plugin/php/_utils_acf_fields.php
index beb858b..0dda8ff 100644
--- a/plugins/cipf_plugin/php/_utils_acf_fields.php
+++ b/plugins/cipf_plugin/php/_utils_acf_fields.php
@@ -44,6 +44,8 @@ if (!defined('ABSPATH')) {
*
* [/] order id ('order_id')
*
+* [/] card price ('somme_a_regler')
+*
*
*/
@@ -52,6 +54,7 @@ if (!defined('ABSPATH')) {
function get_field_init_CIPF($acf_field_name, $acf_id) {
Plgntls::debug_infos();
$acf_state = get_field($acf_field_name, $acf_id);
+
if ($acf_state !== null) {
return $acf_state;
}
@@ -63,16 +66,20 @@ function get_field_init_CIPF($acf_field_name, $acf_id) {
* - if no default value, update with first value
*
*/
- update_field($acf_field_name, 'temp', $acf_id);
+ update_field($acf_field_name, '', $acf_id);
$acf_object = get_field_object($acf_field_name, $acf_id);
- $default = $acf_object['default_value'];
- if (empty($default)) {
- $choices = $acf_object['choices'];
- if (!is_array($choices)) {
- return false;
- }
- $default = reset($choices);
+
+ $default = '';
+ if (isset($acf_object['default_value'])) {
+ $default = $acf_object['default_value'];
}
+ else if (isset($acf_object['choices'])) {
+ $choices = $acf_object['choices'];
+ if (!empty($choices)) {
+ $default = reset($choices);
+ }
+ }
+
update_field($acf_field_name, $default, $acf_id);
$acf_state = get_field($acf_field_name, $acf_id);
@@ -543,18 +550,18 @@ function reset_acf_cgv_CIPF($user_id = null) {
/*
-* date_suppression_compte
+* card price
*
*/
-function isset_acf_prof_account_delete_CIPF($user_id = null) {
+function get_card_price_CIPF($user_id = null) {
Plgntls::debug_infos();
- $acf_prof_delete = Cipf::ACF_PROF_DELETE_ACCOUNT;
+ $acf_card_price_total = Cipf::ACF_CARD_PRICE_TOTAL;
if (is_null($user_id)) {
$user_id = get_current_user_id();
}
$acf_id = 'user_'.$user_id;
- return isset_acf_field_CIPF($acf_prof_delete, $acf_id);
+ return get_acf_field_CIPF($acf_card_price_total, $acf_id);
}
diff --git a/plugins/cipf_plugin/php/admin_menu.php b/plugins/cipf_plugin/php/admin_menu.php
index 8208374..50b8da2 100644
--- a/plugins/cipf_plugin/php/admin_menu.php
+++ b/plugins/cipf_plugin/php/admin_menu.php
@@ -35,7 +35,9 @@ function add_plugin_content_CIPF() {
* options
*
*/
+ //delete_option($option_paypal_object['_name']);
$option_paypal = Plgntls::get_option_safe($option_paypal_object, true);
+ //delete_option($option_payment_object['_name']);
$option_payment = Plgntls::get_option_safe($option_payment_object, true);
//delete_option($option_emails_object['_name']);
$option_emails = Plgntls::get_option_safe($option_emails_object, true);
@@ -96,50 +98,46 @@ function update_payment_messages_option_CIPF($request, $option_name, $option_dat
function update_paypal_credentials_CIPF($request, $option_name, $option_data, $option_default) {
Plgntls::debug_infos();
+ if (!isset(
+ $request['sandbox_or_live'],
+ $request['live_client_id'],
+ $request['live_client_secret'],
+ $request['sandbox_client_id'],
+ $request['sandbox_client_secret'],
+ )) {
+ return;
+ }
+
+ /*
+ * force price 1 cent ?
+ *
+ */
+ $force_1_cent = false;
+ if (isset($request['force_1_cent'])) {
+ $force_1_cent = true;
+ }
/*
* is sandbox or live ?
*
*/
$is_sandbox = false;
- if (!isset($request['sandbox_or_live'])) {
- return;
- }
if ($request['sandbox_or_live'] === 'sandbox') {
$is_sandbox = true;
}
else if ($request['sandbox_or_live'] === 'live') {
$is_sandbox = false;
}
- else {
- return;
- }
/*
- * client id
+ * ids
*
*/
- $client_id = '';
- if (!isset($request['client_id'])) {
- return;
- }
- else {
- $client_id = $request['client_id'];
- }
-
-
- /*
- * client secret
- *
- */
- $client_secret = '';
- if (!isset($request['client_secret'])) {
- return;
- }
- else {
- $client_secret = $request['client_secret'];
- }
+ $live_client_id = $request['live_client_id'];
+ $live_client_secret = $request['live_client_secret'];
+ $sandbox_client_id = $request['sandbox_client_id'];
+ $sandbox_client_secret = $request['sandbox_client_secret'];
/*
@@ -148,9 +146,12 @@ function update_paypal_credentials_CIPF($request, $option_name, $option_data, $o
set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret);
*/
$data = array(
+ 'force_1_cent' => $force_1_cent,
'is_sandbox' => $is_sandbox,
- 'client_id' => $client_id,
- 'client_secret' => $client_secret,
+ 'live_client_id' => $live_client_id,
+ 'live_client_secret' => $live_client_secret,
+ 'sandbox_client_id' => $sandbox_client_id,
+ 'sandbox_client_secret' => $sandbox_client_secret,
);
Plgntls::update_option_safe($option_name, $data);
}
diff --git a/plugins/cipf_plugin/php/paypal/route_api_orders.php b/plugins/cipf_plugin/php/paypal/route_api_orders.php
index a41740b..5fb9504 100644
--- a/plugins/cipf_plugin/php/paypal/route_api_orders.php
+++ b/plugins/cipf_plugin/php/paypal/route_api_orders.php
@@ -92,14 +92,9 @@ function handle_orders_request_CIPF($request_data) {
function create_order_CIPF() {
Plgntls::debug_infos();
$paypal_api_base_url = get_paypal_api_base_url_CIPF();
- $acf_card_price_total = Cipf::ACF_CARD_PRICE_TOTAL;
$access_token = generate_access_token_CIPF();
-
- $user_id = get_current_user_id();
- $acf_id = 'user_' . $user_id;
- $price = get_field($acf_card_price_total['_name'], $acf_id);
-// $price = 0.01;
+ $price = get_paypal_price_CIPF();
$url = $paypal_api_base_url . '/v2/checkout/orders';
$payload = array(