Implementation
981d1f/app/code/Magento/Sales/Model/Order/Payment.php#L1057-L1115
/**
* Void payment either online or offline (process void notification)
* NOTE: that in some cases authorization can be voided after a capture. In such case it makes sense to use
* the amount void amount, for informational purposes.
* Updates payment totals, updates order status and adds proper comments
*
* @param bool $isOnline
* @param float $amount
* @param string $gatewayCallback
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _void($isOnline, $amount = null, $gatewayCallback = 'void')
{
$order = $this->getOrder();
$authTransaction = $this->getAuthorizationTransaction();
$this->setTransactionId(
$this->transactionManager->generateTransactionId($this, Transaction::TYPE_VOID, $authTransaction)
);
$this->setShouldCloseParentTransaction(true);
// attempt to void
if ($isOnline) {
$method = $this->getMethodInstance();
$method->setStore($order->getStoreId());
$method->{$gatewayCallback}($this);
}
if ($this->checkIfTransactionExists()) {
return $this;
}
// if the authorization was untouched, we may assume voided amount = order grand total
// but only if the payment auth amount equals to order grand total
if ($authTransaction &&
$order->getBaseGrandTotal() == $this->getBaseAmountAuthorized() &&
0 == $this->getBaseAmountCanceled()
) {
if ($authTransaction->canVoidAuthorizationCompletely()) {
$amount = (double)$order->getBaseGrandTotal();
}
}
if ($amount) {
$amount = $this->formatAmount($amount);
}
// update transactions, order state and add comments
$transaction = $this->addTransaction(Transaction::TYPE_VOID, null, true);
$message = $this->hasMessage() ? $this->getMessage() : __('Voided authorization.');
$message = $this->prependMessage($message);
if ($amount) {
$message .= ' ' . __('Amount: %1.', $this->formatPrice($amount));
}
$message = $this->_appendTransactionToMessage($transaction, $message);
$this->setOrderStateProcessing($message);
$order->setDataChanges(true);
return $this;
}
Details: How does \Magento\Sales\Model\Order\Payment::_void()
work?
Usages
1. \Magento\Sales\Model\Order\Payment::registerVoidNotification()
2. \Magento\Sales\Model\Order\Payment::cancel()
Details: How is \Magento\Sales\Model\Order\Payment::cancel()
implemented and used?