Skip to content

Commit

Permalink
[FIX] payment: Unable to pay if character '/' in reference
Browse files Browse the repository at this point in the history
- On 'website_payment/pay' if the reference contains a '/' the payment will never succeed.
  It is due to the fact that in the template "payment.pay" were setting "prepare_tx_url" and "form_action" using this reference.
  But having a '/' in the reference breaks the URL to call to create a transaction.
  So when creating a transaction (or even paying in S2S) the payment never succeed and returns a HTTP 404 error.
  • Loading branch information
tbe-odoo committed Mar 2, 2018
1 parent aded844 commit 4d90507
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions addons/payment/controllers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def _get_existing_transaction(self, reference, amount, partner_id, currency_id,

return tx

@http.route(['/website_payment/transaction/<string:reference>/<string:amount>/<string:currency_id>',], type='json', auth='public')
@http.route(['/website_payment/transaction/<string:reference>/<string:amount>/<string:currency_id>',
'/website_payment/transaction/v2/<string:amount>/<string:currency_id>/<path:reference>',], type='json', auth='public')
def transaction(self, acquirer_id, reference, amount, currency_id, **kwargs):
partner_id = request.env.user.partner_id.id if not request.env.user._is_public() else False
acquirer = request.env['payment.acquirer'].browse(acquirer_id)
Expand All @@ -100,7 +101,8 @@ def transaction(self, acquirer_id, reference, amount, currency_id, **kwargs):

return acquirer.sudo().render(reference, float(amount), int(currency_id), values=render_values)

@http.route(['/website_payment/token/<string:reference>/<float:amount>/<int:currency_id>'], type='http', auth='public', website=True)
@http.route(['/website_payment/token/<string:reference>/<string:amount>/<string:currency_id>',
'/website_payment/token/v2/<string:amount>/<string:currency_id>/<path:reference>'], type='http', auth='public', website=True)
def payment_token(self, pm_id, reference, amount, currency_id, return_url=None, **kwargs):
token = request.env['payment.token'].browse(int(pm_id))

Expand Down
4 changes: 2 additions & 2 deletions addons/payment/views/payment_portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
<p><b>Amount:</b> <t t-esc="amount" t-options="{'widget': 'monetary', 'display_currency': currency}"/></p>
<t t-call="payment.payment_tokens_list" t-if="reference and amount and currency">
<t t-set="mode" t-value="'payment'"/>
<t t-set="prepare_tx_url" t-value="'/website_payment/transaction/' + reference + '/' + str(amount) + '/' + str(currency.id)"/>
<t t-set="form_action" t-value="'/website_payment/token/' + reference + '/' + str(amount) + '/' + str(currency.id)"/>
<t t-set="prepare_tx_url" t-value="'/website_payment/transaction/v2/' + str(amount) + '/' + str(currency.id) + '/' + reference"/>
<t t-set="form_action" t-value="'/website_payment/token/v2/' + str(amount) + '/' + str(currency.id) + '/' + reference"/>
</t>
<div t-if="not (s2s_acquirers or form_acquirers)" class="alert alert-danger">
<p>No payment acquirer found.</p>
Expand Down
4 changes: 2 additions & 2 deletions addons/payment_stripe/static/src/js/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ odoo.define('payment_stripe.stripe', function(require) {

if ($('.o_website_payment').length !== 0) {
var invoice_num = $("input[name='invoice_num']").val();
var url = _.str.sprintf("/website_payment/transaction/%s/%f/%s",
invoice_num, amount, currency_id);
var url = _.str.sprintf("/website_payment/transaction/v2/%f/%s/%s",
amount, currency_id, invoice_num);

var create_tx = ajax.jsonRpc(url, 'call', {
acquirer_id: acquirer_id
Expand Down

0 comments on commit 4d90507

Please sign in to comment.