[IMP] website_sale: end of checkout process improvements

- added a controller that validates the payment: confirm the quotation (if paid)
and send it by email
- some fixes in payment routes
- some cleaning in payment template, removed unnecessary code, added a class on a
div to ease the submit button management

bzr revid: tde@openerp.com-20131120140321-mderltwy8xp2vfn4
This commit is contained in:
Thibault Delavallée 2013-11-20 15:03:21 +01:00
parent 91be9da35b
commit 5dcb10fc01
4 changed files with 56 additions and 23 deletions

View File

@ -686,7 +686,8 @@ class Ecommerce(http.Controller):
return request.website.render("website_sale.payment", values)
@website.route(['/shop/payment/transaction/<int:acquirer_id>/'], type='http', auth="public")
@website.route(['/shop/payment/transaction/<int:acquirer_id>'],
type='http', methods=['POST'], 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.
@ -703,7 +704,7 @@ class Ecommerce(http.Controller):
transaction_obj = request.registry.get('payment.transaction')
order = request.registry['website'].get_current_order(request.cr, request.uid, context=request.context)
if not order or not order.order_line or not acquirer_id:
if not order or not order.order_line or acquirer_id is None:
return request.redirect("/shop/checkout/")
# find an already existing transaction
@ -727,21 +728,50 @@ class Ecommerce(http.Controller):
acquirer_total_url = '%s?%s' % (acquirer_form_post_url, urllib.urlencode(post))
return request.redirect(acquirer_total_url)
@website.route([
'/shop/payment/transaction/get_status',
'/shop/payment/transaction/get_status/<int:transaction_>'
], type='json', auth="public", multilang=True)
def payment_validation(self, transaction_id=None, **post):
@website.route('/shop/payment/confirm', type='json', auth="public", multilang=True)
def payment_confirm(self, transaction_id=None, **post):
cr, uid, context = request.cr, request.uid, request.context
payment_obj = request.registry.get('payment.transaction')
if transaction_id:
tx = payment_obj.browse(cr, uid, transaction_id, context=context)
else:
tx = context.get('website_sale_transaction')
return {
'state': tx.state,
}
@website.route('/shop/payment/validate', type='json', auth="public", multilang=True)
def payment_validate(self):
cr, uid, context = request.cr, request.uid, request.context
email_act = None
sale_order_obj = request.registry['sale.order']
order = context.get('website_sale_order')
tx = context.get('website_sale_transaction')
if not order or not tx:
return request.redirect("/shop/checkout/")
if tx.state == 'done':
# confirm the quotation
sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context)
# send by email
email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context)
elif tx.state == 'pending':
# send by email
email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context)
elif tx.state == 'cancel':
# cancel the quotation
sale_order_obj.action_cancel(cr, SUPERUSER_ID, [order.id], context=request.context)
if email_act:
create_ctx = email_act.get('context', context)
compose_id = request.registry['mail.compose.message'].create(cr, uid, {}, context=create_ctx)
request.registry['mail.compose.message'].send_mail(cr, uid, [compose_id], context=create_ctx)
return True
@website.route(['/shop/confirmation/'], type='http', auth="public", multilang=True)
def payment_confirmation(self, **post):
context = request.context

View File

@ -6,9 +6,9 @@ $(document).ready(function () {
* 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 acquirer_id = $(this).closest('form').closest('div.oe_payment_acquirer').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 + '/');
$(this).closest("form").attr("action", '/shop/payment/transaction/' + acquirer_id);
});
});

View File

@ -2,9 +2,14 @@ $(document).ready(function () {
var _poll_nbr = 0;
function payment_transaction_validate() {
return openerp.jsonRpc('/shop/payment/validate', 'call', {});
}
function payment_transaction_poll_status() {
return openerp.jsonRpc('/shop/payment/transaction/get_status', 'call', {
}).then(function (result) {
return openerp.jsonRpc('/shop/payment/confirm', 'call', {
}).done(function (result) {
// console.log('--done', result);
_poll_nbr += 1;
if (result.state == 'done') {
$('div.oe_website_sale_confirmation').html(function() {
@ -12,13 +17,14 @@ $(document).ready(function () {
});
}
else if (result.state == 'pending') {
if (_poll_nbr <= 10) {
if (_poll_nbr <= 2) {
$('div.oe_website_sale_confirmation').html(function() {
return "<h2>Waiting validation ...</h2>";
});
setTimeout(function () {
return payment_transaction_poll_status();
return inner_done = payment_transaction_poll_status();
}, 1000);
// return inner_done;
}
else {
$('div.oe_website_sale_confirmation').html(function() {
@ -34,5 +40,8 @@ $(document).ready(function () {
});
}
payment_transaction_poll_status();
payment_transaction_poll_status().done(function (result) {
// console.log('finished', result);
payment_transaction_validate();
});
});

View File

@ -892,21 +892,15 @@
<div>
<t t-foreach="payments or []" t-as="payment">
<label t-if="payment._content">
<input t-att-value="payment.id" type="radio" name="payment_type"/> <span t-field="payment.name"/> </label>
<input t-att-value="payment.id" type="radio" name="payment_type"/> <span t-field="payment.name"/>
</label>
</t>
</div>
<t t-foreach="payments" t-as="payment">
<div t-att-data-id="payment.id" t-raw="payment._content" class="hidden"/>
<div t-att-data-id="payment.id" t-raw="payment._content" class="oe_payment_acquirer hidden"/>
</t>
</div>
<div class="js_payment_validation mb64" t-if="payment_acquirer_id">
Please wait, we validate your payment.
<div>
<t t-esc="validation"/>
</div>
</div>
</div>
<div class="oe_structure"/>
</div>