Subversion Repositories SmartDukaan

Rev

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