From 31dc6b888eeb2d787f567562fb447e8131c877e3 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 13 Apr 2017 16:18:09 +0200 Subject: [PATCH] [FIX] payment, website_sale: SIPS adaptation SIPS payment has two limitations: - A payment reference can only be used once, even if the payment was not proceeded - A payment reference can only contain alphanumerical characters These limitations do not fit the payment process which: - Reuses existing transactions - Introduces a `-` character when creating a new transaction for the same order. First issue is solved by an ugly hack since there is no link module between `website_sale` and `payment_sips` in order to override the behavior of `sale_get_transaction`. Second issue is solved by modifying the character to `x`. In this case, we could consider overriding the method `get_next_reference` in `payment_sips`. However, this method is called before the creation of the transaction, and we should do a crappy workaround using the context to get the `acquier_id`. opw-728209 --- addons/payment/models/payment_acquirer.py | 2 +- addons/website_sale/models/sale_order.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index e0a7eb61305..0e3e3b0fb5c 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -527,7 +527,7 @@ class PaymentTransaction(models.Model): ref_suffix = 1 init_ref = reference while self.env['payment.transaction'].sudo().search_count([('reference', '=', reference)]): - reference = init_ref + '-' + str(ref_suffix) + reference = init_ref + 'x' + str(ref_suffix) ref_suffix += 1 return reference diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index d845f65ae2a..b95b1afcffd 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -463,7 +463,15 @@ class Website(models.Model): tx_id = request.session.get('sale_transaction_id') if tx_id: transaction = self.env['payment.transaction'].sudo().browse(tx_id) - if transaction.state != 'cancel': + # Ugly hack for SIPS: SIPS does not allow to reuse a payment reference, even if the + # payment was not not proceeded. For example: + # - Select SIPS for payment + # - Be redirected to SIPS website + # - Go back to eCommerce without paying + # - Be redirected to SIPS website again => error + # Since there is no link module between 'website_sale' and 'payment_sips', we prevent + # here to reuse any previous transaction for SIPS. + if transaction.state != 'cancel' and transaction.acquirer_id.provider != 'sips': return transaction else: request.session['sale_transaction_id'] = False