App42 Cloud API

iOS 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 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 allocate and initialize an instance of ServiceAPI. After initialization, apiKey and secretKey needs to be set which has been received while creating an application under App42.

ServiceAPI *serviceAPIObj = [[ServiceAPI alloc]init];
serviceAPIObj.apiKey = @"<API_KEY>";
serviceAPIObj.secretKey = @"<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 = [serviceAPIObj 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.

NSString *user = @"Nick";
Cart *cart = [cartService createCart:cartName]; /* returns the Cart object. */ 
NSLog(@"userName is = %@",cart.userName);
NSLog(@"cartId is = %@",cart.cartId);
NSString *jsonResponse = [cart toString]; /* returns the response in JSON format. */
2

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 '{Id}' does not Exist".

NSString *cartId = @"41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
@try{
	Cart *cart = [cartService getCartDetails:cartId]; /* returns the Cart object. */ 
} @catch(App42Exception *ex) {
	int appErrorCode = ex.appErrorCode;
	int httpErrorCode = ex.httpErrorCode;
	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
	}	
	NSString *jsonText = ex.reason; /* returns the Exception text in JSON format. (as shown below)*/
	{
		"app42Fault": {
			"httpErrorCode": 404,
			"appErrorCode": 3301,
			"message": "Not Found",
			"details": "Cart with the id '1145' 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 cartHistoryXXX methods. 
3303 - BAD REQUEST - The Request parameters are invalid. Item to the Cart with the Id {cartId} cannot be added since it is in {cartRow.state} 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 {cartRow.state} 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 {cartRow.state} 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 {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 {userId} 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 - Cart for  the service {serviceId} does not Exist in Payment History 
3318 - BAD REQUEST - The Request parameters are invalid. Items from the Cart with the Id {cartId} cannot be removed since it is in {cartRow.state} state. 
3319 - BAD REQUEST - The Request parameters are invalid. Payment for Cart with the Id {cartId} cannot be initiated since it is alread in 'AUTHORIZED' state      
3320 - BAD REQUEST - Item with the Id {itemId} in the Cart with the id {cartId} already exist. Please use 'increaseQuantity' api 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.

-(Cart*)createCart:(NSString*)user

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
NSString *user = @"Nick";  
Cart *cart = [cartService createCart:cartName]; /* returns the Cart object. */ 
NSLog(@"userName is = %@",cart.userName);
NSLog(@"cartId is = %@",cart.cartId);
NSString *jsonResponse = [cart toString]; /* returns the response in JSON format. */
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "userName": "Nick",
                    "cartId": "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325",
                    "creationTime": "2012-05-10T03:38:14.000Z",
                    "cartSession": "NEW"
                }
            }
        }
    }
}

-(Cart*)getCartDetails:(NSString*)cartId

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartId = @"41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
Cart *cart = [cartService getCartDetails:cartId]; /* returns the Cart object. */ 
NSString *userName = cart.userName; 
NSString *cartId = cart.cartId; 
NSString *state = cart.state;
double totalAmount = cart.totalAmount;

NSString *jsonResponse = [cart toString];  /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "userName": "Cart20",
                    "cartId": "0aed1d3b855d01c81bc424e770f6b28105bd7fdf12ae0af09ea35a5bce237ecb",
                    "creationTime": "2012-05-10T05:00:36.000Z",
                    "checkOutTime": "2012-05-10T05:00:36.000Z",
                    "state": "CHECKOUT"
                }
            }
        }
    }
}

-(Cart*)addItem:(NSString*)cartID itemID:(NSString*)itemID itemQuantity:(int)itemQuantity price:(double)price

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartID = @"41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
NSString *itemID = @"ItemID01";
int itemQuantity = 12;
double price = 1000;						
Cart *cart = [cartService addItem:cartID itemID:itemID itemQuantity:itemQuantity price:price]; /* returns the Cart object. */ 
NSLog(@"cartId is = %@",cart.cartId);
NSMutableArray *itemList = cart.itemListArray;
for(Item *item in itemList)
{
	NSLog(@"itemId is = %@",item.itemId);
	NSLog(@"quantity is = %i",item.quantity);
	NSLog(@"price is = %f",item.price);
	NSLog(@"totalAmount is = %@",item.totalAmount);
}
NSString *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
                        }
                    }
                }
            }
        }
    }
}



-(Cart*)getItems:(NSString*)cartId

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartId = @"41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
Cart *cart = [cartService getItems:cartId]; /* returns the Cart object. */ 
NSLog(@"cartId is = %@",cart.cartId);
NSMutableArray *itemList = cart.itemListArray;
for(Item *item in itemList)
{
	NSLog(@"itemId is = %@",item.itemId);
	NSLog(@"quantity is = %i",item.quantity);
	NSLog(@"price is = %f",item.price);
	NSLog(@"totalAmount is = %@",item.totalAmount);
}
NSString *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
                            }
                        ]
                    }
                }
            }
        }
    }
}

-(Cart*)getItem:(NSString*)cartId itemId:(NSString*)itemId

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartId = @"41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
NSString *itemId = @"ItemID01";
Cart *cart = [cartService getItem:cartId itemId:itemId]; /* returns the Cart object. */ 
NSLog(@"cartId is = %@",cart.cartId);
NSMutableArray *itemList = cart.itemListArray;
for(Item *item in itemList)
{
	NSLog(@"itemId is = %@",item.itemId);
	NSLog(@"quantity is = %i",item.quantity);
	NSLog(@"price is = %f",item.price);
	NSLog(@"totalAmount is = %@",item.totalAmount);
}
NSString *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
                        }
                    }
                }
            }
        }
    }
}

-(App42Response*)removeItem:(NSString*)cartId itemId:(NSString*)itemId

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartId = @"7452d7ad3d3c86197d95b7060662533e05bd1995313b8aa4ac675728044b205e";
NSString *itemId =	@"itemID";					
App42Response *response = [cartService removeItem:cartId itemId:itemId]; /* returns the App42Response object. */
BOOL success = response.isResponseSuccess;
NSString *jsonResponse = [cart 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
                        }
                    }
                }
            }
        }
    }
}
-(App42Response*)removeAllItems:(NSString*)cartId

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartId = @"665bd3b621b83ff09a6b3a08604ac01148751b5e21438f64c6de4b0256aaa584";
						
App42Response *response = [cartService removeAllItems:cartId]; /* returns the App42Response object. */
BOOL success = response.isResponseSuccess;
NSString *jsonResponse = [cart 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
                            }
                        ]
                    }
                }
            }
        }
    }
}

-(Cart*)isEmpty:(NSString*)cartId

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartId = @"5527cc1eb516ffeaf8c927782f196757ef2feb4ad43efbe8b6bf37e52d83f4af";						

Cart *cart = [cartService isEmpty:cartId]; /* returns the Cart object. */ 
NSLog(@"cartId is = %@",cart.cartId);
NSString *jsonResponse = [cart toString];  /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "5527cc1eb516ffeaf8c927782f196757ef2feb4ad43efbe8b6bf37e52d83f4af",
                    "isEmpty": true
                }
            }
        }
    }
}

-(Cart*)checkOut:(NSString*)cartID

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartID = @"5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";
Cart *cart = [cartService checkOut:cartID]; /* returns the Cart object. */ 
NSLog(@"cartId is = %@",cart.cartId);
NSLog(@"state is = %@",cart.state);
NSLog(@"totalAmount is = %f",cart.totalAmount);
NSString *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"
                }
            }
        }
    }
}

-(Cart*)payment:(NSString*)cartID transactionID:(NSString*)transactionID paymentStatus:(NSString*)paymentStatus

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartID = @"5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";
NSString *transactionID = @"transactionID";
NSString *paymentStatus	= AUTHORIZED;					

Cart *cart = [cartService payment:cartID transactionID:transactionID paymentStatus:paymentStatus]; /* returns the Cart object. */ 
NSLog(@"cartId is = %@",cart.cartId);
NSLog(@"totalAmount is = %f",cart.totalAmount);
Payment *payment = cart.paymentObject;
NSLog(@"transactionId is = %@",payment.transactionId);
NSString *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"
                        }
                    }
                }
            }
        }
    }
}

-(NSArray*)getPaymentsByUser:(NSString*)userId

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:

List containing Cart objects. Payment history can be retrieved from individual Cart object.

Response:NSArray

Exception:

The method throws the following exception with the error code.
/* 
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
NSString *userId = @"mike@123";
						
NSArray *cartList = [cartService getPaymentsByUser:userId]; /* returns the list of Cart object. */ 
for(Cart *cart in cartList){
	NSLog(@"cartId is = %@",cart.cartId);
	NSLog(@"totalAmount is = %f",cart.totalAmount);
	Payment *payment = cart.paymentObject;
	NSLog(@"transactionId is = %@",payment.transactionId);
	NSString *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"
                        }
                    }
                }
            }
        }
    }
}


-(Cart*)getPaymentsByCart:(NSString*)cartID

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:

The method throws the following exception with the error code.
/* 
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
NSString *cartId = @"5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";

Cart *cart = [cartService getPaymentsByCart:cartID]; /* returns the Cart object. */ 
Payment *payment = cart.paymentObject;
NSLog(@"transactionId is = %@",payment.transactionId);
NSLog(@"status is = %@",payment.status);
NSLog(@"date is = %@",payment.date);
NSString *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"
                        }
                    }
                }
            }
        }
    }
}
-(NSArray*)getPaymentsByUserAndStatus:(NSString*)userId status:(NSString*)paymentStatus

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:

List containing Cart objects. Payment history can be retrieved from individual Cart object.
Payment History

Response:NSArray

Exception:

The method throws the following exception with the error code.
/* 
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
NSString *userId = @"mike@123";
NSString *paymentStatus = AUTHORIZED ;

NSArray *cartList = [cartService getPaymentsByUserAndStatus:userId status:paymentStatus]; /* returns the list of Cart object. */ 
for(Cart *cart in cartList){
	NSLog(@"cartId is = %@",cart.cartId);
	Payment *payment = cart.paymentObject;
	NSLog(@"totalAmount is = %f",payment.totalAmount);
	NSLog(@"transactionId is = %@",payment.transactionId);
	NSString *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"
                        }
                    }
                }
            }
        }
    }
}
-(NSArray*)getPaymentsByStatus:(NSString*)paymentStatus

Fetches Payment information based on Status.

Parameters:

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

Returns:

List containing Cart objects. Payment history can be retrieved from individual Cart object.

Response:NSArray

Exception:

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

NSArray *cartList = [cartService getPaymentsByStatus:paymentStatus]; /* returns the list of Cart object. */ 
for(Cart *cart in cartList){
	NSLog(@"cartId is = %@",cart.cartId);
	Payment *payment = cart.paymentObject;
	NSLog(@"totalAmount is = %f",payment.totalAmount);
	NSLog(@"transactionId is = %@",payment.transactionId);
	NSString *jsonResponse = [cart toString];  /* returns the response in JSON format. (as shown below)*/								
}
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "bff030558be32e9225e33b75a825d822a9f30c3c940ebf7be73fdd9680e0ea28",
                    "totalAmount": 5050,
                    "state": "CHECKOUT",
                    "checkOutDate": "2012-05-12T07:19:33.000Z"
                }
            }
        }
    }
}


-(NSArray*)getPaymentHistoryByUser:(NSString*)userId

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:

List containing Cart objects. Payment history can be retrieved from individual Cart object.

Response:NSArray

Exception:

The method throws the following exception with the error code.
/*
3316 - NOT FOUND - Cart for the user with the id '<userId>' does not exist in payment history.
*/ 		       
For more details click Exception
NSString *userId = @"mike@123";
NSArray *cartList = [cartService getPaymentHistoryByUser:userId]; /* returns the list of Cart object. */ 
for(Cart *cart in cartList){
	NSLog(@"userName is = %@",cart.userName);
	NSLog(@"cartId is = %@",cart.cartId);
	NSLog(@"state is = %@",cart.state);
	NSMutableArray *itemList = cart.itemListArray;
	for(Item *item in itemList)
	{
		NSLog(@"itemId is = %@",item.itemId);
		NSLog(@"quantity is = %i",item.quantity);
		NSLog(@"totalAmount is = %f",item.totalAmount);
	}
	Payment *payment = cart.paymentObject;
	NSLog(@"totalAmount is = %f",payment.totalAmount);
	NSLog(@"transactionId is = %@",payment.transactionId);
	NSString *jsonResponse = [cart 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"
                        }
                    }
                }
            }
        }
    }
}
-(NSArray*)getPaymentHistoryAll

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

Parameters:

N/A

Returns:

List containing Cart objects. Payment history can be retrieved from individual Cart object.

Response:NSArray

Exception:

The method throws the following exception with the error code.
/* 
3317 - NOT FOUND - Carts with status ('DECLINED', 'PENDING', 'AUTHORIZED') does not exist in payment history. 
*/ 		  
For more details click Exception
NSArray *cartList = [cartService getPaymentHistoryAll]; /* returns the list of Cart object. */ 
for(Cart *cart in cartList){
	NSLog(@"userName is = %@",cart.userName);
	NSLog(@"cartId is = %@",cart.cartId);
	NSLog(@"state is = %@",cart.state);
	NSMutableArray *itemList = cart.itemListArray;
	for(Item *item in itemList)
	{
		NSLog(@"itemId is = %@",item.itemId);
		NSLog(@"quantity is = %i",item.quantity);
		NSLog(@"totalAmount is = %f",item.totalAmount);
	}
	Payment *payment = cart.paymentObject;
	NSLog(@"totalAmount is = %f",payment.totalAmount);
	NSLog(@"transactionId is = %@",payment.transactionId);
	NSString *jsonResponse = [cart toString];  /* returns the response in JSON format. (as shown below)*/								
}
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": [
                    {
                        "userName": "user01",
                        "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": "cartChaltey06:23:30",
                        "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": "cartChaltey11:17:51",
                        "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"
                            }
                        }
                    }
                ]
            }
        }
    }
}

-(Cart*)increaseQuantity:(NSString*)cartID itemID:(NSString*)itemID itemQuantity:(int)itemQuantity

To increase quantity of existing item in the 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:

The method throws the following exception with the error code.
/*
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
NSString *cartID = @"735eef8a7745cd4c16ca30356d0cfd784736aa695f0200f73980dd154ba8f7fb";
NSString *itemID = @"ItemID090";
int itemQuantity = 5;
 
Cart *cart = [cartService increaseQuantity:cartID itemID:itemID itemQuantity:itemQuantity]; /* returns the Cart object. */ 
for(Cart *cart in cartList){
	NSLog(@"userName is = %@",cart.userName);
	NSLog(@"cartId is = %@",cart.cartId);
	NSLog(@"state is = %@",cart.state);
	NSMutableArray *itemList = cart.itemListArray;
	for(Item *item in itemList)
	{
		NSLog(@"itemId is = %@",item.itemId);
		NSLog(@"quantity is = %i",item.quantity);
		NSLog(@"totalAmount is = %f",item.totalAmount);
		NSLog(@"price is = %f",item.price);
	}
	NSString *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
                        }
                    }
                }
            }
        }
    }
}

-(Cart*)decreaseQuantity:(NSString*)cartID itemID:(NSString*)itemID itemQuantity:(int)itemQuantity

To decrease quantity of existing item in the 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:

The method throws the following exception with the error code.
/*
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
NSString *cartID = @"735eef8a7745cd4c16ca30356d0cfd784736aa695f0200f73980dd154ba8f7fb";
NSString *itemID = @"ItemID090";
int itemQuantity = 3;
Cart *cart = [cartService decreaseQuantity:cartID itemID:itemID itemQuantity:itemQuantity]; /* returns the Cart object. */ 
for(Cart *cart in cartList){
	NSLog(@"userName is = %@",cart.userName);
	NSLog(@"cartId is = %@",cart.cartId);
	NSLog(@"state is = %@",cart.state);
	NSMutableArray *itemList = cart.itemListArray;
	for(Item *item in itemList)
	{
		NSLog(@"itemId is = %@",item.itemId);
		NSLog(@"quantity is = %i",item.quantity);
		NSLog(@"totalAmount is = %f",item.totalAmount);
		NSLog(@"price is = %f",item.price);
	}
	NSString *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
                        }
                    }
                }
            }
        }
    }
}