diff options
| author | tbe-odoo <tbe@odoo.com> | 2017-08-23 15:51:39 +0200 |
|---|---|---|
| committer | tbe-odoo <tbe@odoo.com> | 2017-08-29 17:11:23 +0200 |
| commit | 194d52e8fda35f7a6fd9a9e5c2e1af265e25ce4b (patch) | |
| tree | 925cb915000cdc0be69848d81a1864e1446ead4a /addons/website_quote/controllers | |
| parent | 3c062d934553bc4693bde6bd831fd2a3d6e9423c (diff) | |
[IMP] website_quote/sale,payment: Support of the new payment form
- Online quotation and e-commerce now use the new payment form.
- Added the ability to chose on an acquirer if it uses only form/s2s or both.
(Still need some code cleaning)
Diffstat (limited to 'addons/website_quote/controllers')
| -rw-r--r-- | addons/website_quote/controllers/main.py | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/addons/website_quote/controllers/main.py b/addons/website_quote/controllers/main.py index c0b0648bfd8..8098964c71e 100644 --- a/addons/website_quote/controllers/main.py +++ b/addons/website_quote/controllers/main.py @@ -64,23 +64,29 @@ class sale_quote(http.Controller): } if order_sudo.require_payment or values['need_payment']: - values['acquirers'] = list(request.env['payment.acquirer'].sudo().search([('website_published', '=', True), ('company_id', '=', order_sudo.company_id.id)])) - extra_context = { - 'submit_class': 'btn btn-primary', - 'submit_txt': _('Pay & Confirm') - } - values['buttons'] = {} - for acquirer in values['acquirers']: - values['buttons'][acquirer.id] = acquirer.with_context(**extra_context).render( - '/', - order_sudo.amount_total, - order_sudo.pricelist_id.currency_id.id, + acquirers = request.env['payment.acquirer'].sudo().search([('website_published', '=', True), ('company_id', '=', order_sudo.company_id.id)]) + + values['form_acquirers'] = [acq for acq in acquirers if acq.prefered_payment_type in ['form', 'both'] and acq.view_template_id] + values['s2s_acquirers'] = [acq for acq in acquirers if acq.prefered_payment_type in ['s2s', 'both'] and acq.registration_view_template_id] + values['pms'] = request.env['payment.token'].search( + [('partner_id', '=', order_sudo.partner_id.id), + ('acquirer_id', 'in', [acq.id for acq in values['s2s_acquirers']])]) + + for acq in values['form_acquirers']: + acq.form = acq.render('/', order_sudo.amount_total, order_sudo.pricelist_id.currency_id.id, values={ 'return_url': '/quote/%s/%s' % (order_id, token) if token else '/quote/%s' % order_id, 'type': 'form', 'alias_usage': _('If we store your payment information on our server, subscription payments will be made automatically.'), 'partner_id': order_sudo.partner_id.id, }) + + for acq in values['s2s_acquirers']: + acq.form = acq._registration_render(order_sudo.partner_id.id, { + 'return_url': '/shop/payment/validate', + 'bootstrap_formatting': True + }) + history = request.session.get('my_quotes_history', []) values.update(get_records_pager(history, order_sudo)) return request.render('website_quote.so_quotation', values) @@ -158,8 +164,8 @@ class sale_quote(http.Controller): return werkzeug.utils.redirect("/quote/%s/%s#pricing" % (Order.id, token)) # note dbo: website_sale code - @http.route(['/quote/<int:order_id>/transaction/<int:acquirer_id>'], type='json', auth="public", website=True) - def payment_transaction_token(self, acquirer_id, order_id, access_token=None, tx_type=None): + @http.route(['/quote/<int:order_id>/transaction/'], type='json', auth="public", website=True) + def payment_transaction_token(self, acquirer_id, order_id, save_token=False,access_token=None): """ 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 @@ -170,7 +176,8 @@ class sale_quote(http.Controller): """ order = request.env['sale.order'].sudo().browse(order_id) if not order or not order.order_line or acquirer_id is None: - return request.redirect("/quote/%s" % order_id) + return False + # return request.redirect("/quote/%s" % order_id) # find an already existing transaction acquirer = request.env['payment.acquirer'].browse(int(acquirer_id)) @@ -184,8 +191,44 @@ class sale_quote(http.Controller): }) request.session['quote_%s_transaction_id' % order.id] = tx.id - return tx.render_sale_button(order, '/quote/%s/%s' % (order_id, token) if token else '/quote/%s' % order_id, - submit_txt=_('Pay & Confirm'), render_values={ - 'type': order._get_payment_type(), - 'alias_usage': _('If we store your payment information on our server, subscription payments will be made automatically.'), - }) + return True + # return tx.render_sale_button(order, '/quote/%s/%s' % (order_id, token) if token else '/quote/%s' % order_id, + # submit_txt=_('Pay & Confirm'), render_values={ + # 'type': order._get_payment_type(), + # 'alias_usage': _('If we store your payment information on our server, subscription payments will be made automatically.'), + # }) + + @http.route('/quote/<int:order_id>/transaction/token', type='http', auth='public', website=True) + def payment_token(self, order_id, pm_id=None, **kwargs): + + order = request.env['sale.order'].sudo().browse(order_id) + if not order or not order.order_line or pm_id is None: + return request.redirect("/quote/%s" % order_id) + + # try to convert pm_id into an integer, if it doesn't work redirect the user to the quote + try: + pm_id = int(pm_id) + except ValueError: + return request.redirect('/quote/%s' % order_id) + + # retrieve the token from its id + token = request.env['payment.token'].sudo().browse(pm_id) + if not token: + return request.redirect('/quote/%s' % order_id) + + # find an already existing transaction + tx = request.env['payment.transaction'].sudo().search([('reference', '=', order.name)], limit=1) + # set the transaction type to server2server + tx_type = 'server2server' + # check if the transaction exists, if not then it create one + tx = tx.check_or_create_sale_tx(order, token.acquirer_id, payment_token=token, tx_type=tx_type, add_tx_values={ + 'callback_model_id': request.env['ir.model'].sudo().search([('model', '=', order._name)], limit=1).id, + 'callback_res_id': order.id, + 'callback_method': '_confirm_online_quote', + }) + # set the transaction id into the session + request.session['quote_%s_transaction_id' % order_id] = tx.id + # proceed to the payment + tx.confirm_sale_token() + # redirect the user to the online quote + return request.redirect('/quote/%s/%s' % (order_id, order.access_token)) |
