app\models\Payment::recordRefund PHP Method

recordRefund() public method

public recordRefund ( null $amount = null ) : boolean
$amount null
return boolean
    public function recordRefund($amount = null)
    {
        if ($this->isRefunded() || $this->isVoided()) {
            return false;
        }
        if (!$amount) {
            $amount = $this->amount;
        }
        $new_refund = min($this->amount, $this->refunded + $amount);
        $refund_change = $new_refund - $this->refunded;
        if ($refund_change) {
            $this->refunded = $new_refund;
            $this->payment_status_id = $this->refunded == $this->amount ? PAYMENT_STATUS_REFUNDED : PAYMENT_STATUS_PARTIALLY_REFUNDED;
            $this->save();
            Event::fire(new PaymentWasRefunded($this, $refund_change));
        }
        return true;
    }