| Line 12... |
Line 12... |
| 12 |
import in.shop2020.config.ConfigException;
|
12 |
import in.shop2020.config.ConfigException;
|
| 13 |
import in.shop2020.model.v1.order.LineItem;
|
13 |
import in.shop2020.model.v1.order.LineItem;
|
| 14 |
import in.shop2020.model.v1.order.Order;
|
14 |
import in.shop2020.model.v1.order.Order;
|
| 15 |
import in.shop2020.model.v1.order.Transaction;
|
15 |
import in.shop2020.model.v1.order.Transaction;
|
| 16 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
16 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 17 |
import in.shop2020.model.v1.user.Cart;
|
- |
|
| 18 |
import in.shop2020.model.v1.user.Line;
|
- |
|
| 19 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
17 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 20 |
import in.shop2020.payments.Attribute;
|
18 |
import in.shop2020.payments.Attribute;
|
| 21 |
import in.shop2020.payments.PaymentException;
|
- |
|
| 22 |
import in.shop2020.payments.PaymentStatus;
|
19 |
import in.shop2020.payments.PaymentStatus;
|
| 23 |
import in.shop2020.payments.PaymentService.Client;
|
- |
|
| 24 |
import in.shop2020.serving.utils.Utils;
|
- |
|
| 25 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
20 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
| 26 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
21 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| 27 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
- |
|
| 28 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
22 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 29 |
|
23 |
|
| 30 |
|
24 |
|
| 31 |
|
25 |
|
| 32 |
import com.aciworldwide.commerce.gateway.plugins.NotEnoughDataException;
|
26 |
import com.aciworldwide.commerce.gateway.plugins.NotEnoughDataException;
|
| 33 |
import com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe;
|
27 |
import com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe;
|
| 34 |
@Results({
|
- |
|
| 35 |
@Result(name="redirect", type="redirectAction",
|
- |
|
| 36 |
params = {"actionName" , "${url}"}),
|
- |
|
| 37 |
@Result(name="shipping-redirect", type="redirectAction",
|
- |
|
| 38 |
params = {"actionName" , "shipping"})
|
- |
|
| 39 |
})
|
- |
|
| 40 |
|
28 |
|
| 41 |
public class HdfcPaymentService {
|
29 |
public class HdfcPaymentService implements IPaymentService {
|
| 42 |
private static final long serialVersionUID = 1L;
|
30 |
private static final long serialVersionUID = 1L;
|
| 43 |
private static Logger log = Logger.getLogger(Class.class);
|
31 |
private static Logger log = Logger.getLogger(Class.class);
|
| 44 |
|
32 |
|
| 45 |
private static String resourceFilePath;
|
33 |
private static String resourceFilePath;
|
| 46 |
private static String aliasName;
|
34 |
private static String aliasName;
|
| Line 83... |
Line 71... |
| 83 |
log.error("Unable to get data from config server.");
|
71 |
log.error("Unable to get data from config server.");
|
| 84 |
}
|
72 |
}
|
| 85 |
}
|
73 |
}
|
| 86 |
|
74 |
|
| 87 |
|
75 |
|
| 88 |
public boolean createPayment(long currentCartId, long userId, long txnId){
|
76 |
public long createPayment(long currentCartId, long userId, long txnId){
|
| 89 |
|
- |
|
| 90 |
PaymentServiceClient paymentServiceClient = null;
|
- |
|
| 91 |
try {
|
- |
|
| 92 |
paymentServiceClient = new PaymentServiceClient();
|
- |
|
| 93 |
} catch (Exception e) {
|
- |
|
| 94 |
log.error("Error while getting payment client");
|
- |
|
| 95 |
e.printStackTrace();
|
- |
|
| 96 |
return false;
|
- |
|
| 97 |
}
|
- |
|
| 98 |
|
- |
|
| 99 |
|
- |
|
| 100 |
try {
|
- |
|
| 101 |
amount = getPaymentAmount(currentCartId);
|
- |
|
| 102 |
} catch (ShoppingCartException e1) {
|
- |
|
| 103 |
log.error("Not able to fetch payment amount from cart id." + e1.getId() + e1.getMessage());
|
- |
|
| 104 |
e1.printStackTrace();
|
- |
|
| 105 |
return false;
|
- |
|
| 106 |
} catch (TException e1) {
|
- |
|
| 107 |
log.error("Not able to fetch payment amount." + e1.getMessage());
|
- |
|
| 108 |
e1.printStackTrace();
|
- |
|
| 109 |
return false;
|
- |
|
| 110 |
}
|
- |
|
| 111 |
|
77 |
|
| 112 |
Client paymentClient = paymentServiceClient.getClient();
|
78 |
CommonPaymentService cps = new CommonPaymentService();
|
| 113 |
try {
|
- |
|
| 114 |
this.paymentId = paymentClient.createPayment(userId, amount, gatewayId, txnId);
|
79 |
if(!cps.createPayment(currentCartId, userId, txnId, gatewayId)){
|
| 115 |
} catch (PaymentException e1) {
|
- |
|
| 116 |
log.error("Not able to create payment object." + e1.getError_code() + e1.getMessage());
|
- |
|
| 117 |
e1.printStackTrace();
|
- |
|
| 118 |
return false;
|
- |
|
| 119 |
} catch (TException e) {
|
- |
|
| 120 |
log.error("Not able to create payment object." + e.getMessage());
|
80 |
log.error("Error while creating the basic payment");
|
| 121 |
e.printStackTrace();
|
- |
|
| 122 |
return false;
|
81 |
return PAYMENT_NOT_CREATED;
|
| 123 |
}
|
82 |
}
|
| 124 |
|
83 |
|
| - |
|
84 |
paymentId = cps.getPaymentId();
|
| - |
|
85 |
amount = cps.getAmount();
|
| 125 |
|
86 |
|
| 126 |
try {
|
87 |
try {
|
| 127 |
initializePayment(paymentId,amount);
|
88 |
initializePayment(paymentId, amount);
|
| 128 |
} catch (ShoppingCartException e1) {
|
89 |
} catch (ShoppingCartException e1) {
|
| 129 |
//addActionError("We are experiencing some problems. Please try later.");
|
- |
|
| 130 |
log.error("Error while creating hdfc payment.");
|
90 |
log.error("Error while creating hdfc payment.");
|
| 131 |
e1.printStackTrace();
|
91 |
e1.printStackTrace();
|
| 132 |
return false;
|
92 |
return PAYMENT_NOT_CREATED;
|
| 133 |
} catch (TException e1) {
|
93 |
} catch (TException e1) {
|
| 134 |
//addActionError("We are experiencing some problems. Please try later.");
|
- |
|
| 135 |
log.error("Error while creating hdfc payment.");
|
94 |
log.error("Error while creating hdfc payment.");
|
| 136 |
e1.printStackTrace();
|
95 |
e1.printStackTrace();
|
| 137 |
return false;
|
96 |
return PAYMENT_NOT_CREATED;
|
| 138 |
}
|
97 |
}
|
| 139 |
|
98 |
|
| 140 |
List<Attribute> attributes = null;
|
99 |
List<Attribute> attributes = null;
|
| 141 |
try {
|
100 |
try {
|
| 142 |
attributes = getAttributesAndSetUdfs(txnId);
|
101 |
attributes = getAttributesAndSetUdfs(txnId);
|
| 143 |
} catch (TransactionServiceException e1) {
|
102 |
} catch (TransactionServiceException e1) {
|
| 144 |
//addActionError("We are experiencing some problems. Please try later.");
|
- |
|
| 145 |
log.error("Error while setting udfs to payment.");
|
103 |
log.error("Error while setting udfs to payment.");
|
| 146 |
e1.printStackTrace();
|
104 |
e1.printStackTrace();
|
| 147 |
return false;
|
105 |
return PAYMENT_NOT_CREATED;
|
| 148 |
} catch (TException e1) {
|
106 |
} catch (TException e1) {
|
| 149 |
//addActionError("We are experiencing some problems. Please try later.");
|
- |
|
| 150 |
log.error("Error while setting udfs to payment.");
|
107 |
log.error("Error while setting udfs to payment.");
|
| 151 |
e1.printStackTrace();
|
108 |
e1.printStackTrace();
|
| 152 |
return false;
|
109 |
return PAYMENT_NOT_CREATED;
|
| 153 |
}
|
110 |
}
|
| 154 |
|
111 |
|
| - |
|
112 |
PaymentServiceClient paymentServiceClient = null;
|
| - |
|
113 |
try {
|
| - |
|
114 |
paymentServiceClient = new PaymentServiceClient();
|
| - |
|
115 |
} catch (Exception e) {
|
| - |
|
116 |
log.error("Error while getting payment client");
|
| - |
|
117 |
e.printStackTrace();
|
| - |
|
118 |
return PAYMENT_NOT_CREATED;
|
| - |
|
119 |
}
|
| 155 |
|
120 |
|
| 156 |
try {
|
121 |
try {
|
| 157 |
if(pipe.performPaymentInitialization() != e24PaymentPipe.SUCCESS)
|
122 |
if(pipe.performPaymentInitialization() != e24PaymentPipe.SUCCESS) {
|
| 158 |
{
|
- |
|
| 159 |
System.out.println("Error sending Payment Initialization Request: ");
|
123 |
log.error("Error sending Payment Initialization Request: ");
|
| 160 |
paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, "", "", pipe.getErrorMsg(), "", "", "", "", PaymentStatus.INIT, "", attributes);
|
124 |
paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, "", "", pipe.getErrorMsg(), "", "", "", "", PaymentStatus.INIT, "", attributes);
|
| 161 |
//response.sendRedirect(response.encodeRedirectURL( errorURL + "?ErrorText="+pipe.getErrorMsg()+"&paymentId="+merchantPaymentId));
|
- |
|
| 162 |
redirectURL = errorURL + "?paymentId="+ paymentId + "&ErrorText="+pipe.getErrorMsg();
|
125 |
redirectURL = errorURL + "?paymentId="+ paymentId + "&ErrorText="+pipe.getErrorMsg();
|
| 163 |
//response.setHeader("Location", redirectURL);
|
- |
|
| 164 |
//response.setStatus(HttpServletResponse.SC_FOUND);
|
- |
|
| 165 |
}
|
126 |
}
|
| 166 |
else
|
127 |
else {
|
| 167 |
{
|
- |
|
| - |
|
128 |
log.info("Payment Initialization Request processed successfully for payment Id: " + paymentId);
|
| 168 |
String paymentID = pipe.getPaymentId();
|
129 |
String paymentID = pipe.getPaymentId();
|
| 169 |
// Update of payment information
|
- |
|
| 170 |
paymentServiceClient.getClient().updatePaymentDetails(paymentId, paymentID, "", "", "", "", "", "", "", PaymentStatus.INIT, "", attributes);
|
130 |
paymentServiceClient.getClient().updatePaymentDetails(paymentId, paymentID, "", "", "", "", "", "", "", PaymentStatus.INIT, "", attributes);
|
| 171 |
|
131 |
|
| 172 |
String payURL = pipe.getPaymentPage();
|
132 |
String payURL = pipe.getPaymentPage();
|
| 173 |
redirectURL = payURL + "?PaymentID=" + paymentID;
|
133 |
redirectURL = payURL + "?PaymentID=" + paymentID;
|
| 174 |
//response.sendRedirect(response.encodeRedirectURL( redirectURL ));
|
- |
|
| 175 |
|
- |
|
| 176 |
//response.setHeader("Location", redirectURL);
|
- |
|
| 177 |
//response.setStatus(HttpServletResponse.SC_FOUND);
|
- |
|
| 178 |
}
|
134 |
}
|
| 179 |
return true;
|
135 |
return paymentId;
|
| 180 |
} catch (NotEnoughDataException e) {
|
136 |
} catch (NotEnoughDataException e) {
|
| 181 |
log.error("Error while initializing payment." + e.getMessage());
|
137 |
log.error("Error while initializing payment." + e.getMessage());
|
| 182 |
e.printStackTrace();
|
138 |
e.printStackTrace();
|
| 183 |
}catch (Exception e) {
|
139 |
}catch (Exception e) {
|
| 184 |
log.error("Error while initializing payment." + e.getMessage());
|
140 |
log.error("Error while initializing payment." + e.getMessage());
|
| 185 |
e.printStackTrace();
|
141 |
e.printStackTrace();
|
| 186 |
}
|
142 |
}
|
| 187 |
|
143 |
|
| 188 |
redirectURL = errorURL + "?paymentId="+paymentId + "?ErrorText=Error while initializing payment.";
|
144 |
redirectURL = errorURL + "?paymentId="+paymentId + "?ErrorText=Error while initializing payment.";
|
| 189 |
return false;
|
- |
|
| 190 |
}
|
- |
|
| 191 |
|
- |
|
| 192 |
|
- |
|
| 193 |
private double getPaymentAmount(long cartId) throws ShoppingCartException, TException{
|
- |
|
| 194 |
double totalAmount = 0;
|
- |
|
| 195 |
Cart cart;
|
- |
|
| 196 |
UserContextServiceClient userContextServiceClient = null;
|
- |
|
| 197 |
try {
|
- |
|
| 198 |
userContextServiceClient = new UserContextServiceClient();
|
- |
|
| 199 |
} catch (Exception e) {
|
- |
|
| 200 |
e.printStackTrace();
|
- |
|
| 201 |
}
|
- |
|
| 202 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
- |
|
| 203 |
cart = userClient.getCart(cartId);
|
- |
|
| 204 |
|
- |
|
| 205 |
List<Line> lineItems = cart.getLines();
|
- |
|
| 206 |
|
- |
|
| 207 |
for (Line line : lineItems) {
|
- |
|
| 208 |
long productId = line.getItemId();
|
- |
|
| 209 |
totalAmount = totalAmount + line.getQuantity() * Utils.getItemPrice(productId);
|
- |
|
| 210 |
}
|
- |
|
| 211 |
|
- |
|
| 212 |
return totalAmount;
|
145 |
return PAYMENT_NOT_CREATED;
|
| 213 |
}
|
146 |
}
|
| 214 |
|
147 |
|
| 215 |
|
- |
|
| 216 |
private List<Attribute> getAttributesAndSetUdfs(long txnId) throws TransactionServiceException, TException{
|
148 |
private List<Attribute> getAttributesAndSetUdfs(long txnId) throws TransactionServiceException, TException{
|
| 217 |
StringBuilder orderDetails = new StringBuilder();
|
149 |
StringBuilder orderDetails = new StringBuilder();
|
| 218 |
StringBuilder billingAddress = new StringBuilder();
|
150 |
StringBuilder billingAddress = new StringBuilder();
|
| 219 |
String email = "";
|
151 |
String email = "";
|
| 220 |
String contactNumber = "";
|
152 |
String contactNumber = "";
|
| Line 306... |
Line 238... |
| 306 |
attributes.add(attribute4);
|
238 |
attributes.add(attribute4);
|
| 307 |
attributes.add(attribute5);
|
239 |
attributes.add(attribute5);
|
| 308 |
|
240 |
|
| 309 |
return attributes;
|
241 |
return attributes;
|
| 310 |
}
|
242 |
}
|
| 311 |
|
- |
|
| 312 |
|
- |
|
| 313 |
|
243 |
|
| 314 |
private void initializePayment(long merchantPaymentId, double amounta) throws ShoppingCartException, TException{
|
244 |
private void initializePayment(long merchantPaymentId, double amounta) throws ShoppingCartException, TException{
|
| 315 |
String amount;
|
245 |
String amount;
|
| 316 |
|
246 |
|
| 317 |
amount = (new Double(amounta)).toString();
|
247 |
amount = (new Double(amounta)).toString();
|