| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import in.shop2020.config.ConfigException;
|
3 |
import in.shop2020.config.ConfigException;
|
| 4 |
import in.shop2020.model.v1.order.LineItem;
|
4 |
import in.shop2020.model.v1.order.LineItem;
|
| 5 |
import in.shop2020.model.v1.order.Order;
|
5 |
import in.shop2020.model.v1.order.Order;
|
| 6 |
import in.shop2020.model.v1.order.Transaction;
|
6 |
import in.shop2020.model.v1.order.Transaction;
|
| - |
|
7 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 7 |
import in.shop2020.model.v1.order.TransactionStatus;
|
8 |
import in.shop2020.model.v1.order.TransactionStatus;
|
| - |
|
9 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| - |
|
10 |
import in.shop2020.payments.Attribute;
|
| 8 |
import in.shop2020.payments.Payment;
|
11 |
import in.shop2020.payments.Payment;
|
| 9 |
import in.shop2020.payments.PaymentException;
|
12 |
import in.shop2020.payments.PaymentException;
|
| 10 |
import in.shop2020.payments.PaymentStatus;
|
13 |
import in.shop2020.payments.PaymentStatus;
|
| 11 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
14 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
| 12 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
15 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| Line 61... |
Line 64... |
| 61 |
public static String PAYMENTID = "paymentid";
|
64 |
public static String PAYMENTID = "paymentid";
|
| 62 |
public static String REF = "ref";
|
65 |
public static String REF = "ref";
|
| 63 |
public static String POSTDATE = "postdate";
|
66 |
public static String POSTDATE = "postdate";
|
| 64 |
public static String ERROR = "Error";
|
67 |
public static String ERROR = "Error";
|
| 65 |
public static String ERRORTEXT = "ErrorText";
|
68 |
public static String ERRORTEXT = "ErrorText";
|
| - |
|
69 |
public static String UDF5 = "udf5";
|
| 66 |
String redirectUrl;
|
70 |
String redirectUrl;
|
| 67 |
String amount;
|
71 |
String amount;
|
| 68 |
String trackId;
|
72 |
String trackId;
|
| 69 |
String result;
|
73 |
String result;
|
| 70 |
String postdate;
|
74 |
String postdate;
|
| Line 110... |
Line 114... |
| 110 |
String udf1=request.getParameter("udf1");
|
114 |
String udf1=request.getParameter("udf1");
|
| 111 |
String udf2=request.getParameter("udf2");
|
115 |
String udf2=request.getParameter("udf2");
|
| 112 |
String udf3=request.getParameter("udf3");
|
116 |
String udf3=request.getParameter("udf3");
|
| 113 |
String udf4=request.getParameter("udf4");
|
117 |
String udf4=request.getParameter("udf4");
|
| 114 |
*/
|
118 |
*/
|
| 115 |
String udf5=request.getParameter("udf5");
|
119 |
String udf5=request.getParameter(UDF5);
|
| 116 |
|
- |
|
| 117 |
|
120 |
|
| 118 |
Payment payment = null;
|
121 |
Payment payment = null;
|
| 119 |
try {
|
122 |
try {
|
| 120 |
payment = pclient.getClient().getPayment(merchantPaymentId);
|
123 |
payment = pclient.getClient().getPayment(merchantPaymentId);
|
| - |
|
124 |
String dbUdf5="";
|
| - |
|
125 |
double dbAmount = payment.getAmount();
|
| - |
|
126 |
for(Attribute attribute: payment.getAttributes()){
|
| - |
|
127 |
if(attribute.getName().trim().equalsIgnoreCase(UDF5)){
|
| - |
|
128 |
dbUdf5 = attribute.getValue();
|
| - |
|
129 |
}
|
| - |
|
130 |
}
|
| - |
|
131 |
// verify 3 things: udf5, amount and paymentid
|
| 121 |
if(Long.parseLong(paymentId) != payment.getPaymentId() && udf5.compareToIgnoreCase(payment.getAttributes().get(5).getValue())!=0){
|
132 |
if(Long.parseLong(paymentId) != payment.getPaymentId() && dbAmount == Double.parseDouble(amount) && udf5.equalsIgnoreCase(dbUdf5)){
|
| 122 |
this.redirectUrl = ConfigClient.getClient().get("payment_error_url") + "?paymentId="+merchantPaymentId;
|
133 |
this.redirectUrl = ConfigClient.getClient().get("payment_error_url") + "?paymentId="+merchantPaymentId;
|
| 123 |
return "index";
|
134 |
return "index";
|
| 124 |
}
|
135 |
}
|
| 125 |
} catch (PaymentException e1) {
|
136 |
} catch (PaymentException e1) {
|
| 126 |
// TODO Auto-generated catch block
|
137 |
log.error("Payment exception. It is serious, check merchant payment id + " + merchantPaymentId);
|
| 127 |
e1.printStackTrace();
|
138 |
e1.printStackTrace();
|
| 128 |
} catch (TException e1) {
|
139 |
} catch (TException e1) {
|
| 129 |
// TODO Auto-generated catch block
|
140 |
log.error("Thrift exception. Check payment id "+ merchantPaymentId);
|
| 130 |
e1.printStackTrace();
|
141 |
e1.printStackTrace();
|
| 131 |
} catch (ConfigException e) {
|
142 |
} catch (ConfigException e) {
|
| 132 |
this.redirectUrl = "http://173.230.147.250:8080/pay-error?paymentId="+merchantPaymentId;
|
143 |
this.redirectUrl = "http://173.230.147.250:8080/pay-error?paymentId="+merchantPaymentId;
|
| - |
|
144 |
log.error("Unable to get error url info from Config server. Falling back to default url.");
|
| 133 |
e.printStackTrace();
|
145 |
e.printStackTrace();
|
| 134 |
return "index";
|
146 |
return "index";
|
| 135 |
}
|
147 |
}
|
| 136 |
|
148 |
|
| 137 |
if(result.trim().equals(PaymentReturnStatus.CAPTURED.value())){
|
149 |
if(result.trim().equals(PaymentReturnStatus.CAPTURED.value())){
|
| Line 153... |
Line 165... |
| 153 |
}
|
165 |
}
|
| 154 |
}
|
166 |
}
|
| 155 |
//TODO Optimize the function to send less number of data over network
|
167 |
//TODO Optimize the function to send less number of data over network
|
| 156 |
usc.getClient().resetCart(transaction.getShoppingCartid(), items);
|
168 |
usc.getClient().resetCart(transaction.getShoppingCartid(), items);
|
| 157 |
|
169 |
|
| 158 |
|
- |
|
| 159 |
/*
|
- |
|
| 160 |
this.redirectUrl = "http://173.230.147.250:8080/pay-response?paymentId="+paymentId+"&result="+result+"&auth="+auth+
|
- |
|
| 161 |
"&ref="+ref+"&postdate="+postdate+"&trackid="+trackId+"&tranid="+tranId+"&udf1="+udf1+"&udf2="+udf2+"&udf3="+udf3+"&udf4="+udf4+"&udf5="+udf5+
|
- |
|
| 162 |
"&amt="+amount;
|
- |
|
| 163 |
*/
|
- |
|
| 164 |
|
- |
|
| 165 |
}catch (Exception e) {
|
170 |
}catch (TException e) {
|
| 166 |
log.error("Error while updating information.");
|
171 |
log.error("Error while updating information in payment database.");
|
| - |
|
172 |
e.printStackTrace();
|
| 167 |
//FIXME Even we get exception we should sent url back to payment gateway. And some thing back channel should be done
|
173 |
//FIXME Even we get exception we should sent url back to payment gateway. And some thing back channel should be done
|
| 168 |
|
174 |
|
| - |
|
175 |
} catch (ShoppingCartException e) {
|
| - |
|
176 |
log.error("Error while updating information in cart database.");
|
| - |
|
177 |
e.printStackTrace();
|
| - |
|
178 |
} catch (PaymentException e) {
|
| - |
|
179 |
log.error("Error while updating information in payment database.");
|
| - |
|
180 |
e.printStackTrace();
|
| - |
|
181 |
} catch (TransactionServiceException e) {
|
| - |
|
182 |
log.error("Error while updating information in transaction database.");
|
| - |
|
183 |
e.printStackTrace();
|
| 169 |
}
|
184 |
}
|
| 170 |
try{
|
185 |
try{
|
| 171 |
this.redirectUrl = ConfigClient.getClient().get("payment_success_url") + "?paymentId="+merchantPaymentId;
|
186 |
this.redirectUrl = ConfigClient.getClient().get("payment_success_url") + "?paymentId="+merchantPaymentId;
|
| 172 |
}catch(Exception ex){
|
187 |
}catch(Exception ex){
|
| 173 |
this.redirectUrl = "http://173.230.147.250:8080/pay-success?paymentId="+merchantPaymentId;
|
188 |
this.redirectUrl = "http://173.230.147.250:8080/pay-success?paymentId="+merchantPaymentId;
|
| Line 176... |
Line 191... |
| 176 |
}else{
|
191 |
}else{
|
| 177 |
try{
|
192 |
try{
|
| 178 |
pclient.getClient().updatePaymentDetails(merchantPaymentId, paymentId, sessionId, result, errorText, tranId, auth, ref, errorNo, PaymentStatus.FAILED, null);
|
193 |
pclient.getClient().updatePaymentDetails(merchantPaymentId, paymentId, sessionId, result, errorText, tranId, auth, ref, errorNo, PaymentStatus.FAILED, null);
|
| 179 |
txnId = pclient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
|
194 |
txnId = pclient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
|
| 180 |
tsc.getClient().changeTransactionStatus(txnId, TransactionStatus.FAILED, "Payment failed for the transaction.");
|
195 |
tsc.getClient().changeTransactionStatus(txnId, TransactionStatus.FAILED, "Payment failed for the transaction.");
|
| 181 |
}catch(Exception e){
|
196 |
}catch(TException e){
|
| 182 |
log.error("Error while updating information.");
|
197 |
log.error("Error while updating information.");
|
| - |
|
198 |
e.printStackTrace();
|
| 183 |
//FIXME Even we get exception we should sent url back to payment gateway. And some thing back channel should be done
|
199 |
//FIXME Even we get exception we should sent url back to payment gateway. And some thing back channel should be done
|
| - |
|
200 |
} catch (PaymentException e) {
|
| - |
|
201 |
log.error("Error while updating information in payment database.");
|
| - |
|
202 |
e.printStackTrace();
|
| - |
|
203 |
} catch (TransactionServiceException e) {
|
| - |
|
204 |
log.error("Error while updating information in transaction database.");
|
| - |
|
205 |
e.printStackTrace();
|
| 184 |
}
|
206 |
}
|
| 185 |
|
207 |
|
| 186 |
try{
|
208 |
try{
|
| 187 |
this.redirectUrl = ConfigClient.getClient().get("payment_error_url") + "?paymentId="+merchantPaymentId;
|
209 |
this.redirectUrl = ConfigClient.getClient().get("payment_error_url") + "?paymentId="+merchantPaymentId;
|
| 188 |
}catch(Exception ex){
|
210 |
}catch(Exception ex){
|