Ejemplo n.º 1
0
def show_cart(request):
  """
  Show the contents of the cart, include tax (9.1%) and shipping (Free!)
  When ready to continue they press button
  """
  logger.info(request)
  (cart_list, pretax_total, tax, amountTaxed, shipping_total, total) = get_cart_details(request)

  return render_to_response("website/checkout/show_cart.html", 
    {
      "cart_list" : cart_list,
      "cart_pretax" : "%.2f" % round(pretax_total,2),
      "cart_tax" : "%.1f" % round(tax*100,1),
      "cart_tax_total" : "%.2f" % round(amountTaxed,2),
      "shipping_total" : "%.2f" % round(shipping_total,2),
      "cart_total" : "%.2f" % round(total,2),
    })
Ejemplo n.º 2
0
def shop_item_selected(request, item_id):
  try:
    item = Item.objects.get(id=item_id)
    size_list = item.quantity.order_by("id")
    logger.info(item)
    jsonDict = {
      "item":item.json(),
      "size_list": size_list,
      "quantity_list": range(1,11), 
      "paypal_debug" : settings.PAYPAL_DEBUG,
    }
    jsonDict.update(csrf(request))
    logger.debug(jsonDict)
    return render_to_response("website/shop_item_selected_new.html", jsonDict)
  except Exception, e:
    logger.error(e)
    return HttpResponseRedirect("/shop/")
Ejemplo n.º 3
0
def show_cart(request):
    """
  Show the contents of the cart, include tax (9.1%) and shipping (Free!)
  When ready to continue they press button
  """
    logger.info(request)
    (cart_list, pretax_total, tax, amountTaxed, shipping_total,
     total) = get_cart_details(request)

    return render_to_response(
        "website/checkout/show_cart.html", {
            "cart_list": cart_list,
            "cart_pretax": "%.2f" % round(pretax_total, 2),
            "cart_tax": "%.1f" % round(tax * 100, 1),
            "cart_tax_total": "%.2f" % round(amountTaxed, 2),
            "shipping_total": "%.2f" % round(shipping_total, 2),
            "cart_total": "%.2f" % round(total, 2),
        })
Ejemplo n.º 4
0
def reviewTransaction(request):
  """
  Expects the POST form from /checkout/collect/
  """
  logger.info(request)
  if request.method != "POST":
    #Got here by accident.. Go back to the cart
    return HttpResponseRedirect("/cart/show/")
  #User pressed cancel, send them to the shop
  if "cancel" in request.POST.get("submit","cancel"):
    return HttpResponseRedirect("/shop/")
  #Assert: We have a form full of user data that needs to go back to the next page!
  #if reviewed and ready to complete, run:
  #return completeTransaction(request)
  if "purchase" in request.POST.get("submit"):
    return make_purchase(request)
  else:
    return show_review_page(request)
Ejemplo n.º 5
0
def shop_item_selected(request, item_id):
    try:
        item = Item.objects.get(id=item_id)
        size_list = item.quantity.order_by("id")
        logger.info(item)
        jsonDict = {
            "item": item.json(),
            "size_list": size_list,
            "quantity_list": range(1, 11),
            "paypal_debug": settings.PAYPAL_DEBUG,
        }
        jsonDict.update(csrf(request))
        logger.debug(jsonDict)
        return render_to_response("website/shop_item_selected_new.html",
                                  jsonDict)
    except Exception, e:
        logger.error(e)
        return HttpResponseRedirect("/shop/")
Ejemplo n.º 6
0
def reviewTransaction(request):
    """
  Expects the POST form from /checkout/collect/
  """
    logger.info(request)
    if request.method != "POST":
        #Got here by accident.. Go back to the cart
        return HttpResponseRedirect("/cart/show/")
    #User pressed cancel, send them to the shop
    if "cancel" in request.POST.get("submit", "cancel"):
        return HttpResponseRedirect("/shop/")
    #Assert: We have a form full of user data that needs to go back to the next page!
    #if reviewed and ready to complete, run:
    #return completeTransaction(request)
    if "purchase" in request.POST.get("submit"):
        return make_purchase(request)
    else:
        return show_review_page(request)
Ejemplo n.º 7
0
def make_purchase(request):
    (cart_list,pretax_total, tax, tax_amount, shipping_total, total) = get_cart_details(request)
    card_args = getCardArgs(request.POST)
    billing_args = getBillingArgs(request.POST)
    shipping_args = getShippingArgs(request.POST, billing_args)
    error_list = []



    full_name = "%s %s" % (shipping_args["first_name"], shipping_args["last_name"])
    full_name = "%s %s" % (shipping_args["first_name"], shipping_args["last_name"])
    billing_addr = "%s\n%s,%s %s" % (billing_args["line1"], billing_args["city"], billing_args["state"], billing_args["postal_code"])
    shipping_addr = "%s\n%s,%s %s" % (shipping_args["line1"], shipping_args["city"], shipping_args["state"], shipping_args["postal_code"])
    email = request.POST["email-billing"]
    if not email:
        error_list.append("Please enter an e-mail address")

    if error_list:
        return show_review_page(request, errors=error_list)

    payment = paypalrestsdk.Payment({
      "intent": "sale",
      "payer": {
        "payment_method": "credit_card",
        "funding_instruments": [{
          "credit_card": card_args
          }]
      },
      "transactions": [{
        "amount": {
          "total" : "%.2f" % round(total,2),
          "currency": "USD",
          "details" : {
            "subtotal": "%.2f" % round(pretax_total,2),
            "tax" : "%.2f" % round(tax_amount,2),
            "shipping" : "%.2f" % round(shipping_total,2),
          }
        },
        "description": "Your purchase at Rev-Ink.com." }]})
    
    if not payment.create():
        error_list.append("Your Credit Card was not accepted! Please review the error(s) and try again:%s" % payment.error)
        logger.error("ERROR ACCEPTING PAYMENT! errors included: %s" % payment.__dict__)
        email_to_admin("ERROR ACCEPTING PAYMENT!", "errors included: %s" % payment.__dict__)
        return show_review_page(request, errors=error_list)
    confirmation = payment.id
    billing_args["ipaddress"] = request.META["REMOTE_ADDR"]
    logger.info("Payment created successfully. ID=%s" % confirmation)
    logger.info(full_name)
    card_args["last4"] = card_args["number"][-4:] if len(card_args["number"]) > 4 else ""
    logger.info(card_args["last4"])
    logger.info(email)
    confirm_id = make_transaction(full_name, email, shipping_addr, billing_addr, cart_list, confirmation_id=confirmation)
    del request.session["cart"] 
    #send_confirmation_email(full_name, email)
    params = {
        "cart_list" : cart_list,
        "transaction_id" : confirmation,
        "cart_pretax" : "%.2f" % round(pretax_total,2),
        "cart_tax" : "%.1f" % round(tax*100,1),
        "cart_tax_total" : "%.2f" % round(tax_amount, 2),
        "shipping_total" : "%.2f" % round(shipping_total, 2),
        "cart_total" : "%.2f" % round(total,2),
        "server_url": settings.SERVER_URL,
        "billing_info":billing_args,
        "card_info":card_args,
        "shipping_info":shipping_args,
      }
    logger.info(params)
    c = RequestContext(request, params)
    return render_to_response("website/thank_you_transaction.html",c)
Ejemplo n.º 8
0
def collect_billing_info(request):
  logger.info(request)
  c = RequestContext(request, {})
  return render_to_response("website/checkout/billing_info.html", c)
Ejemplo n.º 9
0
def make_purchase(request):
    (cart_list, pretax_total, tax, tax_amount, shipping_total,
     total) = get_cart_details(request)
    card_args = getCardArgs(request.POST)
    billing_args = getBillingArgs(request.POST)
    shipping_args = getShippingArgs(request.POST, billing_args)
    error_list = []

    full_name = "%s %s" % (shipping_args["first_name"],
                           shipping_args["last_name"])
    full_name = "%s %s" % (shipping_args["first_name"],
                           shipping_args["last_name"])
    billing_addr = "%s\n%s,%s %s" % (
        billing_args["line1"], billing_args["city"], billing_args["state"],
        billing_args["postal_code"])
    shipping_addr = "%s\n%s,%s %s" % (
        shipping_args["line1"], shipping_args["city"], shipping_args["state"],
        shipping_args["postal_code"])
    email = request.POST["email-billing"]
    if not email:
        error_list.append("Please enter an e-mail address")

    if error_list:
        return show_review_page(request, errors=error_list)

    payment = paypalrestsdk.Payment({
        "intent":
        "sale",
        "payer": {
            "payment_method": "credit_card",
            "funding_instruments": [{
                "credit_card": card_args
            }]
        },
        "transactions": [{
            "amount": {
                "total": "%.2f" % round(total, 2),
                "currency": "USD",
                "details": {
                    "subtotal": "%.2f" % round(pretax_total, 2),
                    "tax": "%.2f" % round(tax_amount, 2),
                    "shipping": "%.2f" % round(shipping_total, 2),
                }
            },
            "description": "Your purchase at Rev-Ink.com."
        }]
    })

    if not payment.create():
        error_list.append(
            "Your Credit Card was not accepted! Please review the error(s) and try again:%s"
            % payment.error)
        logger.error("ERROR ACCEPTING PAYMENT! errors included: %s" %
                     payment.__dict__)
        email_to_admin("ERROR ACCEPTING PAYMENT!",
                       "errors included: %s" % payment.__dict__)
        return show_review_page(request, errors=error_list)
    confirmation = payment.id
    billing_args["ipaddress"] = request.META["REMOTE_ADDR"]
    logger.info("Payment created successfully. ID=%s" % confirmation)
    logger.info(full_name)
    card_args["last4"] = card_args["number"][-4:] if len(
        card_args["number"]) > 4 else ""
    logger.info(card_args["last4"])
    logger.info(email)
    confirm_id = make_transaction(full_name,
                                  email,
                                  shipping_addr,
                                  billing_addr,
                                  cart_list,
                                  confirmation_id=confirmation)
    del request.session["cart"]
    #send_confirmation_email(full_name, email)
    params = {
        "cart_list": cart_list,
        "transaction_id": confirmation,
        "cart_pretax": "%.2f" % round(pretax_total, 2),
        "cart_tax": "%.1f" % round(tax * 100, 1),
        "cart_tax_total": "%.2f" % round(tax_amount, 2),
        "shipping_total": "%.2f" % round(shipping_total, 2),
        "cart_total": "%.2f" % round(total, 2),
        "server_url": settings.SERVER_URL,
        "billing_info": billing_args,
        "card_info": card_args,
        "shipping_info": shipping_args,
    }
    logger.info(params)
    c = RequestContext(request, params)
    return render_to_response("website/thank_you_transaction.html", c)
Ejemplo n.º 10
0
def collect_billing_info(request):
    logger.info(request)
    c = RequestContext(request, {})
    return render_to_response("website/checkout/billing_info.html", c)