Subversion Repositories SmartDukaan

Rev

Rev 20112 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20112 Rev 20278
Line 18... Line 18...
18
import in.shop2020.serving.services.HdfcPaymentService;
18
import in.shop2020.serving.services.HdfcPaymentService;
19
import in.shop2020.serving.services.IPaymentService;
19
import in.shop2020.serving.services.IPaymentService;
20
import in.shop2020.serving.services.InnovitiPaymentService;
20
import in.shop2020.serving.services.InnovitiPaymentService;
21
import in.shop2020.serving.services.PayuPaymentService;
21
import in.shop2020.serving.services.PayuPaymentService;
22
import in.shop2020.serving.utils.DesEncrypter;
22
import in.shop2020.serving.utils.DesEncrypter;
-
 
23
import in.shop2020.serving.utils.PaymentUtils;
23
import in.shop2020.serving.utils.Utils;
24
import in.shop2020.serving.utils.Utils;
24
import in.shop2020.thrift.clients.InventoryClient;
25
import in.shop2020.thrift.clients.InventoryClient;
25
import in.shop2020.thrift.clients.TransactionClient;
26
import in.shop2020.thrift.clients.TransactionClient;
26
import in.shop2020.thrift.clients.UserClient;
27
import in.shop2020.thrift.clients.UserClient;
27
import in.shop2020.utils.FedExShipAccountInfo;
28
import in.shop2020.utils.FedExShipAccountInfo;
Line 93... Line 94...
93
    	return "show";
94
    	return "show";
94
    }
95
    }
95
 
96
 
96
    // POST /order/
97
    // POST /order/
97
    public String create(){
98
    public String create(){
-
 
99
    	
-
 
100
    
98
    	String addressIdString = this.request.getParameter("addressid");
101
    	String addressIdString = this.request.getParameter("addressid");
99
    	if(addressIdString == null){
102
    	if(addressIdString == null){
100
    		addActionError("Please specify shipping address to continue.");
103
    		addActionError("Please specify shipping address to continue.");
101
    		return "proceed-to-pay-redirect";
104
    		return "proceed-to-pay-redirect";
102
    	}
105
    	}
Line 134... Line 137...
134
                return "proceed-to-pay-redirect";
137
                return "proceed-to-pay-redirect";
135
            }
138
            }
136
    	}
139
    	}
137
    	
140
    	
138
    	String paymentOption = request.getParameter("payment_option");
141
    	String paymentOption = request.getParameter("payment_option");
-
 
142
    	String paymentType="";
139
    	log.info("Payment Option Selected: " + paymentOption);
143
    	log.info("Payment Option Selected: " + paymentOption);
140
    	if(paymentOption == null || paymentOption.equals("")){
144
    	if(paymentOption == null || paymentOption.equals("")){
141
    		addActionError("Please select a payment method to continue.");
145
    		addActionError("Please select a payment method to continue.");
142
    		return "proceed-to-pay-redirect";
146
    		return "proceed-to-pay-redirect";
143
    	}
147
    	}
-
 
148
    	if(paymentOption.contains("~")){
-
 
149
    		paymentType = paymentOption.split("~")[0];
-
 
150
    		paymentOption = paymentOption.split("~")[1];
144
    	
151
    	}
145
    	
152
    	
146
    	 
153
    	 
147
    	long currentCartId = userinfo.getCartId();
154
    	long currentCartId = userinfo.getCartId();
148
    	long currentUserId = userinfo.getUserId();
155
    	long currentUserId = userinfo.getUserId();
149
    	
156
    	
Line 194... Line 201...
194
                return "proceed-to-pay-redirect";
201
                return "proceed-to-pay-redirect";
195
            }
202
            }
196
    	}
203
    	}
197
    	
204
    	
198
    	try {
205
    	try {
-
 
206
    		
199
    		if(!createOrders(addressId, currentCartId, currentUserId, Long.parseLong(paymentOption))) {
207
    		if(!createOrders(addressId, currentCartId, currentUserId, Long.parseLong(paymentOption))) {
200
    			addActionError("We are experiencing some problems. Please try later.");
208
    			addActionError("We are experiencing some problems. Please try later.");
201
    			return "proceed-to-pay-redirect";
209
    			return "proceed-to-pay-redirect";
202
    		}
210
    		}
203
    		//If tin is available push it to order attribute table
211
    		//If tin is available push it to order attribute table
Line 218... Line 226...
218
    		addActionError("We are experiencing some problems. Please try later.");
226
    		addActionError("We are experiencing some problems. Please try later.");
219
    		log.error("Exception in createOrders function. Something went wrong.", e);
227
    		log.error("Exception in createOrders function. Something went wrong.", e);
220
    		return "proceed-to-pay-redirect";
228
    		return "proceed-to-pay-redirect";
221
		}
229
		}
222
    	
230
    	
223
    	int gatewayId = (int)findGatewayId(paymentOption);
231
    	int gatewayId = (int)findGatewayId(paymentType+paymentOption);
224
    	switch (gatewayId) {
232
    	switch (gatewayId) {
225
    	case 4:
233
    	case 4:
226
    		IPaymentService codPaymentService = new CodPaymentService();
234
    		IPaymentService codPaymentService = new CodPaymentService();
227
    	    paymentId = codPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 4);
235
    	    paymentId = codPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 4, paymentType);
228
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
236
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
229
                //Very unlikely. The only possible reason can be that the payment service is down.
237
                //Very unlikely. The only possible reason can be that the payment service is down.
230
                log.error("Unable to process the COD payment.");
238
                log.error("Unable to process the COD payment.");
231
                addActionError("We are experiencing some problems. Please try later.");
239
                addActionError("We are experiencing some problems. Please try later.");
232
                return "proceed-to-pay-redirect";
240
                return "proceed-to-pay-redirect";
Line 234... Line 242...
234
                CommonPaymentService.processCodTxn(txnId, orderType);
242
                CommonPaymentService.processCodTxn(txnId, orderType);
235
                return "cod-redirect";
243
                return "cod-redirect";
236
            }
244
            }
237
 
245
 
238
    	case 5:
246
    	case 5:
-
 
247
    		IPaymentService payuPaymentService = new PayuPaymentService();
-
 
248
        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId, paymentType);
-
 
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 payu payment.");
-
 
252
 				addActionError("We are experiencing some problems. Please try later.");
-
 
253
 				return "proceed-to-pay-redirect";
239
    	case 10:
254
             } else {
-
 
255
            	 log.info("Successfully created payment for Innoviti to process. Redirecting to /payu-pay/" + paymentId);
240
    	case 11:
256
 				return "payu-pay-redirect";
241
    	case 12:
257
             }
242
    	case 14:
258
    	case 14:
243
			IPaymentService hdfcEmiPaymentService = new HdfcEmiPaymentService();
259
			IPaymentService hdfcEmiPaymentService = new HdfcEmiPaymentService();
244
            paymentId = hdfcEmiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
260
            paymentId = hdfcEmiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId, paymentType);
245
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
261
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
246
                addActionError("We are experiencing some problems. Please try later.");
262
                addActionError("We are experiencing some problems. Please try later.");
247
                log.error("Unable to process payment through HDFC EMI.");
263
                log.error("Unable to process payment through HDFC EMI.");
248
                return "proceed-to-pay-redirect";
264
                return "proceed-to-pay-redirect";
249
            } else {
265
            } else {
Line 252... Line 268...
252
                return "success";
268
                return "success";
253
            }
269
            }
254
        
270
        
255
    	case 13:
271
    	case 13:
256
			IPaymentService innovitiPaymentService = new InnovitiPaymentService();
272
			IPaymentService innovitiPaymentService = new InnovitiPaymentService();
257
			paymentId = innovitiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
273
			paymentId = innovitiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId, paymentType);
258
			if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
274
			if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
259
				//Very unlikely. The only possible reason can be that the payment service is down.
275
				//Very unlikely. The only possible reason can be that the payment service is down.
260
				log.error("Unable to process the COD payment.");
276
				log.error("Unable to process the innoviti payment.");
261
				addActionError("We are experiencing some problems. Please try later.");
277
				addActionError("We are experiencing some problems. Please try later.");
262
				return "proceed-to-pay-redirect";
278
				return "proceed-to-pay-redirect";
263
			} else {
279
			} else {
264
	            log.info("Successfully created payment for Innoviti to process. Redirecting to /innoviti-pay/" + paymentId);
280
	            log.info("Successfully created payment for Innoviti to process. Redirecting to /innoviti-pay/" + paymentId);
265
				return "innoviti-pay-redirect";
281
				return "innoviti-pay-redirect";
266
			}
282
			}
267
		
283
		
268
    	case 17:
284
    	case 17:
269
            IPaymentService couponPaymentService = new CouponPaymentService();
285
            IPaymentService couponPaymentService = new CouponPaymentService();
270
            paymentId = couponPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 17);
286
            paymentId = couponPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 17, paymentType);
271
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
287
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
272
                //Very unlikely. The only possible reason can be that the payment service is down.
288
                //Very unlikely. The only possible reason can be that the payment service is down.
273
                log.error("Unable to process the Coupon payment.");
289
                log.error("Unable to process the Coupon payment.");
274
                addActionError("We are experiencing some problems. Please try later.");
290
                addActionError("We are experiencing some problems. Please try later.");
275
                return "proceed-to-pay-redirect";
291
                return "proceed-to-pay-redirect";
276
            } else {
292
            } else {
277
                CommonPaymentService.processCouponTxn(txnId, orderType);
293
                CommonPaymentService.processCouponTxn(txnId, orderType);
278
                return "cod-redirect";
294
                return "cod-redirect";
279
            }
295
            }
-
 
296
          
-
 
297
    	case 18:
-
 
298
    		IPaymentService ebsPaymentService = new EbsPaymentService();
-
 
299
            paymentId = ebsPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 2, paymentType);
-
 
300
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
-
 
301
                addActionError("We are experiencing some problems. Please try later.");
-
 
302
                log.error("Unable to process payment through EBS.");
-
 
303
                return "proceed-to-pay-redirect";
-
 
304
            } else {
-
 
305
                log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
-
 
306
                return "ebs-pay-redirect";
-
 
307
            } 
280
		default:
308
		default:
281
			break;
309
			break;
282
		}
310
		}
283
    	
311
    	
284
 
312
 
285
		if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || 
313
		/*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)) {
314
		        paymentOption.equals(IPaymentService.HDFC_VISA) || paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
287
            // User has selected Visa or MasterCard
315
            // User has selected Visa or MasterCard
288
            IPaymentService hdfcPaymentService = new HdfcPaymentService();
316
            IPaymentService hdfcPaymentService = new HdfcPaymentService();
289
            paymentId = hdfcPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 1);
317
            paymentId = hdfcPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 1);
290
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
318
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
Line 293... Line 321...
293
            } else {
321
            } else {
294
                this.redirectURL = ((HdfcPaymentService)hdfcPaymentService).getRedirectUrl();
322
                this.redirectURL = ((HdfcPaymentService)hdfcPaymentService).getRedirectUrl();
295
                log.info(this.redirectURL);
323
                log.info(this.redirectURL);
296
                return "success";
324
                return "success";
297
            }
325
            }
298
        }
326
        }*/
299
 
327
 
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;
-
 
304
        else if(paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
-
 
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.
-
 
306
        } else if(paymentOption.equals(IPaymentService.PAYU_CC) || Utils.NET_BANKING_CODES_MAP.containsKey(paymentOption)){
-
 
307
        	IPaymentService payuPaymentService = new PayuPaymentService();
-
 
308
        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
-
 
309
        	return "payu-pay-redirect";
-
 
310
        }else if (paymentOption.equals("91000")){
328
/*    	if (paymentOption.equals("91000")){
311
        	IPaymentService payuPaymentService = new HdfcPaymentService();
329
        	IPaymentService payuPaymentService = new HdfcPaymentService();
312
        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
330
        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
313
        	return "hdfc-pay-redirect";
331
        	return "hdfc-pay-redirect";
314
        }
332
        }*/
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";
333
        return "payu-pay-redirect";
325
        }    	    
334
           	    
326
	}
335
	}
327
 
336
 
328
    private boolean isCouponValid(Cart cart) {
337
    private boolean isCouponValid(Cart cart) {
329
    	String couponCode = cart.getCouponCode();
338
    	String couponCode = cart.getCouponCode();
330
    	double totalAmountD;
339
    	double totalAmountD;
Line 339... Line 348...
339
        }
348
        }
340
    }
349
    }
341
    
350
    
342
    private long findGatewayId(String paymentOption){
351
    private long findGatewayId(String paymentOption){
343
    	long gatewayId = 0;
352
    	long gatewayId = 0;
344
    	gatewayId = ProceedToPayController.getGatewayId(Long.parseLong(paymentOption));
353
    	gatewayId = PaymentUtils.getGatewayId(paymentOption);
345
    	if(gatewayId==0){
-
 
346
    		if(paymentOption.equals(IPaymentService.COD)){
-
 
347
    			gatewayId = 4;
-
 
348
    		}
354
    	
349
    		if(paymentOption.equals(IPaymentService.COUPON)){
-
 
350
                gatewayId = 17;
-
 
351
            }
-
 
352
    	}
355
    	
353
    	return gatewayId;
356
    	return gatewayId;
354
    }
357
    }
355
    
358
    
356
    /**
359
    /**
357
     * Verifies if the recaptcha response matches the recaptcha challenge.
360
     * Verifies if the recaptcha response matches the recaptcha challenge.