fields = $this->payu_fields();
add_action('admin_menu', [$this, 'payu_settings_add_plugin_page']);
add_action('admin_init', [$this, 'payu_settings_page_init']);
}
/**
* @return array
*/
public static function payu_fields()
{
return [
'pos_id' => [
'label' => __('Id point of sales', 'woo-payu-payment-gateway'),
'description' => __('Pos identifier from "Configuration Keys" section of PayU management panel.',
'woo-payu-payment-gateway')
],
'md5' => [
'label' => __('Second key (MD5)', 'woo-payu-payment-gateway'),
'description' => __('Second key from "Configuration Keys" section of PayU management panel.', 'woo-payu-payment-gateway')
],
'client_id' => [
'label' => __('OAuth - client_id', 'woo-payu-payment-gateway'),
'description' => __('Client Id for OAuth identifier from "Configuration Keys" section of PayU management panel.',
'woo-payu-payment-gateway')
],
'client_secret' => [
'label' => __('OAuth - client_secret', 'woo-payu-payment-gateway'),
'description' => __('First key from "Configuration Keys" section of PayU management panel.', 'woo-payu-payment-gateway'),
],
'sandbox_pos_id' => [
'label' => __('Sandbox - Id point of sales', 'woo-payu-payment-gateway'),
'description' => __('Pos identifier from "Configuration Keys" section of PayU management panel.',
'woo-payu-payment-gateway'),
],
'sandbox_md5' => [
'label' => __('Sandbox - Second key (MD5):', 'woo-payu-payment-gateway'),
'description' => __('Second key from "Configuration Keys" section of PayU management panel.', 'woo-payu-payment-gateway'),
],
'sandbox_client_id' => [
'label' => __('Sandbox - OAuth - client_id:', 'woo-payu-payment-gateway'),
'description' => __('Client Id for OAuth identifier from "Configuration Keys" section of PayU management panel.',
'woo-payu-payment-gateway'),
],
'sandbox_client_secret' => [
'label' => __('Sandbox - OAuth - client_secret:', 'woo-payu-payment-gateway'),
'description' => __('First key from "Configuration Keys" section of PayU management panel.', 'woo-payu-payment-gateway'),
],
];
}
/**
* @return null
*/
public function payu_settings_add_plugin_page()
{
add_submenu_page(
'woocommerce',
__('PayU settings', 'woo-payu-payment-gateway'), // page_title
__('PayU settings', 'woo-payu-payment-gateway'), // menu_title
'manage_options', // capability
'payu-settings', // menu_slug
[$this, 'payu_settings_create_admin_page'], // function
100
);
}
/**
* @return void
*/
public function payu_settings_create_admin_page()
{
$this->payu_settings_options = get_option('payu_settings_option_name'); ?>
fields as $field => $desc) {
$args = [
'id' => 'global_' . $field . $idSuffix,
'desc' => $namePrefix . $desc['label'],
'name' => 'payu_settings_option_name'
];
add_settings_field(
$args['id'], // id
$args['desc'], // title
[$this, 'global_callback'], // callback
'payu-settings-admin', // page
'payu_settings_setting_section',
$args
);
}
}
add_settings_field(
'global_default_on_hold_status', // id
__('Default on-hold status', 'woo-payu-payment-gateway'), // title
[$this, 'global_default_on_hold_status_callback'], // callback
'payu-settings-admin', // page
'payu_settings_setting_section' // section
);
add_settings_field(
'global_repayment', // id
__('Enable repayment', 'woo-payu-payment-gateway'), // title
[$this, 'global_repayment_callback'], // callback
'payu-settings-admin', // page
'payu_settings_setting_section' // section
);
}
/**
* @param array $args
* @return void
*/
public function global_callback($args)
{
$id = $args['id'];
$value = isset($this->payu_settings_options[$id]) ? esc_attr($this->payu_settings_options[$id]) : '';
printf('',
$value, $id, $id);
}
/**
* @param array $input
* @return array
*/
public function payu_settings_sanitize($input)
{
$sanitary_values = [];
$currencies = woocommerce_payu_get_currencies();
if (count($currencies) < 2) {
$currencies = [''];
}
foreach ($currencies as $code) {
$idSuffix = ($code ? '_' : '') . $code;
foreach ($this->fields as $field => $desc) {
$field = $field . $idSuffix;
if (isset($input['global_' . $field])) {
$sanitary_values['global_' . $field] = sanitize_text_field($input['global_' . $field]);
}
}
}
if (isset($input['global_default_on_hold_status'])) {
$sanitary_values['global_default_on_hold_status'] = sanitize_text_field($input['global_default_on_hold_status']);
}
if (isset($input['global_repayment'])) {
$sanitary_values['global_repayment'] = sanitize_text_field($input['global_repayment']);
}
return $sanitary_values;
}
/**
* @return null
*/
public function global_repayment_callback()
{
printf(
'',
(isset($this->payu_settings_options['global_repayment']) && $this->payu_settings_options['global_repayment'] === 'global_repayment') ? 'checked' : ''
);
?>
the documentation and disable automatic collection in POS configuration.', 'woo-payu-payment-gateway'), ['a' => ['target' => [], 'href' => []], 'strong' => []]); ?>
$value) {
if (in_array($key, ['wc-pending', 'wc-on-hold'])) {
$available[str_replace('wc-', '', $key)] = $value;
}
}
ksort($available);
return $available;
}
}
if (is_admin()) {
$payu_settings = new PayUSettings();
}