Skip to content

Commit

Permalink
Add payment gateway order condition rule
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Oct 25, 2024
1 parent 272475a commit 1ad4c42
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release Notes for Craft Commerce (WIP)

## Administration

- Added a new "Payment Gateway" order condition rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722))
1 change: 1 addition & 0 deletions src/elements/conditions/orders/OrderCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function selectableConditionRules(): array
ItemTotalConditionRule::class,
OrderStatusConditionRule::class,
OrderSiteConditionRule::class,
PaymentGatewayConditionRule::class,
ReferenceConditionRule::class,
ShippingMethodConditionRule::class,
TotalDiscountConditionRule::class,
Expand Down
66 changes: 66 additions & 0 deletions src/elements/conditions/orders/PaymentGatewayConditionRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace craft\commerce\elements\conditions\orders;

use Craft;
use craft\base\conditions\BaseMultiSelectConditionRule;
use craft\base\conditions\BaseSelectConditionRule;
use craft\base\ElementInterface;
use craft\commerce\elements\db\OrderQuery;
use craft\commerce\elements\Order;
use craft\commerce\Plugin;
use craft\elements\conditions\ElementConditionRuleInterface;
use yii\db\QueryInterface;

/**
* Payment Gateway condition rule.
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 5.3.0
*/
class PaymentGatewayConditionRule extends BaseSelectConditionRule implements ElementConditionRuleInterface
{
/**
* @inheritdoc
*/
public function getLabel(): string
{
return Craft::t('commerce', 'Payment Gateway');
}

/**
* @inheritdoc
*/
public function getExclusiveQueryParams(): array
{
return ['gatewayId'];
}

/**
* @inheritdoc
*/
protected function options(): array
{
return Plugin::getInstance()->getGateways()->getAllGateways()->mapWithKeys(function($gateway) {
return [$gateway->id => $gateway->name];
})->all();
}

/**
* @inheritdoc
*/
public function modifyQuery(QueryInterface $query): void
{
/** @var OrderQuery $query */
$query->gatewayId($this->value);
}

/**
* @inheritdoc
*/
public function matchElement(ElementInterface $element): bool
{
/** @var Order $element */
return $this->matchValue($element->gatewayId);

Check failure on line 64 in src/elements/conditions/orders/PaymentGatewayConditionRule.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Parameter #1 $value of method craft\base\conditions\BaseSelectConditionRule::matchValue() expects string, int|null given.
}
}
1 change: 1 addition & 0 deletions src/translations/en/commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@
'Payment Amount' => 'Payment Amount',
'Payment Currencies' => 'Payment Currencies',
'Payment Method' => 'Payment Method',
'Payment Gateway' => 'Payment Gateway',
'Payment error: {message}' => 'Payment error: {message}',
'Payment method issue' => 'Payment method issue',
'Payment source created.' => 'Payment source created.',
Expand Down

0 comments on commit 1ad4c42

Please sign in to comment.