Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions lib/cli/shopPayment.cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

class shopPaymentCli extends waCliController
{
/** @var shopPayment */
private $adapter;

public function preExecute()
{
parent::preExecute();
$this->adapter = shopPayment::getInstance();
}

public function execute()
{
$plugin_model = new shopPluginModel();
$options = array(
'all' => true,
);
$methods = $plugin_model->listPlugins(shopPluginModel::TYPE_PAYMENT, $options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shopHelper::getPaymentMethods() возвращает только активные плагины


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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waLog::dump($data, 'shop/payment.cli.log')

}
}
}
}