[IMP] website_sale: added basic management of acquirer button in sale.
The action of the rendered button is catched, re-routed to a custom controller in sale that creates the payment.transaction, or fetch an already-existing one. Once the transaction is found or created, the user is redirected to the acquirer transaction url. Next step: display the transaction status in the payment page. bzr revid: tde@openerp.com-20131115133414-jiob0gkpv106db27
This commit is contained in:
parent
d55b40d3a1
commit
28c864b00f
|
@ -2,6 +2,7 @@
|
|||
import random
|
||||
import uuid
|
||||
import simplejson
|
||||
import urllib
|
||||
|
||||
import werkzeug.exceptions
|
||||
|
||||
|
@ -619,6 +620,7 @@ class Ecommerce(http.Controller):
|
|||
'street': post['shipping_street'],
|
||||
'city': post['shipping_city'],
|
||||
'name': post['shipping_name'],
|
||||
'email': post['email'],
|
||||
'type': 'delivery',
|
||||
'parent_id': partner_id,
|
||||
'country_id': post['shipping_country_id'],
|
||||
|
@ -654,8 +656,13 @@ class Ecommerce(http.Controller):
|
|||
if not order or not order.order_line:
|
||||
return request.redirect("/shop/checkout/")
|
||||
|
||||
if 'website_sale_order' in context:
|
||||
shipping_pid = context['website_sale_order'].partner_id.id
|
||||
else:
|
||||
shipping_pid = False
|
||||
|
||||
values = {
|
||||
'partner': False,
|
||||
'partner': shipping_pid,
|
||||
'payment_acquirer_id': payment_acquirer_id,
|
||||
'order': order
|
||||
}
|
||||
|
@ -677,10 +684,52 @@ class Ecommerce(http.Controller):
|
|||
order.name,
|
||||
order.amount_total,
|
||||
order.pricelist_id.currency_id,
|
||||
partner_id=shipping_pid,
|
||||
tx_custom_values={
|
||||
'return_url': '/shop/payment',
|
||||
},
|
||||
context=context)
|
||||
|
||||
return request.website.render("website_sale.payment", values)
|
||||
|
||||
@website.route(['/shop/payment/transaction/<int:acquirer_id>/'], type='http', auth="public")
|
||||
def payment_transaction(self, acquirer_id=None, **post):
|
||||
""" Hook method that creates a payment.transaction and redirect to the
|
||||
acquirer, using post values to re-create the post action.
|
||||
|
||||
:param int acquirer_id: id of a payment.acquirer record. If not set the
|
||||
user is redirected to the checkout page
|
||||
:param dict post: should coutain only post data used by the acquirer
|
||||
"""
|
||||
# @TDEFIXME: don't know why we received those data, but should not be send to the acquirer
|
||||
post.pop('submit.x', None)
|
||||
post.pop('submit.y', None)
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
payment_obj = request.registry.get('payment.acquirer')
|
||||
transaction_obj = request.registry.get('payment.transaction')
|
||||
order = get_current_order()
|
||||
|
||||
if not order or not order.order_line or not acquirer_id:
|
||||
return request.redirect("/shop/checkout/")
|
||||
|
||||
# find an already existing transaction
|
||||
tx_ids = transaction_obj.search(cr, uid, [
|
||||
('reference', '=', order.name), ('acquirer_id', '=', acquirer_id)
|
||||
], context=context)
|
||||
if not tx_ids:
|
||||
transaction_obj.create(cr, uid, {
|
||||
'acquirer_id': acquirer_id,
|
||||
'type': 'form',
|
||||
'amount': order.amount_total,
|
||||
'currency_id': order.pricelist_id.currency_id.id,
|
||||
'partner_id': order.partner_id.id,
|
||||
'reference': order.name,
|
||||
}, context=context)
|
||||
|
||||
acquirer_form_post_url = payment_obj.get_form_action_url(cr, uid, acquirer_id, context=context)
|
||||
acquirer_total_url = '%s?%s' % (acquirer_form_post_url, urllib.urlencode(post))
|
||||
return request.redirect(acquirer_total_url)
|
||||
|
||||
@website.route(['/shop/payment_validation/'], type='json', auth="public", multilang=True)
|
||||
def payment_validation(self, payment_acquirer_id=None, **post):
|
||||
payment_obj = request.registry.get('payment.acquirer')
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
$(document).ready(function () {
|
||||
|
||||
/* Hitting the payment button: payment transaction process begins
|
||||
* We redirect the user to a custom shop page in oder to create the
|
||||
* transaction. The form POST data will be used to perform the post
|
||||
* query.
|
||||
*/
|
||||
$('input#payment_submit').on('click', function (ev) { // TDEFIXME: change input#ID to input inside payment form, less strict
|
||||
var acquirer_id = $(this).closest('form').closest('div').data().id || 0;
|
||||
var form_action = $(this).closest("form").attr('action');
|
||||
console.log('cliking on submit for payment - redirecting from', form_action, 'to shop with acqurier_id', acquirer_id);
|
||||
$(this).closest("form").attr("action", '/shop/payment/transaction/' + acquirer_id + '/');
|
||||
});
|
||||
|
||||
// openerp.jsonRpc('/shop/payment/transaction', 'call', {
|
||||
// }).then(function (result) {
|
||||
// console.log(result);
|
||||
// });
|
||||
});
|
|
@ -792,6 +792,7 @@
|
|||
<t t-call="website.layout">
|
||||
<t t-set="head">
|
||||
<script type="text/javascript" src="/website_sale/static/src/js/website_sale.js"></script>
|
||||
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_payment.js"></script>
|
||||
<link rel='stylesheet' href='/website_sale/static/src/css/website_sale.css'/>
|
||||
<t t-raw="head or ''"/>
|
||||
</t>
|
||||
|
|
Loading…
Reference in New Issue