Skip to content

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.

View source

Public Properties ​

PropertyDescription
allCustomerEnabledGatewayscraft\commerce\base\GatewayInterface[] – all gateways enabled for the customer
allGatewayTypesstring[] – all registered gateway types
allGatewayscraft\commerce\base\GatewayInterface[] – all gateways
allSubscriptionGatewaysarray
behaviorsyii\base\Behavior – List of behaviors attached to this component.

allCustomerEnabledGateways ​

Type
craft\commerce\base\GatewayInterface[]
Default value
null

all gateways enabled for the customer

View source

allGatewayTypes ​

Type
string[]
Default value
null

all registered gateway types

View source

allGateways ​

Type
craft\commerce\base\GatewayInterface[]
Default value
null

all gateways

View source

allSubscriptionGateways ​

Type
array
Default value
null

View source

Public Methods ​

MethodDescription
__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.

View source

Arguments ​

Returns ​

boolean – Whether the archiving was successful or not

Throws ​

createGateway() ​

Creates a gateway with a given config

View source

Arguments ​

  • $config (string, array) – The gateway’s class name, or its config, with a type value and optionally a settings value

Returns ​

craft\commerce\base\Gateway – The gateway

Throws ​

getAllCustomerEnabledGateways() ​

Returns all customer enabled gateways.

View source

Returns ​

\Illuminate\Support\Collection – All gateways that are enabled for frontend

Throws ​

getAllGatewayTypes() ​

Returns all registered gateway types.

View source

Returns ​

string[]

getAllGateways() ​

Returns all gateways

View source

Returns ​

\Illuminate\Support\Collection – All gateways

Throws ​

getAllSubscriptionGateways() ​

Returns all subscription gateways.

View source

Returns ​

\Illuminate\Support\Collection<\craft\commerce\base\GatewayInterface> – All Subscription gateways

Throws ​

getGatewayByHandle() ​

Returns a gateway by its handle.

View source

Arguments ​

Returns ​

craft\commerce\base\Gateway, null – The gateway or null if not found.

Throws ​

getGatewayById() ​

Returns a gateway by its ID.

View source

Arguments ​

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. // TODO Only remove once Craft 4 has lightswitch and dropdown overrides in core

Returns any custom gateway settings form config file.

View source

Arguments ​

  • $handle (string) – The gateway handle

Throws ​

handleArchivedGateway() ​

Handle gateway being archived

View source

Arguments ​

  • $event

Throws ​

handleChangedGateway() ​

Handle gateway change

View source

Arguments ​

  • $event

Throws ​

reorderGateways() ​

Reorders gateways by ids.

View source

Arguments ​

  • $ids (array) – Array of gateways.

Returns ​

boolean – Always true.

Throws ​

saveGateway() ​

Saves a gateway.

View source

Arguments ​

Returns ​

boolean – Whether the gateway was saved successfully or not.

Throws ​

Constants ​

ConstantDescription
CONFIG_GATEWAY_KEY

Events ​

EVENT_REGISTER_GATEWAY_TYPES ​

Type
craft\events\RegisterComponentTypesEvent

The event that is triggered for the registration of additional gateways.

This example registers a custom gateway instance of the MyGateway class:

php
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;
    }
);