Subversion Repositories SmartDukaan

Rev

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

Rev 6353 Rev 6390
Line 10... Line 10...
10
import in.shop2020.serving.services.CommonPaymentService;
10
import in.shop2020.serving.services.CommonPaymentService;
11
import in.shop2020.serving.services.EbsPaymentService;
11
import in.shop2020.serving.services.EbsPaymentService;
12
import in.shop2020.serving.services.HdfcEmiPaymentService;
12
import in.shop2020.serving.services.HdfcEmiPaymentService;
13
import in.shop2020.serving.services.HdfcPaymentService;
13
import in.shop2020.serving.services.HdfcPaymentService;
14
import in.shop2020.serving.services.IPaymentService;
14
import in.shop2020.serving.services.IPaymentService;
-
 
15
import in.shop2020.serving.services.InnovitiPaymentService;
15
import in.shop2020.serving.services.PayuPaymentService;
16
//import in.shop2020.serving.services.PayuPaymentService;
16
import in.shop2020.serving.utils.DesEncrypter;
17
import in.shop2020.serving.utils.DesEncrypter;
17
import in.shop2020.serving.utils.Utils;
18
import in.shop2020.serving.utils.Utils;
18
import in.shop2020.thrift.clients.TransactionClient;
19
import in.shop2020.thrift.clients.TransactionClient;
19
import in.shop2020.thrift.clients.UserClient;
20
import in.shop2020.thrift.clients.UserClient;
20
import in.shop2020.utils.DataLogger;
21
import in.shop2020.utils.DataLogger;
Line 40... Line 41...
40
@Results({
41
@Results({
41
    @Result(name="shipping-redirect", type="redirectAction", params = {"actionName" , "shipping"}),
42
    @Result(name="shipping-redirect", type="redirectAction", params = {"actionName" , "shipping"}),
42
    @Result(name="proceed-to-pay-redirect", type="redirectAction", params = {"actionName" , "proceed-to-pay", "deliveryLocation", "${deliveryLocation}"}),
43
    @Result(name="proceed-to-pay-redirect", type="redirectAction", params = {"actionName" , "proceed-to-pay", "deliveryLocation", "${deliveryLocation}"}),
43
	@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}"),
44
	@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}"),
44
	@Result(name="payu-pay-redirect", type="redirect", location="/payu-pay/${paymentId}"),
45
	@Result(name="payu-pay-redirect", type="redirect", location="/payu-pay/${paymentId}"),
-
 
46
	@Result(name="innoviti-pay-redirect", type="redirect", location="/innoviti-pay/${paymentId}"),
45
	@Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
47
	@Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
46
})
48
})
47
public class OrderController extends BaseController {
49
public class OrderController extends BaseController {
48
	
50
	
49
	public long getPaymentId() {
51
	public long getPaymentId() {
Line 124... Line 126...
124
                return "proceed-to-pay-redirect";
126
                return "proceed-to-pay-redirect";
125
            }
127
            }
126
    	}
128
    	}
127
    	
129
    	
128
    	try {
130
    	try {
129
    		if(!createOrders(addressId, currentCartId, currentUserId)) {
131
    		if(!createOrders(addressId, currentCartId, currentUserId, Long.parseLong(paymentOption))) {
130
    			addActionError("We are experiencing some problems. Please try later.");
132
    			addActionError("We are experiencing some problems. Please try later.");
131
    			return "proceed-to-pay-redirect";
133
    			return "proceed-to-pay-redirect";
132
    		}
134
    		}
133
    	} catch (Exception e) {
135
    	} catch (Exception e) {
134
    		addActionError("We are experiencing some problems. Please try later.");
136
    		addActionError("We are experiencing some problems. Please try later.");
135
    		log.error("Exception in createOrders function. Something went wrong.", e);
137
    		log.error("Exception in createOrders function. Something went wrong.", e);
136
    		return "proceed-to-pay-redirect";
138
    		return "proceed-to-pay-redirect";
137
		}
139
		}
138
    	
140
    	
-
 
141
    	int gatewayId = (int)findGatewayId(paymentOption);
-
 
142
    	switch (gatewayId) {
-
 
143
    	case 10:
-
 
144
			IPaymentService innovitiPaymentService = new InnovitiPaymentService();
-
 
145
			paymentId = innovitiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
139
    	if(paymentOption.equals(IPaymentService.COD)) {
146
			if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
-
 
147
				//Very unlikely. The only possible reason can be that the payment service is down.
-
 
148
				log.error("Unable to process the COD payment.");
-
 
149
				addActionError("We are experiencing some problems. Please try later.");
-
 
150
				return "proceed-to-pay-redirect";
-
 
151
			} else {
-
 
152
	            log.info("Successfully created payment for Innoviti to process. Redirecting to /innoviti-pay/" + paymentId);
-
 
153
				return "innoviti-pay-redirect";
-
 
154
			}
-
 
155
		
-
 
156
    	case 9:
-
 
157
    	case 11:
-
 
158
    	case 12:
-
 
159
    	case 13:
-
 
160
			IPaymentService hdfcEmiPaymentService = new HdfcEmiPaymentService();
-
 
161
            paymentId = hdfcEmiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
-
 
162
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
-
 
163
                addActionError("We are experiencing some problems. Please try later.");
-
 
164
                log.error("Unable to process payment through HDFC EMI.");
-
 
165
                return "proceed-to-pay-redirect";
-
 
166
            } else {
-
 
167
                this.redirectURL = ((HdfcEmiPaymentService)hdfcEmiPaymentService).getRedirectUrl();
-
 
168
                log.info(this.redirectURL);
-
 
169
                return "success";
-
 
170
            }
-
 
171
 
-
 
172
    	case 3:
140
    	    IPaymentService codPaymentService = new CodPaymentService();
173
    		IPaymentService codPaymentService = new CodPaymentService();
141
    	    paymentId = codPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption, sourceId);
174
    	    paymentId = codPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 4);
142
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
175
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
143
                //Very unlikely. The only possible reason can be that the payment service is down.
176
                //Very unlikely. The only possible reason can be that the payment service is down.
144
                log.error("Unable to process the COD payment.");
177
                log.error("Unable to process the COD payment.");
145
                addActionError("We are experiencing some problems. Please try later.");
178
                addActionError("We are experiencing some problems. Please try later.");
146
                return "proceed-to-pay-redirect";
179
                return "proceed-to-pay-redirect";
147
            } else {
180
            } else {
148
                CommonPaymentService.processCodTxn(txnId);
181
                CommonPaymentService.processCodTxn(txnId);
149
                return "cod-redirect";
182
                return "cod-redirect";
150
            }
183
            }
-
 
184
            
-
 
185
		default:
-
 
186
			break;
-
 
187
		}
-
 
188
    	
-
 
189
 
-
 
190
		if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || 
151
    	} else if(paymentOption.equals(IPaymentService.HDFC_EMI)){
191
		        paymentOption.equals(IPaymentService.HDFC_VISA) || paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
-
 
192
            // User has selected Visa or MasterCard
152
    	    IPaymentService hdfcEmiPaymentService = new HdfcEmiPaymentService();
193
            IPaymentService hdfcPaymentService = new HdfcPaymentService();
153
            paymentId = hdfcEmiPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption, sourceId);
194
            paymentId = hdfcPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 1);
154
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
195
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
155
                addActionError("We are experiencing some problems. Please try later.");
-
 
156
                log.error("Unable to process payment through HDFC EMI.");
196
                log.error("Unable to process payment through HDFC. Falling through to EBS.");
157
                return "proceed-to-pay-redirect";
-
 
158
            } else {
197
            } else {
159
                this.redirectURL = ((HdfcEmiPaymentService)hdfcEmiPaymentService).getRedirectUrl();
198
                this.redirectURL = ((HdfcPaymentService)hdfcPaymentService).getRedirectUrl();
160
                log.info(this.redirectURL);
199
                log.info(this.redirectURL);
161
                return "success";
200
                return "success";
162
            }
201
            }
163
    	} else {
-
 
164
    		if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || 
-
 
165
    		        paymentOption.equals(IPaymentService.HDFC_VISA) || paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
-
 
166
                // User has selected Visa or MasterCard
-
 
167
                IPaymentService hdfcPaymentService = new HdfcPaymentService();
-
 
168
                paymentId = hdfcPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption, sourceId);
-
 
169
                if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
-
 
170
                    log.error("Unable to process payment through HDFC. Falling through to EBS.");
-
 
171
                } else {
-
 
172
                    this.redirectURL = ((HdfcPaymentService)hdfcPaymentService).getRedirectUrl();
-
 
173
                    log.info(this.redirectURL);
-
 
174
                    return "success";
-
 
175
                }
-
 
176
            }
202
        }
177
 
203
 
178
            if(paymentOption.equals(IPaymentService.HDFC_VISA))
204
        if(paymentOption.equals(IPaymentService.HDFC_VISA))
179
                paymentOption = IPaymentService.EBS_VISA;
205
            paymentOption = IPaymentService.EBS_VISA;
180
            else if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT))
206
        else if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT))
181
                paymentOption = IPaymentService.EBS_MASTERCARD;
207
            paymentOption = IPaymentService.EBS_MASTERCARD;
182
            else if(paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON))
208
        else if(paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON))
183
                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.
209
            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.
184
            
210
        
185
            if(paymentOption.equals(IPaymentService.PAYU_CC)){
211
//        if(paymentOption.equals(IPaymentService.PAYU_CC)){
186
            	paymentOption = IPaymentService.PAYU_CC;
212
//        	paymentOption = IPaymentService.PAYU_CC;
187
            	IPaymentService payuPaymentService = new PayuPaymentService();
213
//        	IPaymentService payuPaymentService = new PayuPaymentService();
188
            	paymentId = payuPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption, sourceId);
214
//        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
189
            	return "payu-pay-redirect";
215
//        	return "payu-pay-redirect";
190
            }
216
//        }
191
            
217
        
192
            IPaymentService ebsPaymentService = new EbsPaymentService();
218
        IPaymentService ebsPaymentService = new EbsPaymentService();
193
            paymentId = ebsPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption, sourceId);
219
        paymentId = ebsPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 2);
194
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
220
        if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
195
                addActionError("We are experiencing some problems. Please try later.");
221
            addActionError("We are experiencing some problems. Please try later.");
196
                log.error("Unable to process payment through EBS.");
222
            log.error("Unable to process payment through EBS.");
197
                return "proceed-to-pay-redirect";
223
            return "proceed-to-pay-redirect";
198
            } else {
224
        } else {
199
                log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
225
            log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
200
                return "ebs-pay-redirect";
226
            return "ebs-pay-redirect";
201
            }    	    
227
        }    	    
-
 
228
	}
-
 
229
 
-
 
230
    private long findGatewayId(String paymentOption){
-
 
231
    	long gatewayId = 0;
-
 
232
    	gatewayId = ProceedToPayController.getGatewayId(Long.parseLong(paymentOption));
-
 
233
    	if(gatewayId==0){
-
 
234
    		if(paymentOption.equals(IPaymentService.COD)){
-
 
235
    			gatewayId = 5;
-
 
236
    		}
202
    	}
237
    	}
203
    	    
238
    	return gatewayId;
204
    }
239
    }
205
 
240
    
206
    /**
241
    /**
207
     * Verifies if the recaptcha response matches the recaptcha challenge.
242
     * Verifies if the recaptcha response matches the recaptcha challenge.
208
     * 
243
     * 
209
     * @return True if the captcha was valid, false otherwise.
244
     * @return True if the captcha was valid, false otherwise.
210
     */
245
     */
Line 254... Line 289...
254
	 * 
289
	 * 
255
	 * @param addressId
290
	 * @param addressId
256
	 * @param currentCartId
291
	 * @param currentCartId
257
	 * @return
292
	 * @return
258
	 */
293
	 */
259
	private boolean createOrders(long addressId, long currentCartId, long currentUserId){
294
	private boolean createOrders(long addressId, long currentCartId, long currentUserId, long emiSchemeId){
260
		UserClient userServiceClient = null;
295
		UserClient userServiceClient = null;
261
		try {
296
		try {
262
			userServiceClient = new UserClient();
297
			userServiceClient = new UserClient();
263
		} catch (Exception e) {
298
		} catch (Exception e) {
264
			log.error("Unable to talk to the user context service.", e);
299
			log.error("Unable to talk to the user context service.", e);
Line 306... Line 341...
306
            try {
341
            try {
307
                firstSrcTime = Long.parseLong(getCookie(TrackingInterceptor.SRC_TIME_COOKIE, false, null));
342
                firstSrcTime = Long.parseLong(getCookie(TrackingInterceptor.SRC_TIME_COOKIE, false, null));
308
            } catch (Exception e) {
343
            } catch (Exception e) {
309
                log.warn("Unable to parse session src time cookie.", e);
344
                log.warn("Unable to parse session src time cookie.", e);
310
            }
345
            }
311
            txnId = userClient.createOrders(currentCartId, sessionSrc, sessionTime, firstSrc, firstSrcTime, currentUserId);
346
            txnId = userClient.createOrders(currentCartId, sessionSrc, sessionTime, firstSrc, firstSrcTime, currentUserId, emiSchemeId);
312
		} catch (ShoppingCartException e1) {
347
		} catch (ShoppingCartException e1) {
313
			log.error("Error while creating orders from cart.", e1);
348
			log.error("Error while creating orders from cart.", e1);
314
			return false;
349
			return false;
315
		} catch (TException e) {
350
		} catch (TException e) {
316
			log.error("Thrift exception while creating orders from cart.", e);
351
			log.error("Thrift exception while creating orders from cart.", e);