Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
8182 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;
8291 amar.kumar 23
import in.shop2020.model.v1.inventory.VendorItemPricing;
8182 amar.kumar 24
import in.shop2020.model.v1.inventory.Warehouse;
25
import in.shop2020.model.v1.order.EbayOrder;
26
import in.shop2020.model.v1.order.LineItem;
27
import in.shop2020.model.v1.order.Order;
28
import in.shop2020.model.v1.order.OrderSource;
29
import in.shop2020.model.v1.order.OrderStatus;
30
import in.shop2020.model.v1.order.OrderType;
31
import in.shop2020.model.v1.order.SourceDetail;
32
import in.shop2020.model.v1.order.Transaction;
33
import in.shop2020.model.v1.order.TransactionStatus;
34
import in.shop2020.model.v1.order.TransactionService.Client;
35
import in.shop2020.model.v1.user.Address;
36
import in.shop2020.model.v1.user.User;
37
import in.shop2020.payments.Attribute;
38
import in.shop2020.payments.PaymentException;
39
import in.shop2020.payments.PaymentStatus;
40
import in.shop2020.thrift.clients.CatalogClient;
41
import in.shop2020.thrift.clients.InventoryClient;
42
import in.shop2020.thrift.clients.LogisticsClient;
43
import in.shop2020.thrift.clients.PaymentClient;
44
import in.shop2020.thrift.clients.TransactionClient;
45
import in.shop2020.thrift.clients.UserClient;
46
import in.shop2020.support.utils.ReportsUtils;
47
 
48
import javax.servlet.http.HttpServletRequest;
49
import javax.servlet.http.HttpSession;
50
 
51
import org.apache.commons.io.FileUtils;
52
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
53
import org.apache.poi.ss.usermodel.Cell;
54
import org.apache.poi.ss.usermodel.Row;
55
import org.apache.poi.ss.usermodel.Sheet;
56
import org.apache.poi.ss.usermodel.Workbook;
57
import org.apache.struts2.convention.annotation.InterceptorRef;
58
import org.apache.struts2.convention.annotation.InterceptorRefs;
59
import org.apache.struts2.convention.annotation.Result;
60
import org.apache.struts2.convention.annotation.Results;
61
import org.apache.struts2.interceptor.ServletRequestAware;
62
import org.apache.thrift.TException;
63
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
65
 
66
import com.opensymphony.xwork2.ActionSupport;
67
 
68
@SuppressWarnings("serial")
69
@InterceptorRefs({
70
    @InterceptorRef("defaultStack"),
71
    @InterceptorRef("login")
72
})
73
@Results({
74
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
75
})
76
public class EbayNormalOrderCreatorController extends ActionSupport implements ServletRequestAware {
77
 
78
	private static Logger logger = LoggerFactory.getLogger(EbayNormalOrderCreatorController.class);
79
 
80
	private HttpServletRequest request;
81
    private HttpSession session;
82
 
83
    private static final int EBAY_SOURCE_ID = 6;
84
 
85
    private static final int SALES_RECORD_NUM_INDEX = 0;
86
    private static final int BUYER_NAME_INDEX = 2;
87
    private static final int CUST_MOBILE_INDEX = 3;
88
    private static final int EMAIL_INDEX = 4;
89
    private static final int ADDR1_INDEX = 5;
90
    private static final int ADDR2_INDEX = 6;
91
    private static final int CITY_INDEX = 7;
92
    private static final int STATE_INDEX = 8;
93
    private static final int PINCODE_INDEX = 9;
94
    private static final int EBAY_LISTINGID_INDEX = 11;
95
    private static final int QUANTITY_INDEX = 14;
96
    private static final int AMOUNT_INDEX = 15;
97
    private static final int TRANSACTION_DATE_INDEX = 21;
98
    private static final int PAISAPAY_ID_INDEX = 28;
99
    private static final int TRANSACTION_ID_INDEX = 31;
100
 
101
    private static final int SHIP_DATE_INDEX = 24;
102
    private static final int WAREHOUSE_ID_INDEX = 34;
8488 amar.kumar 103
    private static final int OVERRIDE_BILLING_PRICE_INDEX = 35;
8182 amar.kumar 104
 
8196 amar.kumar 105
    private static final int EBAY_GATEWAY_ID = 16;
8182 amar.kumar 106
 
107
    private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
108
    private SimpleDateFormat sdf2 = new SimpleDateFormat("dd-MMM-yyyy");
109
 
110
    private File orderDataFile;
111
    private String orderDataFileName;
112
    private String transactionId;
113
    private String errorMsg = "";
114
    private Long rowId = 0L;
115
 
116
    public String create() throws TException {
117
        File fileToCreate = null;
118
        orderDataFileName = "OrderSheet_"+EBAY_SOURCE_ID+"_"+(new Date().toString());
119
        try {
120
            fileToCreate = new File("/tmp/", this.orderDataFileName);
121
            FileUtils.copyFile(this.orderDataFile, fileToCreate);
122
        } catch (Exception e) {
123
           logger.error("Error while writing order data file to the local file system for Ebay", e);
124
           addActionError("Error while writing order data file to the local file system");
125
        }
126
 
127
 
128
        if(checkForErrors())
129
            return "authsuccess";
130
 
131
        //Parse the file and submit the data for update to the transaction service
132
        Workbook wb = null;
133
        try {
134
            wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
135
        } catch (Exception e) {
136
            logger.error("Unable to open the File for Order Creation for Ebay ", e);
137
            addActionError("Unable to open the File for Order creation");
138
        }
139
        if(checkForErrors())
140
            return "authsuccess";
141
 
142
        SourceDetail sourceDetail = null;
143
        User user = null;
144
        TransactionClient tsc = null;
145
        try {
146
            tsc = new TransactionClient();
147
			sourceDetail = tsc.getClient().getSourceDetail(EBAY_SOURCE_ID);
148
        } catch (Exception e) {
149
            logger.error("Unable to establish connection to the transaction service", e);
150
            addActionError("Unable to establish connection to the transaction service");
151
		}
152
 
153
        if(checkForErrors())
154
            return "authsuccess";
155
 
156
        in.shop2020.model.v1.user.UserContextService.Client userClient = null;
157
	    try {   
158
	        userClient = new UserClient().getClient();
159
	    } catch (Exception e) {
160
	        logger.error("Unable to establish connection to the User service", e);
161
	        addActionError("Unable to establish connection to the User service");
162
		}
163
 
164
        if(checkForErrors())
165
            return "authsuccess";
166
 
167
        Sheet sheet = wb.getSheetAt(0);
168
        Row firstRow = sheet.getRow(0);
169
        logger.info("Last row number is:" + sheet.getLastRowNum());
170
        for (Row row : sheet) {
8656 amar.kumar 171
        	rowId++;
8182 amar.kumar 172
        	long orderCountForRow = 0;
173
            if(row.equals(firstRow))
174
                continue;
8656 amar.kumar 175
 
8182 amar.kumar 176
            try {
177
	            //TODO Get this user from a different method
178
	            if (userClient.userExists(row.getCell(EMAIL_INDEX).getStringCellValue())) {
179
		        	user = userClient.getUserByEmail(row.getCell(EMAIL_INDEX).getStringCellValue());
180
		        } else {
181
		        	user = new User();
182
		        	user.setName(row.getCell(BUYER_NAME_INDEX).getStringCellValue());
183
		        	user.setEmail(row.getCell(EMAIL_INDEX).getStringCellValue());
8723 amar.kumar 184
		        	user.setSourceId(EBAY_SOURCE_ID);
8182 amar.kumar 185
		        	//TODO set mobileNumber for customer
186
		        	//TODO set password for user;
187
		        	user.setIsAnonymous(false);
188
		        	user = userClient.createUser(user);
189
		        }
190
            } catch(Exception e) {
191
	        	logger.error("Unable to establish connection to the User service for row number " + (rowId + 1), e);
192
    	        addActionError("Unable to establish connection to the User servicefor row number " + (rowId + 1));
193
    	        return "authsuccess";
194
	        }
195
            Transaction txn = new Transaction();
196
            txn.setShoppingCartid(user.getActiveCartId());
197
            txn.setCustomer_id(user.getUserId());
198
            txn.setCreatedOn(new Date().getTime());
199
            txn.setTransactionStatus(TransactionStatus.INIT);
200
            txn.setStatusDescription("Order for Ebay ");
201
 
202
            List<Order> orders = new ArrayList<Order>();
203
 
8241 amar.kumar 204
            double listingPrice = 0;
205
    		double overriddenPrice = 0;
206
    		double totalPrice = 0;
207
 
8182 amar.kumar 208
            row.getCell(EBAY_LISTINGID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
209
            String ebayListingId = row.getCell(EBAY_LISTINGID_INDEX).getStringCellValue();
210
    		CatalogService.Client catalogClient = new CatalogClient().getClient();
211
    		EbayItem ebayItem = catalogClient.getEbayItem(ebayListingId);
212
    		long quantity = new Double(row.getCell(QUANTITY_INDEX).getNumericCellValue()).longValue();
8488 amar.kumar 213
    		Cell overriddenPriceCell = row.getCell(OVERRIDE_BILLING_PRICE_INDEX);
8241 amar.kumar 214
        	if(overriddenPriceCell  != null && overriddenPriceCell .getCellType() != Cell.CELL_TYPE_BLANK) {
8488 amar.kumar 215
        		overriddenPrice = row.getCell(OVERRIDE_BILLING_PRICE_INDEX).getNumericCellValue();
8241 amar.kumar 216
        	}
8182 amar.kumar 217
    		String totalPriceString = row.getCell(AMOUNT_INDEX).getStringCellValue();
8241 amar.kumar 218
    		if(overriddenPrice>=1) {
219
    			totalPrice = overriddenPrice*quantity;
220
    			listingPrice = (Double.parseDouble(totalPriceString.substring(3).replace(",","")))/quantity;
221
    		} else {
222
    			totalPrice = Double.parseDouble(totalPriceString.substring(3).replace(",",""));
223
    			listingPrice = totalPrice/quantity;
224
    		}
8182 amar.kumar 225
        	LineItem lineItem = null;
226
        	try {
227
        		lineItem = createLineItem(ebayItem.getItemId(), quantity, totalPrice);
8656 amar.kumar 228
        		Double salesRecordNumber = row.getCell(SALES_RECORD_NUM_INDEX).getNumericCellValue();
229
        		row.getCell(PAISAPAY_ID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
230
            	String paisaPayId = row.getCell(PAISAPAY_ID_INDEX).getStringCellValue();
231
        		lineItem.setExtra_info("PaisaPayId = " + paisaPayId + " SalesRecordNumber = " + salesRecordNumber);
8182 amar.kumar 232
        	} catch (Exception tex) {
233
        		logger.error("Unable to establish connection to the Catalog service", tex);
234
    	        addActionError("Unable to establish connection to the Catalog service");
235
    	        return "authsuccess";
236
        	}
237
            Order order = new Order();
238
            order.setCustomer_id(user.getUserId());
239
            order.setCustomer_email(user.getEmail());
240
        	order.setCustomer_name(user.getName());
241
            try {
242
            	order.setCustomer_mobilenumber(new Double(row.getCell(CUST_MOBILE_INDEX).getNumericCellValue()).toString());
243
            } catch (Exception e) {
244
            	addActionError("Error in reading mobile Number for rowNumber " + row.getRowNum());
245
            	logger.error("Error in reading mobile Number for rowNumber " + row.getRowNum());
246
            }
247
            order.setCustomer_address1(row.getCell(ADDR1_INDEX).getStringCellValue());
8569 amar.kumar 248
            Cell address2Cell = row.getCell(ADDR2_INDEX);
249
        	if(address2Cell != null && address2Cell.getCellType() != Cell.CELL_TYPE_BLANK) {
250
        		order.setCustomer_address2(row.getCell(ADDR2_INDEX).getStringCellValue());
251
        	}
252
//        	order.setCustomer_address2(row.getCell(ADDR2_INDEX).getStringCellValue());
8182 amar.kumar 253
        	order.setCustomer_city(row.getCell(CITY_INDEX).getStringCellValue());
254
        	order.setCustomer_state(row.getCell(STATE_INDEX).getStringCellValue());
255
        	row.getCell(PINCODE_INDEX).setCellType(Cell.CELL_TYPE_STRING);
256
        	order.setCustomer_pincode(row.getCell(PINCODE_INDEX).getStringCellValue());
257
            order.setTotal_amount(totalPrice);            
258
            order.setTotal_weight(lineItem.getTotal_weight());
259
            order.setLineitems(Collections.singletonList(lineItem));            
260
            order.setStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
261
            order.setStatusDescription("In Process");
262
            order.setCreated_timestamp(new Date().getTime());
8303 amar.kumar 263
            order.setCod(false);
8182 amar.kumar 264
            try {
8281 amar.kumar 265
            	Date shippingDate = interchangeDateAndMonth(row.getCell(SHIP_DATE_INDEX).getDateCellValue());
266
            	order.setPromised_shipping_time(shippingDate.getTime());
267
            	order.setExpected_shipping_time(shippingDate.getTime());
8254 amar.kumar 268
            	//order.setPromised_shipping_time(sdf.parse(row.getCell(SHIP_DATE_INDEX).getStringCellValue()).getTime());
269
            	//order.setExpected_shipping_time(sdf.parse(row.getCell(SHIP_DATE_INDEX).getStringCellValue()).getTime());
8182 amar.kumar 270
            	Calendar time = Calendar.getInstance();
271
            	time.setTimeInMillis(order.getExpected_shipping_time());
272
            	time.add(Calendar.DAY_OF_MONTH, 3);
273
            	order.setPromised_delivery_time(time.getTimeInMillis());
274
            	order.setExpected_delivery_time(time.getTimeInMillis());
275
            } catch(Exception e) {
8254 amar.kumar 276
            	addActionError("Error in updating Shipping Time for row number " + (rowId + 1));
8182 amar.kumar 277
            	logger.error("Error in updating Shipping Time for row number " + (rowId + 1),e);
8343 amar.kumar 278
            	continue;
8182 amar.kumar 279
            }
280
 
281
            //TODO Delivery time
282
            InventoryService.Client inventoryClient = null;
283
            Warehouse fulfillmentWarehouse= null; 
284
            try {
285
            	inventoryClient = new InventoryClient().getClient();
286
            	Cell warehouseCell = row.getCell(WAREHOUSE_ID_INDEX);
287
            	if(warehouseCell != null && warehouseCell.getCellType() != Cell.CELL_TYPE_BLANK) { 
288
            		fulfillmentWarehouse = inventoryClient.getWarehouse(new Double(row.getCell(WAREHOUSE_ID_INDEX).getNumericCellValue()).longValue());
289
 
290
            	} else if (ebayItem.getDefaultWarehouseId()!=0 ){
291
            		fulfillmentWarehouse = inventoryClient.getWarehouse(ebayItem.getDefaultWarehouseId());
292
            	} else {
293
            		List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(ebayItem.getItemId(), 1);
294
            		fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
295
            	}
296
            	order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
297
        		order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
8291 amar.kumar 298
        		VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
299
        		order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
300
        		order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
8182 amar.kumar 301
			} catch (InventoryServiceException e) {
302
				addActionError("Error in updating WarehouseId for row number " + rowId + 1);
303
            	logger.error("Error in updating WarehouseId for row number " + (rowId + 1),e);
8488 amar.kumar 304
            	continue;
8182 amar.kumar 305
			}
306
 
307
            order.setTotal_amount(totalPrice);
308
            order.setSource(EBAY_SOURCE_ID);
309
            orders.add(order);
310
            orderCountForRow++;
311
 
312
            txn.setOrders(orders);
313
            Client transaction_client = new TransactionClient().getClient();
314
            try {
315
            	long salesRecNumber = new Double(row.getCell(SALES_RECORD_NUM_INDEX).getNumericCellValue()).longValue();
316
            	if(transaction_client.ebayOrderExists(salesRecNumber, ebayItem.getEbayListingId())) {
8342 amar.kumar 317
            		setErrorMsg(getErrorMsg() + "<br>Duplicate order for salesRecNumber " + salesRecNumber + " and listingId " + ebayItem.getEbayListingId() + " for row number  " + rowId);
318
            		logger.error("Duplicate order for salesRecNumber " + salesRecNumber + " and listingId " + ebayItem.getEbayListingId());
319
            		continue;
8182 amar.kumar 320
            	}
8350 amar.kumar 321
            	try {	
322
	            	LogisticsService.Client logisticsClient = new LogisticsClient().getClient();
323
	            	LogisticsInfo logisticsInfo = logisticsClient.getLogisticsInfo(order.getCustomer_pincode(), 
8779 amar.kumar 324
	            			new Double(order.getLineitems().get(0).getItem_id()).longValue(), DeliveryType.PREPAID, PickUpType.COURIER);
8350 amar.kumar 325
	            	order.setLogistics_provider_id(logisticsInfo.getProviderId());
326
            	} catch (Exception e) {
327
            		logger.error("Error while setting logistics provider for order for rowId " + rowId, e);
328
                    addActionError("Error while setting logistics provider for order for rowId " + rowId);
329
                    setErrorMsg(getErrorMsg() + "<br>Error while setting logistics provider for order for rowId " + rowId);
330
                    continue;
331
            	}
8182 amar.kumar 332
            	transactionId =  String.valueOf(transaction_client.createTransaction(txn));
333
            	row.getCell(PAISAPAY_ID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
334
            	String paisaPayId = row.getCell(PAISAPAY_ID_INDEX).getStringCellValue();
335
            	createPayment(user, paisaPayId, totalPrice);
336
 
337
            	//TODO
338
            	/*in.shop2020.model.v1.order.Attribute orderAttribute = new in.shop2020.model.v1.order.Attribute();
339
                orderAttribute.setName("tinNumber");
340
                orderAttribute.setValue(sourceDetail.getTinNumber());
341
 
342
                if(!sourceDetail.getTinNumber().equals("") && !(sourceDetail.getTinNumber() == null)) {
343
                	transaction_client.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute);
344
                }*/
345
            	//source
346
                //transaction_client.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED, "Ebay Order", 0L, OrderType.B2C, OrderSource.EBAY);
347
                //transaction_client.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS, "Ebay Order", 0L, OrderType.B2C, OrderSource.EBAY);
348
                logger.info("Successfully created transaction: " + transactionId + " for amount: " + totalPrice);
349
 
350
                Transaction transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
8209 amar.kumar 351
                order = transaction.getOrders().get(0);
8182 amar.kumar 352
                inventoryClient.reserveItemInWarehouse(ebayItem.getItemId(), fulfillmentWarehouse.getId(), 1, 
353
                		order.getId(), order.getCreated_timestamp(), order.getPromised_shipping_time(), order.getLineitems().get(0).getQuantity());
354
                transaction_client.updateOrderForEbay(order);
355
                EbayOrder ebayOrder = new EbayOrder();
356
                ebayOrder.setEbayListingId(ebayItem.getEbayListingId());
357
                ebayOrder.setSalesRecordNumber(new Double(row.getCell(SALES_RECORD_NUM_INDEX).getNumericCellValue()).longValue());
358
                row.getCell(TRANSACTION_ID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
359
                ebayOrder.setTransactionId(row.getCell(TRANSACTION_ID_INDEX).getStringCellValue());
360
                try {
8281 amar.kumar 361
                	Date ebayTransactionDate = interchangeDateAndMonth(row.getCell(TRANSACTION_DATE_INDEX).getDateCellValue());
362
                	ebayOrder.setEbayTxnDate(ebayTransactionDate.getTime());
8182 amar.kumar 363
                	//ebayOrder.setEbayTxnDate(sdf2.parse(row.getCell(TRANSACTION_DATE_INDEX).getStringCellValue()).getTime());
8254 amar.kumar 364
                	//ebayOrder.setEbayTxnDate(sdf.parse(row.getCell(TRANSACTION_DATE_INDEX).getStringCellValue()).getTime());
8182 amar.kumar 365
                } catch (Exception e) {
366
                	logger.error("Error in setting transaction date for Ebay Order with OrderId : " + order.getId());
367
                }
368
                ebayOrder.setOrderId(transaction.getOrders().get(0).getId());
369
                ebayOrder.setPaisaPayId(paisaPayId);
370
                ebayOrder.setSubsidyAmount(ebayItem.getSubsidy()*quantity);
371
                ebayOrder.setListingName(ebayItem.getListingName());
8241 amar.kumar 372
                ebayOrder.setListingPrice(listingPrice);
8182 amar.kumar 373
                transaction_client.createEbayOrder(ebayOrder);
374
            } catch (Exception e) {
8350 amar.kumar 375
            	logger.error("Error while creating order for rowId " + rowId, e);
376
                addActionError("Error while creating order for rowId " + rowId);
377
                setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
378
                continue;
8182 amar.kumar 379
    		}
380
        }
381
 
382
        checkForErrors();
383
        return "authsuccess";
384
    }
385
 
8281 amar.kumar 386
    private Date interchangeDateAndMonth(Date date) {
387
		Date updatedDate = new Date(date.getTime());
8286 amar.kumar 388
		updatedDate.setDate(date.getMonth() + 1);
389
		updatedDate.setMonth(date.getDate() - 1);
8281 amar.kumar 390
		return updatedDate;
391
	}
392
 
8182 amar.kumar 393
    private LineItem createLineItem(long itemId, long quantity, double amount) throws CatalogServiceException, TException {
394
    	LineItem lineItem = new LineItem();
395
    	CatalogService.Client catalogClient = new CatalogClient().getClient();
396
    	Item item = catalogClient.getItem(itemId);
397
 
398
    	lineItem.setProductGroup(item.getProductGroup());
399
        lineItem.setBrand(item.getBrand());
400
        lineItem.setModel_number(item.getModelNumber());
401
        lineItem.setModel_name(item.getModelName());
402
        lineItem.setExtra_info(item.getFeatureDescription());
403
        lineItem.setQuantity(quantity);
404
        lineItem.setItem_id(item.getId());
405
        lineItem.setUnit_weight(item.getWeight());
8241 amar.kumar 406
        lineItem.setTotal_weight(item.getWeight()*quantity);
8182 amar.kumar 407
        lineItem.setUnit_price(amount/quantity);
408
        lineItem.setTotal_price(amount);
409
 
410
        if (item.getColor() == null || "NA".equals(item.getColor())) {
411
            lineItem.setColor("");
412
        } else {
413
            lineItem.setColor(item.getColor());
414
        }
415
    	return lineItem;
416
	}
417
 
418
    private void createPayment(User user, String paisaPayId, double amount) throws NumberFormatException, PaymentException, TException {
419
        in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
420
        long paymentId = client.createPayment(user.getUserId(), amount, EBAY_GATEWAY_ID, Long.valueOf(transactionId), false);
421
        client.updatePaymentDetails(paymentId, null, null, null, null, null, null, paisaPayId, null, PaymentStatus.AUTHORIZED, null, null);
422
    }   
423
 
424
	public String index() {
425
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/ebay-dashboard"))
426
            return "authfail";
427
        checkForErrors();
428
        return "authsuccess";
429
    }
430
 
431
	private boolean checkForErrors(){
432
        Collection<String> actionErrors = getActionErrors();
433
        if(actionErrors != null && !actionErrors.isEmpty()){
434
            for (String str : actionErrors) {
435
                errorMsg += "<BR/>" + str;
436
            }
437
            return true;
438
        }
439
        return false;
440
    }
441
 
442
	@Override
443
	public void setServletRequest(HttpServletRequest request) {
444
		this.request = request;
445
        this.session = request.getSession();
446
	}
447
 
448
	public String getErrorMsg() {
449
		return errorMsg;
450
	}
451
 
452
	public void setErrorMsg(String errorMsg) {
453
		this.errorMsg = errorMsg;
454
	}
455
 
456
	public Long getRowId() {
457
		return rowId;
458
	}
459
 
460
	public void setRowId(Long rowId) {
461
		this.rowId = rowId;
462
	}
463
 
464
	public File getOrderDataFile() {
465
		return orderDataFile;
466
	}
467
 
468
	public void setOrderDataFile(File orderDataFile) {
469
		this.orderDataFile = orderDataFile;
470
	}
471
 
472
}