Beispiel #1
0
def cbui(request, settings=None):
    """
    View used when the Co-Branded UI returns.

    This view verifies that the CBUI returned successfully and
    uses the provided authorization to initiate a Pay request.
    """
    log.debug("CBUI Received: \n%s" % pprint.pformat(dict(request.GET), indent=10))
    handler = AmazonIPN()
    cart = _find_cart(request.GET)
    if not handler.verify_signature(request.GET.urlencode(), "GET", handler.settings["CBUI_RETURN_URL"], cart):
        log.error("Validation of Amazon request failed!")
        return HttpResponseRedirect(handler.settings.get("ERROR_RETURN_URL",
                                    handler.settings.get("RETURN_URL", "/")))
    if request.GET["status"] not in ("SA", "SB", "SC"):
        log.error("CBUI unsuccessful. Status code: %s" % request.GET["status"])
        return HttpResponseRedirect(handler.settings.get("CANCEL_RETURN_URL",
                                    handler.settings.get("RETURN_URL", "/")))
    if not cart:
        log.error("Unable to find HiiCart.")
        return HttpResponseRedirect(handler.settings.get("ERROR_RETURN_URL",
                                    handler.settings.get("RETURN_URL", "/")))
    # Address collection. Any data already in cart is assumed correct
    name = request.GET.get("addressName", "").split(" ")
    cart.first_name = cart.first_name or name[0]
    if len(name) > 1:
        cart.last_name = cart.last_name or name[1]
    cart.bill_street1 = cart.bill_street1 or request.GET.get("addressLine1", "")
    cart.bill_street2 = cart.bill_street1 or request.GET.get("addressLine2", "")
    cart.bill_state = cart.bill_state or request.GET.get("state", "")
    cart.bill_postal_code = cart.bill_postal_code or request.GET.get("zip", "")
    country = request.GET.get("country", "").upper()
    if not cart.bill_country and country in COUNTRIES.values():
        cart.bill_country = [k for k,v in COUNTRIES.iteritems() if v == country][0]
    cart.save()
    recurring = cart.recurringlineitems.all()
    if len(recurring) > 0:
        handler.save_recurring_token(cart, request.GET["tokenID"])
        if recurring[0].recurring_start is None:
            result = handler.make_pay_request(cart, request.GET["tokenID"]) 
            if result == "Success":
                handler.begin_recurring(cart)
        else:
            handler.begin_recurring(cart)
    else:
        result = handler.make_pay_request(cart, request.GET["tokenID"])
    if 'RETURN_URL' in handler.settings:
        return HttpResponseRedirect(handler.settings['RETURN_URL'])
    return HttpResponseRedirect("/")
Beispiel #2
0
def cbui(request, settings=None):
    """
    View used when the Co-Branded UI returns.

    This view verifies that the CBUI returned successfully and
    uses the provided authorization to initiate a Pay request.
    """
    log.debug("CBUI Received: \n%s" % pprint.pformat(dict(request.GET), indent=10))
    if "errorMessage" in request.GET:
        raise Exception(request.GET["errorMessage"])
    else:    
        cart = _find_cart(request.GET)
    handler = AmazonIPN(cart)
    handler._update_with_cart_settings(cart_settings_kwargs={'request': request})
    if not cart:
        log.error("Unable to find cart.")
        return HttpResponseRedirect(handler.settings.get("ERROR_RETURN_URL",
                                    handler.settings.get("RETURN_URL", "/")))
    if not handler.verify_signature(request.GET.urlencode(), "GET", handler.settings["CBUI_RETURN_URL"]):
        log.error("Validation of Amazon request failed!")
        return HttpResponseRedirect(handler.settings.get("ERROR_RETURN_URL",
                                    handler.settings.get("RETURN_URL", "/")))
    if request.GET["status"] not in ("SA", "SB", "SC"):
        log.error("CBUI unsuccessful. Status code: %s" % request.GET["status"])
        return HttpResponseRedirect(handler.settings.get("CANCEL_RETURN_URL",
                                    handler.settings.get("RETURN_URL", "/")))
    # Address collection. Any data already in cart is assumed correct
    cart.bill_first_name = cart.bill_first_name or request.GET.get("billingName", "")
    cart.ship_first_name = cart.ship_first_name or request.GET.get("addressName", "")
    cart.bill_street1 = cart.bill_street1 or request.GET.get("addressLine1", "")
    cart.ship_street1 = cart.ship_street1 or cart.bill_street1
    cart.bill_street2 = cart.bill_street1 or request.GET.get("addressLine2", "")
    cart.ship_street2 = cart.ship_street1 or cart.bill_street1
    cart.bill_state = cart.bill_state or request.GET.get("state", "")
    cart.ship_state = cart.ship_state or cart.bill_state
    cart.bill_postal_code = cart.bill_postal_code or request.GET.get("zip", "")
    cart.ship_postal_code = cart.ship_postal_code or cart.bill_postal_code
    country = request.GET.get("country", "").upper()
    cart.bill_country = cart.bill_country or COUNTRIES.get(country, "")
    cart.ship_country = cart.ship_country or cart.bill_country
    cart.bill_email = cart.bill_email = request.GET.get("buyerEmailAddress", "")
    cart.ship_email = cart.ship_email or cart.bill_email
    cart.save()
    recurring = cart.recurring_lineitems
    if len(recurring) > 0:
        handler.save_recurring_token(request.GET["tokenID"])
        if recurring[0].recurring_start is None:
            result = handler.make_pay_request(request.GET["tokenID"])
            if result == "Success":
                handler.begin_recurring()
        else:
            handler.begin_recurring()
    else:
        log.debug("Making pay request: %s" % request.GET['tokenID'])
        result = handler.make_pay_request(request.GET["tokenID"])
        log.debug("Pay request result: %s" % result)
    if 'RETURN_URL' in handler.settings:
        return HttpResponseRedirect(handler.settings['RETURN_URL'])
    return HttpResponseRedirect("/")
Beispiel #3
0
def cbui(request, settings=None):
    """
    View used when the Co-Branded UI returns.

    This view verifies that the CBUI returned successfully and
    uses the provided authorization to initiate a Pay request.
    """
    log.debug("CBUI Received: \n%s" %
              pprint.pformat(dict(request.GET), indent=10))
    if "errorMessage" in request.GET:
        raise Exception(request.GET["errorMessage"])
    else:
        cart = _find_cart(request.GET)
    handler = AmazonIPN(cart)
    handler._update_with_cart_settings(
        cart_settings_kwargs={'request': request})
    if not cart:
        log.error("Unable to find cart.")
        return HttpResponseRedirect(
            handler.settings.get("ERROR_RETURN_URL",
                                 handler.settings.get("RETURN_URL", "/")))
    if not handler.verify_signature(request.GET.urlencode(), "GET",
                                    handler.settings["CBUI_RETURN_URL"]):
        log.error("Validation of Amazon request failed!")
        return HttpResponseRedirect(
            handler.settings.get("ERROR_RETURN_URL",
                                 handler.settings.get("RETURN_URL", "/")))
    if request.GET["status"] not in ("SA", "SB", "SC"):
        log.error("CBUI unsuccessful. Status code: %s" % request.GET["status"])
        return HttpResponseRedirect(
            handler.settings.get("CANCEL_RETURN_URL",
                                 handler.settings.get("RETURN_URL", "/")))
    # Address collection. Any data already in cart is assumed correct
    cart.bill_first_name = cart.bill_first_name or request.GET.get(
        "billingName", "")
    cart.ship_first_name = cart.ship_first_name or request.GET.get(
        "addressName", "")
    cart.bill_street1 = cart.bill_street1 or request.GET.get(
        "addressLine1", "")
    cart.ship_street1 = cart.ship_street1 or cart.bill_street1
    cart.bill_street2 = cart.bill_street1 or request.GET.get(
        "addressLine2", "")
    cart.ship_street2 = cart.ship_street1 or cart.bill_street1
    cart.bill_state = cart.bill_state or request.GET.get("state", "")
    cart.ship_state = cart.ship_state or cart.bill_state
    cart.bill_postal_code = cart.bill_postal_code or request.GET.get("zip", "")
    cart.ship_postal_code = cart.ship_postal_code or cart.bill_postal_code
    country = request.GET.get("country", "").upper()
    cart.bill_country = cart.bill_country or COUNTRIES.get(country, "")
    cart.ship_country = cart.ship_country or cart.bill_country
    cart.bill_email = cart.bill_email = request.GET.get(
        "buyerEmailAddress", "")
    cart.ship_email = cart.ship_email or cart.bill_email
    cart.save()
    recurring = cart.recurring_lineitems
    if len(recurring) > 0:
        handler.save_recurring_token(request.GET["tokenID"])
        if recurring[0].recurring_start is None:
            result = handler.make_pay_request(request.GET["tokenID"])
            if result == "Success":
                handler.begin_recurring()
        else:
            handler.begin_recurring()
    else:
        log.debug("Making pay request: %s" % request.GET['tokenID'])
        result = handler.make_pay_request(request.GET["tokenID"])
        log.debug("Pay request result: %s" % result)
    if 'RETURN_URL' in handler.settings:
        return HttpResponseRedirect(handler.settings['RETURN_URL'])
    return HttpResponseRedirect("/")