Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gateways console controller #3275

Merged
merged 5 commits into from
Sep 19, 2023
Merged
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
83 changes: 83 additions & 0 deletions src/console/controllers/GatewaysController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\commerce\console\controllers;

use craft\commerce\Plugin as Commerce;
use craft\console\Controller;
use craft\helpers\Console;
use yii\console\ExitCode;

/**
* Gateways controller.
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 4.3
*/
class GatewaysController extends Controller
{
public $defaultAction = 'index';

/**
* Default action. See `commerce/gateways/list`.
*/
public function actionIndex()
{
return $this->runAction('list');
}

/**
* Lists the currently-configured, non-archived gateways.
*/
public function actionList()
{
$gateways = Commerce::getInstance()->getGateways()->getAllGateways();
$rows = collect($gateways)
->map(function($gateway) {
/** @var \craft\commerce\base\Gateway $gateway */
return [
$gateway->id,
$gateway->name,
$gateway->handle,
$gateway->getIsFrontendEnabled() ? 'Yes' : 'No',
$gateway::class,
$gateway->uid,
];
})
->all();

Console::table([
'ID',
'Name',
'Handle',
'Enabled',
'Type',
'UUID',
], $rows);
}

/**
* Gets a Webhook URL for the provided gateway
*
* @param string $handle
*/
public function actionWebhookUrl(string $handle)
{
$gateway = Commerce::getInstance()->getGateways()->getGatewayByHandle($handle);

if (!$gateway) {
$this->stderr("A gateway with handle `$handle` does not exist." . PHP_EOL, Console::FG_YELLOW);

return ExitCode::UNSPECIFIED_ERROR;
}

$this->stdout("Webhook URL for the {$gateway->name} gateway:" . PHP_EOL);
$this->stdout($gateway->getWebhookUrl() . PHP_EOL, Console::FG_BLUE);

return ExitCode::OK;
}
}
Loading