fix: redirection

This commit is contained in:
mthiam
2026-02-09 11:05:36 +01:00
parent 5e7d107481
commit 85282bc757
2 changed files with 47 additions and 2 deletions

View File

@@ -9,6 +9,40 @@ _logger = logging.getLogger(__name__)
class PaymentTransaction(models.Model): class PaymentTransaction(models.Model):
_inherit = 'payment.transaction' _inherit = 'payment.transaction'
def _get_paydunya_channel(self, processing_values):
"""Return the PayDunya channel to force based on selected payment method."""
self.ensure_one()
selected_code = (
processing_values.get('payment_method_code')
or processing_values.get('payment_method')
or getattr(getattr(self, 'payment_method_id', False), 'code', False)
)
# Odoo checkout often sends only payment_method_id; resolve it to code.
if not selected_code:
pm_id = processing_values.get('payment_method_id')
if pm_id:
try:
payment_method = self.env['payment.method'].browse(int(pm_id))
if payment_method.exists():
selected_code = payment_method.code
except (TypeError, ValueError):
selected_code = None
if not selected_code:
return None
channel_map = {
'wave-senegal': 'wave-senegal',
'orange-money-senegal': 'orange-money-senegal',
'om': 'orange-money-senegal',
'orange-money': 'orange-money-senegal',
'wave': 'wave-senegal',
'card': 'card',
}
return channel_map.get(str(selected_code).lower())
def _get_specific_rendering_values(self, processing_values): def _get_specific_rendering_values(self, processing_values):
"""Create invoice on PayDunya and return rendering values for redirection.""" """Create invoice on PayDunya and return rendering values for redirection."""
self.ensure_one() self.ensure_one()
@@ -53,6 +87,18 @@ class PaymentTransaction(models.Model):
'phone': self.partner_id.phone or '', 'phone': self.partner_id.phone or '',
} }
channel = self._get_paydunya_channel(processing_values or {})
if channel:
# Force a single payment channel so PayDunya redirects to the selected operator flow.
payload['invoice']['channels'] = [channel]
_logger.info(
'PayDunya checkout channel: selected=%s resolved=%s',
processing_values.get('payment_method_code')
or processing_values.get('payment_method')
or processing_values.get('payment_method_id'),
channel,
)
# Authentication headers # Authentication headers
headers = { headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View File

@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<template id="paydunya_redirect_form"> <template id="paydunya_redirect_form">
<form t-att-action="api_url" method="post"> <form t-att-action="api_url" method="get">
<input type="hidden" name="token" t-att-value="token"/>
</form> </form>
</template> </template>
</odoo> </odoo>