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

Property Description
allCustomerEnabledGateways craft\commerce\base\GatewayInterface[] – All gateways that are enabled for frontend
allGatewayTypes string[]
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[]
Access
Read-only

All gateways that are enabled for frontend

View source

# allGatewayTypes

Type
string[]
Access
Read-only

View source

# allGateways

Type
craft\commerce\base\GatewayInterface[]
Access
Read-only

All gateways

View source

# allSubscriptionGateways

Type
array
Access
Read-only

View source

# 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.

View source

Arguments

Returns

boolean – Whether the archiving was successful or not

# createGateway()

Creates a gateway with a given config

View source

Arguments

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

Returns

craft\commerce\base\GatewayInterface – The gateway

# getAllCustomerEnabledGateways()

Returns all customer enabled gateways.

View source

Returns

craft\commerce\base\GatewayInterface[] – All gateways that are enabled for frontend

# getAllGatewayTypes()

Returns all registered gateway types.

View source

Returns

string[]

# getAllGateways()

Returns all gateways

View source

Returns

craft\commerce\base\GatewayInterface[] – All gateways

# getAllSubscriptionGateways()

Returns all subscription gateways.

View source

Returns

array

# getGatewayByHandle()

Returns a gateway by its handle.

View source

Arguments

Returns

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

# getGatewayById()

Returns a gateway by its ID.

View source

Arguments

Returns

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

# getGatewayOverrides()

Returns any custom gateway settings form config file.

View source

Arguments

  • $handle (string) – The gateway handle

Returns

array, null

# handleArchivedGateway()

Handle gateway being archived

View source

Arguments

Returns

void

Throws

# handleChangedGateway()

Handle gateway change

View source

Arguments

Returns

void

Throws

# reorderGateways()

Reorders gateways by ids.

View source

Arguments

  • $ids (array) – Array of gateways.

Returns

boolean – Always true.

# saveGateway()

Saves a gateway.

View source

Arguments

Returns

boolean – Whether the gateway was saved successfully or not.

Throws

# Constants

Constant Description
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:

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