[IMP] website_sale: allow saving card data from checkout

Instead of having to register a card then do a payment, a little
checkbox during the checkout process is usually simpler.
This commit is contained in:
Damien Bouvy
2016-09-01 15:58:41 +02:00
parent cd98731284
commit d9c9d0c96b
3 changed files with 13 additions and 11 deletions
+3 -4
View File
@@ -769,7 +769,7 @@ class WebsiteSale(http.Controller):
return request.redirect("/shop/payment?error=no_token_or_missmatch_tx")
@http.route(['/shop/payment/transaction/<int:acquirer_id>'], type='json', auth="public", website=True)
def payment_transaction(self, acquirer_id, token=None):
def payment_transaction(self, acquirer_id, tx_type='form', token=None):
""" Json method that creates a payment.transaction, used to create a
transaction when the user clicks on 'pay now' button. After having
created the transaction, the event continues and the user is redirected
@@ -780,7 +780,6 @@ class WebsiteSale(http.Controller):
"""
Transaction = request.env['payment.transaction'].sudo()
order = request.website.sale_get_order()
if not order or not order.order_line or acquirer_id is None:
return request.redirect("/shop/checkout")
@@ -795,11 +794,11 @@ class WebsiteSale(http.Controller):
# new or distinct token
tx = False
elif tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ?
tx.write(dict(Transaction.on_change_partner_id(order.partner_id.id).get('value', {}), amount=order.amount_total))
tx.write(dict(Transaction.on_change_partner_id(order.partner_id.id).get('value', {}), amount=order.amount_total, type=tx_type))
if not tx:
tx_values = {
'acquirer_id': acquirer_id,
'type': 'form',
'type': tx_type,
'amount': order.amount_total,
'currency_id': order.pricelist_id.currency_id.id,
'partner_id': order.partner_id.id,
@@ -24,13 +24,13 @@ $(document).ready(function () {
$("div.js_payment a.list-group-item").removeClass("list-group-item-info");
$('span.js_radio').switchClass(ico_on, ico_off, 0);
if (token) {
$("div.oe_sale_acquirer_button div.pre_msg").hide();
$("div.oe_sale_acquirer_button div.token_hide").hide();
$(ev.currentTarget).find('span.js_radio').switchClass(ico_off, ico_on, 0);
$(ev.currentTarget).parents('li').find('input').prop("checked", true);
$(ev.currentTarget).addClass("list-group-item-info");
}
else{
$("div.oe_sale_acquirer_button div.pre_msg").show();
$("div.oe_sale_acquirer_button div.token_hide").show();
}
$("div.oe_sale_acquirer_button[data-id]", $payment).addClass("hidden");
$("div.oe_sale_acquirer_button[data-id='"+payment_id+"']", $payment).removeClass("hidden");
@@ -46,7 +46,7 @@ $(document).ready(function () {
var acquirer = $(ev.currentTarget).parents('div.oe_sale_acquirer_button').first();
var acquirer_id = acquirer.data('id');
var acquirer_token = acquirer.attr('data-token'); // !=data
var params = {};
var params = {'tx_type': acquirer.find('input[name="odoo_save_token"]').is(':checked')?'form_save':'form'};
if (! acquirer_id) {
return false;
}
+7 -4
View File
@@ -1350,9 +1350,6 @@
<span t-if="token.acquirer_id.fees_active">(processing fees apply)</span>
</a>
</t>
<a href="/my/payment_method?redirect=/shop/payment" class="list-group-item" >
<span class="fa fa-plus-square"/> <b>New card</b>
</a>
</div>
</li>
</ul>
@@ -1361,7 +1358,13 @@
<t t-foreach="acquirers or []" t-as="acquirer" id="acquirers_list">
<div t-att-data-id="acquirer.id" class="oe_sale_acquirer_button hidden pull-right">
<div t-raw="acquirer.button" />
<div class="pre_msg" t-field="acquirer.pre_msg" />
<div class="token_hide">
<div t-if="acquirer.save_token == 'ask'">
<input type="checkbox" name="odoo_save_token"/>
<label for="odoo_save_token">Save my payment data</label>
</div>
<div class="pre_msg" t-field="acquirer.pre_msg" />
</div>
</div>
</t>
</div>