oca-ocb-core/odoo-bringout-oca-ocb-payment_dpo/payment_dpo/controllers/main.py
Ernad Husremovic aee3ee8bf7 add missing payment providers and iot modules for 19.0
Add 19 payment provider modules needed by the sale module:
payment_adyen, payment_aps, payment_asiapay, payment_authorize,
payment_buckaroo, payment_demo, payment_dpo, payment_flutterwave,
payment_iyzico, payment_mercado_pago, payment_mollie, payment_nuvei,
payment_paymob, payment_paypal, payment_razorpay, payment_redsys,
payment_stripe, payment_worldline, payment_xendit

Add 3 IoT modules needed for point_of_sale:
iot_base, iot_box_image, iot_drivers

Note: Stripe test API keys replaced with placeholders.

🤖 assisted by claude
2026-03-09 15:45:22 +01:00

56 lines
1.8 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import pprint
from odoo import http
from odoo.exceptions import ValidationError
from odoo.http import request
from odoo.addons.payment.logging import get_payment_logger
_logger = get_payment_logger(__name__)
class DPOController(http.Controller):
_return_url = '/payment/dpo/return'
@http.route(_return_url, type='http', auth='public', methods=['GET'])
def dpo_return_from_checkout(self, **data):
""" Process the payment data sent by DPO after redirection.
:param dict data: The payment data.
"""
_logger.info("Handling redirection from DPO with data:\n%s", pprint.pformat(data))
self._verify_and_process(data)
# Redirect the user to the status page.
return request.redirect('/payment/status')
@staticmethod
def _verify_and_process(data):
""" Verify and process the payment data sent by DPO.
:param dict data: The payment data.
:return: None
"""
tx_sudo = request.env['payment.transaction'].sudo()._search_by_reference('dpo', data)
if not tx_sudo:
return
try:
# Verify the payment data.
payload = (
f'<?xml version="1.0" encoding="utf-8"?>'
f'<API3G>'
f'<CompanyToken>{tx_sudo.provider_id.dpo_company_token}</CompanyToken>'
f'<Request>verifyToken</Request>'
f'<TransactionToken>{data.get("TransID")}</TransactionToken>'
f'</API3G>'
)
verified_data = tx_sudo._send_api_request('POST', '', data=payload)
except ValidationError:
_logger.error("Unable to verify the payment data.")
else:
data.update(verified_data)
tx_sudo._process('dpo', data)