src/Model/Order.php
protected function statusTransition($fromStatus, $toStatus)
    {
        // Add extension hook to react to order status transitions.
        $this->extend('onStatusChange', $fromStatus, $toStatus);

        if ($toStatus == 'Paid' && !$this->Paid) {
            $this->Paid = DBDatetime::now()->Rfc2822();
            foreach ($this->Items() as $item) {
                $item->onPayment();
            }
            //all payment is settled
            $this->extend('onPaid');

            if (!$this->ReceiptSent) {
                OrderEmailNotifier::create($this)->sendReceipt();
                $this->ReceiptSent = DBDatetime::now()->Rfc2822();
            }
        }

        $logStatus = $this->config()->log_status;
        if (!empty($logStatus) && in_array($toStatus, $logStatus)) {
            $this->flagOrderStatusWrite = $fromStatus != $toStatus;
        }
    }
protected function statusTransition($fromStatus, $toStatus)
    {
        // Add extension hook to react to order status transitions.
        $this->extend('onStatusChange', $fromStatus, $toStatus);

        if ($toStatus == 'Paid' && !$this->Paid) {
            $this->Paid = DBDatetime::now()->Rfc2822();
            foreach ($this->Items() as $item) {
                $item->onPayment();
            }
            //all payment is settled
            $this->extend('onPaid');

            if (!$this->ReceiptSent) {
                OrderEmailNotifier::create($this)->sendReceipt();
                $this->ReceiptSent = DBDatetime::now()->Rfc2822();
            }
        }

        $logStatus = $this->config()->log_status;
        if (!empty($logStatus) && in_array($toStatus, $logStatus)) {
            $this->flagOrderStatusWrite = $fromStatus != $toStatus;
        }
    }
Called from @see onBeforeWrite whenever status changes

@param string $fromStatus status to transition away from
@param string $toStatus   target status