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 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 '<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.
Creates a Cart Session for the specified User.
Parameters:
Returns:
Response: Cart 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. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"carts": {
"cart": {
"userName": "Nick",
"cartId": "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325",
"creationTime": "2012-05-10T03:38:14.000Z",
"cartSession": "NEW"
}
}
}
}
}
Fetch Cart details. Can be used by the App developer to display Cart Details i.e. Items in a Cart.
Parameters:
Returns:
Response: Cart Object
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. */
String cartId = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
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": "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325",
"creationTime": "2012-05-10T05:00:36.000Z",
"checkOutTime": "2012-05-10T05:00:36.000Z",
"state": "CHECKOUT"
}
}
}
}
}
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:
Returns:
Response: Cart Object
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. */
String cartID = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
String itemID = "ItemID01";
int itemQuantity = 12;
double price = 1000;
Cart cart = cartService.addItem(cartID, itemID, itemQuantity, price); /* returns the Cart object. */
System.out.println("cartId is " + cart.getCartId();
ArrayList<Cart.Item> itemList = cart.getItemList();
for(Cart.Item item : itemList)
{
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
}
}
}
}
}
}
}
Fetches the Items from the specified Cart.
Parameters:
Returns:
Response: Cart Object
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. */
String cartId = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
Cart cart = cartService.getItems(cartId); /* returns the Cart object. */
System.out.println("cartId is " + cart.getCartId();
ArrayList<Cart.Item> itemList = cart.getItemList();
for(Cart.Item item : itemList)
{
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
}
]
}
}
}
}
}
}
Fetches the specified Item from the specified Cart.
Parameters:
Returns:
Response: Cart Object
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>'. */
String cartId = "41c0008e1a90e06271534457ca28a92805ead62296780343794344322b5f3325";
String itemId = "ItemID01";
Cart cart = cartService.getItem(cartId, itemId); /* returns the Cart object. */
System.out.println("cartId is " + cart.getCartId();
ArrayList<Cart.Item> itemList = cart.getItemList();
for(Cart.Item item : itemList)
{
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
}
}
}
}
}
}
}
Removes the specified item from the specified Cart.
Parameters:
Returns:
Response: App42Response Object
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. */
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
}
}
}
}
}
}
}
Removes all Items from the specified Cart.
Parameters:
Returns:
Response: App42Response Object
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. */
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
}
]
}
}
}
}
}
}
Checks whether the Cart is empty or not.
Parameters:
Returns:
Response: Cart Object
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. */
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
}
}
}
}
}
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:
Returns:
Response: Cart Object
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 */
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"
}
}
}
}
}
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:
Returns:
Response: Cart Object
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. */
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"
}
}
}
}
}
}
}
Fetches Payment information for a User. This can be used to display Order and Payment History.
Parameters:
Returns:
Response: ArrayList<Cart> Object
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. */
String userId = "mike@123";
ArrayList<Cart> cartList = cartService.getPaymentsByUser(userId);/* returns the list of Cart object. */
for(Cart cart: cartList)
{
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"
}
}
}
}
}
}
}
Fetches Payment information for the specified Cart Id
Parameters:
Returns:
Response: Cart Object
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. */
String cartId = "5b16be7ac5a46dc1524251b6724183d3ba42702dc10309e5d5db1728c3c5fd30";
System.out.println("cartId is " + cart.getCartId());
Cart cart = cartservice.getPaymentByCart(cartId);/* returns the Cart object. */
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"
}
}
}
}
}
}
}
Fetches Payment information based on User Id and Status
Parameters:
Returns:
Response: ArrayList<Cart> Object
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. */
String userId = "mike@123";
PaymentStatus paymentStatus = PaymentStatus.AUTHORIZED ;
ArrayList<Cart> cartList = cartService.getPaymentsByUserAndStatus(userId, paymentStatus); /* returns the list of Cart object. */
for(Cart cart: cartList)
{
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"
}
}
}
}
}
}
}
Fetches Payment information based on Status.
Parameters:
Returns:
Response: ArrayList<Cart> Object
Exception:
/* 3315 - NOT FOUND - Payment transactions for the status '<status>' does not exist. */
PaymentStatus paymentStatus = AUTHORIZED;
ArrayList<Cart> cartList = cartService.getPaymentsByStatus(paymentStatus); /* returns the list of Cart object. */
for(Cart cart : cartList)
{
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"
}
}
}
}
}
}
}
History of Carts and Payments for a User. It gives all the carts which are in AUTHORIZED, DECLINED, PENDING state.
Parameters:
Returns:
Response: ArrayList<Cart> Object
Exception:
/* 3316 - NOT FOUND - Cart for the user with the id '<userId>' does not exist in payment history. */
String userId = "mike@123";
ArrayList<Cart> cartList = cartService.getPaymentHistoryByUser(userId); /* returns the list of Cart object. */
for(Cart cart : cartList)
{
System.out.println("userName is " + cart.getUserName());
System.out.println("cartId is " + cart.getCartId());
System.out.println("state is " + cart.getState());
ArrayList<Cart.Item> itemList = cart.getItemList();
for(Cart.Item item : itemList)
{
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"
}
}
}
}
}
}
}
History of all carts. It gives all the carts which are in AUTHORIZED, DECLINED, PENDING state.
Parameters:
Returns:
Response: ArrayList<Cart> Object
Exception:
/*
3317 - NOT FOUND - Carts with status ('DECLINED', 'PENDING', 'AUTHORIZED') does not exist in payment history.
*/
ArrayList<Cart> cartList = cartService.getPaymentHistoryAll(); /* returns the list of Cart object. */
for(Cart cart : cartList)
{
System.out.println("userName is " + cart.getUserName());
System.out.println("cartId is " + cart.getCartId());
System.out.println("state is " + cart.getState());
ArrayList<Cart.Item> itemList = cart.getItemList();
for(Cart.Item item : itemList)
{
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"
}
}
}
]
}
}
}
}
To increase quantity of existing item in the cart.
Parameters:
Returns:
Response: Cart Object
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. */
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());
ArrayList<Cart.Item> itemList = cart.getItemList();
for(Cart.Item item : itemList)
{
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
}
}
}
}
}
}
}
To decrease quantity of existing item in the cart.
Parameters:
Returns:
Response: Cart Object
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. */
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());
ArrayList<Cart.Item> itemList = cart.getItemList();
for(Cart.Item item : itemList)
{
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
}
}
}
}
}
}
}