Skip to content
Snippets Groups Projects
Commit 3ec5454e authored by Antoine Vandevenne (anv)'s avatar Antoine Vandevenne (anv)
Browse files

[FIX] paypal_paypal: log processing errors in the chatter


opw-3097856

closes odoo/odoo#111819

Signed-off-by: default avatarAntoine Vandevenne (anv) <anv@odoo.com>
parent 0bb74026
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ from werkzeug import urls
from odoo import _, http
from odoo.exceptions import ValidationError
from odoo.http import request
from odoo.tools import html_escape
_logger = logging.getLogger(__name__)
......@@ -56,8 +58,8 @@ class PaypalController(http.Controller):
The validation is done in four steps:
1. Make a POST request to Paypal with the `tx`, the GET param received with the PDT data,
and the two other required params `cmd` and `at`.
1. Make a POST request to Paypal with `tx`, the GET param received with the PDT data, and
with the two other required params `cmd` and `at`.
2. PayPal sends back a response text starting with either 'SUCCESS' or 'FAIL'. If the
validation was a success, the notification data are appended to the response text as a
string formatted as follows: 'SUCCESS\nparam1=value1\nparam2=value2\n...'
......@@ -70,15 +72,26 @@ class PaypalController(http.Controller):
:return: The retrieved notification data
:raise ValidationError: if the authenticity could not be verified
"""
if 'tx' not in data: # We did not receive PDT data but directly notification data
# When PDT is not enabled, PayPal sends directly the notification data instead. We can't
# verify them but we can process them as is.
notification_data = data
tx_sudo = request.env['payment.transaction'].sudo()._get_tx_from_feedback_data(
'paypal', data
)
if 'tx' not in data: # PDT is not enabled and PayPal directly sent the notification data.
tx_sudo._log_message_on_linked_documents(_(
"The status of transaction with reference %(ref)s was not synchronized because the "
"'Payment data transfer' option is not enabled on the PayPal dashboard.",
ref=tx_sudo.reference,
))
raise ValidationError("PayPal: PDT are not enabled; cannot verify data origin")
else:
acquirer_sudo = request.env['payment.transaction'].sudo()._get_tx_from_feedback_data(
'paypal', data
).acquirer_id
acquirer_sudo = tx_sudo.acquirer_id
if not acquirer_sudo.paypal_pdt_token: # We received PDT data but can't verify them
record_link = f'<a href=# data-oe-model=payment.acquirer ' \
f'data-oe-id={acquirer_sudo.id}>{html_escape(acquirer_sudo.name)}</a>'
tx_sudo._log_message_on_linked_documents(_(
"The status of transaction with reference %(ref)s was not synchronized because "
"the PDT Identify Token is not configured on the acquirer %(acq_link)s.",
ref=tx_sudo.reference, acq_link=record_link
))
raise ValidationError("PayPal: The PDT token is not set; cannot verify data origin")
else: # The PayPal account is configured to receive PDT data, and the PDT token is set
# Request a PDT data authenticity check and the notification data to PayPal
......
......@@ -4,10 +4,10 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server saas~14.4\n"
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-07-12 07:49+0000\n"
"PO-Revision-Date: 2021-07-12 07:49+0000\n"
"POT-Creation-Date: 2023-01-31 17:26+0000\n"
"PO-Revision-Date: 2023-01-31 17:26+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
......@@ -143,6 +143,24 @@ msgid ""
"The public business email solely used to identify the account with PayPal"
msgstr ""
#. module: payment_paypal
#: code:addons/payment_paypal/controllers/main.py:0
#, python-format
msgid ""
"The status of transaction with reference %(ref)s was not synchronized "
"because the 'Payment data transfer' option is not enabled on the PayPal "
"dashboard."
msgstr ""
#. module: payment_paypal
#: code:addons/payment_paypal/controllers/main.py:0
#, python-format
msgid ""
"The status of transaction with reference %(ref)s was not synchronized "
"because the PDT Identify Token is not configured on the acquirer "
"%(acq_link)s."
msgstr ""
#. module: payment_paypal
#: model:ir.model.fields,help:payment_paypal.field_payment_transaction__paypal_type
msgid "This has no use in Odoo except for debugging."
......
......@@ -14,7 +14,7 @@
<!-- This field should no longer be used but is kept in debug mode for the time
being, until we are sure that the verification protocol of IPN can be used
for DPT notifications -->
<field name="paypal_pdt_token" groups="base.group_no_one"/>
<field name="paypal_pdt_token"/>
<field name="paypal_use_ipn"
attrs="{'required':[('provider', '=', 'paypal'), ('state', '!=', 'disabled')]}"/>
<a href="https://www.odoo.com/documentation/15.0/applications/general/payment_acquirers/paypal.html"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment