Files
odoo_source/addons/payment_aps/models/payment_provider.py
T
Laurent Desausoi 7593c073d2 [IMP] core: use inert SQL based neutralization
Before this commit the neutralize system introduced in v16 was using ORM
methods in order to change appropriate records. Although flexible, this approach
could lead to call some methods with side effects while neutralizing
(eg: overloads of write).

This patch converts the neutralize system to a safer "inert" SQL based approach
by migrating the generic method _neutralize to SQL files exposed in the
data folder.

Task id: 2961687

closes odoo/odoo#102792

X-original-commit: e5dbded9bb363351feff7ca8a56c7f8a6860f492
Related: odoo/enterprise#32580
Signed-off-by: Fabien Meghazi <fme@odoo.com>
2022-10-09 22:04:00 +02:00

61 lines
2.1 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import hashlib
import logging
from odoo import fields, models
_logger = logging.getLogger(__name__)
class PaymentProvider(models.Model):
_inherit = 'payment.provider'
code = fields.Selection(
selection_add=[('aps', "Amazon Payment Services")], ondelete={'aps': 'set default'}
)
aps_merchant_identifier = fields.Char(
string="APS Merchant Identifier",
help="The code of the merchant account to use with this provider.",
required_if_provider='aps',
)
aps_access_code = fields.Char(
string="APS Access Code",
help="The access code associated with the merchant account.",
required_if_provider='aps',
groups='base.group_system',
)
aps_sha_request = fields.Char(
string="APS SHA Request Phrase",
required_if_provider='aps',
groups='base.group_system',
)
aps_sha_response = fields.Char(
string="APS SHA Response Phrase",
required_if_provider='aps',
groups='base.group_system',
)
#=== BUSINESS METHODS ===#
def _aps_get_api_url(self):
if self.state == 'enabled':
return 'https://checkout.payfort.com/FortAPI/paymentPage'
else: # 'test'
return 'https://sbcheckout.payfort.com/FortAPI/paymentPage'
def _aps_calculate_signature(self, data, incoming=True):
""" Compute the signature for the provided data according to the APS documentation.
:param dict data: The data to sign.
:param bool incoming: Whether the signature must be generated for an incoming (APS to Odoo)
or outgoing (Odoo to APS) communication.
:return: The calculated signature.
:rtype: str
"""
sign_data = ''.join([f'{k}={v}' for k, v in sorted(data.items()) if k != 'signature'])
key = self.aps_sha_response if incoming else self.aps_sha_request
signing_string = ''.join([key, sign_data, key])
return hashlib.sha256(signing_string.encode()).hexdigest()