Subversion Repositories SmartDukaan

Rev

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