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 that are enabled for frontend
$allFrontEndGatewayscraft\commerce\base\GatewayInterface[] – All gateways that are enabled for frontend
$allGatewayTypesstring[]
$allGatewayscraft\commerce\base\GatewayInterface[] – All gateways
$allSubscriptionGatewaysarray
$behaviorsyii\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

Signature

public craft\commerce\base\GatewayInterface[] getAllCustomerEnabledGateways ( )

$allFrontEndGateways

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

All gateways that are enabled for frontend

View source

Signature

public craft\commerce\base\GatewayInterface[] getAllFrontEndGateways ( )

$allGatewayTypes

Type
string[]
Access
Read-only

View source

Signature

public string[] getAllGatewayTypes ( )

$allGateways

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

All gateways

View source

Signature

public craft\commerce\base\GatewayInterface[] getAllGateways ( )

$allSubscriptionGateways

Type
array
Access
Read-only

View source

Signature

public array getAllSubscriptionGateways ( )

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 an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to 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.
getAllFrontEndGateways()Returns all frontend 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.
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.
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

Signature

public boolean archiveGatewayById ( \craft\commerce\services\int $id )

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

Signature

public craft\commerce\base\GatewayInterface createGateway ( $config )

getAllCustomerEnabledGateways()

Returns all customer enabled gateways.

View source

Returns

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

Signature

public craft\commerce\base\GatewayInterface[] getAllCustomerEnabledGateways ( )

getAllFrontEndGateways()

DEPRECATED

Deprecated as of 2.0

Returns all frontend enabled gateways.

View source

Returns

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

Signature

public craft\commerce\base\GatewayInterface[] getAllFrontEndGateways ( )

getAllGatewayTypes()

Returns all registered gateway types.

View source

Returns

string[]

Signature

public string[] getAllGatewayTypes ( )

getAllGateways()

Returns all gateways

View source

Returns

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

Signature

public craft\commerce\base\GatewayInterface[] getAllGateways ( )

getAllSubscriptionGateways()

Returns all subscription gateways.

View source

Returns

array

Signature

public array getAllSubscriptionGateways ( )

getGatewayByHandle()

Returns a gateway by its handle.

View source

Arguments

Returns

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

Signature

public craft\commerce\base\GatewayInterface, null getGatewayByHandle ( \craft\commerce\services\string $handle )

getGatewayById()

Returns a gateway by its ID.

View source

Arguments

Returns

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

Signature

public craft\commerce\base\GatewayInterface, null getGatewayById ( \craft\commerce\services\int $id )

getGatewayOverrides()

Returns any custom gateway settings form config file.

View source

Arguments

  • $handle (string) – The gateway handle

Returns

array, null

Signature

public array, null getGatewayOverrides ( \craft\commerce\services\string $handle )

reorderGateways()

Reorders gateways by ids.

View source

Arguments

  • $ids (array) – Array of gateways.

Returns

boolean – Always true.

Signature

public boolean reorderGateways ( array $ids )

saveGateway()

Saves a gateway.

View source

Arguments

Returns

boolean – Whether the gateway was saved successfully or not.

Throws

Signature

public boolean saveGateway ( craft\commerce\base\Gateway $gateway, \craft\commerce\services\bool $runValidation = true )

Events

EVENT_REGISTER_GATEWAY_TYPES

Type
craft\events\RegisterComponentTypesEvent

The event that is triggered when registering gateways.

Plugins can register their own gateways.

use craft\events\RegisterComponentTypesEvent;
use craft\commerce\services\Purchasables;
use yii\base\Event;

Event::on(Gateways::class, Gateways::EVENT_REGISTER_GATEWAY_TYPES, function(RegisterComponentTypesEvent $e) {
    $e->types[] = MyGateway::class;
});