[FIX] payment_stripe: make it work

The module `payment_stripe` was apparently not designed to work with
module `website_payment`, althought the payment method is available. For
example:
- Go to '/my/home', select "Pay Now" on an invoice
- Try to pay with Stripe ==> nothing happens

This commit brings the necessary modifications to make it compatible
with `website_payment`. Moreover, it prevents the creation of 2
`payment.transactions`, which was not necessary.

opw-693421
This commit is contained in:
Nicolas Martinelli
2016-11-24 12:33:55 +01:00
parent a6b41186ca
commit 7e7205a7bf
4 changed files with 38 additions and 36 deletions
+3 -18
View File
@@ -29,24 +29,9 @@ class StripeController(http.Controller):
""" Create a payment transaction
Expects the result from the user input from checkout.js popup"""
acquirer = request.env['payment.acquirer'].browse(int(post.get('acquirer_id')))
sale_order_id = int(request.session.get('sale_order_id') or post.get('sale_order_id'))
order = request.env['sale.order'].sudo().browse(sale_order_id)
tx = request.env['payment.transaction'].sudo().create({
'acquirer_id': acquirer.id,
'reference': 'STRIPE-%s' % order.id,
'amount': float(post.get('amount')),
'currency_id': request.env['res.currency'].search([('name', '=', post.get('currency'))], limit=1).id,
'partner_id': request.env.user.partner_id.id,
'sale_order_id': order.id
})
order.write({
'payment_acquirer_id': acquirer.id,
'payment_tx_id': tx.id
})
request.session['sale_transaction_id'] = tx.id
tx = request.env['payment.transaction'].sudo().browse(
int(request.session.get('sale_transaction_id') or request.session.get('website_payment_tx_id', False))
)
response = tx._create_stripe_charge(tokenid=post['tokenid'])
_logger.info('Stripe: entering form_feedback with post data %s', pprint.pformat(response))
if response:
@@ -25,8 +25,10 @@ class PaymentAcquirerStripe(models.Model):
self.ensure_one()
stripe_tx_values = dict(tx_values)
temp_stripe_tx_values = {
'company': self.company_id.name,
'amount': tx_values.get('amount'),
'currency': tx_values.get('currency') and tx_values.get('currency').name or '',
'currency_id': tx_values.get('currency') and tx_values.get('currency').id or '',
'address_line1': tx_values['partner_address'],
'address_city': tx_values['partner_city'],
'address_country': tx_values['partner_country'] and tx_values['partner_country'].name or '',
+31 -18
View File
@@ -12,11 +12,6 @@ odoo.define('payment_stripe.stripe', function(require) {
}
},
token: function(token, args) {
var sale_order_id = $("input[name='return_url']").val().match(/quote\/([0-9]+)/);
if (sale_order_id) {
sale_order_id = parseInt(sale_order_id[1]);
}
handler.isTokenGenerate = true;
ajax.jsonRpc("/payment/stripe/create_charge", 'call', {
tokenid: token.id,
@@ -25,8 +20,7 @@ odoo.define('payment_stripe.stripe', function(require) {
acquirer_id: $("#acquirer_stripe").val(),
currency: $("input[name='currency']").val(),
invoice_num: $("input[name='invoice_num']").val(),
return_url: $("input[name='return_url']").val(),
sale_order_id: sale_order_id,
return_url: $("input[name='return_url']").val()
}).done(function(data){
handler.isTokenGenerate = false;
window.location.href = data;
@@ -41,27 +35,46 @@ odoo.define('payment_stripe.stripe', function(require) {
$(this).attr('disabled','disabled');
var $form = $(e.currentTarget).parents('form');
var acquirer_id = $(e.currentTarget).closest('div.oe_sale_acquirer_button,div.oe_quote_acquirer_button').data('id');
var acquirer_id = $(e.currentTarget).closest('div.oe_sale_acquirer_button,div.oe_quote_acquirer_button,div.o_website_payment_new_payment');
acquirer_id = acquirer_id.data('id') || acquirer_id.data('acquirer_id');
if (! acquirer_id) {
return false;
}
var so_token = $("input[name='token']").val();
var so_id = $("input[name='return_url']").val().match(/quote\/([0-9]+)/);
var so_id = $("input[name='return_url']").val().match(/quote\/([0-9]+)/) || undefined;
if (so_id) {
so_id = parseInt(so_id[1]);
}
e.preventDefault();
ajax.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {'so_id': so_id, 'so_token': so_token}).then(function (data) {
$form.html(data);
handler.open({
name: $("input[name='merchant']").val(),
description: $("input[name='invoice_num']").val(),
currency: $("input[name='currency']").val(),
amount: $("input[name='amount']").val()*100
if ($('.o_website_payment').length !== 0) {
ajax.jsonRpc('/website_payment/transaction', 'call', {
reference: $("input[name='invoice_num']").val(),
amount: $("input[name='amount']").val(),
currency_id: $("input[name='currency_id']").val(),
acquirer_id: acquirer_id
}).then(function (data) {
handler.open({
name: $("input[name='merchant']").val(),
description: $("input[name='invoice_num']").val(),
currency: $("input[name='currency']").val(),
amount: $("input[name='amount']").val()*100
});
});
});
} else {
ajax.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {
so_id: so_id,
so_token: so_token
}).then(function (data) {
$form.html(data);
handler.open({
name: $("input[name='merchant']").val(),
description: $("input[name='invoice_num']").val(),
currency: $("input[name='currency']").val(),
amount: $("input[name='amount']").val()*100
});
});
}
});
});
+2
View File
@@ -4,11 +4,13 @@
<template id="stripe_acquirer_button">
<form t-if="acquirer" method="post" target="_self">
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type='hidden' name='merchant' t-att-value="company"/>
<input type='hidden' name='amount' t-att-value="amount"/>
<input type="hidden" name='return_url' t-att-value='returndata'/>
<!--Order Information -->
<input type='hidden' name='invoice_num' t-att-value='reference'/>
<input type='hidden' name='currency' t-att-value='currency'/>
<input type='hidden' name='currency_id' t-att-value='currency_id'/>
<!-- Billing Information-->
<input type='hidden' name='name' t-att-value='name'/>
<input type='hidden' name='address_line1' t-att-value='address_line1'/>