Files
odoo_source/addons/payment_adyen/utils.py
T
Horacio Tellez 6769a42e92 [FIX] payment_adyen: incorrect parsing of partner's address
When passing the customer data to adyen to execute a payment an error occurred if the address did not follow a pattern that might be
unkown to the customer.
This fix allows for the user to be aware of what the issue is through
the logs and inform the customer if necessary.

opw - 3171407

closes odoo/odoo#116936

X-original-commit: 66716551f1f75d228876b49cda9fd92732756afc
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
Signed-off-by: Horacio Tellez Perez (hote) <hote@odoo.com>
2023-03-29 08:28:52 +02:00

59 lines
2.0 KiB
Python

from odoo.addons.payment import utils as payment_utils
def format_partner_name(partner_name):
""" Format the partner name to comply with the payload structure of the API request.
:param str partner_name: The name of the partner making the payment.
:return: The formatted partner name.
:rtype: dict
"""
first_name, last_name = payment_utils.split_partner_name(partner_name)
return {
'firstName': first_name,
'lastName': last_name,
}
def include_partner_addresses(tx_sudo):
""" Include the billing and delivery addresses of the related sales order to the payload of the
API request.
If no related sales order exists, the addresses are not included.
Note: `self.ensure_one()`
:param payment.transaction tx_sudo: The sudoed transaction of the payment.
:return: The subset of the API payload that includes the billing and delivery addresses.
:rtype: dict
"""
tx_sudo.ensure_one()
if 'sale_order_ids' in tx_sudo._fields: # The module `sale` is installed.
order = tx_sudo.sale_order_ids[:1]
if order:
return {
'billingAddress': format_partner_address(order.partner_invoice_id),
'deliveryAddress': format_partner_address(order.partner_shipping_id),
}
return {}
def format_partner_address(partner):
""" Format the partner address to comply with the payload structure of the API request.
:param res.partner partner: The partner making the payment.
:return: The formatted partner address.
:rtype: dict
"""
street_data = partner._get_street_split()
return {
'city': partner.city,
'country': partner.country_id.code or 'ZZ', # 'ZZ' if the country is not known.
'stateOrProvince': partner.state_id.code,
'postalCode': partner.zip,
# Fill in the address fields if the format is supported, or fallback to the raw address.
'street': street_data.get('street_name', partner.street),
'houseNumberOrName': street_data.get('street_number'),
}