Context: How does a payment saving work?
958164/app/code/Magento/OfflinePayments/Observer/BeforeOrderPaymentSaveObserver.php#L19-L48
class BeforeOrderPaymentSaveObserver implements ObserverInterface
{
/**
* Sets current instructions for bank transfer account
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var \Magento\Sales\Model\Order\Payment $payment */
$payment = $observer->getEvent()->getPayment();
$instructionMethods = [
Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE,
Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE
];
if (in_array($payment->getMethod(), $instructionMethods)) {
$payment->setAdditionalInformation(
'instructions',
$payment->getMethodInstance()->getInstructions()
);
} elseif ($payment->getMethod() === Checkmo::PAYMENT_METHOD_CHECKMO_CODE) {
$payment->setAdditionalInformation(
'payable_to',
$payment->getMethodInstance()->getPayableTo()
);
$payment->setAdditionalInformation(
'mailing_address',
$payment->getMethodInstance()->getMailingAddress()
);
}
}
}