Subversion Repositories SmartDukaan

Rev

Rev 9119 | Rev 9136 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8488 amar.kumar 1
package in.shop2020.support.controllers;
2
 
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.text.SimpleDateFormat;
6
import java.util.ArrayList;
7
import java.util.Calendar;
8
import java.util.Collection;
9
import java.util.Collections;
10
import java.util.Date;
11
import java.util.List;
12
 
13
import in.shop2020.logistics.DeliveryType;
14
import in.shop2020.logistics.LogisticsInfo;
15
import in.shop2020.logistics.LogisticsService;
16
import in.shop2020.logistics.PickUpType;
17
import in.shop2020.model.v1.catalog.CatalogService;
18
import in.shop2020.model.v1.catalog.CatalogServiceException;
19
import in.shop2020.model.v1.catalog.EbayItem;
20
import in.shop2020.model.v1.catalog.Item;
21
import in.shop2020.model.v1.inventory.InventoryService;
22
import in.shop2020.model.v1.inventory.InventoryServiceException;
8892 amar.kumar 23
import in.shop2020.model.v1.inventory.InventoryType;
8488 amar.kumar 24
import in.shop2020.model.v1.inventory.VendorItemPricing;
25
import in.shop2020.model.v1.inventory.Warehouse;
8892 amar.kumar 26
import in.shop2020.model.v1.inventory.WarehouseType;
8488 amar.kumar 27
import in.shop2020.model.v1.order.LineItem;
28
import in.shop2020.model.v1.order.Order;
29
import in.shop2020.model.v1.order.OrderSource;
30
import in.shop2020.model.v1.order.OrderStatus;
31
import in.shop2020.model.v1.order.OrderType;
32
import in.shop2020.model.v1.order.SnapdealOrder;
33
import in.shop2020.model.v1.order.SourceDetail;
34
import in.shop2020.model.v1.order.Transaction;
35
import in.shop2020.model.v1.order.TransactionStatus;
36
import in.shop2020.model.v1.order.TransactionService.Client;
37
import in.shop2020.model.v1.user.Address;
38
import in.shop2020.model.v1.user.User;
39
import in.shop2020.payments.Attribute;
40
import in.shop2020.payments.PaymentException;
41
import in.shop2020.payments.PaymentStatus;
42
import in.shop2020.thrift.clients.CatalogClient;
43
import in.shop2020.thrift.clients.InventoryClient;
44
import in.shop2020.thrift.clients.LogisticsClient;
45
import in.shop2020.thrift.clients.PaymentClient;
46
import in.shop2020.thrift.clients.TransactionClient;
47
import in.shop2020.thrift.clients.UserClient;
48
import in.shop2020.support.utils.ReportsUtils;
49
 
50
import javax.servlet.http.HttpServletRequest;
51
import javax.servlet.http.HttpSession;
52
 
53
import org.apache.commons.io.FileUtils;
54
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
55
import org.apache.poi.ss.usermodel.Cell;
56
import org.apache.poi.ss.usermodel.Row;
57
import org.apache.poi.ss.usermodel.Sheet;
58
import org.apache.poi.ss.usermodel.Workbook;
59
import org.apache.struts2.convention.annotation.InterceptorRef;
60
import org.apache.struts2.convention.annotation.InterceptorRefs;
61
import org.apache.struts2.convention.annotation.Result;
62
import org.apache.struts2.convention.annotation.Results;
63
import org.apache.struts2.interceptor.ServletRequestAware;
64
import org.apache.thrift.TException;
65
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
67
 
68
import com.opensymphony.xwork2.ActionSupport;
69
 
70
@SuppressWarnings("serial")
71
@InterceptorRefs({
72
    @InterceptorRef("defaultStack"),
73
    @InterceptorRef("login")
74
})
75
@Results({
76
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
77
})
78
public class SnapdealOrderCreatorController extends ActionSupport implements ServletRequestAware {
79
 
80
	private static Logger logger = LoggerFactory.getLogger(SnapdealOrderCreatorController.class);
81
 
82
	private HttpServletRequest request;
83
    private HttpSession session;
84
 
85
    private static final int SNAPDEAL_SOURCE_ID = 7;
86
 
87
    private static final int COURIER_INDEX = 0;
88
    private static final int PRODUCT_NAME_INDEX = 1;
89
    private static final int REFERENCE_CODE_INDEX = 2;
90
    private static final int SUBORDER_ID_INDEX = 3;
91
    private static final int ITEMID_INDEX = 4;
92
    private static final int AWB_INDEX = 5;
93
    private static final int TRANSACTION_DATE_INDEX = 6;
94
    private static final int BUYER_NAME_INDEX = 8;
95
    private static final int CITY_INDEX = 9;
96
    private static final int STATE_INDEX = 10;
97
    private static final int PINCODE_INDEX = 11;
98
    private static final int AMOUNT_INDEX = 12;
99
    private static final int WAREHOUSE_ID_INDEX = 14;
100
    private static final int OVERRIDE_BILLING_PRICE_INDEX = 15;
101
 
102
 
103
    private static final int SNAPDEAL_GATEWAY_ID = 18;
104
 
105
    private static final String FIRSTFLIGHT = "First Flight";
9110 vikram.rag 106
	private static final String DELHIVERY = "DELHIVERY";
107
	private static final String BLUEDART = "Bluedart";
108
	private static final String CHHOTU = "CHHOTU";	
109
	private static final String LAST_MILE = "LAST_MILE";
110
	private static final String  ECOM = "Ecom Express";
111
	private static final String  EWINGS = "EWINGS";
112
	private static final String DTDC = "DTDC";
113
	private static final String WAREOLOG = "DTDC";
114
	private static final String  MIRAKLE = "MIRAKLE";
115
	private static final String RAJIV_TRANSPORT = "RAJIV_TRANSPORT";
116
	private static final String BLUEDART_HIGH_VALUE = "BLUEDART_HIGH_VALUE";
117
	private static final String BLUEDART_SURFACE = "BLUEDART_SURFACE";
118
	private static final String BLUEDART_APEX = "BLUEDART_APEX";
119
	private static final String ARAMEX = "ARAMEX";
120
	private static final String GATI = "GATI";
121
	private static final String INDIA_POST = "INDIA_POST";
122
	private static final String FEDEX = "FEDEX";
123
	private static final String IOT = "IOT";
124
	private static final String RED_EXP = "RED_EXP";
125
	private static final String GHARPAY = "GHARPAY";
9127 vikram.rag 126
	private static final String QUANTIUM = "Quantium Solutions";
9119 vikram.rag 127
	private static final String GATI_AIR = "GATI AIR";
9110 vikram.rag 128
	private static final String VDELIVER = "VDELIVER";
129
 
8488 amar.kumar 130
    private File orderDataFile;
131
    private String orderDataFileName;
132
    private String transactionId;
133
    private String errorMsg = "";
134
    private Long rowId = 0L;
135
 
136
    public String create() throws TException {
137
        File fileToCreate = null;
138
        orderDataFileName = "OrderSheet_Snapdeal_"+(new Date().toString());
139
        try {
140
            fileToCreate = new File("/tmp/", this.orderDataFileName);
141
            FileUtils.copyFile(this.orderDataFile, fileToCreate);
142
        } catch (Exception e) {
143
           logger.error("Error while writing order data file to the local file system for Snapdeal", e);
144
           addActionError("Error while writing order data file to the local file system");
145
        }
146
 
147
 
148
        if(checkForErrors())
149
            return "authsuccess";
150
 
151
        //Parse the file and submit the data for update to the transaction service
152
        Workbook wb = null;
153
        try {
154
            wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
155
        } catch (Exception e) {
156
            logger.error("Unable to open the File for Order Creation for Snapdeal ", e);
157
            setErrorMsg(getErrorMsg() + "Error in opening File for Order creation");
158
            addActionError("Unable to open the File for Order creation");
159
        }
160
        if(checkForErrors())
161
            return "authsuccess";
162
 
163
        SourceDetail sourceDetail = null;
164
        User user = null;
165
        TransactionClient tsc = null;
166
        try {
167
            tsc = new TransactionClient();
168
			sourceDetail = tsc.getClient().getSourceDetail(SNAPDEAL_SOURCE_ID);
169
        } catch (Exception e) {
170
            logger.error("Unable to establish connection to the transaction service while getting Snapdeal Source Detail", e);
171
            setErrorMsg(getErrorMsg() + "Error in Order Service while getting Snapdeal Source Detail");
172
            addActionError("Error in connecting to Order Service");
173
		}
174
 
175
        if(checkForErrors())
176
            return "authsuccess";
177
 
178
	    try {   
179
	        in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
180
	        user = userClient.getUserByEmail(sourceDetail.getEmail());
181
	    } catch (Exception e) {
182
	        logger.error("Unable to establish connection to the User service", e);
183
	        setErrorMsg(getErrorMsg() + "Unable to get Default Email for Snapdeal ");
184
	        addActionError("Unable to get Default Email for Snapdeal ");
185
		}
186
 
187
        if(checkForErrors())
188
            return "authsuccess";
189
 
190
        Sheet sheet = wb.getSheetAt(0);
191
        Row firstRow = sheet.getRow(0);
192
        for (Row row : sheet) {
193
        	long orderCountForRow = 0;
194
        	rowId++;
195
            if(row.equals(firstRow))
196
                continue;
197
        	try {
198
	            Transaction txn = new Transaction();
199
	            txn.setShoppingCartid(user.getActiveCartId());
200
	            txn.setCustomer_id(user.getUserId());
201
	            txn.setCreatedOn(new Date().getTime());
202
	            txn.setTransactionStatus(TransactionStatus.INIT);
203
	            txn.setStatusDescription("Order for Snapdeal ");
204
 
205
	            List<Order> orders = new ArrayList<Order>();
206
 
207
	            row.getCell(ITEMID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
208
	            Long itemId = Long.parseLong(row.getCell(ITEMID_INDEX).getStringCellValue());
209
	    		double listingPrice = 0;
210
	    		double overriddenPrice = 0;
211
	    		double totalPrice = 0;
212
	    		Cell overriddenPriceCell = row.getCell(OVERRIDE_BILLING_PRICE_INDEX);
213
	        	if(overriddenPriceCell  != null && overriddenPriceCell .getCellType() != Cell.CELL_TYPE_BLANK) {
214
	        		overriddenPrice = row.getCell(OVERRIDE_BILLING_PRICE_INDEX).getNumericCellValue();
215
	        	}
216
 
217
	    		totalPrice = row.getCell(AMOUNT_INDEX).getNumericCellValue();
218
	    		listingPrice = totalPrice;
219
	    		if(overriddenPrice>=1) {
220
	    			totalPrice = overriddenPrice;
221
	    		}
222
	        	LineItem lineItem = null;
223
	        	try {
224
	        		lineItem = createLineItem(itemId, totalPrice);
8569 amar.kumar 225
	        		Double subOrderId = row.getCell(SUBORDER_ID_INDEX).getNumericCellValue();
226
	            	String refCode = row.getCell(REFERENCE_CODE_INDEX).getStringCellValue();
227
	        		lineItem.setExtra_info("SubOrderId = " + subOrderId + " ReferenceCode = " + refCode);
8488 amar.kumar 228
	        	} catch (Exception tex) {
229
	        		logger.error("Unable to create order for RowId " + rowId, tex);
230
	        		setErrorMsg(getErrorMsg() + "<br>Unable to create lineitem using catalog info for RowId " + rowId);
231
	    	        continue;
232
	        	}
233
	            Order t_order = new Order();
234
	            t_order.setCustomer_id(user.getUserId());
235
	            t_order.setCustomer_email(sourceDetail.getEmail());
236
	            row.getCell(BUYER_NAME_INDEX).setCellType(Cell.CELL_TYPE_STRING);
237
	        	t_order.setCustomer_name(row.getCell(BUYER_NAME_INDEX).getStringCellValue());
238
	        	t_order.setCustomer_address1("");
239
	        	t_order.setCustomer_address2("");
240
	        	t_order.setCustomer_city(row.getCell(CITY_INDEX).getStringCellValue());
241
	        	t_order.setCustomer_state(row.getCell(STATE_INDEX).getStringCellValue());
242
	        	row.getCell(PINCODE_INDEX).setCellType(Cell.CELL_TYPE_STRING);
243
	        	t_order.setCustomer_pincode(row.getCell(PINCODE_INDEX).getStringCellValue());
244
	            t_order.setTotal_amount(lineItem.getTotal_price());            
245
	            t_order.setTotal_weight(lineItem.getTotal_weight());
246
	            t_order.setLineitems(Collections.singletonList(lineItem));            
8761 vikram.rag 247
	            t_order.setStatus(OrderStatus.PAYMENT_PENDING);
8488 amar.kumar 248
	            t_order.setStatusDescription("In Process");
249
	            t_order.setCreated_timestamp(new Date().getTime());
250
	            t_order.setOrderType(OrderType.B2C);
251
	            t_order.setCod(false);
252
	            try {
253
	            	Calendar time = Calendar.getInstance();
254
	            	time.add(Calendar.DAY_OF_MONTH, 1);
255
	            	t_order.setPromised_shipping_time(time.getTimeInMillis());
256
	            	t_order.setExpected_shipping_time(time.getTimeInMillis());
257
	            	time.add(Calendar.DAY_OF_MONTH, 3);
258
	            	t_order.setPromised_delivery_time(time.getTimeInMillis());
259
	            	t_order.setExpected_delivery_time(time.getTimeInMillis());
260
	            } catch(Exception e) {
261
	            	addActionError("Error in updating Shipping or Delivery Time for row number " + rowId);
262
	            	logger.error("Error in updating Shipping or Delivery Time for row number " + rowId,e);
263
	            	continue;
264
	            }
265
 
266
	            InventoryService.Client inventoryClient = null;
267
	            Warehouse fulfillmentWarehouse= null; 
268
	            try {
269
	            	inventoryClient = new InventoryClient().getClient();
270
	            	Cell warehouseCell = row.getCell(WAREHOUSE_ID_INDEX);
271
	            	if(warehouseCell != null && warehouseCell.getCellType() != Cell.CELL_TYPE_BLANK) {
272
	            		fulfillmentWarehouse = inventoryClient.getWarehouse(new Double(row.getCell(WAREHOUSE_ID_INDEX).getNumericCellValue()).longValue());
273
	            	} else {
274
	            		List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(itemId, 1);
275
	            		fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
276
	            	}
277
	            	t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
8892 amar.kumar 278
 
279
					long billingWarehouseId = 0;
280
					if(fulfillmentWarehouse.getBillingWarehouseId()== 0) {
281
						inventoryClient = new InventoryClient().getClient();
282
						List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, fulfillmentWarehouse.getVendor().getId(), 0, 0);
283
						for(Warehouse warehouse : warehouses) {
284
							if(warehouse.getBillingWarehouseId()!=0) {
285
								billingWarehouseId = warehouse.getBillingWarehouseId();
286
				                break;
287
							}
288
						}
289
					} else {
290
						billingWarehouseId = fulfillmentWarehouse.getBillingWarehouseId();
291
					}
292
 
293
					t_order.setWarehouse_id(billingWarehouseId);
294
					//t_order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
8488 amar.kumar 295
	        		VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
296
	        		t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
297
	        		t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
298
				} catch (InventoryServiceException e) {
299
					addActionError("Error in updating WarehouseId for row number " + rowId);
300
					setErrorMsg(getErrorMsg() + "<br>Error in updating WarehouseId for row number  " + rowId);
301
	            	logger.error("Error in updating WarehouseId for row number " + rowId,e);
302
	            	continue;
303
				}
304
 
305
				String provider = row.getCell(COURIER_INDEX).getStringCellValue();
9110 vikram.rag 306
				if(provider.equalsIgnoreCase(FIRSTFLIGHT)) {
8488 amar.kumar 307
					t_order.setLogistics_provider_id(12);
9110 vikram.rag 308
				} else if(provider.equalsIgnoreCase(DELHIVERY)) {
8488 amar.kumar 309
					t_order.setLogistics_provider_id(13);
9110 vikram.rag 310
				} else if(provider.equalsIgnoreCase(BLUEDART)) {
8508 amar.kumar 311
					t_order.setLogistics_provider_id(14);
9110 vikram.rag 312
				} else if(provider.equalsIgnoreCase(ECOM)) {
8796 anupam.sin 313
                    t_order.setLogistics_provider_id(18);
9110 vikram.rag 314
                }else if(provider.equalsIgnoreCase(EWINGS)){
315
    				t_order.setLogistics_provider_id(19);
316
    			}
317
    			else if(provider.equalsIgnoreCase(DTDC)){
318
    				t_order.setLogistics_provider_id(20);
319
    			}
320
    			else if(provider.equalsIgnoreCase(WAREOLOG)){
321
    				t_order.setLogistics_provider_id(21);
322
    			}
323
    			else if(provider.equalsIgnoreCase(MIRAKLE)){
324
    				t_order.setLogistics_provider_id(22);
325
    			}
326
    			else if(provider.equalsIgnoreCase(RAJIV_TRANSPORT)){
327
    				t_order.setLogistics_provider_id(23);
328
    			}
329
    			else if(provider.equalsIgnoreCase(BLUEDART_HIGH_VALUE)){
330
    				t_order.setLogistics_provider_id(24);
331
    			}
332
    			else if(provider.equalsIgnoreCase(BLUEDART_SURFACE)){
333
    				t_order.setLogistics_provider_id(25);
334
    			}
335
    			else if(provider.equalsIgnoreCase(BLUEDART_APEX)){
336
    				t_order.setLogistics_provider_id(26);
337
    			}
338
    			else if(provider.equalsIgnoreCase(ARAMEX)){
339
    				t_order.setLogistics_provider_id(27);
340
    			}
341
    			else if(provider.equalsIgnoreCase(GATI)){
342
    				t_order.setLogistics_provider_id(28);
343
    			}
344
    			else if(provider.equalsIgnoreCase(INDIA_POST)){
345
    				t_order.setLogistics_provider_id(29);
346
    			}
347
    			else if(provider.equalsIgnoreCase(FEDEX)){
348
    				t_order.setLogistics_provider_id(30);
349
    			}
350
    			else if(provider.equalsIgnoreCase(IOT)){
351
    				t_order.setLogistics_provider_id(31);
352
    			}
353
    			else if(provider.equalsIgnoreCase(RED_EXP)){
354
    				t_order.setLogistics_provider_id(32);
355
    			}
356
    			else if(provider.equalsIgnoreCase(VDELIVER)){
357
    				t_order.setLogistics_provider_id(33);
358
    			}
359
    			else if(provider.equalsIgnoreCase(GHARPAY)){
360
    				t_order.setLogistics_provider_id(34);
361
    			}
362
    			else if(provider.equalsIgnoreCase(QUANTIUM)){
363
    				t_order.setLogistics_provider_id(35);
364
    			}
365
    			else if(provider.equalsIgnoreCase(GATI_AIR)){
366
    				t_order.setLogistics_provider_id(36);
367
    			} else {
8488 amar.kumar 368
					addActionError("Unknown logistics provider found for row number " + rowId);
369
					setErrorMsg(getErrorMsg() + "<br>Unknown logistics provider found for row number " + rowId);
370
	            	logger.error("Unknown logistics provider found for row number " + rowId);
371
	            	continue;
372
				}
373
 
374
				row.getCell(AWB_INDEX).setCellType(Cell.CELL_TYPE_STRING);
375
				t_order.setAirwaybill_no(row.getCell(AWB_INDEX).getStringCellValue());
376
				t_order.setTracking_id(row.getCell(AWB_INDEX).getStringCellValue());
377
	            t_order.setTotal_amount(totalPrice);
378
	            t_order.setOrderType(OrderType.B2C);
379
	            t_order.setSource(SNAPDEAL_SOURCE_ID);
380
	            t_order.setOrderType(OrderType.B2C);
381
	            orders.add(t_order);
382
	            orderCountForRow++;
383
 
384
	            txn.setOrders(orders);
385
	            Client transaction_client = new TransactionClient().getClient();
386
	            try {
387
	            	long subOrderId = new Double(row.getCell(SUBORDER_ID_INDEX).getNumericCellValue()).longValue();
388
	            	String referenceCode = row.getCell(REFERENCE_CODE_INDEX).getStringCellValue();
389
	            	String productName = row.getCell(PRODUCT_NAME_INDEX).getStringCellValue();
390
	            	Date snapdealTxnDate = row.getCell(TRANSACTION_DATE_INDEX).getDateCellValue();
391
 
8802 amar.kumar 392
	            	if(transaction_client.snapdealOrderExists(subOrderId, referenceCode)) {
8488 amar.kumar 393
	            		setErrorMsg(getErrorMsg() + "<br>Duplicate order for subOrderId " + subOrderId + " for row number  " + rowId);
394
	            		logger.error("Duplicate order for subOrderId " + subOrderId + " for row number  " + rowId);
395
	            		continue;
396
	            	}
397
 
398
	            	transactionId =  String.valueOf(transaction_client.createTransaction(txn));
399
	            	createPayment(user, (new Long(subOrderId)).toString(), totalPrice);
400
 
401
	                logger.info("Successfully created transaction: " + transactionId + " for amount: " + totalPrice);
402
 
403
	                Transaction transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
404
	                Order order = transaction.getOrders().get(0);
405
 
406
	                inventoryClient.reserveItemInWarehouse(itemId, fulfillmentWarehouse.getId(), 1, 
407
	                		order.getId(), order.getCreated_timestamp(), order.getPromised_shipping_time(), order.getLineitems().get(0).getQuantity());
408
 
409
 
410
	                SnapdealOrder snapdealOrder = new SnapdealOrder();
411
	                snapdealOrder.setOrderId(order.getId());
412
	                snapdealOrder.setSubOrderId(subOrderId);
413
	                snapdealOrder.setReferenceCode(referenceCode);
414
	                snapdealOrder.setProductName(productName);
415
	                snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
416
	                snapdealOrder.setListingPrice(listingPrice);
417
	                transaction_client.createSnapdealOrder(snapdealOrder);
418
 
419
 
420
	            } catch (Exception e) {
421
	                logger.error("Error while creating order for rowId " + rowId, e);
422
	                addActionError("Error while creating order for rowId " + rowId);
423
	                setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
424
	                continue;
425
	    		}
426
        	} catch (Exception e) {
8748 amar.kumar 427
        		logger.error("Error while creating order for row number " + rowId, e);
8488 amar.kumar 428
        		setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
429
        		continue;
430
        	}
431
        }
432
 
433
        checkForErrors();
434
        return "authsuccess";
435
    }
436
 
437
    private Date interchangeDateAndMonth(Date date) {
438
		Date updatedDate = new Date(date.getTime());
439
		updatedDate.setDate(date.getMonth() + 1);
440
		updatedDate.setMonth(date.getDate() - 1);
441
		return updatedDate;
442
	}
443
 
444
	private LineItem createLineItem(long itemId, double amount) throws CatalogServiceException, TException {
445
    	LineItem lineItem = new LineItem();
446
    	CatalogService.Client catalogClient = new CatalogClient().getClient();
447
    	Item item = catalogClient.getItem(itemId);
448
 
449
    	lineItem.setProductGroup(item.getProductGroup());
450
        lineItem.setBrand(item.getBrand());
451
        lineItem.setModel_number(item.getModelNumber());
452
        lineItem.setModel_name(item.getModelName());
453
        lineItem.setExtra_info(item.getFeatureDescription());
454
        lineItem.setQuantity(1);
455
        lineItem.setItem_id(item.getId());
456
        lineItem.setUnit_weight(item.getWeight());
457
        lineItem.setTotal_weight(item.getWeight());
458
        lineItem.setUnit_price(amount);
459
        lineItem.setTotal_price(amount);
460
 
461
        if (item.getColor() == null || "NA".equals(item.getColor())) {
462
            lineItem.setColor("");
463
        } else {
464
            lineItem.setColor(item.getColor());
465
        }
466
    	return lineItem;
467
	}
468
 
469
    private void createPayment(User user, String subOrderId, double amount) throws NumberFormatException, PaymentException, TException {
470
        in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
471
        long paymentId = client.createPayment(user.getUserId(), amount, SNAPDEAL_GATEWAY_ID, Long.valueOf(transactionId), false);
472
        client.updatePaymentDetails(paymentId, null, null, null, null, null, null, subOrderId, null, PaymentStatus.AUTHORIZED, null, null);
473
    }   
474
 
475
	public String index() {
476
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/ebay-dashboard"))
477
            return "authfail";
478
        checkForErrors();
479
        return "authsuccess";
480
    }
481
 
482
	private boolean checkForErrors(){
483
        Collection<String> actionErrors = getActionErrors();
484
        if(actionErrors != null && !actionErrors.isEmpty()){
485
            for (String str : actionErrors) {
486
                errorMsg += "<BR/>" + str;
487
            }
488
            return true;
489
        }
490
        return false;
491
    }
492
 
493
	@Override
494
	public void setServletRequest(HttpServletRequest request) {
495
		this.request = request;
496
        this.session = request.getSession();
497
	}
498
 
499
	public String getErrorMsg() {
500
		return errorMsg;
501
	}
502
 
503
	public void setErrorMsg(String errorMsg) {
504
		this.errorMsg = errorMsg;
505
	}
506
 
507
	public Long getRowId() {
508
		return rowId;
509
	}
510
 
511
	public void setRowId(Long rowId) {
512
		this.rowId = rowId;
513
	}
514
 
515
	public File getOrderDataFile() {
516
		return orderDataFile;
517
	}
518
 
519
	public void setOrderDataFile(File orderDataFile) {
520
		this.orderDataFile = orderDataFile;
521
	}
522
 
523
}