Gateways

Type
Class
Namespace
craft\commerce\services
Inherits
craft\commerce\services\Gateways » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
2.0

Gateway service.

View source (opens new window)

# Public Properties

Property Description
allCustomerEnabledGateways craft\commerce\base\GatewayInterface[] – all gateways enabled for the customer
allGatewayTypes string (opens new window)[] – all registered gateway types
allGateways craft\commerce\base\GatewayInterface[] – all gateways
allSubscriptionGateways array (opens new window)
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component.

# allCustomerEnabledGateways

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

all gateways enabled for the customer

View source (opens new window)

# allGatewayTypes

Type
string (opens new window)[]
Default value
null

all registered gateway types

View source (opens new window)

# allGateways

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

all gateways

View source (opens new window)

# allSubscriptionGateways

Type
array (opens new window)
Default value
null

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() (opens new window) Constructor.
__get() (opens new window) Returns the value of a component property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets the value of a component property.
__unset() (opens new window) Sets a component property to be null.
archiveGatewayById() Archives a gateway by its ID.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
behaviors() (opens new window) Returns a list of behaviors that this component should behave as.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
createGateway() Creates a gateway with a given config
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) 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() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) 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() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined for this component.
init() (opens new window) Initializes the object.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
reorderGateways() Reorders gateways by ids.
saveGateway() Saves a gateway.
trigger() (opens new window) Triggers an event.

# archiveGatewayById()

Archives a gateway by its ID.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the archiving was successful or not

# createGateway()

Creates a gateway with a given config

View source (opens new window)

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 (opens new window)

Returns

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

# getAllGatewayTypes()

Returns all registered gateway types.

View source (opens new window)

Returns

string (opens new window)[]

# getAllGateways()

Returns all gateways

View source (opens new window)

Returns

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

# getAllSubscriptionGateways()

Returns all subscription gateways.

View source (opens new window)

Returns

array (opens new window)

# getGatewayByHandle()

Returns a gateway by its handle.

View source (opens new window)

Arguments

Returns

craft\commerce\base\Gateway, craft\commerce\base\GatewayInterface, null (opens new window) – The gateway or null if not found.

# getGatewayById()

Returns a gateway by its ID.

View source (opens new window)

Arguments

Returns

craft\commerce\base\GatewayInterface, null (opens new window) – The gateway or null if not found.

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

View source (opens new window)

Arguments

Returns

array (opens new window), null (opens new window)

# handleArchivedGateway()

Handle gateway being archived

View source (opens new window)

Arguments

Returns

void

Throws

# handleChangedGateway()

Handle gateway change

View source (opens new window)

Arguments

Returns

void

Throws

# reorderGateways()

Reorders gateways by ids.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Always true.

# saveGateway()

Saves a gateway.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the gateway was saved successfully or not.

Throws

# Constants

Constant Description
CONFIG_GATEWAY_KEY

# Events

# EVENT_REGISTER_GATEWAY_TYPES

Type
craft\events\RegisterComponentTypesEvent (opens new window)

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