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>
74 lines
2.6 KiB
Python
74 lines
2.6 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 import utils as payment_utils
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class PaymentTransaction(models.Model):
|
|
_inherit = 'payment.transaction'
|
|
|
|
def _send_payment_request(self):
|
|
""" Override of payment to simulate a payment request.
|
|
|
|
Note: self.ensure_one()
|
|
|
|
:return: None
|
|
"""
|
|
super()._send_payment_request()
|
|
if self.provider != 'test':
|
|
return
|
|
|
|
self._handle_notification_data('test', None)
|
|
|
|
def _get_tx_from_notification_data(self, provider, notification_data):
|
|
""" Override of payment to find the transaction based on dummy data.
|
|
|
|
:param str provider: The provider of the acquirer that handled the transaction
|
|
:param dict notification_data: The dummy notification 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 != 'test' or len(tx) == 1:
|
|
return tx
|
|
|
|
reference = notification_data.get('reference')
|
|
tx = self.search([('reference', '=', reference), ('provider', '=', 'test')])
|
|
if not tx:
|
|
raise ValidationError(
|
|
"Test: " + _("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 dummy data.
|
|
|
|
Note: self.ensure_one()
|
|
|
|
:param dict notification_data: The dummy notification data
|
|
:return: None
|
|
:raise: ValidationError if inconsistent data were received
|
|
"""
|
|
super()._process_notification_data(notification_data)
|
|
if self.provider != "test":
|
|
return
|
|
|
|
self._set_done() # Dummy transactions are always successful
|
|
if self.tokenize:
|
|
payment_details_short = notification_data['cc_summary']
|
|
token = self.env['payment.token'].create({
|
|
'acquirer_id': self.acquirer_id.id,
|
|
'name': payment_utils.build_token_name(payment_details_short=payment_details_short),
|
|
'partner_id': self.partner_id.id,
|
|
'acquirer_ref': 'fake acquirer reference',
|
|
'verified': True,
|
|
})
|
|
self.token_id = token.id
|