From 25411cfbd06b2914bc09a4416ec309009aa068f6 Mon Sep 17 00:00:00 2001 From: fka-odoo Date: Thu, 2 Feb 2017 19:41:21 +0530 Subject: [PATCH] [IMP] payment_paypal: finally add a field to store PDT token instead of hidden configuration parameter --- addons/payment_paypal/controllers/main.py | 8 ++++---- addons/payment_paypal/data/payment_acquirer_data.xml | 1 + addons/payment_paypal/models/payment.py | 1 + addons/payment_paypal/views/payment_views.xml | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/payment_paypal/controllers/main.py b/addons/payment_paypal/controllers/main.py index 768cb8062a3..56023740d27 100644 --- a/addons/payment_paypal/controllers/main.py +++ b/addons/payment_paypal/controllers/main.py @@ -28,7 +28,7 @@ class PaypalController(http.Controller): return return_url def _parse_pdt_response(self, response): - """ Parse a text response for a PDT verification . + """ Parse a text response for a PDT verification. :param response str: text response, structured in the following way: STATUS\nkey1=value1\nkey2=value2...\n @@ -72,7 +72,7 @@ class PaypalController(http.Controller): if pdt_request: # this means we are in PDT instead of DPN like before # fetch the PDT token - new_post['at'] = request.env['ir.config_parameter'].sudo().get_param('payment_paypal.pdt_token') + new_post['at'] = tx and tx.acquirer_id.paypal_pdt_token or '' new_post['cmd'] = '_notify-synch' # command is different in PDT than IPN/DPN validate_url = paypal_urls['paypal_form_url'] urequest = urllib2.Request(validate_url, werkzeug.url_encode(new_post)) @@ -80,10 +80,10 @@ class PaypalController(http.Controller): resp = uopen.read() if pdt_request: resp, post = self._parse_pdt_response(resp) - if resp == 'VERIFIED' or pdt_request and resp == 'SUCCESS': + if resp in ['VERIFIED', 'SUCCESS']: _logger.info('Paypal: validated data') res = request.env['payment.transaction'].sudo().form_feedback(post, 'paypal') - elif resp == 'INVALID' or pdt_request and resp == 'FAIL': + elif resp in ['INVALID', 'FAIL']: _logger.warning('Paypal: answered INVALID/FAIL on data verification') else: _logger.warning('Paypal: unrecognized paypal answer, received %s instead of VERIFIED/SUCCESS or INVALID/FAIL (validation: %s)' % (resp, 'PDT' if pdt_request else 'IPN/DPN')) diff --git a/addons/payment_paypal/data/payment_acquirer_data.xml b/addons/payment_paypal/data/payment_acquirer_data.xml index 13c8caf4391..de73e6105b5 100644 --- a/addons/payment_paypal/data/payment_acquirer_data.xml +++ b/addons/payment_paypal/data/payment_acquirer_data.xml @@ -15,6 +15,7 @@ dummy dummy dummy + dummy diff --git a/addons/payment_paypal/models/payment.py b/addons/payment_paypal/models/payment.py index 60c5f57ea51..3219e3cc469 100644 --- a/addons/payment_paypal/models/payment.py +++ b/addons/payment_paypal/models/payment.py @@ -25,6 +25,7 @@ class AcquirerPaypal(models.Model): 'Paypal Merchant ID', groups='base.group_user', help='The Merchant ID is used to ensure communications coming from Paypal are valid and secured.') paypal_use_ipn = fields.Boolean('Use IPN', default=True, help='Paypal Instant Payment Notification', groups='base.group_user') + paypal_pdt_token = fields.Char(string='Paypal PDT Token', required_if_provider='paypal', help='Payment Data Transfer allows you to receive notification of successful payments as they are made.', groups='base.group_user') # Server 2 server paypal_api_enabled = fields.Boolean('Use Rest API', default=False) paypal_api_username = fields.Char('Rest API Username', groups='base.group_user') diff --git a/addons/payment_paypal/views/payment_views.xml b/addons/payment_paypal/views/payment_views.xml index 83d5cf71c4c..89288a41c4c 100644 --- a/addons/payment_paypal/views/payment_views.xml +++ b/addons/payment_paypal/views/payment_views.xml @@ -11,6 +11,7 @@ +