diff --git a/addons/payment_adyen/views/adyen.xml b/addons/payment_adyen/views/adyen.xml index 75e166f92fe713f8a1d80086bd05246e41954ce8..79281f43a99694d79701db86207baafef5ca5585 100644 --- a/addons/payment_adyen/views/adyen.xml +++ b/addons/payment_adyen/views/adyen.xml @@ -20,7 +20,7 @@ <input t-if="tx_values.get('merchantReturnData')" type='hidden' name='merchantReturnData' t-att-value="tx_values.get('merchantReturnData')"/> <!-- submit --> - <button type="image" name="submit" width="100px" + <button type="submit" width="100px" t-att-class="submit_class"> <img t-if="not submit_txt" src="/payment_adyen/static/src/img/adyen_icon.png"/> <span t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span> diff --git a/addons/payment_ogone/views/ogone.xml b/addons/payment_ogone/views/ogone.xml index be89579c84ae458723921e95b8e05eaf99d9ce93..48480da23ebf3f8d97442ef5995efedbd06e3001 100644 --- a/addons/payment_ogone/views/ogone.xml +++ b/addons/payment_ogone/views/ogone.xml @@ -41,7 +41,7 @@ <input type='hidden' name='EXCEPTIONURL' t-att-value='tx_values["EXCEPTIONURL"]'/> <input type='hidden' name='CANCELURL' t-att-value='tx_values["CANCELURL"]'/> <!-- submit --> - <button type="image" name="submit" width="100px" + <button type="submit" width="100px" t-att-class="submit_class"> <img t-if="not submit_txt" src="/payment_ogone/static/src/img/ogone_icon.png"/> <span t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span> diff --git a/addons/payment_paypal/views/paypal.xml b/addons/payment_paypal/views/paypal.xml index 3c9ffacf2bf1f8faa87e733202970fdab034be59..7a9731c4dfe87d2c2ad093f90f36e498e204a7d4 100644 --- a/addons/payment_paypal/views/paypal.xml +++ b/addons/payment_paypal/views/paypal.xml @@ -31,7 +31,7 @@ <input t-if="tx_values.get('cancel_return')" type="hidden" name="cancel_return" t-att-value="tx_values.get('cancel_return')"/> <!-- submit --> - <button type="image" name="submit" width="100px" + <button type="submit" width="100px" t-att-class="submit_class"> <img t-if="not submit_txt" src="/payment_paypal/static/src/img/paypal_icon.png"/> <span t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span> diff --git a/addons/payment_transfer/views/transfer.xml b/addons/payment_transfer/views/transfer.xml index ddb45d32e8d31394e7bedb9c1c146b815355681c..e972677a4a1e0d5ae9598cbdedf1f2f92a09c2ed 100644 --- a/addons/payment_transfer/views/transfer.xml +++ b/addons/payment_transfer/views/transfer.xml @@ -11,7 +11,7 @@ <input type='hidden' name='amount' t-att-value='amount or "0.0"'/> <input type='hidden' name='currency' t-att-value='currency.name'/> <!-- submit --> - <button name="submit" width="100px" + <button type="submit" width="100px" t-att-class="submit_class"> <img t-if="not submit_txt" src="/payment_transfer/static/src/img/transfer_icon.png"/> <span t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span> diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index ff4761a848cd4c5d97bf8d6c2cbc2912c36757e1..bbd8f83fd7d9afc577b7028bd4f712ff02cb4b00 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/<int:acquirer_id>'], 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/<int:acquirer_id>'], 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/<int:sale_order_id>', 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 d20f00d0305c0c9b746c553fd904ded710dd2dbf..d4d4a6712c33d2d42bce570084511ec42f07f137 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,18 @@ $(document).ready(function () { }) .find("input[name='acquirer']:checked").click(); + // When clicking on payment button: create the tx using json then continue to the acquirer + $('button[type="submit"]').on("click", function (ev) { + ev.preventDefault(); + ev.stopPropagation(); + var $form = $(ev.currentTarget).parents('form'); + var acquirer_id = $(ev.currentTarget).parents('div.oe_sale_acquirer_button').first().data('id'); + if (! acquirer_id) { + return false; + } + openerp.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {}).then(function (data) { + $form.submit(); + }); + }); + });