App42 Cloud API

Ruby 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.

  api = App42::ServiceAPI.new("<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 = 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.

cartName = "Nick";
						
cart = cartService.create_cart(cartName); /* returns the Cart object. */ 
puts "userName is #{cart.userName}";
puts "cartId is #{cart.cartId}";
jsonResponse = cart.to_s(); /* returns the response in JSON format. */

The functions available under Shopping Cart 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".

user = "Nick";
							
begin
  cart = cartService.get_cart_details(cartId);
rescue App42Exception => ex
  appErrorCode = ex.app_error_code;
  httpErrorCode = ex.http_error_code;

  if(appErrorCode == 3301)
    #Handle here for Not Found (Cart with the id '<cartId>' does not exist.)

  elsif(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.)

  elsif(appErrorCode == 1401)
    #handle here for Client is not authorized

  else(appErrorCode == 1500)
    #handle here for Internal Server Error
  end

  jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
end
	{
		"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 '<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 - 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.

def create_cart(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
user = "Nick";		
				
cart = cartService.create_cart(user); /* returns the Cart object. */ 
puts "userName is #{cart.userName}";
puts "cartId is #{cart.cartId}";
jsonResponse = cart.to_s(); /* 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"
                }
            }
        }
    }
}
def get_cart_details(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 '' state. Please use the paymentHistoryXXX methods.
*/
For more details click Exception
cartId = "0aed1d3b855d01c81bc424e770f6b28105bd7fdf12ae0af09ea35a5bce237ecb";
						
cart = cartService.get_cart_details(cartId); /* returns the Cart object. */ 
puts "userName is #{cart.userName}";
puts "cartId is #{cart.cartId}";
puts "state is #{cart.state}";
jsonResponse = cart.to_s(); /* 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"
                }
            }
        }
    }
}
def add_item(cartID, itemID, itemQuantity, 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
cartID = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
itemID = "ItemID01";
itemQuantity = 12;
price = 1000;
						
cart = cartService.add_item(cartID, itemID, itemQuantity, price); /* returns the Cart object. */
puts "cartId is #{cart.cartId}";
itemList = Array.new();
itemList = cart.getItemList();
for item in itemList do
  puts "itemid is #{item.itemId}";
  puts "quantity is #{item.quantity}";
  puts "price is #{item.price}";
  puts "totalAmount is #{item.totalAmount}";
end
jsonResponse = cart.to_s(); /* 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
                        }
                    }
                }
            }
        }
    }
}
def get_items(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
cartId = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
						
cart = cartService.get_items(cartID); /* returns the Cart object. */
puts "cartId is #{cart.cartId}";
itemList = Array.new();
itemList = cart.getItemList();
for item in itemList do
  puts "itemid is #{item.itemId}";
  puts "quantity is #{item.quantity}";
  puts "price is #{item.price}";
  puts "totalAmount is #{item.totalAmount}";
end
jsonResponse = cart.to_s(); /* 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
                            }
                        ]
                    }
                }
            }
        }
    }
}
def get_item(cartId, 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
cartId = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
itemId = "ItemID01";
						
cart = cartService.get_item(cartID,itemId); /* returns the Cart object. */
puts "cartId is #{cart.cartId}";
itemList = Array.new();
itemList = cart.getItemList();
for item in itemList do
  puts "itemid is #{item.itemId}";
  puts "quantity is #{item.quantity}";
  puts "price is #{item.price}";
  puts "totalAmount is #{item.totalAmount}";
end
jsonResponse = cart.to_s(); /* 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
                        }
                    }
                }
            }
        }
    }
}
def remove_item(cartId, 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
cartId = "7452d7ad3d3c86197d95b7060662533e05bd1995313b8aa4ac675728044b205e";
itemId = "itemID";
						
response = cartService.remove_item(cartId, itemId); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* 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
                        }
                    }
                }
            }
        }
    }
}
def remove_all_items(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
cartId = "665bd3b621b83ff09a6b3a08604ac01148751b5e21438f64c6de4b0256aaa584";
						
response = cartService.remove_all_items(cartId); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* 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
                            }
                        ]
                    }
                }
            }
        }
    }
}
def is_empty(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
cartId = "5527cc1eb516ffeaf8c927782f196757ef2feb4ad43efbe8b6bf37e52d83f4af";
						
cart = cartService.is_empty(cartId); /* returns the Cart object. */ 
puts "cartId is #{cart.cartId}"; 
jsonResponse = cart.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "carts": {
                "cart": {
                    "cartId": "5527cc1eb516ffeaf8c927782f196757ef2feb4ad43efbe8b6bf37e52d83f4af",
                    "isEmpty": true
                }
            }
        }
    }
}
def check_out(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 - TThe 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
cartID = "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";
						
cart = cartService.check_out(cartID); /* returns the Cart object. */ 
puts "itemid is #{item.itemId}";
puts "quantity is #{item.quantity}";
puts "price is #{item.price}";
puts "totalAmount is #{item.totalAmount}";
jsonResponse = cart.to_s(); /* 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"
                }
            }
        }
    }
}
def payment(cartId, transactionID, 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 '' 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
cartID = "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";
transactionID = "transactionID";
paymentStatus = AUTHORIZED;
						
cart = cartService.payment(cartID, transactionID, paymentStatus); /* returns the Cart object. */ 
puts "cartId is #{cart.cartId}";
puts "payment is #{cart.payment}"; 
puts "transactionId is #{cart.transactionId}";
puts "totalAmount is #{cart.totalAmount}";
jsonResponse = cart.to_s(); /* 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"
                        }
                    }
                }
            }
        }
    }
}
def get_payments_by_user(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:

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

Response: ArrayList<Cart> Object

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
userId = "mike@123";
						
cartList = Array.new();
cartList = cart.get_payments_by_user(userId);/* returns the list of Cart object. */
for cart in cartList do
  puts "cartId is #{cart.cartId}";
  puts "payment is #{cart.payment}";
  puts "transactionId is #{cart.transactionId}";
  puts "totalAmount is #{cart.totalAmount}";
end
jsonResponse = cartList.to_s(); /* 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"
                        }
                    }
                }
            }
        }
    }
}
def get_payment_by_cart(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
cartId = "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";
						
cartList = Array.new();
cartList = cart.get_payment_by_cart(cartId);/* returns the list of Cart object. */
for cart in cartList do
  puts "cartId is #{cart.cartId}";
  puts "payment is #{cart.payment}";
  puts "transactionId is #{cart.transactionId}";
  puts "totalAmount is #{cart.totalAmount}";
end
jsonResponse = cartList.to_s(); /* 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"
                        }
                    }
                }
            }
        }
    }
}
def get_payments_by_user_and_status(userId, 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:

Payment History

Response: ArrayList<Cart> Object

Exception:

The method throws the following exception with the error code
/* 
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. 
*/
For more details click Exception
userId = "mike@123";
pStatus = App42::Shopping::PaymentStatus.new();
paymentStatus = pStatus.enum("AUTHORIZED");
				
cartList = Array.new();
cartList = cartService.get_payments_by_user_and_status(userId, paymentStatus); /* returns the list of Cart object. */
for cart in cartList do
  puts "cartId is #{cart.cartId}";
  puts "payment is #{cart.payment}";
  puts "transactionId is #{cart.transactionId}";
  puts "totalAmount is #{cart.totalAmount}";
end
jsonResponse = cartList.to_s(); /* 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"
                        }
                    }
                }
            }
        }
    }
}
def get_payments_by_status(paymentStatus)

Fetches Payment information based on Status.

Parameters:

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

Returns:

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

Response: ArrayList<Cart> Object

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
pStatus = App42::Shopping::PaymentStatus.new();
paymentStatus = pStatus.enum("AUTHORIZED");
						
cartList = Array.new();
cartList = cartList = cartService.get_payments_by_status(paymentStatus); /* returns the list of Cart object. */
for cart in cartList do
  puts "cartId is #{cart.cartId}";
  puts "payment is #{cart.payment}";
  puts "transactionId is #{cart.transactionId}";
  puts "totalAmount is #{cart.totalAmount}";
end
jsonResponse = cartList.to_s(); /* 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"
                        }
                    }
                }
            }
        }
    }
}
def get_payment_history_by_user(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:

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

Response: ArrayList<Cart> Object

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
userId = "mike@123";
						
cartList = Array.new();
cartList = cartService.get_payment_history_by_user(userId);  /* returns the list of Cart object. */
for cart in cartList do
  puts "userName is #{cart.userName}";
  puts "cartId is #{cart.cartId}";
  puts "state is #{cart.state}";
  itemList =Array.new();
  itemList = cart.getItemList();
  for item in itemList do
    puts "itemid is #{item.itemId}";
    puts "quantity is #{item.quantity}";
    puts "price is #{item.price}";
    puts "totalAmount is #{item.totalAmount}";
  end
  puts "payment is #{cart.payment}";
  puts "transactionId is #{cart.transactionId}";
  puts "totalAmount is #{cart.totalAmount}";
end
jsonResponse = cartList.to_s(); /* 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"
                        }
                    }
                }
            }
        }
    }
}
def get_payment_history_all()

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

Parameters:

N/A

Returns:

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

Response: ArrayList<Cart> Object

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
cartList = Array.new();
cartList = cartService.get_payment_history_all(); /* returns the list of Cart object. */
for cart in cartList do
  puts "userName is #{cart.userName}";
  puts "cartId is #{cart.cartId}";
  puts "state is #{cart.state}";
  itemList =Array.new();
  itemList = cart.getItemList();
  for item in itemList do
    puts "itemid is #{item.itemId}";
    puts "quantity is #{item.quantity}";
    puts "price is #{item.price}";
    puts "totalAmount is #{item.totalAmount}";
  end
  puts "cartId is #{cart.cartId}";
  puts "payment is #{cart.payment}";
  puts "transactionId is #{cart.transactionId}";
  puts "totalAmount is #{cart.totalAmount}";
end
jsonResponse = cartList.to_s(); /* 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"
                            }
                        }
                    }
                ]
            }
        }
    }
}
def increase_quantity(cartID, itemID, itemQuantity)

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:

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
cartID = "735eef8a7745cd4c16ca30356d0cfd784736aa695f0200f73980dd154ba8f7fb";
itemID = "ItemID090";
itemQuantity = 5;	
					
cart = cartService.increase_quantity(cartID, itemID, itemQuantity); /* returns the Cart object. */
puts "cartId is #{cart.cartId}";
itemList = Array.new();
itemList = cart.getItemList();
for item in itemList do
  puts "itemid is #{item.itemId}";
  puts "quantity is #{item.quantity}";
  puts "price is #{item.price}";
  puts "totalAmount is #{item.totalAmount}";
end
jsonResponse = cart.to_s(); /* 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
                        }
                    }
                }
            }
        }
    }
}
def decrease_quantity(cartId, itemId, itemQuantity)

Decrease the quantity of specified Item from the specified Cart

Parameters:

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

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
cartID = "735eef8a7745cd4c16ca30356d0cfd784736aa695f0200f73980dd154ba8f7fb";
itemID = "ItemID090";
itemQuantity = 3;
						
cart = cartService.decrease_quantity(cartID, itemID, itemQuantity); /* returns the Cart object. */
puts "cartId is #{cart.cartId}";
itemList = Array.new();
itemList = cart.getItemList();
for item in itemList do
  puts "itemid is #{item.itemId}";
  puts "quantity is #{item.quantity}";
  puts "price is #{item.price}";
  puts "totalAmount is #{item.totalAmount}";
end
jsonResponse = cart.to_s(); /* 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
                        }
                    }
                }
            }
        }
    }
}