Package client.ws.milanas.helpers.beans

Examples of client.ws.milanas.helpers.beans.Cart


     */
    public boolean addItem(String offerId, int quantity) throws SOAPEnvelopeCreationException
    {
        ArrayList<CartItem> items = new ArrayList<CartItem>();
        CartItem item = null;
        Cart auxCart = null;
        HashMap<String, String> parameters = new HashMap<String, String>();
        SOAPMessage message, response = null;
        DOMCartHandler dch = null;
        Document doc = null;
       
        if(quantity <= 0)
        {
            return true;
        }
       
        item = new CartItem();
        item.setOfferId(offerId);
        item.setQuantity(quantity);
        items.add(item);
       
        if(cart != null)
        {
            parameters.put("CartId", cart.getCartId());
            parameters.put("HMAC", cart.getCartHmac());
            message = SOAPEnvelopeCreator.createAmazonCartSOAPEnvelope("CartAdd", parameters, items, properties);
            try
            {
                response = connection.call(message, properties.getProperty("endpoint"));
                dch = new DOMCartHandler();
                doc = response.getSOAPBody().extractContentAsDocument();
                auxCart = dch.getCart(doc);
                cart.setItems(auxCart.getItems());
                cart.setTotal(auxCart.getTotal());
                cart.setUrl(auxCart.getUrl());
                if(dch.isItemAdded(doc))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch(SOAPException se){return false;}
        }
        else
        {
            parameters.put("AssociateTag", properties.getProperty("AssociateTag"));
            message = SOAPEnvelopeCreator.createAmazonCartSOAPEnvelope("CartCreate", parameters, items, properties);
            try
            {
               
                response = connection.call(message, properties.getProperty("endpoint"));              
                dch = new DOMCartHandler();
                doc = response.getSOAPBody().extractContentAsDocument();
                if(dch.isItemAdded(doc))
                {
                    cart = new Cart(dch.getCartId(doc), dch.getCartHmac(doc));
                    auxCart = dch.getCart(doc);
                    cart.setItems(auxCart.getItems());
                    cart.setTotal(auxCart.getTotal());
                    cart.setUrl(auxCart.getUrl());
                    return true;
                }
                else
                {
                    return false;
View Full Code Here


    {
        HashMap<String, String> parameters = new HashMap<String, String>();
        SOAPMessage message, response = null;
        DOMCartHandler dch = null;
        Document doc = null;
        Cart auxCart = null;
        if(cart != null)
        {
            parameters.put("CartId", cart.getCartId());
            parameters.put("HMAC", cart.getCartHmac());
            message = SOAPEnvelopeCreator.createAmazonCartSOAPEnvelope("CartModify", parameters,  items, properties);
            try
            {
                response = connection.call(message, properties.getProperty("endpoint"));
                dch = new DOMCartHandler();
                doc = response.getSOAPBody().extractContentAsDocument();
                auxCart = dch.getCart(doc);
                cart.setItems(auxCart.getItems());
                cart.setTotal(auxCart.getTotal());
                cart.setUrl(auxCart.getUrl());
            }
            catch(SOAPException se){}
        }
    }
View Full Code Here

    {
        HashMap<String, String> parameters = new HashMap<String, String>();
        SOAPMessage message, response = null;
        DOMCartHandler dch = null;
        Document doc = null;
        Cart auxCart = null;
        if(cart != null)
        {
            parameters.put("CartId", cart.getCartId());
            parameters.put("HMAC", cart.getCartHmac());
            parameters.put("AssociateTag", properties.getProperty("AssociateTag"));
            message = SOAPEnvelopeCreator.createAmazonCartSOAPEnvelope("CartClear", parameters,  new ArrayList<CartItem>(), properties);
            try
            {
                response = connection.call(message, properties.getProperty("endpoint"));
                dch = new DOMCartHandler();
                doc = response.getSOAPBody().extractContentAsDocument();
                auxCart = dch.getCart(doc);
                cart.setItems(auxCart.getItems());
                cart.setTotal(auxCart.getTotal());
                cart.setUrl(auxCart.getUrl());
            }
            catch(SOAPException se){}
        }
    }
View Full Code Here

    {
        if(cart != null)
        { 
            return cart;
        }
        return new Cart("", "");
    }
View Full Code Here

     * Parsers a response to any Cart operation from Amazon.
     * Returns the state of the Amazon's Cart.
     */
    public Cart getCart(Document doc)
    {
        Cart cart = new Cart("", "");
        CartItem cartItem = null;
        Item item = null;
        NodeList nodes, kids1, kids2 = null;
        Node node, kid1, kid2 = null;
        int i, j, k = 0;
       
        nodes = doc.getElementsByTagName("CartItem");
        for(i = 0; i < nodes.getLength(); i++)
        {
            cartItem = new CartItem();
            item = new Item();
            node = nodes.item(i);
            kids1 = node.getChildNodes();
            for(j = 0; j < kids1.getLength(); j++)
            {
                kid1 = kids1.item(j);
                if(kid1.getNodeName().equals("ASIN"))
                {
                    item.setAsin(kid1.getTextContent());
                }
                if(kid1.getNodeName().equals("Title"))
                {
                    item.setTitle(kid1.getTextContent());
                }
                if(kid1.getNodeName().equals("CartItemId"))
                {
                    cartItem.setCartItemId(kid1.getTextContent());
                }
                if(kid1.getNodeName().equals("Quantity"))
                {
                    try
                    {
                        cartItem.setQuantity(Integer.parseInt(kid1.getTextContent()));
                    }
                    catch(NumberFormatException nfe)
                    {
                        cartItem.setQuantity(0);
                    }
                }
                if(kid1.getNodeName().equals("Price"))
                {
                    kids2 = kid1.getChildNodes();
                    for(k = 0; k < kids2.getLength(); k++)
                    {
                        kid2 = kids2.item(k);
                        if(kid2.getNodeName().equals("FormattedPrice"))
                        {
                            cartItem.setUnitPrice(kid2.getTextContent());
                        }
                    }
                }
                if(kid1.getNodeName().equals("ItemTotal"))
                {
                    kids2 = kid1.getChildNodes();
                    for(k = 0; k < kids2.getLength(); k++)
                    {
                        kid2 = kids2.item(k);
                        if(kid2.getNodeName().equals("FormattedPrice"))
                        {
                            cartItem.setTotalPrice(kid2.getTextContent());
                        }
                    }
                }
            }
            cartItem.setItem(item);
            cart.addItem(cartItem);
        }

        nodes = doc.getElementsByTagName("SubTotal");
        for(i = 0; i < nodes.getLength(); i++)
        {
            node = nodes.item(i);
            kids1 = node.getChildNodes();
            for(j = 0; j < kids1.getLength(); j++)
            {
                kid1 = kids1.item(j);
                if(kid1.getNodeName().equals("FormattedPrice"))
                {
                    cart.setTotal(kid1.getTextContent());
                }
            }
        }
       
        nodes = doc.getElementsByTagName("PurchaseURL");
        if(nodes.getLength() > 0)
        {
            cart.setUrl(nodes.item(0).getTextContent());
        }
        return cart;
    }
View Full Code Here

TOP

Related Classes of client.ws.milanas.helpers.beans.Cart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.