diff options
| author | tbe-odoo <tbe@odoo.com> | 2017-07-28 15:52:34 +0200 |
|---|---|---|
| committer | Damien Bouvy <dbo@odoo.com> | 2017-08-14 08:30:59 +0200 |
| commit | 2df9c22d80be82b4ed7ffcd79f858e46c34e6479 (patch) | |
| tree | 5f3d7d68c4fc4e461e1a3f235266b14c23d0340a /addons/website_payment | |
| parent | c089d39a668fa6ab1f5d7867747da19d0b75f035 (diff) | |
[IMP] Payments & subscriptions: Improved Payments
- When registering a payment token, validating it using a payment of a small amount (~1.50€) followed by a refund allows ensuring
that the payment method is valid (i.e. checksumming the card number simple ensure the number is valid but not that the card exists).
This commit introduces a generic approach that must be implemented for each acquirer that has tokenization support.
This commit also introduces a generic payment token registration/usage template that can be adapted according to one's need.
- Introducing a new payment form that handles payment, deletion and adding payment method (only for server2server for the moment).
- On /my/payment_method, changed strings 'Payment Acquirers' to 'Payment Methods' which is more clear.
- Stripe can now be used to pay subscriptions.
Diffstat (limited to 'addons/website_payment')
5 files changed, 16 insertions, 117 deletions
diff --git a/addons/website_payment/controllers/main.py b/addons/website_payment/controllers/main.py index f3548e9090f..2dad4025b47 100644 --- a/addons/website_payment/controllers/main.py +++ b/addons/website_payment/controllers/main.py @@ -18,16 +18,9 @@ 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, 'verify_validity': 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}) return request.render("website_payment.pay_methods", values) - @http.route(['/website_payment/delete/'], methods=['POST'], type='http', auth="user", website=True) - def delete(self, delete_pm_id=None): - if delete_pm_id: - pay_meth = request.env['payment.token'].browse(int(delete_pm_id)) - pay_meth.unlink() - return request.redirect('/my/payment_method') - @http.route(['/website_payment/pay'], type='http', auth='public', website=True) def pay(self, reference='', amount=False, currency_id=None, acquirer_id=None, **kw): env = request.env @@ -90,25 +83,3 @@ 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/css/website_payment.css b/addons/website_payment/static/src/css/website_payment.css index 1892700fdd0..e9db1fd8d28 100644 --- a/addons/website_payment/static/src/css/website_payment.css +++ b/addons/website_payment/static/src/css/website_payment.css @@ -8,7 +8,7 @@ div.card_placeholder { width: 32px; height: 20px; position: absolute; - top: 34px; + top: 8px; right: 20px; -webkit-transition: 0.4s cubic-bezier(0.455, 0.03, 0.515, 0.955); transition: 0.4s cubic-bezier(0.455, 0.03, 0.515, 0.955); diff --git a/addons/website_payment/static/src/css/website_payment.sass b/addons/website_payment/static/src/css/website_payment.sass index a396bae99c1..e7de8c55cd5 100644 --- a/addons/website_payment/static/src/css/website_payment.sass +++ b/addons/website_payment/static/src/css/website_payment.sass @@ -10,7 +10,7 @@ div.card_placeholder width: 32px height: 20px position: absolute - top: 34px + top: 8px right: 20px -webkit-transition: .4s cubic-bezier(0.455,0.03,0.515,0.955) transition: .4s cubic-bezier(0.455,0.03,0.515,0.955) diff --git a/addons/website_payment/static/src/js/payment_acquirer.js b/addons/website_payment/static/src/js/payment_acquirer.js index e047694ac03..d7397f1b04d 100644 --- a/addons/website_payment/static/src/js/payment_acquirer.js +++ b/addons/website_payment/static/src/js/payment_acquirer.js @@ -60,58 +60,3 @@ $(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 += '<p><a href="/my/subscription/' + sub.id + '">' + sub.name + '</a><p/>'; - }); - - content = $('<div>').html('<p>This card is currently linked to the following records:<p/>' + 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 bdaff74d0c4..27a4cada196 100644 --- a/addons/website_payment/views/website_payment_templates.xml +++ b/addons/website_payment/views/website_payment_templates.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <odoo> <data> - <template id="header_footer_custom_payment" inherit_id="website.footer_default" customize_show="True" active="False" name="Payment Acquirers"> + <template id="header_footer_custom_payment" inherit_id="website.footer_default" customize_show="True" active="False" name="Payment Methods"> <xpath expr="//div[@id='info']" position="inside"> <h4 class="payment_method_title">Payment Acquirer</h4> <ul class="payment_method_list list-inline"> @@ -24,45 +24,28 @@ </xpath> </template> - <template id="pay_methods" name="Payment Acquirers"> + <template id="pay_methods" name="Payment Methods"> <t t-call="website.layout"> - <t t-set="additional_title">Payment Acquirers</t> + <t t-set="additional_title">Payment Methods</t> <div class="wrap"> <div class="container"> <div class="row"> <div class="col-sm-6"> <ol class="breadcrumb mt8"> <li><a href="/my/home"><i class="fa fa-home"/></a></li> - <li>Payment Acquirers</li> + <li>Payment Methods</li> </ol> </div> </div> - <h1>Payment Acquirers</h1> - <h4 t-if="acquirers">Add a new payment acquirer:</h4> - <div t-if="acquirers" class="row"> - <div class="col-sm-8"> - <div t-if="error_message" class="alert alert-danger"> - <t t-foreach="error_message" t-as="err"><t t-esc="err"/><br /></t> + <div class="clearfix"> + <div class="row"> + <div class="col-sm-8"> + <h3>Manage your Payment Methods</h3> + <t t-call="payment.payment_tokens_list"> + <t t-set="mode" t-value="'manage'"/> + <t t-set="verify_validity" t-value="True"/> + </t> </div> - <div t-if='len(acquirers)>1'> - <label class="control-label" for="pm_acquirer_id">Acquirer</label> - <select name="pm_acquirer_id" class="form-control"> - <t t-foreach="acquirers" t-as="acquirer"> - <option t-att-value="acquirer.id" t-esc="acquirer.name"/> - </t> - </select> - </div> - <t t-foreach="acquirers" t-as="acquirer"> - <div t-raw="acquirer.form" t-att-data-acquirer-id="acquirer.id" t-attf-class="acquirer #{'hidden' if acquirer!=acquirers[0] else ''}"/> - </t> - </div> - </div> - <div t-if="pms" class="clearfix"> - <h4>Your payment Methods</h4> - <t t-set="show_delete" t-value="True"/> - <t t-set="form_action" t-value="'/website_payment/delete/'"/> - <div class="col-sm-8"> - <t t-call="payment.payment_tokens_list"/> </div> </div> </div> @@ -73,7 +56,7 @@ <template id="pay_meth_link" inherit_id="website_portal.portal_layout" customize_show="True"> <xpath expr="//div[@class='o_my_details']" position="inside"> <t t-if="request.env['payment.acquirer'].search([('website_published', '=', True), ('registration_view_template_id', '!=', False)])"> - <div class='manage_payment_method mt16'><a href="/my/payment_method">Manage your payment acquirers</a></div> + <div class='manage_payment_method mt16'><a href="/my/payment_method">Manage your Payment Methods</a></div> </t> </xpath> </template> |
