Payments

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

Payments service.

View source (opens new window)

# Public Properties

Property Description
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component

# 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 an object property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets value of an object property.
__unset() (opens new window) Sets an object property to null.
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.
captureTransaction() Capture a transaction.
className() (opens new window) Returns the fully qualified name of this class.
completePayment() Process return from off-site payment.
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.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getTotalAuthorizedForOrder() Gets the total transactions amount with authorized.
getTotalPaidForOrder() Gets the total transactions amount really paid (not authorized).
getTotalRefundedForOrder() Gets the total transactions amount refunded.
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.
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.
processPayment() Process a payment.
refundTransaction() Refund a transaction.
trigger() (opens new window) Triggers an event.

# captureTransaction()

Capture a transaction.

View source (opens new window)

Arguments

Returns

craft\commerce\models\Transaction

Throws

# completePayment()

Process return from off-site payment.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# getTotalAuthorizedForOrder()

Gets the total transactions amount with authorized.

View source (opens new window)

Arguments

Returns

float (opens new window)

# getTotalPaidForOrder()

Gets the total transactions amount really paid (not authorized).

View source (opens new window)

Arguments

Returns

float (opens new window)

# getTotalRefundedForOrder()

Gets the total transactions amount refunded.

View source (opens new window)

Arguments

Returns

float (opens new window)

# processPayment()

Process a payment.

View source (opens new window)

Arguments

Returns

void, null (opens new window)

Throws

# refundTransaction()

Refund a transaction.

View source (opens new window)

Arguments

Returns

craft\commerce\models\Transaction

Throws

# Events

# EVENT_AFTER_CAPTURE_TRANSACTION

Type
craft\commerce\events\TransactionEvent

The event that is triggered after a transaction is captured

Plugins can get notified after a payment transaction is captured

use craft\commerce\events\TransactionEvent;
use craft\commerce\services\Payments;
use yii\base\Event;

Event::on(Payments::class, Payments::EVENT_AFTER_CAPTURE_TRANSACTION, function(TransactionEvent $e) {
    // Do something - probably notify warehouse that we're ready to ship
});

# EVENT_AFTER_PAYMENT_TRANSACTION

Type
craft\commerce\events\TransactionEvent

The event that is triggered after a payment transaction is made

Plugins can get notified after a payment transaction is made

use craft\commerce\events\TransactionEvent;
use craft\commerce\services\Payments;
use yii\base\Event;

Event::on(Payments::class, Payments::EVENT_AFTER_PAYMENT_TRANSACTION, function(TransactionEvent $e) {
    // Do something - perhaps check if that was a authorize transaction and make sure that warehouse team is on top of it
});

# EVENT_AFTER_PROCESS_PAYMENT

Type
craft\commerce\events\ProcessPaymentEvent

The event is triggered after a payment is being processed

Plugins can get notified after a payment is processed

use craft\commerce\events\ProcessPaymentEvent;
use craft\commerce\services\Payments;
use yii\base\Event;

Event::on(Payments::class, Payments::EVENT_AFTER_PROCESS_PAYMENT, function(ProcessPaymentEvent $e) {
    // Do something - maybe let accounting dept. know that a transaction went through for an order.
});

# EVENT_AFTER_REFUND_TRANSACTION

Type
craft\commerce\events\TransactionEvent

The event that is triggered after a transaction is refunded

Plugins can get notified after a transaction is refunded

use craft\commerce\events\RefundTransactionEvent;
use craft\commerce\services\Payments;
use yii\base\Event;

Event::on(Payments::class, Payments::EVENT_AFTER_REFUND_TRANSACTION, function(RefundTransactionEvent $e) {
    // Do something - perhaps check if refund amount more than half the transaction and do something based on that
});

# EVENT_BEFORE_CAPTURE_TRANSACTION

Type
craft\commerce\events\TransactionEvent

The event that is triggered before a transaction is captured

Plugins can get notified before a payment transaction is captured

use craft\commerce\events\TransactionEvent;
use craft\commerce\services\Payments;
use yii\base\Event;

Event::on(Payments::class, Payments::EVENT_BEFORE_CAPTURE_TRANSACTION, function(TransactionEvent $e) {
    // Do something - maybe check if the shipment is really ready before capturing
});

# EVENT_BEFORE_PROCESS_PAYMENT

Type
craft\commerce\events\ProcessPaymentEvent

The event is triggered before a payment is being processed You may set craft\commerce\events\ProcessPaymentEvent::$isValid (opens new window) to false to prevent the payment from being processed

Plugins can get notified before a payment is being processed

use craft\commerce\events\ProcessPaymentEvent;
use craft\commerce\services\Payments;
use yii\base\Event;

Event::on(Payments::class, Payments::EVENT_BEFORE_PROCESS_PAYMENT, function(ProcessPaymentEvent $e) {
    // Do something - perhaps check if the transaction is allowed for the order based on some business rules.
});

# EVENT_BEFORE_REFUND_TRANSACTION

Type
craft\commerce\events\TransactionEvent

The event that is triggered before a transaction is refunded

Plugins can get notified before a transaction is refunded

use craft\commerce\events\RefundTransactionEvent;
use craft\commerce\services\Payments;
use yii\base\Event;

Event::on(Payments::class, Payments::EVENT_BEFORE_REFUND_TRANSACTION, function(RefundTransactionEvent $e) {
    // Do something - perhaps check if refund amount more than half the transaction and do something based on that
});