From 0eaba842a7029cf75754c128036ce36005e439d3 Mon Sep 17 00:00:00 2001 From: "creative-office.ru" Date: Sun, 24 Oct 2021 22:13:51 +0300 Subject: [PATCH] Create shopPayment.cli.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавить CLI для платежных плагинов --- lib/cli/shopPayment.cli.php | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/cli/shopPayment.cli.php diff --git a/lib/cli/shopPayment.cli.php b/lib/cli/shopPayment.cli.php new file mode 100644 index 000000000..673e1b50d --- /dev/null +++ b/lib/cli/shopPayment.cli.php @@ -0,0 +1,70 @@ +adapter = shopPayment::getInstance(); + } + + public function execute() + { + $plugin_model = new shopPluginModel(); + $options = array( + 'all' => true, + ); + $methods = $plugin_model->listPlugins(shopPluginModel::TYPE_PAYMENT, $options); + + if ($methods) { + /** + * @event payment_sync_cli + * @param array $params['methods'] + * @return void + */ + $params = [ + 'methods' => $methods + ]; + wa('shop')->event('payment_sync_cli', $params); + } + + $adapter = shopPayment::getInstance(); + foreach ($methods as $payment_id => $method) { + try { + $plugin = waPayment::factory($method['plugin'], $payment_id, $adapter); + + $this->runSync($plugin, $method); + + } catch (waException $ex) { + $message = $ex->getMessage(); + $data = compact('message', 'payment_id'); + waLog::log(var_export($data, true), 'shop/payment.cli.log'); + } + } + + $app_settings_model = new waAppSettingsModel(); + $app_settings_model->set('shop', 'payment_plugins_sync', time()); + } + + /** + * @param waPayment $plugin + * @param string[] $method + */ + protected function runSync($plugin, $method) + { + if (!empty($method['status']) && method_exists($plugin, 'runSync')) { + try { + $plugin->runSync(); + } catch (waException $ex) { + $data = [ + 'message' => $ex->getMessage(), + 'payment' => $method + ]; + waLog::log(var_export($data, true), 'shop/payment.cli.log'); + } + } + } +}