Subversion Repositories SmartDukaan

Rev

Rev 13505 | Rev 18057 | 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;
13425 amit.gupta 23
import in.shop2020.serving.utils.Utils;
9338 manish.sha 24
import in.shop2020.thrift.clients.InventoryClient;
3126 rajveer 25
import in.shop2020.thrift.clients.TransactionClient;
26
import in.shop2020.thrift.clients.UserClient;
7954 manish.sha 27
import in.shop2020.utils.FedExShipAccountInfo;
517 rajveer 28
 
3394 vikas 29
import java.util.ArrayList;
7001 rajveer 30
import java.util.Arrays;
2419 vikas 31
import java.util.List;
32
 
12788 amit.gupta 33
import nl.captcha.Captcha;
34
 
832 rajveer 35
import org.apache.log4j.Logger;
822 vikas 36
import org.apache.struts2.convention.annotation.InterceptorRef;
37
import org.apache.struts2.convention.annotation.InterceptorRefs;
419 rajveer 38
import org.apache.struts2.convention.annotation.Result;
39
import org.apache.struts2.convention.annotation.Results;
517 rajveer 40
import org.apache.thrift.TException;
4325 mandeep.dh 41
import org.apache.thrift.transport.TTransportException;
7954 manish.sha 42
 
43
import com.ShipWebServiceClient;
8940 manish.sha 44
import com.fedex.ship.stub.AssociatedShipmentDetail;
7954 manish.sha 45
import com.fedex.ship.stub.CompletedPackageDetail;
46
import com.fedex.ship.stub.CompletedShipmentDetail;
8940 manish.sha 47
import com.fedex.ship.stub.OperationalInstruction;
48
import com.fedex.ship.stub.PackageOperationalDetail;
7954 manish.sha 49
import com.fedex.ship.stub.ProcessShipmentReply;
8940 manish.sha 50
import com.fedex.ship.stub.StringBarcode;
7954 manish.sha 51
import com.fedex.ship.stub.TrackingId;
52
 
2159 chandransh 53
@SuppressWarnings("serial")
822 vikas 54
@InterceptorRefs({
55
    @InterceptorRef("myDefault"),
56
    @InterceptorRef("login")
57
})
58
 
419 rajveer 59
@Results({
3101 chandransh 60
    @Result(name="shipping-redirect", type="redirectAction", params = {"actionName" , "shipping"}),
5716 anupam.sin 61
    @Result(name="proceed-to-pay-redirect", type="redirectAction", params = {"actionName" , "proceed-to-pay", "deliveryLocation", "${deliveryLocation}"}),
3063 chandransh 62
	@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}"),
6060 rajveer 63
	@Result(name="payu-pay-redirect", type="redirect", location="/payu-pay/${paymentId}"),
6390 rajveer 64
	@Result(name="innoviti-pay-redirect", type="redirect", location="/innoviti-pay/${paymentId}"),
3063 chandransh 65
	@Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
419 rajveer 66
})
650 rajveer 67
public class OrderController extends BaseController {
419 rajveer 68
 
1905 chandransh 69
	public long getPaymentId() {
70
		return paymentId;
71
	}
419 rajveer 72
 
832 rajveer 73
	private static Logger log = Logger.getLogger(Class.class);
3063 chandransh 74
 
507 rajveer 75
	private String id;
712 rajveer 76
	private long txnId = 0;
650 rajveer 77
 
1905 chandransh 78
	private long paymentId;
79
 
1318 rajveer 80
	private String redirectURL;
5716 anupam.sin 81
	private String deliveryLocation = "";
681 rajveer 82
 
419 rajveer 83
	public OrderController(){
507 rajveer 84
		super();
419 rajveer 85
	}
86
 
507 rajveer 87
    // GET /order/ orderid
88
    public String show() {
89
    	log.info("id=" + id);
822 vikas 90
    	htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
4815 phani.kuma 91
    	htmlSnippets.put("ORDER_DETAILS", pageLoader.getOrderDetailsHtml(Long.parseLong(id), userinfo));
507 rajveer 92
    	return "show";
419 rajveer 93
    }
517 rajveer 94
 
572 chandransh 95
    // POST /order/
96
    public String create(){
786 rajveer 97
    	String addressIdString = this.request.getParameter("addressid");
12788 amit.gupta 98
    	OrderType orderType = OrderType.B2C;
99
    	String tin = null;
100
    	if(userinfo.isPrivateDealUser()){
101
    		try {
102
    			UserClient userServiceClient = new UserClient();
103
                in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
104
                PrivateDealUser user = userClient.getPrivateDealUser(userinfo.getUserId());
12789 amit.gupta 105
                log.info(user);
12788 amit.gupta 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)){
13521 amit.gupta 143
    	    if(!userinfo.isPrivateDealUser() && !verifyCaptcha()){
3063 chandransh 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)) {
13521 amit.gupta 168
    		if(!userinfo.isPrivateDealUser() && !verifyCaptcha()){
7862 anupam.sin 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 {
13505 amit.gupta 269
                CommonPaymentService.processCouponTxn(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
 
13425 amit.gupta 299
        if(paymentOption.equals(IPaymentService.PAYU_CC) || Utils.NET_BANKING_CODES_MAP.containsKey(paymentOption)){
13372 amit.gupta 300
        	IPaymentService payuPaymentService = new PayuPaymentService();
301
        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
302
        	return "payu-pay-redirect";
303
        }
13425 amit.gupta 304
        String bankCode = Utils.NET_BANKING_CODES_MAP.get(paymentOption);
6390 rajveer 305
 
13425 amit.gupta 306
 
6390 rajveer 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
}