function paymill_check_webhook() { load_paymill(); // this function-call can and should be used whenever working with Paymill API try { if (get_option('paymill_webhook_id') == false) { return '<div>' . __('No Webhook created yet.', 'paymill') . ' ' . __('Please insert API Keys in <strong>General Settings</strong> and submit the form.', 'paymill') . '</div>'; } else { $webhooks = $GLOBALS['paymill_loader']->request->getAll($GLOBALS['paymill_loader']->request_webhook); $webhook_found = false; $nothing_found = true; $additional_webhooks = array(); $output = false; $output .= '<div><h3>' . __('Webhook Status Check', 'paymill') . '</h3><h4>' . __('Please note that Webhooks are currently used in WooCommerce integration only.', 'paymill') . '</h4>'; if (count($webhooks) > 0) { foreach ($webhooks as $webhook) { if (get_option('paymill_webhook_id') == $webhook['id']) { $webhook_found .= ' <div> <div><strong>' . __('Saved Webhook found:', 'paymill') . '</strong></div> <div><strong>' . __('ID:', 'paymill') . ' </strong> ' . $webhook['id'] . '</div> <div><strong>' . __('Livemode:', 'paymill') . ' </strong> ' . ($webhook['livemode'] ? __('yes', 'paymill') : __('no', 'paymill')) . '</div> <div><strong>' . __('Active:', 'paymill') . ' </strong> ' . ($webhook['active'] ? 'yes' : 'no - <strong>please activate this webhook!</strong>') . '</div> <div><strong>' . __('Event Types:', 'paymill') . ' </strong> ' . implode(', ', $webhook['event_types']) . '</div> <div><strong>' . __('URL:', 'paymill') . ' </strong> ' . $webhook['url'] . '</div> '; if ($webhook['url'] != get_site_url() . '/?wc-api=WC_Gateway_Paymill_Gateway') { $webhook_found .= '<div><strong>' . __('Webhook URL is not correct!', 'paymill') . '</strong> ' . __('Please update the Webhook URL via saving Paymill API Keys again. The correct Webhook URL would be', 'paymill') . ' <em>' . get_site_url() . '/?wc-api=WC_Gateway_Paymill_Gateway</em></div>'; } elseif ($webhook['active']) { $webhook_found .= '<div><strong>' . __('Status:') . ' </strong>' . __('It seems everything is correct.', 'paymill') . '</div>'; } $webhook_found .= '</div>'; $nothing_found = false; } else { $additional_webhooks[] = $webhook['id']; } } } // add webhook status if (!$webhook_found && $nothing_found) { $output .= '<h3>' . __('No Webhook registered.') . '</h3><div>' . __('Please insert API Keys in <strong>General Settings</strong> and submit the form.') . '</div>'; } elseif ($webhook_found) { $output .= $webhook_found; } if (count($additional_webhooks) > 0) { $output .= '<h3>' . __('Orphaned Webhooks found:') . '</h3><div>' . implode('<br />', $additional_webhooks) . '</div>'; $output .= '<p>' . __('These orphaned Webhooks should be deleted. Normally this will be done automaticly when saving new API keys via General Settings, but you can delete them via Paymill Dashboard, too.') . '</p>'; } $output .= '</div>'; return $output; } } catch (Exception $e) { return paymill_install_webhooks(); //return __($e->getMessage(),'paymill'); } }
public function paymill_register_general_settings() { if (paymill_BENCHMARK) { paymill_doBenchmark(true, 'paymill_register_general_settings'); } // benchmark // create or update webhooks when API key changes if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && isset($GLOBALS['paymill_settings']->paymill_general_settings['api_key_private']) && strlen($GLOBALS['paymill_settings']->paymill_general_settings['api_key_private']) > 0) { paymill_install_webhooks(); } $this->plugin_settings_tabs[$this->setting_keys['paymill_general_settings']] = 'General'; register_setting($this->setting_keys['paymill_general_settings'], $this->setting_keys['paymill_general_settings']); add_settings_section('section_general', __('General Plugin Settings', 'paymill'), array(&$this, 'section_general_desc'), $this->setting_keys['paymill_general_settings']); $settings = array('api_key_private' => __('Paymill PRIVATE API key', 'paymill'), 'api_key_public' => __('Paymill PUBLIC API key', 'paymill'), 'payments_display' => __('Display Payment Types', 'paymill'), 'no_default_css' => __('Do not load default CSS', 'paymill'), 'pci_dss_3' => __('Deactivate PCI DSS 3.0 Compatibility', 'paymill')); foreach ($settings as $setting => $description) { add_settings_field($setting, $description, array(&$this, 'print_config_form_fields'), $this->setting_keys['paymill_general_settings'], 'section_general', array('desc' => $setting, 'page' => $this->setting_keys['paymill_general_settings'])); } if (paymill_BENCHMARK) { paymill_doBenchmark(false, 'paymill_register_general_settings'); } // benchmark }