Exemple #1
0
def _find_cart(data):
    # invoice may have a suffix due to retries
    invoice = data["invoice"] if "invoice" in data else data["item_number"]
    if not invoice:
        log.warn("No invoice # in data, aborting IPN")
        return None
    return cart_by_uuid(invoice[:36])
Exemple #2
0
def _find_cart(data):
    # invoice may have a suffix due to retries
    invoice = data.get("invoice") or data.get("item_number") or data.get("rp_invoice_id")
    if not invoice:
        log.warn("No invoice # in data, aborting IPN")
        return None
    return cart_by_uuid(invoice[:36])
Exemple #3
0
def _find_cart(data):
    # invoice may have a suffix due to retries
    invoice = data["invoice"] if "invoice" in data else data["item_number"]
    if not invoice:
        log.warn("No invoice # in data, aborting IPN")
        return None
    return cart_by_uuid(invoice[:36])
Exemple #4
0
def _find_cart(request):
    request_data = request.GET
    uuid = request_data.get('cart') or request.session.get('hiicart_cart_uuid')
    cart = cart_by_uuid(uuid)
    if not cart:
        raise GatewayError("Paypal Express Checkout: Unknown transaction with cart uuid %s" % uuid)
    return cart
Exemple #5
0
    def accept_adaptive_payment(self, data):
        """Accept a payment IPN coming through the Adaptive API.

        Paypal sends out two kind of IPNs when using Adaptive. The
        payment initiator (HiiCart) will get an Adaptive-specific IPN
        relating to the overall state of the payment.  HiiCart may also
        receive normal Paypal IPNs if the user has their IPN url pointing
        here."""
        self.log.debug("IPN for cart %s received" % data["tracking_id"])
        cart = cart_by_uuid(data["tracking_id"])
        for i in range(6):
            key_base = "transaction[%i]." % i
            if not any([k.startswith(key_base) for k in data.keys()]):
                break
            p = self.cart.payment_class.objects.filter(transaction_id=data[key_base + "id"])
            if len(p) == 0:
                p = self.cart.payment_class(cart=cart, gateway=cart.gateway,
                                            transaction_id=data[key_base + "id"])
            else:
                p = p[0]
            amount = re.sub("[^0-9.]", "", data[key_base + "amount"])
            p.amount = Decimal(amount)
            p.state = _adaptive_states[data[key_base + "status"]]
            p.save() # Need .id if creating new payment
            p.notes.create(text="Payment receiver: %s" % data[key_base + "receiver"])
        if "memo" in data:
            cart.notes.create(text="IPN Memo: %s" % data["memo"])
        cart.update_state()
Exemple #6
0
    def accept_adaptive_payment(self, data):
        """Accept a payment IPN coming through the Adaptive API.

        Paypal sends out two kind of IPNs when using Adaptive. The
        payment initiator (HiiCart) will get an Adaptive-specific IPN
        relating to the overall state of the payment.  HiiCart may also
        receive normal Paypal IPNs if the user has their IPN url pointing
        here."""
        self.log.debug("IPN for cart %s received" % data["tracking_id"])
        cart = cart_by_uuid(data["tracking_id"])
        for i in range(6):
            key_base = "transaction[%i]." % i
            if not any([k.startswith(key_base) for k in data.keys()]):
                break
            p = self.cart.payment_class.objects.filter(
                transaction_id=data[key_base + "id"])
            if len(p) == 0:
                p = self.cart.payment_class(cart=cart,
                                            gateway=cart.gateway,
                                            transaction_id=data[key_base +
                                                                "id"])
            else:
                p = p[0]
            amount = re.sub("[^0-9.]", "", data[key_base + "amount"])
            p.amount = Decimal(amount)
            p.state = _adaptive_states[data[key_base + "status"]]
            p.save()  # Need .id if creating new payment
            p.notes.create(text="Payment receiver: %s" %
                           data[key_base + "receiver"])
        if "memo" in data:
            cart.notes.create(text="IPN Memo: %s" % data["memo"])
        cart.update_state()
Exemple #7
0
def _find_cart(data):
    # invoice may have a suffix due to retries
    invoice = data.get('invoice') or data.get('item_number') or data.get(
        'rp_invoice_id')
    if not invoice:
        log.warn("No invoice # in data, aborting IPN")
        return None
    return cart_by_uuid(invoice[:36])
Exemple #8
0
def _find_cart(request):
    request_data = request.GET
    uuid = request_data.get('cart') or request.session.get('hiicart_cart_uuid')
    cart = cart_by_uuid(uuid)
    if not cart:
        raise GatewayError(
            "Paypal Express Checkout: Unknown transaction with cart uuid %s" %
            uuid)
    return cart
Exemple #9
0
def _find_cart(data):
    # invoice may have a suffix due to retries
    if 'invoice' in data:
        invoice = data['invoice']
    elif 'rp_invoice_id' in data:
        invoice = data['invoice']
    else:
        invoice = data['item_number']
    if not invoice:
        log.warn("No invoice # in data, aborting IPN")
        return None
    return cart_by_uuid(invoice[:36])
Exemple #10
0
def _find_cart(data):
    # invoice may have a suffix due to retries
    if 'invoice' in data:
        invoice = data['invoice']
    elif 'rp_invoice_id' in data:
        invoice = data['invoice']
    else:
        invoice = data['item_number']
    if not invoice:
        log.warn("No invoice # in data, aborting IPN")
        return None
    return cart_by_uuid(invoice[:36])
Exemple #11
0
def do_pay(request):
    if "token" not in request.POST or "PayerID" not in request.POST or "cart" not in request.POST:
        raise GatewayError("Incorrect values POSTed to do_buy")
    cart = cart_by_uuid(request.POST["cart"])
    ipn = Paypal2IPN(cart)
    if len(cart.one_time_lineitems) > 0:
        api.do_express_payment(request.POST["token"], request.POST["PayerID"],
                               cart, ipn.settings)
    if len(cart.recurring_lineitems) > 0:
        api.create_recurring_profile(request.POST["token"],
                                     request.POST["PayerID"],
                                     cart, ipn.settings)
    # TODO: Redirect to HiiCart complete URL
    return HttpResponseRedirect("/")
Exemple #12
0
def do_pay(request):
    if "token" not in request.POST or "PayerID" not in request.POST \
        or "cart" not in request.POST:
        raise GatewayError("Incorrect values POSTed to do_buy")
    cart = cart_by_uuid(request.POST["cart"])
    ipn = Paypal2IPN(cart)
    if len(cart.one_time_lineitems) > 0:
        api.do_express_payment(request.POST["token"], request.POST["PayerID"],
                               cart, ipn.settings)
    if len(cart.recurring_lineitems) > 0:
        api.create_recurring_profile(request.POST["token"],
                                     request.POST["PayerID"], cart,
                                     ipn.settings)
    # TODO: Redirect to HiiCart complete URL
    return HttpResponseRedirect("/")
Exemple #13
0
def _find_cart(data):
    """Find purchase using a google id, or other things"""
    # If this is an existing order, then we'll find it in the db by transaction id
    payment = GoogleIPN._find_payment(data)
    if payment:
        return payment.cart

    # Otherwise, it's more complex, because we need to find the cart's uuid somewhere
    private_data = None
    if "shopping-cart.merchant-private-data" in data:
        private_data = data["shopping-cart.merchant-private-data"]
    else:
        items = [x for x in data.keys() if x.endswith("merchant-private-item-data")]
        if len(items) > 0:
            private_data = data[items[0]]
    if not private_data:
        logger.error("Could not find private data in:\n%s" % format_data(data))
        return None  # Not a HiiCart purchase ?
    return cart_by_uuid(private_data)
Exemple #14
0
def _find_cart(data):
    """Find purchase using a google id, or other things"""
    # If this is an existing order, then we'll find it in the db by transaction id
    payment = GoogleIPN._find_payment(data)
    if payment:
        return payment.cart

    # Otherwise, it's more complex, because we need to find the cart's uuid somewhere
    private_data = None
    if "shopping-cart.merchant-private-data" in data:
        private_data = data["shopping-cart.merchant-private-data"]
    else:
        items = [
            x for x in data.keys() if x.endswith("merchant-private-item-data")
        ]
        if len(items) > 0:
            private_data = data[items[0]]
    if not private_data:
        log.error("Could not find private data. Data: %s" % str(data.items()))
        return None  # Not a HiiCart purchase ?
    return cart_by_uuid(private_data)
Exemple #15
0
def _find_cart(data):
    return cart_by_uuid(data['cart_id'])
Exemple #16
0
def _find_cart(request_data):
    # Subscription payments look like '<uuid>-4' so grab the uuid id
    if 'callerReference' in request_data and len(request_data['callerReference']) >= 36:
        uuid = request_data["callerReference"][:36]
        return cart_by_uuid(uuid)
    return None
Exemple #17
0
def _find_cart(data):
    return cart_by_uuid(data['cart_id'])
Exemple #18
0
def _find_cart(request_data):
    # Subscription payments look like '<uuid>-4' so grab the uuid id
    uuid = request_data["callerReference"][:36]
    return cart_by_uuid(uuid)
Exemple #19
0
def _find_cart(request_data):
    # Subscription payments look like '<uuid>-4' so grab the uuid id
    uuid = request_data["callerReference"][:36]
    return cart_by_uuid(uuid)