App42 Cloud API

J2ME(S40) Cloud SDK

Shopping Cart

This is Cloud Persistent Shopping Cart Service. App Developers can use this to create a Shopping Cart. Add Items and Check Out items. It also maintains the transactions and the corresponding Payment Status. The Payment Gateway interface is not provided by the Platform. It is left to the App developer how he wants to do the Payment Integration. This can be used along with Catalogue or used independently. The Cart service can be used along with Catalogue service to create an end to end Shopping feature for a Mobile and Web App

In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.

	ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>"); 

After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of CartService, buildCartService() method needs to be called.

CartService cartService = api.buildCartService();

Once the API instance has been retrieved, You are ready to use the functions available for that particular API.

The methods available under a particular API will return the domain object (like Cart in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.

String user = "Nick";

Cart cart = cartService.createCart(user); /* returns the Cart object. */ 
System.out.println("userName is " + cart.getUserName());
System.out.println("cartId is " + cart.getCartId());
String jsonResponse = cart.toString(); /* returns the response in JSON format. */ 
                            

The functions available under User API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is requesting a cart with id which is not in database, the function will throw the App42Exception (as shown below) with message as "Not Found" and the appErrorCode as "3301" and the details as "Cart with the id '<cartId>' does not exist.".

String cartId = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";

try{
	Cart cart = cartService.getCartDetails(cartId);
   }
catch(App42Exception ex)
{
	int appErrorCode = ex.getAppErrorCode();
	int httpErrorCode = ex.getHttpErrorCode();
	if(appErrorCode == 3301)
{
    // Handle here for Not Found (Cart with the id '<cartId>' does not exist.)
}
    else if(appErrorCode  == 3302){
    // Handle here for Bad Request (The request parameters are invalid. The details of the cart with the Id '<cartId>' cannot be fetched since it is in '<cartRow.state>' state. Please use the paymentHistoryXXX methods.)
}
    else if(appErrorCode == 1401){
    // handle here for Client is not authorized
}
    else if(appErrorCode == 1500){
    // handle here for Internal Server Error
}	
	
	String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/	
}                            
	{
		"app42Fault": {
			"httpErrorCode": 404,
			"appErrorCode": 3301,
			"message": "Not Found",
			"details": "Cart with the id '41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325' does not Exist"
		}
	}							

Below are the HTTP Error Codes and their description, the function under the Shopping Cart API can throw.

/*
1400 - BAD REQUEST - The Request parameters are invalid
1401 - UNAUTHORIZED - Client is not authorized
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again		
*/					

Below are the Application Error Codes and their description, the function under the Shopping Cart API can throw.

/*
3300 - NOT FOUND - User by the name '<userName>' does not exist.
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.
3302 - BAD REQUEST - The request parameters are invalid. The details of the cart with the Id '<cartId>' cannot be fetched since it is in '<cartRow.state>' state. Please use the paymentHistoryXXX methods.
3303 - BAD REQUEST - The request parameters are invalid. Item to the cart with the Id '<cartId>' cannot be added since it is in '<cartState>' state.
3304 - NOT FOUND - Cart with the id '<cartId>' does not have any items.
3305 - BAD REQUEST - The request parameters are invalid. The cart with the Id '<cartId>' cannot be checked out since it is in '<cartState>' state.
3306 - NOT FOUND - Cart with the id '<cartId>' does not have any items.to checkout 
3307 - BAD REQUEST - The request parameters are invalid. Cart with the Id '<cartId>' is already in '<cartState>' state.
3308 - BAD REQUEST - The request parameters are invalid. Cart with the Id '<cartId>' is not in 'CHECKOUT' state. Payment cannot be initiated.
3309 - NOT FOUND - Cart with the id '<cartId>' does not have the item with the Id '<itemId>'.
3310 - NOT FOUND - Cart for the user with the id '<userId>' does not exist. 
3311 - NOT FOUND - Payment transactions for the user with the id '<userId>' does not exist. 
3312 - NOT FOUND - Payment transactions for the  Cart with the id '<cartId>' does not exist.
3313 - NOT FOUND - Cart for the user with the id '<userIdgt;' and status '<status>' does not exist. 
3314 - NOT FOUND - Payment transactions for the user with the id '<userId>' and status '<status>' does not exist. 
3315 - NOT FOUND - Payment transactions for the status '<status>' does not exist. 
3316 - NOT FOUND - Cart for the user with the id '<userId>' does not exist in payment history.
3317 - NOT FOUND - Carts with status ('DECLINED', 'PENDING', 'AUTHORIZED') does not exist in payment history. 
3318 - BAD REQUEST - The request parameters are invalid. Item from the cart with the Id '<cartId>' cannot be removed since it is in '<cartState>' state. 
3319 - BAD REQUEST - The request parameters are invalid. Payment for cart with the Id '<cartId>' cannot be initiated since it is already in 'AUTHORIZED' state.      
3320 - BAD REQUEST - Item with the Id '<itemId>' in the cart with the id '<cartId>' already exists. Please use 'increaseQuantity' method to add more quantity.
3321 - BAD REQUEST - The request parameters are invalid. Requested quantity should be less then existing quantity.
3322 - NOT FOUND - Item with the id '<itemId>' in the cart with the id '<cartId>' does not exist.	
*/					

Various functions available under Shopping Cart/E-Commerce API has been explained below.

public Cart createCart(String user) throws App42Exception

Creates a Cart Session for the specified User.

Parameters:

user - User for whom Cart Session has to be created returns The Cart Id with Creation Time. The id has to be used in subsequent calls for adding and checking out

Returns:

Cart Object containing Cart Id with Creation Time. The id has to be used in subsequent calls for adding and checking out

Response: Cart Object

For more details click Exception
String user = "Nick";

Cart cart = cartService.createCart(user); /* returns the Cart object. */ 
System.out.println("userName is " + cart.getUserName());
System.out.println("cartId is " + cart.getCartId()); 
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "userName": "Nick",
                    "cartId": "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325",
                    "creationTime": "2012-05-10T03:38:14.000Z",
                    "cartSession": "NEW"
                }
            }
        }
    }
}
public Cart getCartDetails(String cartId) throws App42Exception

Fetch Cart details. Can be used by the App developer to display Cart Details i.e. Items in a Cart.

Parameters:

cartId - The Cart Id that has to be fetched

Returns:

Cart object containing cart details with all the items which are in it. It also tells the state of the Cart

Response: Cart Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.
3302 - BAD REQUEST - The request parameters are invalid. The details of the cart with the Id '<cartId>' cannot be fetched since it is in '<cartRow.state>' state. Please use the paymentHistoryXXX methods.
*/		        
For more details click Exception
String cartId = "0aed1d3b855d01c81bc424e770f6b28105bd7fdf12ae0af09ea35a5bce237ecb";

Cart cart = cartService.getCartDetails(cartId); /* returns the Cart object. */ 
System.out.println("userName is " + cart.getUserName());
System.out.println("cartId is " + cart.getCartId());
System.out.println("state is " + cart.getState());
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "userName": "Nick",
                    "cartId": "0aed1d3b855d01c81bc424e770f6b28105bd7fdf12ae0af09ea35a5bce237ecb",
                    "creationTime": "2012-05-10T05:00:36.000Z",
                    "checkOutTime": "2012-05-10T05:00:36.000Z",
                    "state": "CHECKOUT"
                }
            }
        }
    }
}
public Cart addItem(String cartID, String itemID, int itemQuantity,double price) throws App42Exception

Adds an Item in the Cart with quantity and price. This method does not take currency. Its the onus of the App developer to maintain the currency. It takes only the price.

Parameters:

cartID - The Cart Id into which item has to be added
itemID - The Item id which has to be added in the cart. If the Catalogue Service is used along with the Cart Service then the Item ids should be same.
itemQuantity - Quantity of the Item to be purchased
price - Price of the item

Returns:

Cart object containing added item.

Response: Cart Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.
3303 - BAD REQUEST - The request parameters are invalid. Item to the cart with the Id '<cartId>' cannot be added since it is in '<cartState>' state.    
3320 - BAD REQUEST - Item with the Id '<itemId>' in the cart with the id '<cartId>' already exists. Please use 'increaseQuantity' method to add more quantity.
*/	       
For more details click Exception
String cartID = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
String itemID = "ItemID01";
int itemQuantity = 12;
double price = 1000;	
					
Cart cart = cartService.addItem(cartID, itemID, itemQuantity, price); /* returns the Cart object. */ 
String cartId = cart.getCartId();
Vector itemList = cart.getItemList();
for(int i=0;i < itemList.size();i++)
{ 
	Cart.Item item = (Cart.Item) itemList.elementAt(i); 
	System.out.println("itemId is " + item.getItemId());
	System.out.println("quantity is " + item.getQuantity());
	System.out.println("price is " + item.getPrice());
	System.out.println("totalAmount is " + item.getTotalAmount());
} 
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                           
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325",
                    "items": {
                        "item": {
                            "itemId": "ItemID01",
                            "quantity": 12,
                            "price": 1000,
                            "totalAmount": 12000
                        }
                    }
                }
            }
        }
    }
}
public Cart getItems(String cartId) throws App42Exception

Fetches the Items from the specified Cart.

Parameters:

cartId - The cart id from which items have to be fetched

Returns:

Cart object which contains all items in the cart

Response: Cart Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.
3302 - BAD REQUEST - The request parameters are invalid. The details of the cart with the Id '<cartId>' cannot be fetched since it is in '<cartRow.state>' state. Please use the paymentHistoryXXX methods.
3304 - NOT FOUND - Cart with the id '<cartId>' does not have any items.
*/ 		       
For more details click Exception
String cartId = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";

Cart cart = cartService.getItems(cartId); /* returns the Cart object. */ 
System.out.println("cartId is " + cart.getCartId());
Vector itemList = cart.getItemList();
for(int i=0;i < itemList.size();i++)
{ 
	Cart.Item item = (Cart.Item) itemList.elementAt(i); 
	System.out.println("itemId is " + item.getItemId());
	System.out.println("quantity is " + item.getQuantity());
	System.out.println("price is " + item.getPrice());
	System.out.println("totalAmount is " + item.getTotalAmount());
} 
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325",
                    "items": {
                        "item": [
                            {
                                "itemId": "ItemID",
                                "quantity": 2,
                                "price": 100,
                                "totalAmount": 200
                            },
                            {
                                "itemId": "ItemID01",
                                "quantity": 12,
                                "price": 1000,
                                "totalAmount": 12000
                            }
                        ]
                    }
                }
            }
        }
    }
}
public Cart getItem(String cartId, String itemId) throws App42Exception

Fetches the specified Item from the specified Cart.

Parameters:

cartId - The cart id from which item has to be fetched
itemId - The item for which the information has to be fetched

Returns:

Cart Object

Response: Cart Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.
3302 - BAD REQUEST - The request parameters are invalid. The details of the cart with the Id '<cartId>' cannot be fetched since it is in '<cartRow.state>' state. Please use the paymentHistoryXXX methods. 
3309 - NOT FOUND - Cart with the id '<cartId>' does not have the item with the Id '<itemId>'.
*/	       
For more details click Exception
String cartId = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
String itemId = "ItemID01";

Cart cart = cartService.getItem(cartId, itemId); /* returns the Cart object. */ 
System.out.println("cartId is " + cart.getCartId());
Vector itemList = cart.getItemList();
for(int i=0;i < itemList.size();i++)
{ 
	Cart.Item item = (Cart.Item) itemList.elementAt(i); 
	System.out.println("itemId is " + item.getItemId());
	System.out.println("quantity is " + item.getQuantity());
	System.out.println("price is " + item.getPrice());
	System.out.println("totalAmount is " + item.getTotalAmount());
} 
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325",
                    "items": {
                        "item": {
                            "itemId": "ItemID01",
                            "quantity": 12,
                            "price": 1000,
                            "totalAmount": 12000
                        }
                    }
                }
            }
        }
    }
}
public App42Response removeItem(String cartId, String itemId)throws App42Exception

Removes the specified item from the specified Cart.

Parameters:

cartId - The cart id from which the item has to be removed
itemId - Id of the Item which has to be removed

Returns:

App42Response if removed successfully

Response: App42Response Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.  
3309 - NOT FOUND - Cart with the id '<cartId>' does not have the item with the Id '<itemId>'.
3318 - BAD REQUEST - The request parameters are invalid. Item from the cart with the Id '<cartId>' cannot be removed since it is in '<cartState>' state. 
*/ 	       
For more details click Exception
String cartId = "7452d7ad3d3c86197d95b7060662533e05bd1995313b8aa4ac675728044b205e";
String itemId =	"itemID";					

App42Response response = cartService.removeItem(cartId, itemId); /* returns the App42Response object. */
boolean success = response.isResponseSuccess();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "7452d7ad3d3c86197d95b7060662533e05bd1995313b8aa4ac675728044b205e",
                    "items": {
                        "item": {
                            "itemId": "itemID",
                            "quantity": 2,
                            "price": 100,
                            "totalAmount": 200
                        }
                    }
                }
            }
        }
    }
}
public App42Response removeAllItems(String cartId) throws App42Exception

Removes all Items from the specified Cart.

Parameters:

cartId - The cart id from which items have to be removed

Returns:

App42Response if removed successfully

Response: App42Response Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.   
3304 - NOT FOUND - Cart with the id '<cartId>' does not have any items.
3318 - BAD REQUEST - The request parameters are invalid. Item from the cart with the Id '<cartId>' cannot be removed since it is in '<cartState>' state. 
*/ 	       
For more details click Exception
String cartId = "665bd3b621b83ff09a6b3a08604ac01148751b5e21438f64c6de4b0256aaa584";
					
App42Response response = cartService.removeAllItems(cartId); /* returns the App42Response object. */
boolean success = response.isResponseSuccess();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "665bd3b621b83ff09a6b3a08604ac01148751b5e21438f64c6de4b0256aaa584",
                    "items": {
                        "item": [
                            {
                                "itemId": "itemID",
                                "quantity": 12,
                                "price": 1030,
                                "totalAmount": 12360
                            },
                            {
                                "itemId": "itemID09",
                                "quantity": 22,
                                "price": 1060,
                                "totalAmount": 23320
                            }
                        ]
                    }
                }
            }
        }
    }
}
public Cart isEmpty(String cartId) throws App42Exception

Checks whether the Cart is empty or not.

Parameters:

cartId - The cart id to check for empty

Returns:

Cart object (isEmpty method on Cart object can be used to check status)

Response: Cart Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.  
3302 - BAD REQUEST - The request parameters are invalid. The details of the cart with the Id '<cartId>' cannot be fetched since it is in '<cartRow.state>' state. Please use the paymentHistoryXXX methods.
*/	   
For more details click Exception
String cartId = "5527cc1eb516ffeaf8c927782f196757ef2feb4ad43efbe8b6bf37e52d83f4af";		

Cart cart = cartService.isEmpty(cartId); /* returns the Cart object. */  
System.out.println("cartId is " + cart.getCartId());
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "5527cc1eb516ffeaf8c927782f196757ef2feb4ad43efbe8b6bf37e52d83f4af",
                    "isEmpty": true
                }
            }
        }
    }
}
public Cart checkOut(String cartID) throws App42Exception

Checks out the Cart and put it in CheckOut Stage and returns the Transaction Id The transaction id has to be used in future to update the Payment Status.

Parameters:

cartID - The cart id that has to be checkedout

Returns:

Cart object containing Checked Out Cart Information with the Transaction Id

Response: Cart Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist. 
3305 - BAD REQUEST - The request parameters are invalid. The cart with the Id '<cartId>' cannot be checked out since it is in '<cartState>' state.
3306 - NOT FOUND - Cart with the id '<cartId>' does not have any items.to checkout 
*/ 		     
For more details click Exception
String cartID = "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";

Cart cart = cartService.checkOut(cartID); /* returns the Cart object. */ 
System.out.println("cartId is " + cart.getCartId());
System.out.println("state is " + cart.getState());
System.out.println("totalAmount is " + cart.getTotalAmount());
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30",
                    "totalAmount": 1000,
                    "state": "CHECKOUT",
                    "checkOutDate": "2012-05-10T04:07:21.000Z"
                }
            }
        }
    }
}
public Cart payment(String cartID, String transactionID,PaymentStatus paymentStatus) throws App42Exception

Update Payment Status of the Cart. When a Cart is checkout, It is in Checkout state. The payment status has to be updated based on the Payment Gateway interaction.

Parameters:

cartID - The cart id for which the payment status has to be updated
transactionID - Transaction id for which the payment status has to be updated
paymentStatus - Payment Status to be updated. The probable values are PaymentStatus.DECLINED, PaymentStatus.AUTHORIZED, PaymentStatus.PENDING

Returns:

Cart object which contains Payment Status

Response: Cart Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.
3307 - BAD REQUEST - The request parameters are invalid. Cart with the Id '<cartId>' is already in '<cartState>' state.
3308 - BAD REQUEST - The request parameters are invalid. Cart with the Id '<cartId>' is not in 'CHECKOUT' state. Payment cannot be initiated.
3319 - BAD REQUEST - The request parameters are invalid. Payment for cart with the Id '<cartId>' cannot be initiated since it is already in 'AUTHORIZED' state.
*/ 	      
For more details click Exception
String cartID = "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";
String transactionID = "transactionID";
PaymentStatus paymentStatus	= AUTHORIZED;					

Cart cart = cartService.payment(cartID, transactionID, paymentStatus); /* returns the Cart object. */ 
System.out.println("cartId is " + cart.getCartId());
Cart.Payment payment = cart.getPayment();
System.out.println("transactionId is " + payment.getTransactionId());
System.out.println("totalAmount is " + payment.getTotalAmount()); 
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                           
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30",
                    "payments": {
                        "payment": {
                            "transactionId": "transactionID",
                            "totalAmount": 1000,
                            "status": "AUTHORIZED",
                            "date": "2012-05-10T04:07:22.000Z"
                        }
                    }
                }
            }
        }
    }
}
public Vector getPaymentsByUser(String userId) throws App42Exception

Fetches Payment information for a User. This can be used to display Order and Payment History.

Parameters:

userId - User Id for whom payment information has to be fetched

Returns:

Vector Cart objects. Payment history can be retrieved from individual Cart object.

Response: Vector Cart Object

Exception:

This method throws following exception.
/* 
3310 - NOT FOUND - Cart for the user with the id '<userId>' does not exist. 
3311 - NOT FOUND - Payment transactions for the user with the id '<userId>' does not exist. 
*/ 		       
For more details click Exception
String userId = "mike@123";

Vector  cartList = cartService.getPaymentsByUser(userId); /* returns the list of Cart object. */ 
for(int i=0;i< cartList.size();i++)
{  
    Cart cart = (Cart) cartList.elementAt(i);  
	System.out.println("cartId is " + cart.getCartId());
	Cart.Payment payment = cart.getPayment();
	System.out.println("transactionId is " + payment.getTransactionId());
    System.out.println("totalAmount is " + payment.getTotalAmount()); 
}  
String jsonResponse = cartList.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30",
                    "payments": {
                        "payment": {
                            "transactionId": "transactionID",
                            "totalAmount": 1000,
                            "status": "AUTHORIZED",
                            "date": "2012-05-10T04:07:22.000Z"
                        }
                    }
                }
            }
        }
    }
}
public Cart getPaymentByCart(String cartId) throws App42Exception

Fetches Payment information for the specified Cart Id

Parameters:

cartId - Cart Id for which the payment information has to be fetched

Returns:

Cart object which contains Payment History for the specified Cart

Response: Cart Object

Exception:

This method throws following exception.
/* 
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist. 
3312 - NOT FOUND - Payment transactions for the  Cart with the id '<cartId>' does not exist. 
*/ 		       
For more details click Exception
String cartId = "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";

Cart cart = cartService.getPaymentByCart(cartId); /* returns the Cart object. */ 
System.out.println("cartId is " + cart.getCartId()); 
Cart.Payment payment = cart.getPayment();
System.out.println("transactionId is " + payment.getTransactionId());
System.out.println("totalAmount is " + payment.getTotalAmount());   
System.out.println("status is " + payment.getstatus());
System.out.println("date is " + payment.getdate()); 
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30",
                    "payments": {
                        "payment": {
                            "transactionId": "transactionID",
                            "totalAmount": 1000,
                            "status": "AUTHORIZED",
                            "date": "2012-05-10T04:07:22.000Z"
                        }
                    }
                }
            }
        }
    }
}
public Vector getPaymentsByUserAndStatus(String userId, PaymentStatus paymentStatus) throws App42Exception

Fetches Payment information based on User Id and Status

Parameters:

userId - User Id for whom payment information has to be fetched
paymentStatus - Status of type which payment information has to be fetched

Returns:

Payment History

Response: Vector Cart Object

Exception:

This method throws following exception.
/* 
3313 - NOT FOUND - Cart for the user with the id '<userIdgt;' and status '<status>' does not exist. 
3314 - NOT FOUND - Payment transactions for the user with the id '<userId>' and status '<status>' does not exist. 
*/ 	     
For more details click Exception
String userId = "mike@123";
String paymentStatus = PaymentStatus.AUTHORIZED ;

Vector  cartList = cartService.getPaymentsByUserAndStatus(userId, paymentStatus); /* returns the list of Cart object. */ 
for(int i=0;i< cartList.size();i++)
{  
    Cart cart = (Cart) cartList.elementAt(i);  
	System.out.println("cartId is " + cart.getCartId()); 
	Cart.Payment payment = cart.getPayment();
	System.out.println("transactionId is " + payment.getTransactionId());
    System.out.println("totalAmount is " + payment.getTotalAmount());           
} 
String jsonResponse = cartList.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30",
                    "payments": {
                        "payment": {
                            "transactionId": "transactionID",
                            "totalAmount": 1000,
                            "status": "AUTHORIZED",
                            "date": "2012-05-10T04:07:22.000Z"
                        }
                    }
                }
            }
        }
    }
}
public Vector getPaymentsByStatus(PaymentStatus paymentStatus) throws App42Exception

Fetches Payment information based on Status.

Parameters:

paymentStatus - Status of type which payment information has to be fetched

Returns:

Vector Cart objects. Payment history can be retrieved from individual Cart object.

Response: Vector Cart Object

Exception:

This method throws following exception.
/* 
3315 - NOT FOUND - Payment transactions for the status '<status>' does not exist. 
*/ 		      
For more details click Exception
String paymentStatus = AUTHORIZED;

Vector  cartList = cartService.getPaymentsByStatus(paymentStatus); /* returns the list of Cart object. */ 
for(int i=0;i< cartList.size();i++)
{  
    Cart cart = (Cart) cartList.elementAt(i);  
	System.out.println("cartId is " + cart.getCartId()); 
	Cart.Payment payment = cart.getPayment();
	System.out.println("transactionId is " + payment.getTransactionId());
	System.out.println("totalAmount is " + payment.getTotalAmount());       
}  
String jsonResponse = cartList.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "154a1ec1af463eaf0780fc580f19e853613518fde415eacebde89993ef633b92",
                    "payments": {
                        "payment": {
                            "transactionId": "transactionID",
                            "totalAmount": 5050,
                            "status": "AUTHORIZED",
                            "date": "2012-06-01T03:11:41.000Z"
                        }
                    }
                }
            }
        }
    }
}
public Vector getPaymentHistoryByUser(String userId) throws App42Exception

History of Carts and Payments for a User. It gives all the carts which are in AUTHORIZED, DECLINED, PENDING state.

Parameters:

userId - User Id for whom payment history has to be fetched

Returns:

Vector Cart objects. Payment history can be retrieved from individual Cart object.

Response: Vector Cart Object

Exception:

This method throws following exception.
/*
3316 - NOT FOUND - Cart for the user with the id '<userId>' does not exist in payment history.
*/  		       
For more details click Exception
String userId = "mike@123";

Vector  cartList = cartService.getPaymentHistoryByUser(userId); /* returns the list of Cart object. */ 
for(int i=0;i< cartList.size();i++)
{    
   Cart cart = (Cart) cartList.elementAt(i);    
   System.out.println("userName is " + cart.getUserName()); 
   System.out.println("cartId is " + cart.getCartId()); 
   System.out.println("state is " + cart.getState()); 	
   Vector itemList = cart.getItemList();
for(int j=0;j< itemList.size();j++)
{ 
	Cart.Item item = (Cart.Item) itemList.elementAt(j); 
	System.out.println("itemId is " + item.getItemId()); 
	System.out.println("quantity is " + item.getQuantity());
	System.out.println("totalAmount is " + item.getTotalAmount());
}
	Cart.Payment payment = cart.getPayment();  
	System.out.println("transactionId is " + payment.getTransactionId()); 
    System.out.println("totalAmount is " + payment.getTotalAmount());  
} 
String jsonResponse = cartList.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "userName": "Nick",
                    "cartId": "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30",
                    "creationTime": "2012-05-10T04:06:18.000Z",
                    "checkOutTime": "2012-05-10T04:07:21.000Z",
                    "state": "AUTHORIZED",
                    "items": {
                        "item": {
                            "itemId": "ItemID01",
                            "quantity": 122,
                            "totalAmount": 1000
                        }
                    },
                    "payments": {
                        "payment": {
                            "transactionId": "transactionID",
                            "totalAmount": 1000,
                            "status": "AUTHORIZED",
                            "date": "2012-05-10T04:07:22.000Z"
                        }
                    }
                }
            }
        }
    }
}
public Vector getPaymentHistoryAll() throws App42Exception

History of all carts. It gives all the carts which are in AUTHORIZED, DECLINED, PENDING state.

Parameters:

N/A

Returns:

Vector Cart objects. Payment history can be retrieved from individual Cart object.

Response: Vector Cart Object

Exception:

This method throws following exception.
/* 
3317 - NOT FOUND - Carts with status ('DECLINED', 'PENDING', 'AUTHORIZED') does not exist in payment history. 
*/ 		  
For more details click Exception
Vector  cartList = cartService.getPaymentHistoryAll(); /* returns the list of Cart object. */ 
for(int i=0;i< cartList.size();i++)
{    
    Cart cart = (Cart) cartList.elementAt(i);    
    System.out.println("userName is " + cart.getUserName()); 
	System.out.println("cartId is " + cart.getCartId()); 
    System.out.println("state is " + cart.getState()); 
    Vector itemList = cart.getItemList();
for(int j=0;j< itemList.size();j++)
{ 
	Cart.Item item = (Cart.Item) itemList.elementAt(j); 
	System.out.println("itemId is " + item.getItemId()); 
	System.out.println("quantity is " + item.getQuantity());
	System.out.println("totalAmount is " + item.getTotalAmount()); 
}
	Cart.Payment payment = cart.getPayment();  
	System.out.println("transactionId is " + payment.getTransactionId()); 
    System.out.println("totalAmount is " + payment.getTotalAmount());  
}
String jsonResponse = cartList.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": [
                    {
                        "userName": "Nick",
                        "cartId": "bff030558be32e9225e33b75a825d822a9f30c3c940ebf7be73fdd9680e0ea28",
                        "creationTime": "2012-05-12T07:19:32.000Z",
                        "checkOutTime": "2012-05-12T07:19:33.000Z",
                        "state": "AUTHORIZED",
                        "items": {
                            "item": {
                                "itemId": "itemID",
                                "quantity": 5,
                                "totalAmount": 5050
                            }
                        },
                        "payments": {
                            "payment": {
                                "transactionId": "transactionID",
                                "totalAmount": 5050,
                                "status": "AUTHORIZED",
                                "date": "2012-05-12T07:19:33.000Z"
                            }
                        }
                    },
                    {
                        "userName": "Nick",
                        "cartId": "1f37c7045c18455f5dc9aea5877ed5f469e18436d32fbf0922699d951ec09263",
                        "creationTime": "2012-05-12T07:23:52.000Z",
                        "checkOutTime": "2012-05-12T07:23:53.000Z",
                        "state": "AUTHORIZED",
                        "items": {
                            "item": {
                                "itemId": "itemID",
                                "quantity": 5,
                                "totalAmount": 5050
                            }
                        },
                        "payments": {
                            "payment": {
                                "transactionId": "transactionID",
                                "totalAmount": 5050,
                                "status": "AUTHORIZED",
                                "date": "2012-05-12T07:23:53.000Z"
                            }
                        }
                    },
                    {
                        "userName": "userName": "Nick",
                        "cartId": "e0ad6792876b5682bf57de10dd1076787212accbda5e2270778862e5c81c9aba",
                        "creationTime": "2012-05-13T00:17:55.000Z",
                        "checkOutTime": "2012-05-13T00:17:55.000Z",
                        "state": "AUTHORIZED",
                        "items": {
                            "item": {
                                "itemId": "itemID",
                                "quantity": 5,
                                "totalAmount": 5050
                            }
                        },
                        "payments": {
                            "payment": {
                                "transactionId": "transactionID",
                                "totalAmount": 5050,
                                "status": "AUTHORIZED",
                                "date": "2012-05-13T00:17:55.000Z"
                            }
                        }
                    }
                ]
            }
        }
    }
}
public Cart increaseQuantity(String cartID, String itemID, int itemQuantity) throws App42Exception

Increase the quantity of specified Item to the specified Cart

Parameters:

cartID - The cart id for which item has to be increased
itemID - The item id that has to be increased
itemQuantity - The quantity of the item that has to be increased

Returns:

Cart object containing updated item.

Response: Cart Object

Exception:

This method throws following exception.
/*
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.
3303 - BAD REQUEST - The request parameters are invalid. Item to the cart with the Id '<cartId>' cannot be added since it is in '<cartState>' state.
3322 - NOT FOUND - Item with the id '<itemId>' in the cart with the id '<cartId>' does not exist.	
*/		   
For more details click Exception
String cartID = "735eef8a7745cd4c16ca30356d0cfd784736aa695f0200f73980dd154ba8f7fb";
String itemID = "ItemID090";
int itemQuantity = 5;
		  
Cart cart = cartService.increaseQuantity(cartID, itemID, itemQuantity); /* returns the Cart object. */ 
System.out.println("cartId is " + cart.getCartId()); 
Vector itemList = cart.getItemList();
for (int i= 0; i< itemList.size(); i++)
{
	Cart.Item item = (Cart.Item) itemList.elementAt(i);
	System.out.println("itemId is " + item.getItemId()); 
	System.out.println("quantity is " + item.getQuantity());
	System.out.println("price is " + item.getPrice());
	System.out.println("totalAmount is " + item.getTotalAmount());
}
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "735eef8a7745cd4c16ca30356d0cfd784736aa695f0200f73980dd154ba8f7fb",
                    "items": {
                        "item": {
                            "itemId": "ItemID090",
                            "quantity": 5,
                            "price": 5050,
                            "totalAmount": 25250
                        }
                    }
                }
            }
        }
    }
}
public Cart decreaseQuantity(String cartID, String itemID, int itemQuantity) throws App42Exception

Increase the quantity of specified Item to the specified Cart

Parameters:

cartID - The cart id for which item has to be increased
itemID - The item id that has to be increased
itemQuantity - The quantity of the item that has to be increased

Returns:

Cart object containing updated item.

Response: Cart Object

Exception:

This method throws following exception.
/*
3301 - NOT FOUND - Cart with the id '<cartId>' does not exist.
3303 - BAD REQUEST - The request parameters are invalid. Item to the cart with the Id '<cartId>' cannot be added since it is in '<cartState>' state.
3321 - BAD REQUEST - The request parameters are invalid. Requested quantity should be less then existing quantity.
3322 - NOT FOUND - Item with the id '<itemId>' in the cart with the id '<cartId>' does not exist.	
*/  		 
For more details click Exception
String cartID = "735eef8a7745cd4c16ca30356d0cfd784736aa695f0200f73980dd154ba8f7fb";
String itemID = "ItemID090";
int itemQuantity = 3;

Cart cart = cartService.decreaseQuantity(cartID, itemID, itemQuantity); /* returns the Cart object. */ 
System.out.println("cartId is " + cart.getCartId()); 
Vector itemList = cart.getItemList();
for (int i= 0; i< itemList.size(); i++)
{
	Cart.Item item = (Cart.Item) itemList.elementAt(i);
	System.out.println("itemId is " + item.getItemId()); 
	System.out.println("quantity is " + item.getQuantity());
	System.out.println("price is " + item.getPrice());
	System.out.println("totalAmount is " + item.getTotalAmount());
}
String jsonResponse = cart.toString(); /* returns the response in JSON format. (as shown below)*/                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "735eef8a7745cd4c16ca30356d0cfd784736aa695f0200f73980dd154ba8f7fb",
                    "items": {
                        "item": {
                            "itemId": "ItemID090",
                            "quantity": 3,
                            "price": 5050,
                            "totalAmount": 15150
                        }
                    }
                }
            }
        }
    }
}