Subversion Repositories SmartDukaan

Rev

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