$success, 'failure' => $failure, 'problem' => $problem, ); Plgntls::update_option_safe($option_name, $data); } 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 ($request['sandbox_or_live'] === 'sandbox') { $is_sandbox = true; } else if ($request['sandbox_or_live'] === 'live') { $is_sandbox = false; } /* * ids * */ $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']; /* * update the option with new credentials * set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret); */ $data = array( 'force_1_cent' => $force_1_cent, 'is_sandbox' => $is_sandbox, '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); } /* * update emails * */ function update_emails_settings_option_CIPF($request, $option_name, $option_data, $option_default) { Plgntls::debug_infos(); /* * first check if saved option has the same data as default option * */ $new_option = update_option_with_default_CIPF($option_data, $option_default); /* * then update the option with the request * */ foreach ($new_option as $email_type => $email_options) { $new_option[$email_type] = update_email_type_with_request_CIPF($email_type, $email_options, $request); } Plgntls::update_option_safe($option_name, $new_option); } /* * utility * */ function update_option_with_default_CIPF($option_data, $option_default) { Plgntls::debug_infos(); $new_option_values = array(); foreach ($option_default as $email_type => $email_default_options) { if (!isset($option_data[$email_type])) { $new_option_values[$email_type] = $email_default_options; } else { $new_email_options = update_email_type_with_default_CIPF($option_data[$email_type], $email_default_options); $new_option_values[$email_type] = $new_email_options; } } return $new_option_values; } function update_email_type_with_default_CIPF($email_options, $email_default_options) { Plgntls::debug_infos(); $new_email_type = array(); foreach ($email_default_options as $default_key => $default_value) { if (!isset($email_options[$default_key])) { $new_email_type[$default_key] = $default_value; } else { $new_email_type[$default_key] = $email_options[$default_key]; } } return $new_email_type; } function update_email_type_with_request_CIPF($email_type, $email_options, $request) { Plgntls::debug_infos(); foreach ($email_options as $email_key => $email_value) { /* * special update for notification/confirmation_send * default them to false, since they will only be in request if they value 'on' * */ if (in_array($email_key, array('notification_send', 'confirmation_send'))) { $email_options[$email_key] = 'off'; } /* * search in request needs the prefix * */ $request_name = $email_type.'_'.$email_key; if (isset($request[$request_name])) { $email_options[$email_key] = $request[$request_name]; } } return $email_options; } ?>