7e5776e15f
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
64 lines
3.0 KiB
PHP
64 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* Batch 58 — Moyasar for WooCommerce tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
|
|
* Inert unless Moyasar (MOYASAR_WC_VERSION) is active. Read-only; API keys are always redacted.
|
|
*/
|
|
|
|
namespace AskTamMCP\Extensions;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class Batch58 {
|
|
|
|
public static function register($registry): void {
|
|
if (!defined('MOYASAR_WC_VERSION')) return;
|
|
|
|
$def = function (string $name, string $desc, array $props, array $required, string $scope, string $method) {
|
|
$schema = ['type' => 'object', 'properties' => $props ?: new \stdClass()];
|
|
if ($required) $schema['required'] = $required;
|
|
return ['name' => $name, 'description' => $desc, 'scope' => $scope,
|
|
'handler' => 'AskTamMCP\\Extensions\\Batch58::' . $method, 'inputSchema' => $schema];
|
|
};
|
|
|
|
$registry->register($def('moyasar_detect', 'Report whether Moyasar for WooCommerce is active and its version.', [], [], 'read', 'detect'));
|
|
$registry->register($def('moyasar_list_gateways', 'List the Moyasar WooCommerce payment methods and whether each is enabled (CC, Apple Pay, STC Pay, etc.).', [], [], 'read', 'listGateways'));
|
|
$registry->register($def('moyasar_get_settings', 'Read Moyasar gateway settings (enabled, title, mode). API keys are redacted.', [], [], 'read', 'getSettings'));
|
|
}
|
|
|
|
public static function detect(array $args): array {
|
|
return ['active' => defined('MOYASAR_WC_VERSION'), 'version' => defined('MOYASAR_WC_VERSION') ? MOYASAR_WC_VERSION : null];
|
|
}
|
|
|
|
public static function listGateways(array $args): array {
|
|
if (!class_exists('WooCommerce') || !function_exists('WC')) {
|
|
return ['supported' => false, 'note' => 'WooCommerce not active.', 'gateways' => []];
|
|
}
|
|
$gws = WC()->payment_gateways() ? WC()->payment_gateways()->payment_gateways() : [];
|
|
$out = [];
|
|
foreach ((array) $gws as $id => $g) {
|
|
if (stripos((string) $id, 'moyasar') === false) continue;
|
|
$out[] = ['id' => $id, 'title' => $g->get_title(), 'enabled' => ($g->enabled === 'yes'), 'method_title' => $g->get_method_title()];
|
|
}
|
|
return ['supported' => true, 'count' => count($out), 'gateways' => $out];
|
|
}
|
|
|
|
private static function redact(array $settings): array {
|
|
$out = [];
|
|
foreach ($settings as $k => $v) {
|
|
if (preg_match('/key|secret|token|password/i', (string) $k)) { $out[$k] = $v ? '***redacted***' : ''; }
|
|
else $out[$k] = $v;
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
public static function getSettings(array $args): array {
|
|
$out = [];
|
|
foreach (['woocommerce_moyasar_settings', 'woocommerce_moyasar_cc_settings'] as $opt) {
|
|
$s = get_option($opt, null);
|
|
if (is_array($s)) $out[$opt] = self::redact($s);
|
|
}
|
|
if (!$out) return ['supported' => false, 'note' => 'No Moyasar gateway settings found.'];
|
|
return ['supported' => true, 'settings' => $out];
|
|
}
|
|
}
|