Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
419 rajveer 1
package in.shop2020.serving.controllers;
2
 
9338 manish.sha 3
import in.shop2020.model.v1.inventory.Warehouse;
8940 manish.sha 4
import in.shop2020.model.v1.order.Attribute;
2183 vikas 5
import in.shop2020.model.v1.order.Order;
11526 amit.gupta 6
import in.shop2020.model.v1.order.OrderSource;
12788 amit.gupta 7
import in.shop2020.model.v1.order.OrderType;
4325 mandeep.dh 8
import in.shop2020.model.v1.order.TransactionServiceException;
3063 chandransh 9
import in.shop2020.model.v1.user.Address;
8428 rajveer 10
import in.shop2020.model.v1.user.Cart;
12788 amit.gupta 11
import in.shop2020.model.v1.user.PrivateDealUser;
894 rajveer 12
import in.shop2020.model.v1.user.ShoppingCartException;
12788 amit.gupta 13
import in.shop2020.model.v1.user.User;
2817 vikas 14
import in.shop2020.serving.interceptors.TrackingInterceptor;
3063 chandransh 15
import in.shop2020.serving.services.CodPaymentService;
16
import in.shop2020.serving.services.CommonPaymentService;
7862 anupam.sin 17
import in.shop2020.serving.services.CouponPaymentService;
1905 chandransh 18
import in.shop2020.serving.services.EbsPaymentService;
3616 chandransh 19
import in.shop2020.serving.services.HdfcEmiPaymentService;
1318 rajveer 20
import in.shop2020.serving.services.HdfcPaymentService;
1905 chandransh 21
import in.shop2020.serving.services.IPaymentService;
6390 rajveer 22
import in.shop2020.serving.services.InnovitiPaymentService;
6050 anupam.sin 23
import in.shop2020.serving.utils.DesEncrypter;
3212 vikas 24
import in.shop2020.serving.utils.Utils;
9338 manish.sha 25
import in.shop2020.thrift.clients.InventoryClient;
3126 rajveer 26
import in.shop2020.thrift.clients.TransactionClient;
27
import in.shop2020.thrift.clients.UserClient;
7954 manish.sha 28
import in.shop2020.utils.FedExShipAccountInfo;
517 rajveer 29
 
3394 vikas 30
import java.util.ArrayList;
7001 rajveer 31
import java.util.Arrays;
2419 vikas 32
import java.util.List;
33
 
12788 amit.gupta 34
import nl.captcha.Captcha;
35
 
832 rajveer 36
import org.apache.log4j.Logger;
822 vikas 37
import org.apache.struts2.convention.annotation.InterceptorRef;
38
import org.apache.struts2.convention.annotation.InterceptorRefs;
419 rajveer 39
import org.apache.struts2.convention.annotation.Result;
40
import org.apache.struts2.convention.annotation.Results;
517 rajveer 41
import org.apache.thrift.TException;
4325 mandeep.dh 42
import org.apache.thrift.transport.TTransportException;
7954 manish.sha 43
 
44
import com.ShipWebServiceClient;
8940 manish.sha 45
import com.fedex.ship.stub.AssociatedShipmentDetail;
7954 manish.sha 46
import com.fedex.ship.stub.CompletedPackageDetail;
47
import com.fedex.ship.stub.CompletedShipmentDetail;
8940 manish.sha 48
import com.fedex.ship.stub.OperationalInstruction;
49
import com.fedex.ship.stub.PackageOperationalDetail;
7954 manish.sha 50
import com.fedex.ship.stub.ProcessShipmentReply;
8940 manish.sha 51
import com.fedex.ship.stub.StringBarcode;
7954 manish.sha 52
import com.fedex.ship.stub.TrackingId;
53
 
2159 chandransh 54
@SuppressWarnings("serial")
822 vikas 55
@InterceptorRefs({
56
    @InterceptorRef("myDefault"),
57
    @InterceptorRef("login")
58
})
59
 
419 rajveer 60
@Results({
3101 chandransh 61
    @Result(name="shipping-redirect", type="redirectAction", params = {"actionName" , "shipping"}),
5716 anupam.sin 62
    @Result(name="proceed-to-pay-redirect", type="redirectAction", params = {"actionName" , "proceed-to-pay", "deliveryLocation", "${deliveryLocation}"}),
3063 chandransh 63
	@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}"),
6060 rajveer 64
	@Result(name="payu-pay-redirect", type="redirect", location="/payu-pay/${paymentId}"),
6390 rajveer 65
	@Result(name="innoviti-pay-redirect", type="redirect", location="/innoviti-pay/${paymentId}"),
3063 chandransh 66
	@Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
419 rajveer 67
})
650 rajveer 68
public class OrderController extends BaseController {
419 rajveer 69
 
1905 chandransh 70
	public long getPaymentId() {
71
		return paymentId;
72
	}
419 rajveer 73
 
832 rajveer 74
	private static Logger log = Logger.getLogger(Class.class);
3063 chandransh 75
 
507 rajveer 76
	private String id;
712 rajveer 77
	private long txnId = 0;
650 rajveer 78
 
1905 chandransh 79
	private long paymentId;
80
 
1318 rajveer 81
	private String redirectURL;
5716 anupam.sin 82
	private String deliveryLocation = "";
681 rajveer 83
 
419 rajveer 84
	public OrderController(){
507 rajveer 85
		super();
419 rajveer 86
	}
87
 
507 rajveer 88
    // GET /order/ orderid
89
    public String show() {
90
    	log.info("id=" + id);
822 vikas 91
    	htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
4815 phani.kuma 92
    	htmlSnippets.put("ORDER_DETAILS", pageLoader.getOrderDetailsHtml(Long.parseLong(id), userinfo));
507 rajveer 93
    	return "show";
419 rajveer 94
    }
517 rajveer 95
 
572 chandransh 96
    // POST /order/
97
    public String create(){
786 rajveer 98
    	String addressIdString = this.request.getParameter("addressid");
12788 amit.gupta 99
    	OrderType orderType = OrderType.B2C;
100
    	String tin = null;
101
    	if(userinfo.isPrivateDealUser()){
102
    		try {
103
    			UserClient userServiceClient = new UserClient();
104
                in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
105
                PrivateDealUser user = userClient.getPrivateDealUser(userinfo.getUserId());
106
                if(user.getTin() != null && !user.getTin().equals("")) {
107
                	orderType = OrderType.B2B;
108
                	tin = user.getTin().trim();
109
                }
110
 
111
            } catch (Exception e) {
112
                log.error("Unable to talk to the user context service.", e);
113
                addActionError("We are experiencing some problems. Please try later.");
114
                return "proceed-to-pay-redirect";
115
            }
116
    	}
786 rajveer 117
    	if(addressIdString == null){
894 rajveer 118
    		addActionError("Please specify shipping address to continue.");
3101 chandransh 119
    		return "proceed-to-pay-redirect";
786 rajveer 120
    	}
2159 chandransh 121
 
122
    	String paymentOption = request.getParameter("payment_option");
123
    	log.info("Payment Option Selected: " + paymentOption);
124
    	if(paymentOption == null || paymentOption.equals("")){
125
    		addActionError("Please select a payment method to continue.");
3101 chandransh 126
    		return "proceed-to-pay-redirect";
2159 chandransh 127
    	}
128
 
129
 
3101 chandransh 130
    	long addressId;
131
    	try {
132
    	    addressId = Long.parseLong(addressIdString);   
133
    	} catch(NumberFormatException nfe){
134
    	    log.error("Unable to get address id", nfe);
135
    	    addActionError("Invalid address. Please add an address to the cart.");
136
    	    return "shipping-redirect";
137
    	}
138
 
572 chandransh 139
    	long currentCartId = userinfo.getCartId();
5326 rajveer 140
    	long currentUserId = userinfo.getUserId();
3063 chandransh 141
 
142
    	if(paymentOption.equals(IPaymentService.COD)){
143
    	    if(!verifyCaptcha()){
144
    	        addActionError("Invalid captcha");
4815 phani.kuma 145
    	        log.info("Invalid captcha error msg has been added");
3101 chandransh 146
    	        return "proceed-to-pay-redirect";    
3063 chandransh 147
    	    }
148
 
6353 rajveer 149
	        //Check that this address is eligible for COD shipping.
150
    	    UserClient userServiceClient = null;
151
            try {
152
                userServiceClient = new UserClient();
153
                in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
154
                Address address = userClient.getAddressById(addressId);
155
 
156
                if(!userClient.showCODOption(currentCartId, sourceId, address.getPin())){
157
                    addActionError("Cash on Delivery is currently not available for this pincode. Please choose a different payment option.");
158
                    return "proceed-to-pay-redirect";    
159
                }
160
            } catch (Exception e) {
161
                log.error("Unable to talk to the user context service.", e);
162
                addActionError("We are experiencing some problems. Please try later.");
163
                return "proceed-to-pay-redirect";
164
            }
3063 chandransh 165
    	}
166
 
7862 anupam.sin 167
    	if(paymentOption.equals(IPaymentService.COUPON)) {
168
    	    if(!verifyCaptcha()){
169
                addActionError("Invalid captcha");
170
                log.info("Invalid captcha error msg has been added");
171
                return "proceed-to-pay-redirect";    
172
            }
8428 rajveer 173
	    	UserClient userServiceClient = null;
174
            try {
175
                userServiceClient = new UserClient();
176
                in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
177
                Cart cart = userClient.getCart(currentCartId);
178
                if(!isCouponValid(cart)){
179
                    addActionError("Cart amount is not zero.");
180
                    log.info("Cart amount is not zero.");
181
                    return "proceed-to-pay-redirect";    
182
                }
183
            } catch (Exception e) {
184
                log.error("Unable to talk to the user context service.", e);
185
                addActionError("We are experiencing some problems. Please try later.");
186
                return "proceed-to-pay-redirect";
187
            }
7862 anupam.sin 188
    	}
189
 
3063 chandransh 190
    	try {
6390 rajveer 191
    		if(!createOrders(addressId, currentCartId, currentUserId, Long.parseLong(paymentOption))) {
1128 rajveer 192
    			addActionError("We are experiencing some problems. Please try later.");
3101 chandransh 193
    			return "proceed-to-pay-redirect";
894 rajveer 194
    		}
12788 amit.gupta 195
    		//If tin is available push it to order attribute table
196
    		if(tin != null){
197
    			TransactionClient transactionServiceClient = null;
198
 
199
    	        try {
200
    	            transactionServiceClient = new TransactionClient();
201
    	            Attribute attr1 = new Attribute();
202
    	            attr1.setName("tinNumber");
203
    	            attr1.setValue(tin);
204
    	            transactionServiceClient.getClient().setOrderAttributeForTransaction(txnId, attr1);
205
    	        } catch (Exception e1) {
206
    	        	log.warn("Unable to log orders through the datalogger", e1);
207
    	        }
208
    		}
3063 chandransh 209
    	} catch (Exception e) {
1128 rajveer 210
    		addActionError("We are experiencing some problems. Please try later.");
2296 chandransh 211
    		log.error("Exception in createOrders function. Something went wrong.", e);
3101 chandransh 212
    		return "proceed-to-pay-redirect";
693 rajveer 213
		}
2159 chandransh 214
 
6390 rajveer 215
    	int gatewayId = (int)findGatewayId(paymentOption);
216
    	switch (gatewayId) {
6419 rajveer 217
    	case 4:
218
    		IPaymentService codPaymentService = new CodPaymentService();
219
    	    paymentId = codPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 4);
220
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
221
                //Very unlikely. The only possible reason can be that the payment service is down.
222
                log.error("Unable to process the COD payment.");
223
                addActionError("We are experiencing some problems. Please try later.");
224
                return "proceed-to-pay-redirect";
225
            } else {
12788 amit.gupta 226
                CommonPaymentService.processCodTxn(txnId, orderType);
6419 rajveer 227
                return "cod-redirect";
228
            }
229
 
230
    	case 5:
6390 rajveer 231
    	case 10:
232
    	case 11:
233
    	case 12:
7001 rajveer 234
    	case 14:
6390 rajveer 235
			IPaymentService hdfcEmiPaymentService = new HdfcEmiPaymentService();
236
            paymentId = hdfcEmiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
237
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
238
                addActionError("We are experiencing some problems. Please try later.");
239
                log.error("Unable to process payment through HDFC EMI.");
240
                return "proceed-to-pay-redirect";
241
            } else {
242
                this.redirectURL = ((HdfcEmiPaymentService)hdfcEmiPaymentService).getRedirectUrl();
243
                log.info(this.redirectURL);
244
                return "success";
245
            }
6419 rajveer 246
 
247
    	case 13:
248
			IPaymentService innovitiPaymentService = new InnovitiPaymentService();
249
			paymentId = innovitiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
250
			if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
251
				//Very unlikely. The only possible reason can be that the payment service is down.
252
				log.error("Unable to process the COD payment.");
253
				addActionError("We are experiencing some problems. Please try later.");
254
				return "proceed-to-pay-redirect";
255
			} else {
256
	            log.info("Successfully created payment for Innoviti to process. Redirecting to /innoviti-pay/" + paymentId);
257
				return "innoviti-pay-redirect";
258
			}
259
 
8428 rajveer 260
    	case 17:
7862 anupam.sin 261
            IPaymentService couponPaymentService = new CouponPaymentService();
8428 rajveer 262
            paymentId = couponPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 17);
7862 anupam.sin 263
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
264
                //Very unlikely. The only possible reason can be that the payment service is down.
265
                log.error("Unable to process the Coupon payment.");
266
                addActionError("We are experiencing some problems. Please try later.");
267
                return "proceed-to-pay-redirect";
268
            } else {
12788 amit.gupta 269
                CommonPaymentService.processCodTxn(txnId, orderType);
7862 anupam.sin 270
                return "cod-redirect";
271
            }
6390 rajveer 272
		default:
273
			break;
274
		}
275
 
276
 
277
		if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || 
278
		        paymentOption.equals(IPaymentService.HDFC_VISA) || paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
279
            // User has selected Visa or MasterCard
280
            IPaymentService hdfcPaymentService = new HdfcPaymentService();
281
            paymentId = hdfcPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 1);
282
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
10968 amit.gupta 283
            	//TODO:Update order gatewayTxnStatus in case its not processed using txnId
6390 rajveer 284
                log.error("Unable to process payment through HDFC. Falling through to EBS.");
3616 chandransh 285
            } else {
6390 rajveer 286
                this.redirectURL = ((HdfcPaymentService)hdfcPaymentService).getRedirectUrl();
3616 chandransh 287
                log.info(this.redirectURL);
288
                return "success";
289
            }
6390 rajveer 290
        }
2199 chandransh 291
 
6390 rajveer 292
        if(paymentOption.equals(IPaymentService.HDFC_VISA))
293
            paymentOption = IPaymentService.EBS_VISA;
294
        else if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT))
295
            paymentOption = IPaymentService.EBS_MASTERCARD;
296
        else if(paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON))
297
            paymentOption = null;           //Since we don't know the bank's name in this case, we'll let the user select the bank on the EBS page.
298
 
299
//        if(paymentOption.equals(IPaymentService.PAYU_CC)){
300
//        	paymentOption = IPaymentService.PAYU_CC;
301
//        	IPaymentService payuPaymentService = new PayuPaymentService();
302
//        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
303
//        	return "payu-pay-redirect";
304
//        }
305
 
306
        IPaymentService ebsPaymentService = new EbsPaymentService();
307
        paymentId = ebsPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 2);
308
        if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
309
            addActionError("We are experiencing some problems. Please try later.");
310
            log.error("Unable to process payment through EBS.");
311
            return "proceed-to-pay-redirect";
312
        } else {
313
            log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
314
            return "ebs-pay-redirect";
315
        }    	    
316
	}
317
 
8428 rajveer 318
    private boolean isCouponValid(Cart cart) {
319
    	String couponCode = cart.getCouponCode();
320
    	double totalAmountD;
321
        if(couponCode == null || "".equals(couponCode))
322
        	totalAmountD = cart.getTotalPrice();
323
        else
324
            totalAmountD = cart.getDiscountedPrice();
325
        if(totalAmountD == 0) {
326
            return true;
327
        }else{
328
        	return false;
329
        }
330
    }
331
 
6390 rajveer 332
    private long findGatewayId(String paymentOption){
333
    	long gatewayId = 0;
334
    	gatewayId = ProceedToPayController.getGatewayId(Long.parseLong(paymentOption));
335
    	if(gatewayId==0){
336
    		if(paymentOption.equals(IPaymentService.COD)){
6419 rajveer 337
    			gatewayId = 4;
6390 rajveer 338
    		}
7862 anupam.sin 339
    		if(paymentOption.equals(IPaymentService.COUPON)){
8428 rajveer 340
                gatewayId = 17;
7862 anupam.sin 341
            }
3063 chandransh 342
    	}
6390 rajveer 343
    	return gatewayId;
572 chandransh 344
    }
6390 rajveer 345
 
3063 chandransh 346
    /**
347
     * Verifies if the recaptcha response matches the recaptcha challenge.
348
     * 
349
     * @return True if the captcha was valid, false otherwise.
350
     */
351
    private boolean verifyCaptcha() {
4609 phani.kuma 352
        String cookieCaptchaAnswer = getCookie(Captcha.NAME, true, "saholic");
353
    	String captchaReceived = (String) request.getParameter("captcha_response_field");
354
 
355
    	if (captchaReceived.equalsIgnoreCase(cookieCaptchaAnswer)) {
356
			try {
12616 anikendra 357
//				DataLogger.logData(EventType.CAPTCHA_SUCCESS, getSessionId(), userinfo.getUserId(), userinfo.getEmail());
4609 phani.kuma 358
			} catch (Exception e1) {
359
	        	log.warn("Unable to log orders through the datalogger", e1);
360
	        }
361
			return true;
362
		} 
363
		else {
364
			try {
12616 anikendra 365
//				DataLogger.logData(EventType.CAPTCHA_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail());
4609 phani.kuma 366
			} catch (Exception e1) {
367
	        	log.warn("Unable to log orders through the datalogger", e1);
368
	        }
369
			return false;
370
		}
3063 chandransh 371
    }
572 chandransh 372
 
507 rajveer 373
	public String getId(){
374
		return id;
375
	}
419 rajveer 376
 
507 rajveer 377
	public void setId(String id){
378
		this.id = id;
379
	}
419 rajveer 380
 
507 rajveer 381
	public String getMyaccountHeaderSnippet(){
382
		return htmlSnippets.get("MYACCOUNT_HEADER");
383
	}
384
 
385
	public String getOrderDetailsSnippet(){
386
		return htmlSnippets.get("ORDER_DETAILS");
387
	}
388
 
712 rajveer 389
	public long getTxn(){
390
		return this.txnId;
517 rajveer 391
	}
894 rajveer 392
 
393
	/**
394
	 * 
395
	 * @param addressId
396
	 * @param currentCartId
397
	 * @return
398
	 */
6390 rajveer 399
	private boolean createOrders(long addressId, long currentCartId, long currentUserId, long emiSchemeId){
3126 rajveer 400
		UserClient userServiceClient = null;
894 rajveer 401
		try {
3126 rajveer 402
			userServiceClient = new UserClient();
894 rajveer 403
		} catch (Exception e) {
2296 chandransh 404
			log.error("Unable to talk to the user context service.", e);
894 rajveer 405
			return false;
406
		}
407
 
408
		in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
409
		try {
410
			userClient.addAddressToCart(currentCartId, addressId);
411
		} catch (ShoppingCartException e1) {
2296 chandransh 412
			log.error("Not able to set address in the cart.", e1);
894 rajveer 413
			return false;
414
		} catch (TException e1) {
2296 chandransh 415
			log.error("Thrift exception while setting address in cart.", e1);
894 rajveer 416
			return false;
417
		}
418
 
419
 
420
		try {
6736 amit.gupta 421
			String errorMsg = userClient.validateCart(currentCartId, sourceId).get(0); 
1466 ankur.sing 422
			if(!errorMsg.isEmpty()){
423
				addActionError(errorMsg);
894 rajveer 424
				return false;
425
			}
426
		} catch (ShoppingCartException e1) {
2296 chandransh 427
			log.error("Error while validating shopping cart.", e1);
894 rajveer 428
			return false;
429
		} catch (TException e) {
2296 chandransh 430
			log.error("Thrift exception while validating cart.", e);
894 rajveer 431
			return false;
432
		}
433
 
434
 
435
		try {
3859 vikas 436
		    String sessionSrc = getCookie(TrackingInterceptor.SESSION_SRC_COOKIE, true, TrackingInterceptor.ENCRIPTION_STRING);
437
		    String firstSrc = getCookie(TrackingInterceptor.SRC_COOKIE, true, TrackingInterceptor.ENCRIPTION_STRING);
2817 vikas 438
 
3859 vikas 439
		    long sessionTime = 0;
440
            try {
441
                sessionTime = Long.parseLong(getCookie(TrackingInterceptor.SESSION_SRC_TIME_COOKIE, false, null));
442
            } catch (Exception e) {
443
                log.warn("Unable to parse session src time cookie.", e);
2817 vikas 444
            }
3859 vikas 445
            long firstSrcTime = 0;
446
            try {
447
                firstSrcTime = Long.parseLong(getCookie(TrackingInterceptor.SRC_TIME_COOKIE, false, null));
448
            } catch (Exception e) {
449
                log.warn("Unable to parse session src time cookie.", e);
450
            }
11526 amit.gupta 451
            txnId = userClient.createOrders(currentCartId, sessionSrc, sessionTime, firstSrc, firstSrcTime, currentUserId, emiSchemeId, OrderSource.WEBSITE.getValue());
894 rajveer 452
		} catch (ShoppingCartException e1) {
2296 chandransh 453
			log.error("Error while creating orders from cart.", e1);
894 rajveer 454
			return false;
455
		} catch (TException e) {
2296 chandransh 456
			log.error("Thrift exception while creating orders from cart.", e);
894 rajveer 457
			return false;
458
		}
459
 
3126 rajveer 460
		TransactionClient transactionServiceClient = null;
4325 mandeep.dh 461
 
12788 amit.gupta 462
        /*try {
3126 rajveer 463
            transactionServiceClient = new TransactionClient();
2183 vikas 464
            List<Order> orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
465
            for (Order order : orders) {
3394 vikas 466
                List<Order> tmpOrders = new ArrayList<Order>();
467
                tmpOrders.add(order);
468
                String itemIdString = Utils.getItemIdStringFromOrders(tmpOrders);
12616 anikendra 469
//                DataLogger.logData(EventType.ORDER_CREATION, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), 
470
//                        Long.toString(order.getId()), Long.toString(currentCartId), itemIdString);
2183 vikas 471
            }
472
        } catch (Exception e1) {
2296 chandransh 473
        	log.warn("Unable to log orders through the datalogger", e1);
12788 amit.gupta 474
        }*/
894 rajveer 475
 
476
		return true;
477
	}
4325 mandeep.dh 478
 
479
	/**
480
	 * This method updates address of a given order.
481
	 *
482
	 * @return
483
	 */
484
	public String modifyAddress() {
485
        long orderId   = Long.parseLong(request.getParameter("orderId"));
486
        long addressId = Long.valueOf(request.getParameter("addressId"));
487
 
488
		try {
489
		    TransactionClient transactionServiceClient = new TransactionClient();
490
			in.shop2020.model.v1.order.TransactionService.Client transactionClient
491
			    = transactionServiceClient.getClient();			
492
			transactionClient.updateShipmentAddress(orderId, addressId);
7954 manish.sha 493
			in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
9338 manish.sha 494
			Warehouse warehouse = null;
495
			try{
496
	    		InventoryClient isc = new InventoryClient();
497
	    		warehouse = isc.getClient().getWarehouse(t_order.getWarehouse_id());
498
			} catch(Exception e) {
499
			    log.error("Unable to get warehouse for id : " + t_order.getWarehouse_id(), e);
500
			    //TODO throw e;
501
			}
7954 manish.sha 502
			if(t_order.getLogistics_provider_id()==7L){
9338 manish.sha 503
				FedExShipAccountInfo fedexAccountInfo = FedExShipAccountInfo.getFedExInfo(warehouse.getLogisticsLocation());
7954 manish.sha 504
				ProcessShipmentReply  processShipmentReply = ShipWebServiceClient.getShipmentCreationReply(t_order,fedexAccountInfo.getClientDetail(),fedexAccountInfo.getWad(),fedexAccountInfo.getEndPointAddress());
505
				CompletedShipmentDetail completedShipmentDetails = processShipmentReply.getCompletedShipmentDetail();
506
				CompletedPackageDetail completedPackageDetails =  completedShipmentDetails.getCompletedPackageDetails(0);
507
				TrackingId  trackId= completedPackageDetails.getTrackingIds(0);
508
				t_order = transactionClient.updateOrderAWB(t_order.getId(), trackId.getTrackingNumber());
8940 manish.sha 509
				//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
510
				CompletedPackageDetail[] cpd= completedShipmentDetails.getCompletedPackageDetails();
511
				AssociatedShipmentDetail[] asdetails = completedShipmentDetails.getAssociatedShipments();
512
				List<Attribute> attrList = new ArrayList<Attribute>();
513
				if(t_order.isCod()){
514
					if(asdetails!=null){
515
						for(AssociatedShipmentDetail as : asdetails){
516
							if(as.getType().getValue().equalsIgnoreCase("COD_RETURN")){
517
								PackageOperationalDetail pod = as.getPackageOperationalDetail();
518
								StringBarcode[] barcodes = pod.getBarcodes().getStringBarcodes();
519
								for(StringBarcode bc : barcodes){
520
									Attribute attr3 = new Attribute();
521
									attr3.setName("FedEx_COD_Return_BarCode");
522
									attr3.setValue(bc.getValue());
523
									attrList.add(attr3);
524
								}
525
 
526
								String codReturnTrackingNo= as.getTrackingId().getTrackingNumber();
527
								Attribute attr4 = new Attribute();
528
								attr4.setName("FedEx_COD_Return_Tracking_No");
529
								attr4.setValue(codReturnTrackingNo);
530
								attrList.add(attr4);
531
							}
532
						}
533
					}
534
				}
535
				for(CompletedPackageDetail cd : cpd){
536
					PackageOperationalDetail pod = cd.getOperationalDetail();
537
					StringBarcode[] barcodes = pod.getBarcodes().getStringBarcodes();
538
					for(StringBarcode bc : barcodes){
539
						Attribute attr1 = new Attribute();
540
						attr1.setName("FedEx_Package_BarCode");
541
						attr1.setValue(bc.getValue());
542
						attrList.add(attr1);
543
					}
544
					OperationalInstruction[] ois = pod.getOperationalInstructions();
545
					Attribute attr2 = new Attribute();
546
					for(OperationalInstruction oi : ois){
547
						if(oi.getNumber().intValue()==5){
548
							attr2.setName("FedEx_Location_Code");
549
							attr2.setValue(oi.getContent());
550
							attrList.add(attr2);
551
						}
552
					}						
553
				}
554
				transactionClient.setOrderAttributes(t_order.getId(), attrList);
555
				//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
556
 
7954 manish.sha 557
			}
4325 mandeep.dh 558
		} catch (TTransportException e) {
559
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
560
		} catch (NumberFormatException e) {
561
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
562
		} catch (TransactionServiceException e) {
563
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
564
		} catch (TException e) {
565
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
566
		}			
567
 
568
		return "index";
569
	}
570
 
1318 rajveer 571
	public String getRedirectURL(){
572
		return this.redirectURL;
573
	}
5716 anupam.sin 574
 
575
    public String getDeliveryLocation() {
576
        return deliveryLocation;
577
    }
578
 
579
    public void setDeliveryLocation(String deliveryLocation) {
580
        this.deliveryLocation = deliveryLocation;
581
    }
6050 anupam.sin 582
 
583
    public static void main(String[] args) {
584
        DesEncrypter d = new DesEncrypter("shop2020");
585
        System.out.println(d.decrypt("pmkcWEzhf4IFRLyHce89Cg"));
7001 rajveer 586
    	long[] HDFC_EMI_GATEWAY_IDS = {5,10,11,12};
587
    	List<Long> stooges = Arrays.asList(5L,10L,11L,12L);
588
    	List<Long> lista = new ArrayList<Long>();
589
    	lista.add(5L);
590
    	lista.add(10L);
591
    	lista.add(11L);
592
    	lista.add(12L);
593
    	long gatewayId = 10;
594
    	if(stooges.contains(gatewayId)){
595
    		System.out.println("true");
596
    	}else{
597
    		System.out.println("false");
598
    	}
6050 anupam.sin 599
    }
419 rajveer 600
}