def simple_pay_ship_process_form(request, contact, working_cart, payment_module, allow_skip=True): if request.method == "POST": new_data = request.POST.copy() form = SimplePayShipForm(request, payment_module, new_data) if form.is_valid(): form.save(request, working_cart, contact, payment_module) url = lookup_url(payment_module, 'satchmo_checkout-step3') return (True, http.HttpResponseRedirect(url)) else: return (False, form) else: order_data = None try: order = Order.objects.from_request(request) if order.shipping_model: order_data = {} order_data['shipping'] = order.shipping_model ordershippable = order.is_shippable except Order.DoesNotExist: pass form = SimplePayShipForm(request, payment_module, order_data) if allow_skip: skipping = False skipstep = form.shipping_hidden or not ordershippable or (len(form.shipping_dict) == 1) if skipstep: log.debug('Skipping pay ship, nothing to select for shipping') # no shipping choice = skip this step form.save(request, working_cart, contact, payment_module, data={'shipping' : form.fields['shipping'].initial}) skipping = True elif not form.is_needed(): log.debug('Skipping pay ship because form is not needed, nothing to pay') form.save(request, working_cart, contact, None, data={'shipping' : form.shipping_dict.keys()[0]}) skipping = True if skipping: url = lookup_url(payment_module, 'satchmo_checkout-step3') return (True, http.HttpResponseRedirect(url)) return (False, form)
def simple_pay_ship_process_form(request, contact, working_cart, payment_module): if request.method == "POST": new_data = request.POST.copy() form = SimplePayShipForm(request, payment_module, new_data) if form.is_valid(): form.save(request, working_cart, contact, payment_module) else: form = SimplePayShipForm(request, payment_module) if config_value('PAYMENT','USE_DISCOUNTS') or not form.shipping_hidden: return (False, form) else: # No discounts, no shipping choice = skip this step order = get_or_create_order( request, working_cart, contact, {'shipping': form.fields['shipping'].initial, 'discount': ''} ) processor_module = payment_module.MODULE.load_module('processor') processor = processor_module.PaymentProcessor(payment_module) orderpayment = processor.create_pending_payment(order=order) url = lookup_url(payment_module, 'satchmo_checkout-step3') return (True, http.HttpResponseRedirect(url))
def simple_pay_ship_process_form(request, contact, working_cart, payment_module, allow_skip=True): if request.method == "POST": new_data = request.POST.copy() form = SimplePayShipForm(request, payment_module, new_data) if form.is_valid(): form.save(request, working_cart, contact, payment_module) url = lookup_url(payment_module, 'satchmo_checkout-step3') return (True, http.HttpResponseRedirect(url)) else: return (False, form) else: order_data = None try: order = Order.objects.from_request(request) if order.shipping_model: order_data = {} order_data['shipping'] = order.shipping_model ordershippable = order.is_shippable except Order.DoesNotExist: ordershippable = False form = SimplePayShipForm(request, payment_module, order_data) if allow_skip: skipping = False skipstep = form.shipping_hidden or not ordershippable or (len( form.shipping_dict) == 1) if skipstep: log.debug('Skipping pay ship, nothing to select for shipping') # no shipping choice = skip this step form.save(request, working_cart, contact, payment_module, data={'shipping': form.fields['shipping'].initial}) skipping = True elif not form.is_needed(): log.debug( 'Skipping pay ship because form is not needed, nothing to pay' ) form.save(request, working_cart, contact, None, data={'shipping': form.shipping_dict.keys()[0]}) skipping = True if skipping: url = lookup_url(payment_module, 'satchmo_checkout-step3') return (True, http.HttpResponseRedirect(url)) return (False, form)