[FIX] payment, payment_sips: compute reference correctly and encode return url
Sips does not accept special characters as a transaction reference. Replacing '-' solve this issue. Parsing Sips response was failing when the return url had query parameters. This was due to the split on '='. Encoding the url solve this issue.
This commit is contained in:
committed by
Toufik Benjaa
parent
2521b9990e
commit
5dd187c566
@@ -110,6 +110,7 @@ class WebsitePayment(http.Controller):
|
||||
values['sale_order_ids'] = [(6, 0, [order_id])]
|
||||
|
||||
reference_values = order_id and {'sale_order_ids': [(4, order_id)]} or {}
|
||||
reference_values.update(acquirer_id=int(acquirer_id))
|
||||
values['reference'] = request.env['payment.transaction']._compute_reference(values=reference_values, prefix=reference)
|
||||
tx = request.env['payment.transaction'].sudo().with_context(lang=None).create(values)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class SipsController(http.Controller):
|
||||
Tx = request.env['payment.transaction']
|
||||
data = Tx._sips_data_to_object(post.get('Data'))
|
||||
custom = json.loads(data.pop('returnContext', False) or '{}')
|
||||
return_url = custom.get('return_url', '/')
|
||||
return_url = werkzeug.urls.url_unquote(custom.get('return_url', '/'))
|
||||
return return_url
|
||||
|
||||
def sips_validate_data(self, **post):
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from hashlib import sha256
|
||||
|
||||
from werkzeug import urls
|
||||
@@ -98,7 +99,7 @@ class AcquirerSips(models.Model):
|
||||
|
||||
return_context = {}
|
||||
if sips_tx_values.get('return_url'):
|
||||
return_context[u'return_url'] = u'%s' % sips_tx_values.pop('return_url')
|
||||
return_context[u'return_url'] = u'%s' % urls.url_quote(sips_tx_values.pop('return_url'))
|
||||
return_context[u'reference'] = u'%s' % sips_tx_values['reference']
|
||||
sips_tx_values['Data'] += u'|returnContext=%s' % (json.dumps(return_context))
|
||||
|
||||
@@ -124,13 +125,11 @@ class TxSips(models.Model):
|
||||
|
||||
@api.model
|
||||
def _compute_reference(self, values=None, prefix=None):
|
||||
acquirer = self.env['payment.acquirer'].browse(values['acquirer_id'])
|
||||
res = super(TxSips, self)._compute_reference(values=values, prefix=prefix)
|
||||
acquirer = self.env['payment.acquirer'].browse(values.get('acquirer_id'))
|
||||
if acquirer and acquirer.provider == 'sips':
|
||||
if not prefix and values:
|
||||
prefix = self._compute_reference_prefix(values)
|
||||
prefix = re.sub(r'[^0-9a-zA-Z-]+', 'x', prefix)
|
||||
|
||||
return super(TxSips, self)._compute_reference(values=values, prefix=prefix)
|
||||
return re.sub(r'[^0-9a-zA-Z]+', 'x', res) + 'x' + str(int(time.time()))
|
||||
return res
|
||||
|
||||
# --------------------------------------------------
|
||||
# FORM RELATED METHODS
|
||||
|
||||
Reference in New Issue
Block a user