GatewayInterface

Type
Interface
Namespace
craft\commerce\base
Extends
craft\base\SavableComponentInterface (opens new window)
Implemented by
craft\commerce\base\Gateway, craft\commerce\base\SubscriptionGateway, craft\commerce\gateways\Dummy, craft\commerce\gateways\Manual, craft\commerce\gateways\MissingGateway
Since
2.0

GatewayInterface defines the common interface to be implemented by gateway classes.

A class implementing this interface should also use \craft\commerce\base\SavableComponentTrait and craft\commerce\base\GatewayTrait.

View source (opens new window)

# Public Methods

Method Description
afterDelete() (opens new window) Performs actions after a component is deleted.
afterSave() (opens new window) Performs actions after a component is saved.
authorize() Makes an authorize request.
availableForUseWithOrder() Returns true if gateway supports payments for the supplied order.
beforeApplyDelete() (opens new window) Performs actions before a component delete is applied to the database.
beforeDelete() (opens new window) Performs actions before a component is deleted.
beforeSave() (opens new window) Performs actions before a component is saved.
capture() Makes a capture request.
completeAuthorize() Complete the authorization for offsite payments.
completePurchase() Complete the purchase for offsite payments.
createPaymentSource() Creates a payment source from source data and user id.
deletePaymentSource() Deletes a payment source on the gateway by its token.
displayName() (opens new window) Returns the display name of this class.
getIsNew() (opens new window) Returns whether the component is new (unsaved).
getPaymentFormModel() Returns payment form model to use in payment forms.
getSettings() (opens new window) Returns an array of the component’s settings.
getSettingsHtml() (opens new window) Returns the component’s settings HTML.
getTransactionHashFromWebhook() Retrieves the transaction hash from the webhook data. This could be a query string param or part of the response data.
isSelectable() (opens new window) Returns whether the component should be selectable in component Type selects.
processWebHook() Processes a webhook and return a response
purchase() Makes a purchase request.
refund() Makes an refund request.
settingsAttributes() (opens new window) Returns the list of settings attribute names.
supportsAuthorize() Returns true if gateway supports authorize requests.
supportsCapture() Returns true if gateway supports capture requests.
supportsCompleteAuthorize() Returns true if gateway supports completing authorize requests
supportsCompletePurchase() Returns true if gateway supports completing purchase requests
supportsPartialPayment() Returns true if gateway supports partial payment requests.
supportsPartialRefund() Returns true if gateway supports partial refund requests.
supportsPaymentSources() Returns true if gateway supports storing payment sources
supportsPurchase() Returns true if gateway supports purchase requests.
supportsRefund() Returns true if gateway supports refund requests.
supportsWebhooks() Returns true if gateway supports webhooks.

# authorize()

Makes an authorize request.

View source (opens new window)

Arguments

Returns

craft\commerce\base\RequestResponseInterface

# availableForUseWithOrder()

Returns true if gateway supports payments for the supplied order.

This method is called before a payment is made for the supplied order. It can be used by developers building a checkout and deciding if this gateway should be shown as and option to the customer.

It also can prevent a gateway from being used with a particular order.

An example of this can be found in the manual payment gateway: It has a setting that can limit its use to only be used with orders that are of a zero value amount. See below for an example of how it uses this method to reject the gateway's use on orders that are not $0.00 if the setting is turned on

public function availableForUseWithOrder($order): bool
 if ($this->onlyAllowForZeroPriceOrders && $order->getTotalPrice() != 0) {
   return false;
 }
return true;
}

View source (opens new window)

Arguments

  • $order – Order The order this gateway can or can not be available for payment with.

Returns

boolean (opens new window)

# capture()

Makes a capture request.

View source (opens new window)

Arguments

Returns

craft\commerce\base\RequestResponseInterface

# completeAuthorize()

Complete the authorization for offsite payments.

View source (opens new window)

Arguments

Returns

craft\commerce\base\RequestResponseInterface

# completePurchase()

Complete the purchase for offsite payments.

View source (opens new window)

Arguments

Returns

craft\commerce\base\RequestResponseInterface

# createPaymentSource()

Creates a payment source from source data and user id.

View source (opens new window)

Arguments

Returns

craft\commerce\models\PaymentSource

# deletePaymentSource()

Deletes a payment source on the gateway by its token.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# getPaymentFormModel()

Returns payment form model to use in payment forms.

View source (opens new window)

Returns

craft\commerce\models\payments\BasePaymentForm

# getTransactionHashFromWebhook()

Since
3.1.9

Retrieves the transaction hash from the webhook data. This could be a query string param or part of the response data.

View source (opens new window)

Returns

mixed

# processWebHook()

Processes a webhook and return a response

View source (opens new window)

Returns

craft\web\Response (opens new window)

Throws

# purchase()

Makes a purchase request.

View source (opens new window)

Arguments

Returns

craft\commerce\base\RequestResponseInterface

# refund()

Makes an refund request.

View source (opens new window)

Arguments

Returns

craft\commerce\base\RequestResponseInterface

# supportsAuthorize()

Returns true if gateway supports authorize requests.

View source (opens new window)

Returns

boolean (opens new window)

# supportsCapture()

Returns true if gateway supports capture requests.

View source (opens new window)

Returns

boolean (opens new window)

# supportsCompleteAuthorize()

Returns true if gateway supports completing authorize requests

View source (opens new window)

Returns

boolean (opens new window)

# supportsCompletePurchase()

Returns true if gateway supports completing purchase requests

View source (opens new window)

Returns

boolean (opens new window)

# supportsPartialPayment()

Returns true if gateway supports partial payment requests.

View source (opens new window)

Returns

boolean (opens new window)

# supportsPartialRefund()

Returns true if gateway supports partial refund requests.

View source (opens new window)

Returns

boolean (opens new window)

# supportsPaymentSources()

Returns true if gateway supports storing payment sources

View source (opens new window)

Returns

boolean (opens new window)

# supportsPurchase()

Returns true if gateway supports purchase requests.

View source (opens new window)

Returns

boolean (opens new window)

# supportsRefund()

Returns true if gateway supports refund requests.

View source (opens new window)

Returns

boolean (opens new window)

# supportsWebhooks()

Returns true if gateway supports webhooks.

If true is returned, this show the webhook url to the person setting up your gateway (after the gateway is saved). This also affects whether the webhook controller should route webhook requests to your processWebHook() method in this class.

View source (opens new window)

Returns

boolean (opens new window)