Gateways ​
- Type
- Class
- Namespace
- craft\commerce\services
- Inherits
- craft\commerce\services\Gateways » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 2.0
Gateway service.
Public Properties ​
Property | Description |
---|---|
allCustomerEnabledGateways | craft\commerce\base\GatewayInterface[] – all gateways enabled for the customer |
allGatewayTypes | string[] – all registered gateway types |
allGateways | craft\commerce\base\GatewayInterface[] – all gateways |
allSubscriptionGateways | array |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
allCustomerEnabledGateways
​
- Type
- craft\commerce\base\GatewayInterface[]
- Default value
null
all gateways enabled for the customer
allGatewayTypes
​
- Type
- string[]
- Default value
null
all registered gateway types
allGateways
​
- Type
- craft\commerce\base\GatewayInterface[]
- Default value
null
all gateways
allSubscriptionGateways
​
- Type
- array
- Default value
null
Public Methods ​
Method | Description |
---|---|
__call() | Calls the named method which is not a class method. |
__clone() | This method is called after the object is created by cloning an existing one. |
__construct() | Constructor. |
__get() | Returns the value of a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be null. |
archiveGatewayById() | Archives a gateway by its ID. |
attachBehavior() | Attaches a behavior to this component. |
attachBehaviors() | Attaches a list of behaviors to the component. |
behaviors() | Returns a list of behaviors that this component should behave as. |
canGetProperty() | Returns a value indicating whether a property can be read. |
canSetProperty() | Returns a value indicating whether a property can be set. |
className() | Returns the fully qualified name of this class. |
createGateway() | Creates a gateway with a given config |
detachBehavior() | Detaches a behavior from the component. |
detachBehaviors() | Detaches all behaviors from the component. |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
getAllCustomerEnabledGateways() | Returns all customer enabled gateways. |
getAllGatewayTypes() | Returns all registered gateway types. |
getAllGateways() | Returns all gateways |
getAllSubscriptionGateways() | Returns all subscription gateways. |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getGatewayByHandle() | Returns a gateway by its handle. |
getGatewayById() | Returns a gateway by its ID. |
getGatewayOverrides() | Returns any custom gateway settings form config file. |
handleArchivedGateway() | Handle gateway being archived |
handleChangedGateway() | Handle gateway change |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() | Returns a value indicating whether a method is defined. |
hasProperty() | Returns a value indicating whether a property is defined for this component. |
init() | Initializes the object. |
off() | Detaches an existing event handler from this component. |
on() | Attaches an event handler to an event. |
reorderGateways() | Reorders gateways by ids. |
saveGateway() | Saves a gateway. |
trigger() | Triggers an event. |
archiveGatewayById()
​
Archives a gateway by its ID.
Arguments ​
$id
(integer) – Gateway ID
Returns ​
boolean – Whether the archiving was successful or not
Throws ​
- yii\base\ErrorException
- yii\base\Exception
- yii\base\InvalidConfigException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
- yii\db\Exception
createGateway()
​
Creates a gateway with a given config
Arguments ​
$config
(string, array) – The gateway’s class name, or its config, with atype
value and optionally asettings
value
Returns ​
craft\commerce\base\Gateway – The gateway
Throws ​
getAllCustomerEnabledGateways()
​
Returns all customer enabled gateways.
Returns ​
\Illuminate\Support\Collection
– All gateways that are enabled for frontend
Throws ​
getAllGatewayTypes()
​
Returns all registered gateway types.
Returns ​
string[]
getAllGateways()
​
Returns all gateways
Returns ​
\Illuminate\Support\Collection
– All gateways
Throws ​
getAllSubscriptionGateways()
​
Returns all subscription gateways.
Returns ​
\Illuminate\Support\Collection<\craft\commerce\base\GatewayInterface>
– All Subscription gateways
Throws ​
getGatewayByHandle()
​
Returns a gateway by its handle.
Arguments ​
$handle
(string)
Returns ​
craft\commerce\base\Gateway, null – The gateway or null if not found.
Throws ​
getGatewayById()
​
Returns a gateway by its ID.
Arguments ​
$id
(integer)
Returns ​
craft\commerce\base\Gateway, null – The gateway or null if not found.
Throws ​
getGatewayOverrides()
​
DEPRECATED
Deprecated in 3.3. Overriding gateway settings using the commerce-gateways.php
file has been deprecated. Use the gateway’s config file instead.
Returns any custom gateway settings form config file.
Arguments ​
$handle
(string) – The gateway handle
Throws ​
handleArchivedGateway()
​
Handle gateway being archived
Arguments ​
$event
Throws ​
- Throwable
if reasons
handleChangedGateway()
​
Handle gateway change
Arguments ​
$event
Throws ​
- Throwable
if reasons
reorderGateways()
​
Reorders gateways by ids.
Arguments ​
$ids
(array) – Array of gateways.
Returns ​
boolean – Always true.
Throws ​
- yii\base\ErrorException
- yii\base\Exception
- yii\base\InvalidConfigException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
saveGateway()
​
Saves a gateway.
Arguments ​
$gateway
(craft\commerce\base\Gateway) – The gateway to be saved.$runValidation
(boolean) – Whether the gateway should be validated
Returns ​
boolean – Whether the gateway was saved successfully or not.
Throws ​
- yii\base\Exception
- yii\base\InvalidConfigException
- yii\base\ErrorException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
Constants ​
Constant | Description |
---|---|
CONFIG_GATEWAY_KEY |
Events ​
EVENT_REGISTER_GATEWAY_TYPES ​
The event that is triggered for the registration of additional gateways.
This example registers a custom gateway instance of the MyGateway
class:
use craft\events\RegisterComponentTypesEvent;
use craft\commerce\services\Purchasables;
use yii\base\Event;
Event::on(
Gateways::class,
Gateways::EVENT_REGISTER_GATEWAY_TYPES,
function(RegisterComponentTypesEvent $event) {
$event->types[] = MyGateway::class;
}
);