Skip to content
Permalink
Browse files

[FIX] account_payment: success url

- Activate online payment of invoices
- Activate and configure Stripe
- Create an invoice, access it through the portal
- Pay it with Stripe

The user is redirected to `/my` instead of `/my/invoices/<id>`.

The root cause is because Stripe creates 2 transactions, the second
being created at:

https://github.com/odoo/odoo/blob/43295c2a3741fb98f9c5d1a506652442efed0a82/addons/payment_stripe/static/src/js/stripe.js#L108

This second transaction, which is used to record the payment, doesn't
contain the appropriate `success_url`.

The best fix would probably be to either:
- prevent the creation of the second transaction by refactoring
  `stripe.js`
- pass the appropriate `success_url` to the `stripe_form` template
- reuse existing draft transactions instead of creating a new one

None of these solutions is really suitable for stable since it might
require some heavy modification. However, a simple workaround is to
change the fallback `success_url`since we have all the necessary information
to build it.

opw-1997283
  • Loading branch information...
nim-odoo committed May 15, 2019
1 parent 43295c2 commit d0e0450e6f2b5395329462a4f1266c057c8bbb38
Showing with 9 additions and 3 deletions.
  1. +9 −3 addons/account_payment/controllers/payment.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from werkzeug.urls import url_encode

from odoo import http, _
from odoo.addons.portal.controllers.portal import _build_url_w_params
from odoo.addons.payment.controllers.portal import PaymentProcessing
@@ -17,8 +19,6 @@ def invoice_pay_form(self, acquirer_id, invoice_id, save_token=False, access_tok
:return html: form containing all values related to the acquirer to
redirect customers to the acquirer website """
success_url = kwargs.get('success_url', '/my')

invoice_sudo = request.env['account.invoice'].sudo().browse(invoice_id)
if not invoice_sudo:
return False
@@ -30,6 +30,10 @@ def invoice_pay_form(self, acquirer_id, invoice_id, save_token=False, access_tok

if request.env.user._is_public():
save_token = False # we avoid to create a token for the public user

success_url = kwargs.get(
'success_url', "%s?%s" % (invoice_sudo.access_url, url_encode({'access_token': access_token}) if access_token else '')
)
vals = {
'acquirer_id': acquirer_id,
'return_url': success_url,
@@ -54,7 +58,6 @@ def invoice_pay_form(self, acquirer_id, invoice_id, save_token=False, access_tok
def invoice_pay_token(self, invoice_id, pm_id=None, **kwargs):
""" Use a token to perform a s2s transaction """
error_url = kwargs.get('error_url', '/my')
success_url = kwargs.get('success_url', '/my')
access_token = kwargs.get('access_token')
params = {}
if access_token:
@@ -65,6 +68,9 @@ def invoice_pay_token(self, invoice_id, pm_id=None, **kwargs):
params['error'] = 'pay_invoice_invalid_doc'
return request.redirect(_build_url_w_params(error_url, params))

success_url = kwargs.get(
'success_url', "%s?%s" % (invoice_sudo.access_url, url_encode({'access_token': access_token}) if access_token else '')
)
try:
token = request.env['payment.token'].sudo().browse(int(pm_id))
except (ValueError, TypeError):

0 comments on commit d0e0450

Please sign in to comment.
You can’t perform that action at this time.