Subversion Repositories SmartDukaan

Rev

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

Rev 13380 Rev 13393
Line 8... Line 8...
8
import in.shop2020.payments.PaymentException;
8
import in.shop2020.payments.PaymentException;
9
import in.shop2020.payments.PaymentStatus;
9
import in.shop2020.payments.PaymentStatus;
10
import in.shop2020.serving.services.CommonPaymentService;
10
import in.shop2020.serving.services.CommonPaymentService;
11
import in.shop2020.thrift.clients.PaymentClient;
11
import in.shop2020.thrift.clients.PaymentClient;
12
import in.shop2020.thrift.clients.TransactionClient;
12
import in.shop2020.thrift.clients.TransactionClient;
-
 
13
import in.shop2020.thrift.clients.UserClient;
13
import in.shop2020.thrift.clients.config.ConfigClient;
14
import in.shop2020.thrift.clients.config.ConfigClient;
14
 
15
 
15
import java.security.MessageDigest;
16
import java.security.MessageDigest;
16
import java.security.NoSuchAlgorithmException;
17
import java.security.NoSuchAlgorithmException;
17
import java.text.SimpleDateFormat;
18
import java.text.SimpleDateFormat;
Line 69... Line 70...
69
		surl = successUrl;
70
		surl = successUrl;
70
		updatePaymentParams(request.getParameterMap());
71
		updatePaymentParams(request.getParameterMap());
71
 
72
 
72
		PaymentClient paymentServiceClient = null;
73
		PaymentClient paymentServiceClient = null;
73
		TransactionClient transactionServiceClient = null;
74
		TransactionClient transactionServiceClient = null;
-
 
75
		UserClient userServiceClient = null;
74
		try {
76
		try {
-
 
77
			userServiceClient = new UserClient();
75
			paymentServiceClient = new PaymentClient();
78
			paymentServiceClient = new PaymentClient();
76
			transactionServiceClient = new TransactionClient();
79
			transactionServiceClient = new TransactionClient();
77
		} catch (Exception e) {
80
		} catch (Exception e) {
78
			log.error("Unable to initialize one of the clients", e);
81
			log.error("Unable to initialize one of the clients", e);
79
		}
82
		}
Line 161... Line 164...
161
                        transactionServiceClient.getClient().updateRechargeOrderStatus(rechargeOrder.getId(), RechargeOrderStatus.PAYMENT_FAILED);
164
                        transactionServiceClient.getClient().updateRechargeOrderStatus(rechargeOrder.getId(), RechargeOrderStatus.PAYMENT_FAILED);
162
		            }
165
		            }
163
		        } catch (Exception e) {
166
		        } catch (Exception e) {
164
		            log.error("Problem with txn client while trying to recharge", e);
167
		            log.error("Problem with txn client while trying to recharge", e);
165
		        }
168
		        }
-
 
169
            } else {
-
 
170
		        CommonPaymentService.processSuccessfulTxn(txnId, userServiceClient, transactionServiceClient, false);
166
            }
171
            }
-
 
172
            this.redirectUrl = surl + "?paymentId=" + merchantPaymentId;
167
			
173
			
168
		}else{
174
		} else{
169
			try {
175
			try {
170
				paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, gatewayPaymentId,
176
				paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, gatewayPaymentId,
171
						"", gatewayTxnStatus, "Payment Failed at PG", "", "", "", "", PaymentStatus.FAILED, new SimpleDateFormat().format(new Date()), attributes);
177
						"", gatewayTxnStatus, "Payment Failed at PG", "", "", "", "", PaymentStatus.FAILED, new SimpleDateFormat().format(new Date()), attributes);
172
			} catch (PaymentException e) {
178
			} catch (PaymentException e) {
173
			    log.error("Unable to mark the payment as failed", e);
179
			    log.error("Unable to mark the payment as failed", e);
Line 176... Line 182...
176
			}
182
			}
177
 
183
 
178
			CommonPaymentService.processFailedTxn(txnId, transactionServiceClient);
184
			CommonPaymentService.processFailedTxn(txnId, transactionServiceClient);
179
 
185
 
180
			this.redirectUrl = errorUrl + "?paymentId=" + merchantPaymentId;
186
			this.redirectUrl = errorUrl + "?paymentId=" + merchantPaymentId;
-
 
187
			
181
		}
188
		}
182
 
189
 
183
		log.info("User will be redirected to: " + "?paymentId=" + merchantPaymentId);
190
		log.info("User will be redirected to: " + surl + "?paymentId=" + merchantPaymentId);
184
		this.redirectUrl = surl + "?paymentId=" + merchantPaymentId;
-
 
185
		return "index";
191
		return "index";
186
	}
192
	}
187
 
193
 
188
	private boolean validatePaymentParams(double returnedAmount, Payment payment, String hash){
194
	private boolean validatePaymentParams(double returnedAmount, Payment payment, String hash){
189
		if(!(payment != null && Math.abs(payment.getAmount() - returnedAmount) <= 0.50 && hash.equals(getSecureHash()))){
195
		if(!(payment != null && Math.abs(payment.getAmount() - returnedAmount) <= 0.50 && hash.equals(getSecureHash()))){