Beispiel #1
0
def pay_ship_info(request):
    template = 'satchmo_stripe/pay_ship.html'
    payment_module = stripe_config
    form_handler = stripe_pay_ship_process_form
    result = payship.pay_ship_info_verify(request, payment_module)

    if not result[0]:
        return result[1]

    contact = result[1]
    working_cart = result[2]

    success, form = form_handler(request, contact, working_cart, payment_module)
    if success:
        return form

    template = lookup_template(payment_module, template)
    live = gateway_live(payment_module)

    last4=''
    cc_type=''
    user = threadlocals.get_current_user()
    if user and user.is_authenticated:
      stripe_id = utils.check_stripe_customer(threadlocals.get_current_user())
      if stripe_id:
        customer = utils.get_customer(stripe_id)
        if customer:
          last4 = customer.active_card.last4
          cc_type = customer.active_card.type
          if utils.card_is_about_to_expire(customer.active_card):
#Raise message telling user that the card is about to expire
            message = "The %s card ending in %s will expire in less than %d days, please enter a new card" % (cc_type,last4,payment_module.MIN_DAYS.value)
            messages.add_message(request, messages.WARNING, message)
            cc_type = ''
            last4=''


    ctx = RequestContext(request, {
        'form': form,
        'PAYMENT_LIVE': live,        
        'saved_card' : last4,
        'cc_type' : cc_type,
        'show_save_option' : payment_module.CAPTURE.value,
        })

    return render_to_response(template, context_instance=ctx)
Beispiel #2
0
def stripe_pay_ship_process_form(request, contact, working_cart, payment_module, allow_skip=True, *args, **kwargs):
    def _get_form(request, payment_module, *args, **kwargs):
        return StripePayShipForm(request, payment_module, *args, **kwargs) 

    
    if request.method == "POST":
        new_data = request.POST.copy()
        #if using saved card, fill in the stripe token field with the customer_id
        if not new_data['stripe_token'] and new_data['use_saved_cc']:
            new_data['stripe_token'] = utils.check_stripe_customer(threadlocals.get_current_user())
        form = _get_form(request, payment_module, new_data, *args, **kwargs)

        if form.is_valid():
            data = form.cleaned_data
            form.save(request, working_cart, contact, payment_module, data=data)
            url = lookup_url(payment_module, 'satchmo_checkout-step3')
            return (True, http.HttpResponseRedirect(url))
        else:
            log.info('Form didn\'t pass!!!!')
            for error in form.errors:
              log.info(error)
            pass
    else:
        order_data = {}
        try:
            order = Order.objects.from_request(request)
            if order.shipping_model:
                order_data['shipping'] = order.shipping_model

            kwargs['initial'] = order_data
            ordershippable = order.is_shippable
        except Order.DoesNotExist:
            pass

        form = _get_form(request, payment_module, *args, **kwargs)
        if not form.is_needed():
            form.save(request, working_cart, contact, None, data={'shipping': form.shipping_dict.keys()[0]})

            url = lookup_url(payment_module, 'satchmo_checkout-step3')
            return (True, http.HttpResponseRedirect(url))

    return (False, form)