[IMP] payment: small code improvements
- treat s2s transactions as such - don't filter out tokens saved on acquirers that are not set for full s2s mode, as tokens might get created through a form and still be usable - detect the submit event as well as the click on the 'Pay Now' button to avoid completely wrecking the payment flow by pressing the return key - correct start override in JS should chain promises
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import logging
|
||||
from unicodedata import normalize
|
||||
import psycopg2
|
||||
|
||||
from odoo import http, _
|
||||
@@ -131,6 +132,7 @@ class WebsitePayment(http.Controller):
|
||||
def pay(self, reference='', order_id=None, amount=False, currency_id=None, acquirer_id=None, **kw):
|
||||
env = request.env
|
||||
user = env.user.sudo()
|
||||
reference = normalize('NFKD', reference).encode('ascii','ignore').decode('utf-8')
|
||||
|
||||
# Default values
|
||||
values = {
|
||||
@@ -188,7 +190,7 @@ class WebsitePayment(http.Controller):
|
||||
})
|
||||
|
||||
values['acquirers'] = [acq for acq in acquirers if acq.payment_flow in ['form', 's2s']]
|
||||
values['pms'] = request.env['payment.token'].search([('acquirer_id', 'in', acquirers.filtered(lambda x: x.payment_flow == 's2s').ids)])
|
||||
values['pms'] = request.env['payment.token'].search([('acquirer_id', 'in', acquirers.ids)])
|
||||
|
||||
return request.render('payment.pay', values)
|
||||
|
||||
@@ -246,7 +248,7 @@ class WebsitePayment(http.Controller):
|
||||
'currency_id': int(currency_id),
|
||||
'partner_id': partner_id,
|
||||
'payment_token_id': pm_id,
|
||||
'type': 'form_save' if token.acquirer_id.save_token != 'none' and partner_id else 'form',
|
||||
'type': 'server2server',
|
||||
'return_url': return_url,
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ var _t = core._t;
|
||||
publicWidget.registry.PaymentForm = publicWidget.Widget.extend({
|
||||
selector: '.o_payment_form',
|
||||
events: {
|
||||
'submit': 'async payEvent',
|
||||
'click #o_payment_form_pay': 'async payEvent',
|
||||
'click #o_payment_form_add_pm': 'addPmEvent',
|
||||
'click button[name="delete_pm"]': 'deletePmEvent',
|
||||
@@ -21,10 +22,12 @@ publicWidget.registry.PaymentForm = publicWidget.Widget.extend({
|
||||
* @override
|
||||
*/
|
||||
start: function () {
|
||||
this.options = _.extend(this.$el.data(), this.options);
|
||||
this.updateNewPaymentDisplayStatus();
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
return this._super.apply(this, arguments);
|
||||
var self = this;
|
||||
return this._super.apply(this, arguments).then(function () {
|
||||
self.options = _.extend(self.$el.data(), self.options);
|
||||
self.updateNewPaymentDisplayStatus();
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -147,7 +150,11 @@ publicWidget.registry.PaymentForm = publicWidget.Widget.extend({
|
||||
var form = this.el;
|
||||
var checked_radio = this.$('input[type="radio"]:checked');
|
||||
var self = this;
|
||||
var button = ev.target;
|
||||
if (ev.type === 'submit') {
|
||||
var button = $(ev.target).find('*[type="submit"]')[0]
|
||||
} else {
|
||||
var button = ev.target;
|
||||
}
|
||||
|
||||
// first we check that the user has selected a payment method
|
||||
if (checked_radio.length === 1) {
|
||||
|
||||
@@ -152,7 +152,7 @@
|
||||
<t t-if="show_manage_btn">
|
||||
<a class="btn btn-link mb8 mt8" href="/my/payment_method">Manage your payment methods</a>
|
||||
</t>
|
||||
<button t-if="mode == 'manage' and list(filter(lambda x: x.payment_flow == 's2s', acquirers))" id="o_payment_form_add_pm" class="btn btn-primary btn-lg mb8 mt8">
|
||||
<button t-if="mode == 'manage' and list(filter(lambda x: x.payment_flow == 's2s', acquirers))" type="submit" id="o_payment_form_add_pm" class="btn btn-primary btn-lg mb8 mt8">
|
||||
<i class="fa fa-plus-circle"/> Add new card
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user