Skip to content

GatewayInterface ​

Type
Interface
Namespace
craft\commerce\base
Extends
craft\base\SavableComponentInterface
Implemented by
craft\commerce\base\Gateway, craft\commerce\base\SubscriptionGateway, craft\commerce\base\SubscriptionGatewayInterface, 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

Public Methods ​

MethodDescription
afterDelete()Performs actions after a component is deleted.
afterSave()Performs actions after a component is saved.
authorize()Makes an authorize request.
availableForUseWithOrder()Returns true if gateway supports payments for the supplied order.
beforeApplyDelete()Performs actions before a component delete is applied to the database.
beforeDelete()Performs actions before a component is deleted.
beforeSave()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 customer id.
deletePaymentSource()Deletes a payment source on the gateway by its token.
displayName()Returns the display name of this class.
extraFields()Returns the list of additional fields that can be returned by toArray() in addition to those listed in fields().
fields()Returns the list of fields that should be returned by default by toArray() when no specific fields are specified.
getIsNew()Returns whether the component is new (unsaved).
getPaymentFormModel()Returns payment form model to use in payment forms.
getSettings()Returns an array of the component’s settings.
getSettingsHtml()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.
instance()Returns static class instance, which can be used to obtain meta information.
isSelectable()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()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.
toArray()Converts the object into an array.

authorize() ​

Makes an authorize request.

View source

Arguments ​

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

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

View source

Arguments ​

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

capture() ​

Makes a capture request.

View source

Arguments ​

completeAuthorize() ​

Complete the authorization for offsite payments.

View source

Arguments ​

completePurchase() ​

Complete the purchase for offsite payments.

View source

Arguments ​

createPaymentSource() ​

Creates a payment source from source data and customer id.

View source

Arguments ​

  • $sourceData
  • $customerId

deletePaymentSource() ​

Deletes a payment source on the gateway by its token.

View source

Arguments ​

getPaymentFormModel() ​

Returns payment form model to use in payment forms.

View source

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

Returns ​

string, null

processWebHook() ​

Processes a webhook and return a response

View source

Throws ​

purchase() ​

Makes a purchase request.

View source

Arguments ​

refund() ​

Makes an refund request.

View source

Arguments ​

supportsAuthorize() ​

Returns true if gateway supports authorize requests.

View source

supportsCapture() ​

Returns true if gateway supports capture requests.

View source

supportsCompleteAuthorize() ​

Returns true if gateway supports completing authorize requests

View source

supportsCompletePurchase() ​

Returns true if gateway supports completing purchase requests

View source

supportsPartialPayment() ​

Returns true if gateway supports partial payment requests.

View source

supportsPartialRefund() ​

Returns true if gateway supports partial refund requests.

View source

supportsPaymentSources() ​

Returns true if gateway supports storing payment sources

View source

supportsPurchase() ​

Returns true if gateway supports purchase requests.

View source

supportsRefund() ​

Returns true if gateway supports refund requests.

View source

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