Files
odoo_source/addons/payment_transfer/models/payment_transaction.py
T
Antoine Vandevenne (anv) f4ca7290ac [IMP] payment(_*): search only once for the transaction
Before this commit, most acquirers needed to run several successive
searches for the transaction whose reference was received by a
controller in notification data. This is because the security checks
run on the notification data require access to the acquirer through the
transaction record which was immediately discarded.

Starting with this commit, all `*_feedback_data` method are no longer
decorated with `api.model` and can use the transaction record they're
called on if provided. They are also renamed to `*_notification_data`.

task-2737144

closes odoo/odoo#83850

Related: odoo/enterprise#23938
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
2022-02-02 19:50:49 +00:00

94 lines
3.3 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo import _, api, models
from odoo.exceptions import ValidationError
from odoo.addons.payment_transfer.controllers.main import TransferController
_logger = logging.getLogger(__name__)
class PaymentTransaction(models.Model):
_inherit = 'payment.transaction'
def _get_specific_rendering_values(self, processing_values):
""" Override of payment to return Transfer-specific rendering values.
Note: self.ensure_one() from `_get_processing_values`
:param dict processing_values: The generic and specific processing values of the transaction
:return: The dict of acquirer-specific processing values
:rtype: dict
"""
res = super()._get_specific_rendering_values(processing_values)
if self.provider != 'transfer':
return res
return {
'api_url': TransferController._accept_url,
'reference': self.reference,
}
def _get_tx_from_notification_data(self, provider, notification_data):
""" Override of payment to find the transaction based on transfer data.
:param str provider: The provider of the acquirer that handled the transaction
:param dict notification_data: The notification feedback data
:return: The transaction if found
:rtype: recordset of `payment.transaction`
:raise: ValidationError if the data match no transaction
"""
tx = super()._get_tx_from_notification_data(provider, notification_data)
if provider != 'transfer' or len(tx) == 1:
return tx
reference = notification_data.get('reference')
tx = self.search([('reference', '=', reference), ('provider', '=', 'transfer')])
if not tx:
raise ValidationError(
"Wire Transfer: " + _("No transaction found matching reference %s.", reference)
)
return tx
def _process_notification_data(self, notification_data):
""" Override of payment to process the transaction based on transfer data.
Note: self.ensure_one()
:param dict notification_data: The transfer data
:return: None
"""
super()._process_notification_data(notification_data)
if self.provider != 'transfer':
return
_logger.info(
"validated transfer payment for transaction with reference %s: set as pending",
self.reference
)
self._set_pending()
def _log_received_message(self):
""" Override of payment to remove transfer acquirer from the recordset.
:return: None
"""
other_provider_txs = self.filtered(lambda t: t.provider != 'transfer')
super(PaymentTransaction, other_provider_txs)._log_received_message()
def _get_sent_message(self):
""" Override of payment to return a different message.
:return: The 'transaction sent' message
:rtype: str
"""
message = super()._get_sent_message()
if self.provider == 'transfer':
message = _(
"The customer has selected %(acq_name)s to make the payment.",
acq_name=self.acquirer_id.name
)
return message