create_payment_plugin
Create a payment plugin for Webasyst to add new payment methods to your online store or website. Specify plugin ID, title, and Webasyst installation path.
Instructions
Создать плагин оплаты (wa-plugins/payment/)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| plugin_name | Yes | ID плагина (латиница) | |
| plugin_title | Yes | Название плагина | |
| webasyst_path | Yes | Путь к Webasyst |
Implementation Reference
- webasyst-mcp.js:822-920 (handler)Main handler function that creates the full structure of a Webasyst payment plugin including config, PHP class implementing waIPayment with payment() and callbackInit() methods, payment form template, directories, and security .htaccess files.async function createPaymentPluginTool({ plugin_name, plugin_title, webasyst_path }) { // Payment плагины располагаются в wa-plugins/payment/ const p = path.join(webasyst_path, 'wa-plugins', 'payment', plugin_name); for (const d of ['lib', 'lib/config', 'img', 'templates', 'locale']) await ensureDir(p, d); const pluginConfig = `<?php return array( 'name' => /*_wp*/('${plugin_title}'), 'description' => /*_wp*/('Плагин оплаты'), 'icon' => 'img/${plugin_name}16.png', 'logo' => 'img/${plugin_name}.png', 'version' => '1.0.0', 'vendor' => 'custom', 'type' => waPayment::TYPE_ONLINE, ); `; await fs.writeFile(path.join(p, 'lib', 'config', 'plugin.php'), pluginConfig); // Класс без префикса shop, имплементирует waIPayment const code = `<?php /** * ${plugin_title} payment plugin. */ class ${plugin_name}Payment extends waPayment implements waIPayment { /** * Возвращает список поддерживаемых валют. * @return array|string */ public function allowedCurrency() { return array('RUB', 'USD', 'EUR'); } /** * Инициирует платёж. * @param array \$payment_form_data * @param array \$order_data * @param bool \$auto_submit * @return string HTML форма для перенаправления на платёжный шлюз */ public function payment(\$payment_form_data, \$order_data, \$auto_submit = false) { \$order = waOrder::factory(\$order_data); \$form_fields = array( 'order_id' => \$order->id, 'amount' => number_format(\$order->total, 2, '.', ''), 'currency' => \$order->currency, ); \$view = wa()->getView(); \$view->assign(array( 'form_fields' => \$form_fields, 'form_url' => 'https://example.com/pay', 'auto_submit' => \$auto_submit, )); return \$view->fetch(\$this->path.'/templates/payment.html'); } /** * Обработка callback от платёжной системы. * @param array \$request * @return array */ protected function callbackInit(\$request) { if (!empty(\$request['order_id'])) { \$this->order_id = \$request['order_id']; } return parent::callbackInit(\$request); } } `; await fs.writeFile(path.join(p, 'lib', `${plugin_name}Payment.class.php`), code); // Создаём шаблон формы оплаты const paymentTemplate = `<form method="post" action="{\$form_url}" id="{\$order.id}-payment-form"> {foreach \$form_fields as \$name => \$value} <input type="hidden" name="{\$name}" value="{\$value|escape}"> {/foreach} <input type="submit" value="{\$_w('Pay')}"> </form> {if \$auto_submit} <script> document.getElementById('{\$order.id}-payment-form').submit(); </script> {/if} `; await fs.writeFile(path.join(p, 'templates', 'payment.html'), paymentTemplate); // Создаём .htaccess для защиты await fs.writeFile(path.join(p, 'lib', '.htaccess'), 'Deny from all\n'); await fs.writeFile(path.join(p, 'templates', '.htaccess'), 'Deny from all\n'); return { content: [{ type: 'text', text: `Payment plugin "${plugin_title}" создан в wa-plugins/payment/${plugin_name}` }] }; }
- webasyst-mcp.js:1726-1727 (registration)Tool registration in the ListTools handler, defining name, description, and input schema.{ name: 'create_payment_plugin', description: 'Создать плагин оплаты (wa-plugins/payment/)', inputSchema: { type: 'object', properties: { plugin_name: { type: 'string', description: 'ID плагина (латиница)' }, plugin_title: { type: 'string', description: 'Название плагина' }, webasyst_path: { type: 'string', description: 'Путь к Webasyst' } }, required: ['plugin_name', 'plugin_title', 'webasyst_path'] } }, { name: 'create_shop_report', description: 'Создать отчет Shop-Script', inputSchema: { type: 'object', properties: { report_key: { type: 'string' }, report_title: { type: 'string' }, webasyst_path: { type: 'string' } }, required: ['report_key', 'report_title', 'webasyst_path'] } },
- webasyst-mcp.js:1788-1788 (registration)Registration in the CallToolRequestHandler switch statement that maps the tool name to the handler function.case 'create_payment_plugin': return await createPaymentPluginTool(args);
- webasyst-mcp.js:1726-1727 (schema)Input schema definition for the create_payment_plugin tool, specifying required parameters.{ name: 'create_payment_plugin', description: 'Создать плагин оплаты (wa-plugins/payment/)', inputSchema: { type: 'object', properties: { plugin_name: { type: 'string', description: 'ID плагина (латиница)' }, plugin_title: { type: 'string', description: 'Название плагина' }, webasyst_path: { type: 'string', description: 'Путь к Webasyst' } }, required: ['plugin_name', 'plugin_title', 'webasyst_path'] } }, { name: 'create_shop_report', description: 'Создать отчет Shop-Script', inputSchema: { type: 'object', properties: { report_key: { type: 'string' }, report_title: { type: 'string' }, webasyst_path: { type: 'string' } }, required: ['report_key', 'report_title', 'webasyst_path'] } },