diff --git a/addons/website_payment/controllers/main.py b/addons/website_payment/controllers/main.py
index 31244b87cda..f3548e9090f 100644
--- a/addons/website_payment/controllers/main.py
+++ b/addons/website_payment/controllers/main.py
@@ -18,7 +18,7 @@ class WebsitePayment(http.Controller):
}
return_url = request.params.get('redirect', '/my/payment_method')
for acquirer in acquirers:
- acquirer.form = acquirer.sudo()._registration_render(request.env.user.partner_id.id, {'error': {}, 'error_message': [], 'return_url': return_url, 'json': False, 'bootstrap_formatting': True})
+ acquirer.form = acquirer.sudo()._registration_render(request.env.user.partner_id.id, {'error': {}, 'error_message': [], 'return_url': return_url, 'json': False, 'bootstrap_formatting': True, 'verify_validity': True})
return request.render("website_payment.pay_methods", values)
@http.route(['/website_payment/delete/'], methods=['POST'], type='http', auth="user", website=True)
@@ -90,3 +90,25 @@ class WebsitePayment(http.Controller):
return request.render('website_payment.confirm', {'tx': tx, 'status': status, 'message': message})
else:
return request.redirect('/my/home')
+
+ @http.route(['/website_payment/get_linked_records'], type='json', auth='user', website=True)
+ def get_linked_records(self, payment_token_id):
+ payment_token_id = int(payment_token_id)
+
+ res = []
+ token = request.env['payment.token'].search([('id','=',payment_token_id)])
+ # if the payment token is valid
+ if token:
+ # then we retrieve the description for the model sale.subscription
+ subscription_description = request.env['sale.subscription']._description
+ # we retrieve all the linked records for the token
+ records = token._get_linked_records()
+ # transform the list of tuple into a dict so we can search easily
+ records = dict(records[payment_token_id])
+ # if there's subscriptions linked to that token
+ if records.get(subscription_description):
+ subscriptions = records[subscription_description]
+ # we create our json with all the info needed
+ for r in subscriptions:
+ res.append({'id': r.id, 'name': r.name})
+ return res
\ No newline at end of file
diff --git a/addons/website_payment/static/src/js/payment_acquirer.js b/addons/website_payment/static/src/js/payment_acquirer.js
index d7397f1b04d..e047694ac03 100644
--- a/addons/website_payment/static/src/js/payment_acquirer.js
+++ b/addons/website_payment/static/src/js/payment_acquirer.js
@@ -60,3 +60,58 @@ $(document).ready(function () {
});
});
+
+
+odoo.define('website_payment.payment_acquirer', function (require) {
+"use strict";
+
+var website = require('website.website');
+var ajax = require('web.ajax');
+var Dialog = require('web.Dialog');
+
+ var payment_methods = $('#payment_tokens_list');
+
+ payment_methods.find('button[name="delete_pm_id"]').on('click', function(ev){
+ ev.stopPropagation();
+ ev.preventDefault();
+ var self = this;
+
+ // we retrieve the selected payment method id
+ var payment_method_id = ev.target.value;
+
+ var Delete = function()
+ {
+ payment_methods.find('button[name="delete_pm_id"]').off("click");
+ ev.target.click();
+ };
+
+ ajax.jsonRpc('/website_payment/get_linked_records', 'call', {
+ 'payment_token_id': payment_method_id,
+ }).done(function (response) {
+ // if there's records linked to the payment method we're trying to delete
+ if(response.length > 0)
+ {
+ var content = '';
+
+ response.forEach(function(sub) {
+ content += '
' + sub.name + '
';
+ });
+
+ content = $('
').html('
This card is currently linked to the following records:
' + content);
+ // Then we display the list of the records and ask the user if he really want to remove the ppayment method.
+ new Dialog(self, {
+ title: 'Warning!',
+ size: 'medium',
+ $content: content,
+ buttons: [
+ {text: 'Confirm Deletion', classes: 'btn-primary', close: true, click: Delete},
+ {text: 'Cancel', close: true}]}).open();
+ }
+ // otherwise if the user has no records linked to this payment method, then we just delete it.
+ else
+ {
+ Delete();
+ }
+ });
+ });
+});
diff --git a/addons/website_payment/views/website_payment_templates.xml b/addons/website_payment/views/website_payment_templates.xml
index 074d59a0552..bdaff74d0c4 100644
--- a/addons/website_payment/views/website_payment_templates.xml
+++ b/addons/website_payment/views/website_payment_templates.xml
@@ -40,11 +40,11 @@
Payment Acquirers
Add a new payment acquirer:
-
+
-
+
-
-
Delete a payment acquirer:
-
-
-
+
+
Your payment Methods
+
+
+
+