[IMP] payment_paypal: finally add a field to store PDT token instead of hidden configuration parameter

This commit is contained in:
fka-odoo
2017-05-10 13:57:02 +02:00
committed by Thibault Delavallée
parent 2df2af8a52
commit 25411cfbd0
4 changed files with 7 additions and 4 deletions
+4 -4
View File
@@ -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'))
@@ -15,6 +15,7 @@
<field name="paypal_seller_account">dummy</field>
<field name="paypal_api_username">dummy</field>
<field name="paypal_api_password">dummy</field>
<field name="paypal_pdt_token">dummy</field>
</record>
</data>
+1
View File
@@ -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')
@@ -11,6 +11,7 @@
<group attrs="{'invisible': [('provider', '!=', 'paypal')]}">
<field name="paypal_email_account"/>
<field name="paypal_seller_account"/>
<field name="paypal_pdt_token"/>
<field name="paypal_use_ipn"/>
<field name="paypal_api_enabled" invisible="1"/>
<field name="paypal_api_username" invisible="1"/>