VirtualNewspaper Cart Management

VNP

VirtualNewspaper Cart Management

Using this service you can build your own ecommerce site, you can add, remove products to a cart dedicated for each user. You can also choose special prices for single products and use standard shop to complete the purchase.

The Flow

The user chooses his products from the ecommerce site, for each choice a call to this service will add or remove products.
once the user completed his shopping he will be redirected to the standard VirtualNewsPaper shop flow with a dedicated cart. From there he will be requested to pay and activate/receive his purchases.

Add a product

When the user chooses add to cart a POST request to this service will add to the user session the product.

Example:
http://checkout.editorname.com/webservice/shop/cartAdd.jsp?productId=492&_=1407775530572

Parameters

PARAMETER NAME VALUE FORMAT DESCRIPTION
productId int the internal VNP Product ID (can be taken from products panel)
_ symbol (underscore) Valued with a timestamp could avoid older browser (let's call em Internet Explorer) to cache requests. Not mandatory

Code Example

<html>
  <head>
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  </head>
  <body>
    <button onclick="add_product_to_cart(492)">Add product to Cart</button>
 
    <script type="text/javascript">
      function add_product_to_cart(vnp_id_product) {
        $.ajax({
          url: "http://checkout.editorname.com/webservice/shop/cartAdd.jsp",
          data: {"productId":vnp_id_product,"_":new Date().getTime()},
          dataType: "json",
          success: function(data) {
            if (data.success) {
              // Product added, do something
            } else {
              // Failed adding product, do something
            }
          }
        })
      }
    </script>
  </body>
</html>

Remove a product

When the user chooses to remove a product from his cart a POST request to this service will remove from the user session the product.

Example:
http://checkout.editorname.com/webservice/shop/cartRemove.jsp?productId=492&_=1407775530572

Parameters

PARAMETER NAME VALUE FORMAT DESCRIPTION
productId int the internal VNP Product ID (can be taken from products panel)
_ symbol (underscore) Valued with a timestamp could avoid older browser (let's call em Internet Explorer) to cache requests. Not mandatory

Code Example

<html>
  <head>
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  </head>
  <body>
    <button onclick="remove_product_from_cart(492)">Remove product from Cart</button>
 
    <script type="text/javascript">
      function remove_product_from_cart(vnp_id_product) {
        $.ajax({
          url: "http://checkout.editorname.com/webservice/shop/cartRemove.jsp",
          data: {"productId":vnp_id_product,"_":new Date().getTime()},
          dataType: "json",
          success: function(data) {
            if (data.success) {
              // Product added, do something
            } else {
              // Failed adding product, do something
            }
          }
        })
      }
    </script>
  </body>
</html>

Add a product with custom price

When the user chooses add to cart a POST request to this service will add to the user session the product.
At the same step a custom price for the product can be choosen

Example:
http://checkout.editorname.com/webservice/shop/cartAdd.jsp?productId=179&_=1407775530572&ts=1407775530572&authCode=396360741fdc4ba600c60df579bc3b70&price_179=9.5

Parameters

PARAMETER NAME VALUE FORMAT DESCRIPTION
productId int the internal VNP Product ID (can be taken from products panel)
_ symbol (underscore) Valued with a timestamp could avoid older browser (let's call em Internet Explorer) to cache requests. Not mandatory
ts int A key that changes at every single request (you could use a timestamp for example)
authCode String The md5 of ts parameter concatenated to the Private WS key (you can find your own in the Settings module) e.g. md5(ts+privateKeyWS)
price_[productId] float The price you want set to this product. it must contain the ID of the product (in this case the name of this parameter will be price_179)

Code Example

<!--This example uses JSP and apache commons Digest library-->
<html>
 <html>
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  </head>
  <body>
    <button onclick="add_product_to_cart(179)">Add product to Cart</button>
 
    <script type="text/javascript">
      <%String ts = ""+System.currentTimeMillis();%>
      var ts = '<%=ts%>'
      var authCode = '<%=org.apache.commons.codec.digest.DigestUtils.md5Hex(ts+"9204ce470e2b8812d5a6951c902826c6")%>'
      function add_product_to_cart(vnp_id_product) {
        var postData={};
        postData.productId=vnp_id_product;
        postData["_"]=new Date().getTime();
        postData.ts=ts;
        postData.authCode=authCode;
        postData["price_"+vnp_id_product]=9.5;
        $.ajax({
          url: "http://checkout.editorname.com/webservice/shop/cartAdd.jsp",
          data: postData,
          dataType: "json",
          success: function(data) {
            if (data.success) {
              // Product added, do something
            } else {
              // Failed adding product, do something
            }
          }
        })
      }
    </script>
  </body>
</html>

Important:
Whenever the authCode is wrong no message will be provided and the product will be added to the cart at its full price.

The Response

Each service responds as below:

{
  "cart": {
     "total":14.3, <!--sum of each product in the cart-->
     "items": [ <!-- Array with list of products-->
        {
          "product": {  <!-- Single product instance description -->
            "fullprice":16.9, <!--Originary price of this product-->
            "weight":1, <!--Weigth of the product (used for physical shippings)-->
            "productDescription":"Description", <!-- The description of the product as from ''products'' panel-->
            "label":"Label", <!-- The label of the product as from ''products'' panel-->
            "productId":492, <!-- VNP product ID -->
            "currency":"EUR", <!-- Currency referred to price -->
            "months":1, <!-- Period validity of the product -->
            "price":14.3, <!-- Price of this product -->
            "imageLink":"http://checkout.editorname.com/upload/a261c1b1871a0de09c8333a1662a93a8.jpg", <!-- URL to the image of the product -->
            "issues":"", <!-- Issues associated to this product -->
            "titles":"[ecommerce]", <!-- Titles associated to this product -->
            "productName":"Name", <!-- The name of the product as from ''products'' panel-->
            "availability":61 <!-- How many copies are available in the store -->
          },
          "singlePrice":14.3, <!-- price for each instance of this product -->
          "cartQuantity":1, <!-- how many copies of this product are in the cart -->
          "totalPrice":14.3 <!-- the singlePrice multiplied for the cartQuantity -->
         }
       ],
       "totalWeight":1, <!-- Weight for all the cart -->
       "currency":"EUR" <!-- Currency of the product -->
  },
  "success":true <!-- True or False whenever the product was added/removed from the product for this call -->
}

Go to Cart

When the user completed the shopping can be exposed a button that redirects him to pay.

The url must be:

http://checkout.editorname.com/webservice/shop/initCheckout.jsp

Notes

Prices of products are automatically calculated.
Whenever a custom price is choosen for a product it cannot be changed for the current session. Any attempt of adding product to the cart will increase only the quantity.