From 5d7fdbde8a611a0c563a2f70caadf42f20415c88 Mon Sep 17 00:00:00 2001 From: August Miller Date: Tue, 12 Sep 2023 11:13:13 -0700 Subject: [PATCH 1/4] Add gateways console controller --- .../controllers/GatewaysController.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/console/controllers/GatewaysController.php diff --git a/src/console/controllers/GatewaysController.php b/src/console/controllers/GatewaysController.php new file mode 100644 index 0000000000..432460e6df --- /dev/null +++ b/src/console/controllers/GatewaysController.php @@ -0,0 +1,83 @@ + + * @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(); + + return 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; + } +} From 63e2881c6e0a5d144c5f2c53e8708c57f7f92425 Mon Sep 17 00:00:00 2001 From: August Miller Date: Tue, 12 Sep 2023 11:21:00 -0700 Subject: [PATCH 2/4] Comment whitespace --- src/console/controllers/GatewaysController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/console/controllers/GatewaysController.php b/src/console/controllers/GatewaysController.php index 432460e6df..2e366534a6 100644 --- a/src/console/controllers/GatewaysController.php +++ b/src/console/controllers/GatewaysController.php @@ -62,7 +62,7 @@ public function actionList() /** * Gets a Webhook URL for the provided gateway - * + * * @param string $handle */ public function actionWebhookUrl(string $handle) From 9247d05bd7bec5ecbe64c5d49af2417a2abebb4d Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 19 Sep 2023 20:34:49 +0800 Subject: [PATCH 3/4] fix-cs --- src/console/controllers/GatewaysController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/console/controllers/GatewaysController.php b/src/console/controllers/GatewaysController.php index 2e366534a6..c8b255249f 100644 --- a/src/console/controllers/GatewaysController.php +++ b/src/console/controllers/GatewaysController.php @@ -7,9 +7,9 @@ namespace craft\commerce\console\controllers; +use craft\commerce\Plugin as Commerce; use craft\console\Controller; use craft\helpers\Console; -use craft\commerce\Plugin as Commerce; use yii\console\ExitCode; /** From 5c4ae45d93e3b4766f1bf21c4b8c0bd6659c18ad Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 19 Sep 2023 20:37:48 +0800 Subject: [PATCH 4/4] phpstan fixes --- src/console/controllers/GatewaysController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/console/controllers/GatewaysController.php b/src/console/controllers/GatewaysController.php index c8b255249f..69b75b32ce 100644 --- a/src/console/controllers/GatewaysController.php +++ b/src/console/controllers/GatewaysController.php @@ -38,7 +38,7 @@ public function actionList() $gateways = Commerce::getInstance()->getGateways()->getAllGateways(); $rows = collect($gateways) ->map(function($gateway) { - /** @var craft\commerce\base\Gateway $gateway */ + /** @var \craft\commerce\base\Gateway $gateway */ return [ $gateway->id, $gateway->name, @@ -50,7 +50,7 @@ public function actionList() }) ->all(); - return Console::table([ + Console::table([ 'ID', 'Name', 'Handle',