diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index ff4761a848c..bbd8f83fd7d 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -490,7 +490,6 @@ class website_sale(http.Controller): values['acquirers'] = payment_obj.browse(cr, uid, acquirer_ids, context=context) render_ctx = dict(context, submit_class='btn btn-primary', submit_txt='Pay Now') for acquirer in values['acquirers']: - render_ctx['tx_url'] = '/shop/payment/transaction/%s' % acquirer.id acquirer.button = payment_obj.render( cr, SUPERUSER_ID, acquirer.id, order.name, @@ -504,20 +503,17 @@ class website_sale(http.Controller): return request.website.render("website_sale.payment", values) - @http.route(['/shop/payment/transaction/'], type='http', methods=['POST'], auth="public", website=True) - def payment_transaction(self, acquirer_id, **post): - """ Hook method that creates a payment.transaction and redirect to the - acquirer, using post values to re-create the post action. + @http.route(['/shop/payment/transaction/'], type='json', auth="public", website=True) + def payment_transaction(self, acquirer_id): + """ Json method that creates a payment.transaction, used to create a + transaction when the user clicks on 'pay now' button. After having + created the transaction, the event continues and the user is redirected + to the acquirer website. :param int acquirer_id: id of a payment.acquirer record. If not set the user is redirected to the checkout page - :param dict post: should coutain all post data for the acquirer """ - # @TDEFIXME: don't know why we received those data, but should not be send to the acquirer - post.pop('submit.x', None) - post.pop('submit.y', None) cr, uid, context = request.cr, request.uid, request.context - payment_obj = request.registry.get('payment.acquirer') transaction_obj = request.registry.get('payment.transaction') sale_order_obj = request.registry['sale.order'] order = request.website.sale_get_order(context=context) @@ -529,7 +525,13 @@ class website_sale(http.Controller): # find an already existing transaction tx = request.website.sale_get_transaction() - if not tx: + if tx: + if tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ? + tx.write({ + 'acquirer_id': acquirer_id, + }) + tx_id = tx.id + else: tx_id = transaction_obj.create(cr, SUPERUSER_ID, { 'acquirer_id': acquirer_id, 'type': 'form', @@ -541,10 +543,6 @@ class website_sale(http.Controller): 'sale_order_id': order.id, }, context=context) request.session['sale_transaction_id'] = tx_id - elif tx and tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ? - tx.write({ - 'acquirer_id': acquirer_id, - }) # update quotation sale_order_obj.write( @@ -555,9 +553,7 @@ class website_sale(http.Controller): # confirm the quotation sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context) - acquirer_form_post_url = payment_obj.get_form_action_url(cr, uid, acquirer_id, context=context) - acquirer_total_url = '%s?%s' % (acquirer_form_post_url, werkzeug.url_encode(post)) - return request.redirect(acquirer_total_url) + return tx_id @http.route('/shop/payment/get_status/', type='json', auth="public", website=True) def payment_get_status(self, sale_order_id, **post): diff --git a/addons/website_sale/static/src/js/website_sale_payment.js b/addons/website_sale/static/src/js/website_sale_payment.js index d20f00d0305..d991c86a6b9 100644 --- a/addons/website_sale/static/src/js/website_sale_payment.js +++ b/addons/website_sale/static/src/js/website_sale_payment.js @@ -9,4 +9,16 @@ $(document).ready(function () { }) .find("input[name='acquirer']:checked").click(); + // When clicking on payment button: create the tx using json then continue to the acquirer + $payment.on("click", "button[name='submit']", function (ev) { + var acquirer_id = $(ev.currentTarget).parents('div.oe_sale_acquirer_button').first().data('id'); + if (! acquirer_id) { + return false; + } + var def = openerp.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {}); + $.when(def).then(function (data) { + return true; + }); + }); + });