Payments

Type
Class
Namespace
craft\commerce\services
Inherits
craft\commerce\services\Payments » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
2.0

Payments service.

View source

Public Properties

PropertyDescription
$behaviorsyii\base\Behavior – List of behaviors attached to this component

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.
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.
captureTransaction()Capture a transaction.
className()Returns the fully qualified name of this class.
completePayment()Process return from off-site payment.
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.
getBehavior()Returns the named behavior object.
getBehaviors()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()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.
processPayment()Process a payment.
refundTransaction()Regund a transcation.
trigger()Triggers an event.

captureTransaction()

Capture a transaction.

View source

Arguments

Returns

craft\commerce\models\Transaction

Throws

Signature

public craft\commerce\models\Transaction captureTransaction ( craft\commerce\models\Transaction $transaction )

completePayment()

Process return from off-site payment.

View source

Arguments

Returns

boolean

Signature

public boolean completePayment ( craft\commerce\models\Transaction $transaction, &$customError )

getTotalAuthorizedForOrder()

Gets the total transactions amount with authorized.

View source

Arguments

Returns

float

Signature

public float getTotalAuthorizedForOrder ( craft\commerce\elements\Order $order )

getTotalPaidForOrder()

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

View source

Arguments

Returns

float

Signature

public float getTotalPaidForOrder ( craft\commerce\elements\Order $order )

getTotalRefundedForOrder()

Gets the total transactions amount refunded.

View source

Arguments

Returns

float

Signature

public float getTotalRefundedForOrder ( craft\commerce\elements\Order $order )

processPayment()

Process a payment.

View source

Arguments

Throws

Signature

public void processPayment ( craft\commerce\elements\Order $order, craft\commerce\models\payments\BasePaymentForm $form, &$redirect, &$transaction )

refundTransaction()

Regund a transcation.

View source

Arguments

Returns

craft\commerce\models\Transaction

Throws

Signature

public craft\commerce\models\Transaction refundTransaction ( craft\commerce\models\Transaction $transaction, $amount = null, $note = '' )

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_EVENT

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_EVENT, 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_EVENT

Type
craft\commerce\events\ProcessPaymentEvent

The event is triggered before a payment is being processed You may set craft\commerce\events\ProcessPaymentEvent::$isValid 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_EVENT, 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
});