Subversion Repositories SmartDukaan

Rev

Rev 1905 | Rev 2009 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1905 Rev 1981
Line 5... Line 5...
5
import in.shop2020.model.v1.order.Transaction;
5
import in.shop2020.model.v1.order.Transaction;
6
import in.shop2020.model.v1.order.TransactionServiceException;
6
import in.shop2020.model.v1.order.TransactionServiceException;
7
import in.shop2020.model.v1.order.TransactionStatus;
7
import in.shop2020.model.v1.order.TransactionStatus;
8
import in.shop2020.model.v1.user.Cart;
8
import in.shop2020.model.v1.user.Cart;
9
import in.shop2020.model.v1.user.Line;
9
import in.shop2020.model.v1.user.Line;
-
 
10
import in.shop2020.model.v1.user.PromotionException;
10
import in.shop2020.model.v1.user.ShoppingCartException;
11
import in.shop2020.model.v1.user.ShoppingCartException;
-
 
12
import in.shop2020.model.v1.user.UserContextService;
11
import in.shop2020.payments.PaymentException;
13
import in.shop2020.payments.PaymentException;
12
import in.shop2020.payments.PaymentService.Client;
14
import in.shop2020.payments.PaymentService.Client;
13
import in.shop2020.serving.utils.Utils;
15
import in.shop2020.serving.utils.Utils;
14
import in.shop2020.thrift.clients.PaymentServiceClient;
16
import in.shop2020.thrift.clients.PaymentServiceClient;
-
 
17
import in.shop2020.thrift.clients.PromotionServiceClient;
15
import in.shop2020.thrift.clients.TransactionServiceClient;
18
import in.shop2020.thrift.clients.TransactionServiceClient;
16
import in.shop2020.thrift.clients.UserContextServiceClient;
19
import in.shop2020.thrift.clients.UserContextServiceClient;
17
 
20
 
18
import java.util.HashMap;
21
import java.util.HashMap;
19
import java.util.List;
22
import java.util.List;
Line 144... Line 147...
144
		
147
		
145
		try {
148
		try {
146
			//TODO Optimize the function to send less amount of data over network
149
			//TODO Optimize the function to send less amount of data over network
147
			log.info("Transaction shopping cart id is: " + transaction.getShoppingCartid());
150
			log.info("Transaction shopping cart id is: " + transaction.getShoppingCartid());
148
			log.info("Items to restr in cart are: " + items );
151
			log.info("Items to restr in cart are: " + items );
-
 
152
			           
149
			userServiceClient.getClient().resetCart(transaction.getShoppingCartid(), items);
153
            userServiceClient.getClient().resetCart(transaction.getShoppingCartid(), items);
-
 
154
			
150
		}catch (TException e) {
155
		}catch (TException e) {
151
			log.error("Error while updating information in payment database.");
156
			log.error("Error while updating information in payment database.");
152
			e.printStackTrace();
157
			e.printStackTrace();
153
			//FIXME Even we get exception we should sent url back to payment gateway. And some thing back channel should be done
158
			//FIXME Even we get exception we should sent url back to payment gateway. And some thing back channel should be done
154
			
159
			
155
		} catch (ShoppingCartException e) {
160
		} catch (ShoppingCartException e) {
156
			log.error("Error while reseting the cart in cart database.");
161
			log.error("Error while reseting the cart in cart database.");
157
			e.printStackTrace();
162
			e.printStackTrace();
-
 
163
		}catch (Exception e) {
-
 
164
            // TODO: handle exception
-
 
165
        }
158
		}
166
		
-
 
167
		try   {
-
 
168
            // Tracking Coupon Usage 
-
 
169
		    UserContextService.Client userClient = userServiceClient.getClient();
-
 
170
		    Cart cart = userClient.getCart(transaction.getShoppingCartid());
-
 
171
            
-
 
172
            PromotionServiceClient promotionServiceClient = new PromotionServiceClient();
-
 
173
            String couponCode = cart.getCouponCode();
-
 
174
 
-
 
175
            if (couponCode != null && !couponCode.isEmpty()) {
-
 
176
                promotionServiceClient.getClient().trackCouponUsage(couponCode, txnId, transaction.getCustomer_id());
-
 
177
            }
-
 
178
		} catch (ShoppingCartException e) {
-
 
179
		    log.error("Error occurred in reading CardId for transaction");
-
 
180
            e.printStackTrace();
-
 
181
        } catch (PromotionException e) {
-
 
182
            log.error("Promotion Exception: " + e.getMessage());
-
 
183
            e.printStackTrace();
-
 
184
        } catch (TException e)  {
-
 
185
            log.error("Transport from Promotion Service failed");
-
 
186
            e.printStackTrace();
-
 
187
        } catch (Exception e) {
-
 
188
            e.printStackTrace();
-
 
189
        }
159
	}
190
	}
160
	
191
	
161
	/**
192
	/**
162
	 * Enqueues the transaction successful email, containing transaction info,
193
	 * Enqueues the transaction successful email, containing transaction info,
163
	 * to be sent later by batch job.
194
	 * to be sent later by batch job.
Line 214... Line 245...
214
		} catch (Exception e) {
245
		} catch (Exception e) {
215
			e.printStackTrace();
246
			e.printStackTrace();
216
		}
247
		}
217
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
248
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
218
		cart = userClient.getCart(cartId);
249
		cart = userClient.getCart(cartId);
219
	
250
		
-
 
251
		if(cart.getCouponCode() == null || cart.getDiscountedPrice() == 0.0)  {
220
		List<Line> lineItems = cart.getLines(); 
252
		    List<Line> lineItems = cart.getLines(); 
221
	
253
		    
222
		for (Line line : lineItems) {
254
	        for (Line line : lineItems) {
223
			long productId = line.getItemId();
255
	            long productId = line.getItemId();
224
			// FIXME: It's expensive to get the price of each item from the
256
	            // FIXME: It's expensive to get the price of each item from the
225
			// catalog service. We maintain the pricing info in the line items
257
	            // catalog service. We maintain the pricing info in the line items
226
			// themselves now.
258
	            // themselves now.
227
			totalAmount =  totalAmount + line.getQuantity() * Utils.getItemPrice(productId);
259
	            totalAmount =  totalAmount + line.getQuantity() * Utils.getItemPrice(productId);
-
 
260
	        }
-
 
261
		} else    {
-
 
262
		    totalAmount = cart.getDiscountedPrice();
228
		}
263
		}
229
 
264
		
230
		return totalAmount;
265
		return totalAmount;
231
	}
266
	}
232
 
267
 
233
	// TODO: The service client parameters are unnecessary but initializing them
268
	// TODO: The service client parameters are unnecessary but initializing them
234
	// again when the caller has the necessary references has a performance
269
	// again when the caller has the necessary references has a performance