Files
Yamen Ahmad 3e83d8d7d5 feat: add complete EnCoach backend — Odoo 19 + all addons
Includes:
- Odoo 19 framework (odoo/)
- 27 custom EnCoach addons (new_project/custom_addons/)
  - encoach_core, encoach_api, encoach_lms_api, encoach_adaptive_api
  - encoach_exam, encoach_taxonomy, encoach_adaptive, encoach_assignment
  - encoach_ai, encoach_ai_grading, encoach_ai_generation, encoach_ai_media
  - encoach_courseware, encoach_communication, encoach_subscription
  - encoach_notification, encoach_approval, encoach_branding
  - encoach_classroom, encoach_registration, encoach_stats
  - encoach_faq, encoach_ticket, encoach_training, encoach_resources
  - encoach_adaptive_ai, encoach_sis
- 21 OpenEduCat Enterprise modules (new_project/enterprise-19/)
- 14 OpenEduCat Community modules (new_project/openeducat_erp-19.0/)
- Configuration: odoo.conf, requirements.txt, scripts
- 200+ REST API endpoints with JWT authentication
- SRS and test documentation

Made-with: Cursor
2026-04-01 17:10:04 +04:00

77 lines
3.1 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import base64
import hmac
import json
import pprint
from werkzeug.exceptions import Forbidden
from odoo import http
from odoo.http import request
from odoo.addons.payment.logging import get_payment_logger
_logger = get_payment_logger(__name__)
class RedsysController(http.Controller):
_return_url = '/payment/redsys/return'
_webhook_url = '/payment/redsys/webhook'
@http.route(_return_url, type='http', auth='public', methods=['GET'])
def redsys_return_from_checkout(self, **encoded_data):
"""Process the payment data sent by Redsys after redirection.
:param dict encoded_data: The encoded payment data.
"""
data = json.loads(base64.b64decode(encoded_data['Ds_MerchantParameters']).decode())
_logger.info("Handling redirection from Redsys with data:\n%s", pprint.pformat(data))
tx_sudo = request.env['payment.transaction'].sudo()._search_by_reference('redsys', data)
if tx_sudo:
self._verify_signature(encoded_data, tx_sudo)
tx_sudo._process('redsys', data)
return request.redirect('/payment/status')
@http.route(_webhook_url, type='http', auth='public', methods=['POST'], csrf=False)
def redsys_webhook(self, **encoded_data):
"""Process the payment data sent by Redsys to the webhook.
:param dict encoded_data: The encoded payment data.
:return: The 'OK' string to acknowledge the notification.
:rtype: str
"""
data = json.loads(base64.b64decode(encoded_data.get('Ds_MerchantParameters')).decode())
_logger.info("Received webhook notification from Redsys:\n%s", pprint.pformat(data))
tx_sudo = request.env['payment.transaction'].sudo()._search_by_reference('redsys', data)
if tx_sudo:
self._verify_signature(encoded_data, tx_sudo)
tx_sudo._process('redsys', data)
return ''
@staticmethod
def _verify_signature(payment_data, tx_sudo):
"""Check that the received signature matches the expected one.
:param dict payment_data: The payment data to verify.
:param payment.transaction tx_sudo: The transaction referenced by the payment data.
:return: None
:raise Forbidden: If the signatures don't match.
"""
# Retrieve the received signature from the payment data.
received_signature = payment_data.get('Ds_Signature')
if not received_signature:
_logger.warning("Received notification with missing signature.")
raise Forbidden()
# Compare the received signature with the expected signature computed from the payment data.
expected_signature = tx_sudo.provider_id._redsys_calculate_signature(
payment_data.get('Ds_MerchantParameters'),
tx_sudo.reference,
tx_sudo.provider_id.redsys_secret_key,
)
if not hmac.compare_digest(received_signature, expected_signature):
_logger.warning("Received notification with invalid signature.")
raise Forbidden()