From 7e5776e15f229a4ceec43bb381bdb3da28e74636 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:53:17 +0000 Subject: [PATCH] Batch58: Moyasar payments tools (guarded, net-new, secrets redacted) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch58.php | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 includes/Extensions/Batch58.php diff --git a/includes/Extensions/Batch58.php b/includes/Extensions/Batch58.php new file mode 100644 index 0000000..9fecc5e --- /dev/null +++ b/includes/Extensions/Batch58.php @@ -0,0 +1,63 @@ + '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]; + } +}