| 2391 |
chandransh |
1 |
package in.shop2020.payment.service.handler;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.config.ConfigException;
|
|
|
4 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
5 |
import in.shop2020.model.v1.order.Order;
|
| 6050 |
anupam.sin |
6 |
import in.shop2020.model.v1.order.RechargeOrder;
|
| 2391 |
chandransh |
7 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
8 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 6050 |
anupam.sin |
9 |
import in.shop2020.model.v1.user.Address;
|
| 2391 |
chandransh |
10 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
|
|
11 |
import in.shop2020.payment.domain.Payment;
|
|
|
12 |
import in.shop2020.payments.Attribute;
|
| 3046 |
chandransh |
13 |
import in.shop2020.payments.PaymentException;
|
| 2391 |
chandransh |
14 |
import in.shop2020.payments.PaymentStatus;
|
| 3128 |
rajveer |
15 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 6050 |
anupam.sin |
16 |
import in.shop2020.thrift.clients.UserClient;
|
| 2391 |
chandransh |
17 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
18 |
|
| 4641 |
rajveer |
19 |
import java.io.File;
|
|
|
20 |
import java.io.FileNotFoundException;
|
|
|
21 |
import java.io.FileOutputStream;
|
|
|
22 |
import java.io.IOException;
|
|
|
23 |
import java.io.InputStream;
|
|
|
24 |
import java.io.OutputStream;
|
| 2391 |
chandransh |
25 |
import java.util.ArrayList;
|
|
|
26 |
import java.util.HashMap;
|
|
|
27 |
import java.util.List;
|
|
|
28 |
import java.util.Map;
|
|
|
29 |
import java.util.Random;
|
|
|
30 |
|
|
|
31 |
import org.apache.log4j.Logger;
|
|
|
32 |
import org.apache.thrift.TException;
|
|
|
33 |
|
|
|
34 |
import com.aciworldwide.commerce.gateway.plugins.NotEnoughDataException;
|
|
|
35 |
import com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe;
|
|
|
36 |
import com.aciworldwide.commerce.gateway.plugins.e24TranPipe;
|
|
|
37 |
|
| 3010 |
chandransh |
38 |
public class HdfcPaymentHandler implements IPaymentHandler {
|
| 4421 |
mandeep.dh |
39 |
private static final int CAPTURE_STATUS_FOR_CONNECTION_ISSUE = -1;
|
|
|
40 |
|
|
|
41 |
private static Logger log = Logger.getLogger(HdfcPaymentHandler.class);
|
| 2391 |
chandransh |
42 |
|
|
|
43 |
private static String aliasName;
|
|
|
44 |
private static String responseURL;
|
|
|
45 |
private static String errorURL;
|
|
|
46 |
private static final String regex = "[^a-zA-Z0-9\\s\\-\\@\\/\\.]";
|
|
|
47 |
private static final String replacement = " ";
|
|
|
48 |
private static final int MAX_UDF_LENGTH = 30;
|
|
|
49 |
private static final String currencyCode = "356";
|
| 4643 |
rajveer |
50 |
private static String resourceDirPath = "/tmp/resource/";
|
| 6050 |
anupam.sin |
51 |
|
|
|
52 |
private static String responseURLforRecharge;
|
|
|
53 |
|
|
|
54 |
private static String errorURLforRecharge;
|
| 4641 |
rajveer |
55 |
private static final String resourceFileName = "resource.cgn";
|
| 2391 |
chandransh |
56 |
|
|
|
57 |
private enum ActionType{
|
|
|
58 |
PURCHASE("1"),
|
| 6482 |
rajveer |
59 |
REFUND("2"),
|
| 2391 |
chandransh |
60 |
AUTH ("4"),
|
|
|
61 |
CAPTURE("5");
|
|
|
62 |
private String value;
|
|
|
63 |
ActionType(String value) {
|
|
|
64 |
this.value = value;
|
|
|
65 |
}
|
|
|
66 |
public String value(){
|
|
|
67 |
return this.value;
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public HdfcPaymentHandler() {
|
|
|
72 |
// TODO Auto-generated constructor stub
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
static{
|
|
|
76 |
try {
|
| 4641 |
rajveer |
77 |
InputStream inputStream = Class.class.getResourceAsStream(ConfigClient.getClient().get("payment_resource_file_path") + resourceFileName);
|
|
|
78 |
File resourceDir = new File(resourceDirPath);
|
|
|
79 |
if(!resourceDir.exists()){
|
|
|
80 |
resourceDir.mkdir();
|
|
|
81 |
}
|
|
|
82 |
|
| 4643 |
rajveer |
83 |
OutputStream outStream = new FileOutputStream(resourceDirPath + resourceFileName);
|
| 4641 |
rajveer |
84 |
byte buf[]=new byte[1024];
|
|
|
85 |
int len;
|
|
|
86 |
while((len=inputStream.read(buf))>0)
|
|
|
87 |
outStream.write(buf,0,len);
|
|
|
88 |
outStream.close();
|
|
|
89 |
inputStream.close();
|
|
|
90 |
|
| 4617 |
rajveer |
91 |
aliasName = ConfigClient.getClient().get("payment_alias_name");
|
| 2391 |
chandransh |
92 |
responseURL = ConfigClient.getClient().get("payment_response_url");
|
|
|
93 |
errorURL = ConfigClient.getClient().get("payment_error_url");
|
| 6050 |
anupam.sin |
94 |
responseURLforRecharge = ConfigClient.getClient().get("payment_response_url_for_recharge");
|
|
|
95 |
errorURLforRecharge = ConfigClient.getClient().get("recharge_success_url");
|
| 2391 |
chandransh |
96 |
} catch (ConfigException e) {
|
|
|
97 |
log.error("Unable to get data from config server.");
|
| 4641 |
rajveer |
98 |
} catch (FileNotFoundException e) {
|
|
|
99 |
// TODO Auto-generated catch block
|
|
|
100 |
e.printStackTrace();
|
|
|
101 |
} catch (IOException e) {
|
|
|
102 |
// TODO Auto-generated catch block
|
|
|
103 |
e.printStackTrace();
|
| 2391 |
chandransh |
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
public static Map<String, String> capturePayment(Payment payment){
|
|
|
108 |
String amount = "" + payment.getAmount();
|
|
|
109 |
String gatewayPaymentId = payment.getGatewayPaymentId();
|
|
|
110 |
log.info("Capturing amount: Rs " + amount + " for payment Id: " + gatewayPaymentId);
|
|
|
111 |
|
|
|
112 |
//Prepare resultMap to elicit failure behaviour in case anything goes wrong.
|
|
|
113 |
Map<String, String> resultMap = new HashMap<String, String>();
|
| 4421 |
mandeep.dh |
114 |
resultMap.put(STATUS, Errors.CAPTURE_FAILURE.code);
|
|
|
115 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
|
|
116 |
resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
|
| 2391 |
chandransh |
117 |
|
|
|
118 |
e24TranPipe pipe = new e24TranPipe();
|
| 4641 |
rajveer |
119 |
pipe.setResourcePath(resourceDirPath);
|
| 2391 |
chandransh |
120 |
pipe.setAlias(aliasName);
|
|
|
121 |
pipe.setAction(ActionType.CAPTURE.value());
|
|
|
122 |
pipe.setAmt(amount);
|
|
|
123 |
pipe.setTrackId("" + payment.getId());
|
|
|
124 |
pipe.setMember("SAHOLIC");
|
|
|
125 |
pipe.setCurrencyCode(currencyCode);
|
|
|
126 |
pipe.setTransId(payment.getGatewayTxnId());
|
|
|
127 |
|
|
|
128 |
//Check if the values have been set properly
|
|
|
129 |
log.info("Pipe Amount: " + pipe.getAmt());
|
|
|
130 |
log.info("Pipe Action Code: " + pipe.getAction());
|
|
|
131 |
log.info("Pipe Currency Code: " + pipe.getCurrencyCode());
|
|
|
132 |
log.info("Pipe Track Id: " + pipe.getTrackId());
|
|
|
133 |
log.info("Pipe Trans Id:" + pipe.getTransId());
|
|
|
134 |
|
|
|
135 |
int captureStatus = e24TranPipe.FAILURE;
|
|
|
136 |
try {
|
|
|
137 |
captureStatus = pipe.performTransaction();
|
|
|
138 |
|
|
|
139 |
log.info("Capture Status: " + captureStatus);
|
|
|
140 |
log.info("Gateway Txn Status: " + pipe.getResult());
|
|
|
141 |
log.info("Debug Msg: " + pipe.getDebugMsg());
|
|
|
142 |
log.info("Auth: " + pipe.getAuth());
|
|
|
143 |
log.info("Ref: " + pipe.getRef());
|
|
|
144 |
log.info("TransId:" + pipe.getTransId());
|
|
|
145 |
log.info("Amount: " + pipe.getAmt());
|
|
|
146 |
|
|
|
147 |
resultMap.put(STATUS, "" + captureStatus);
|
|
|
148 |
String result = pipe.getResult();
|
|
|
149 |
resultMap.put(GATEWAY_STATUS, result.substring(0, Math.min(result.length(), 20)).trim()); //This will return the result of the transaction. (Successful or Failed)
|
|
|
150 |
if(captureStatus != e24TranPipe.SUCCESS || !"CAPTURED".equals(result)){
|
|
|
151 |
resultMap.put(ERROR, pipe.getErrorMsg()); // In case of any error, we only need to get the error message
|
| 4421 |
mandeep.dh |
152 |
|
|
|
153 |
if (captureStatus == CAPTURE_STATUS_FOR_CONNECTION_ISSUE) {
|
|
|
154 |
resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
else {
|
| 2391 |
chandransh |
158 |
resultMap.put(CAPTURE_AUTH_ID, pipe.getAuth()); // Unique ID generated by Authorizer of the transaction
|
|
|
159 |
resultMap.put(CAPTURE_REF_ID, pipe.getRef()); // Unique reference number generated during the transaction
|
|
|
160 |
resultMap.put(CAPTURE_TXN_ID, pipe.getTransId()); // Unique Transaction ID generated after every successful transaction
|
|
|
161 |
resultMap.put(CAPTURE_AMNT, pipe.getAmt()); // Original Amount of the transaction
|
|
|
162 |
}
|
|
|
163 |
} catch (NotEnoughDataException e) {
|
| 4421 |
mandeep.dh |
164 |
log.error(Errors.CAPTURE_FAILURE.message, e);
|
|
|
165 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
|
|
166 |
resultMap.put(ERROR, e.getMessage());
|
| 2391 |
chandransh |
167 |
}
|
|
|
168 |
|
|
|
169 |
return resultMap;
|
|
|
170 |
}
|
|
|
171 |
|
| 6482 |
rajveer |
172 |
public static Map<String, String> refundPayment(Payment payment, double amount){
|
| 6489 |
rajveer |
173 |
String ramount = "" + amount;
|
| 6482 |
rajveer |
174 |
String gatewayPaymentId = payment.getGatewayPaymentId();
|
|
|
175 |
log.info("Refunding amount: Rs " + amount + " for payment Id: " + gatewayPaymentId);
|
|
|
176 |
|
|
|
177 |
//Prepare resultMap to elicit failure behaviour in case anything goes wrong.
|
|
|
178 |
Map<String, String> resultMap = new HashMap<String, String>();
|
|
|
179 |
resultMap.put(STATUS, Errors.CAPTURE_FAILURE.code);
|
|
|
180 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
|
|
181 |
resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
|
|
|
182 |
|
|
|
183 |
e24TranPipe pipe = new e24TranPipe();
|
|
|
184 |
pipe.setResourcePath(resourceDirPath);
|
|
|
185 |
pipe.setAlias(aliasName);
|
|
|
186 |
pipe.setAction(ActionType.REFUND.value());
|
|
|
187 |
pipe.setAmt(ramount);
|
|
|
188 |
pipe.setTrackId("" + payment.getId());
|
|
|
189 |
pipe.setMember("SAHOLIC");
|
|
|
190 |
pipe.setCurrencyCode(currencyCode);
|
|
|
191 |
pipe.setTransId(payment.getGatewayTxnId());
|
|
|
192 |
|
|
|
193 |
//Check if the values have been set properly
|
|
|
194 |
log.info("Pipe Amount: " + pipe.getAmt());
|
|
|
195 |
log.info("Pipe Action Code: " + pipe.getAction());
|
|
|
196 |
log.info("Pipe Currency Code: " + pipe.getCurrencyCode());
|
|
|
197 |
log.info("Pipe Track Id: " + pipe.getTrackId());
|
|
|
198 |
log.info("Pipe Trans Id:" + pipe.getTransId());
|
|
|
199 |
|
|
|
200 |
int refundStatus = e24TranPipe.FAILURE;
|
|
|
201 |
try {
|
|
|
202 |
refundStatus = pipe.performTransaction();
|
|
|
203 |
|
|
|
204 |
log.info("Refund Status: " + refundStatus);
|
|
|
205 |
log.info("Gateway Txn Status: " + pipe.getResult());
|
|
|
206 |
log.info("Debug Msg: " + pipe.getDebugMsg());
|
|
|
207 |
log.info("Auth: " + pipe.getAuth());
|
|
|
208 |
log.info("Ref: " + pipe.getRef());
|
|
|
209 |
log.info("TransId:" + pipe.getTransId());
|
|
|
210 |
log.info("Amount: " + pipe.getAmt());
|
|
|
211 |
|
|
|
212 |
resultMap.put(STATUS, "" + refundStatus);
|
|
|
213 |
String result = pipe.getResult();
|
|
|
214 |
log.info("Result: " + pipe.getResult());
|
|
|
215 |
resultMap.put(GATEWAY_STATUS, result.substring(0, Math.min(result.length(), 20)).trim()); //This will return the result of the transaction. (Successful or Failed)
|
|
|
216 |
if(refundStatus != e24TranPipe.SUCCESS){
|
|
|
217 |
resultMap.put(ERROR, pipe.getErrorMsg()); // In case of any error, we only need to get the error message
|
|
|
218 |
|
|
|
219 |
if (refundStatus == CAPTURE_STATUS_FOR_CONNECTION_ISSUE) {
|
|
|
220 |
resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
|
|
|
221 |
}
|
|
|
222 |
}
|
|
|
223 |
else {
|
|
|
224 |
resultMap.put(CAPTURE_AUTH_ID, pipe.getAuth()); // Unique ID generated by Authorizer of the transaction
|
|
|
225 |
resultMap.put(CAPTURE_REF_ID, pipe.getRef()); // Unique reference number generated during the transaction
|
|
|
226 |
resultMap.put(CAPTURE_TXN_ID, pipe.getTransId()); // Unique Transaction ID generated after every successful transaction
|
|
|
227 |
resultMap.put(CAPTURE_AMNT, pipe.getAmt()); // Original Amount of the transaction
|
|
|
228 |
}
|
|
|
229 |
} catch (NotEnoughDataException e) {
|
|
|
230 |
log.error(Errors.CAPTURE_FAILURE.message, e);
|
|
|
231 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
|
|
232 |
resultMap.put(ERROR, e.getMessage());
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
return resultMap;
|
|
|
236 |
}
|
|
|
237 |
|
| 2391 |
chandransh |
238 |
public static String initializeHdfcPayment(Payment payment, PaymentServiceHandler handler) throws Exception{
|
|
|
239 |
long merchantPaymentId = payment.getId();
|
|
|
240 |
double amount = payment.getAmount();
|
|
|
241 |
e24PaymentPipe pipe = new e24PaymentPipe();
|
|
|
242 |
|
|
|
243 |
try {
|
| 6050 |
anupam.sin |
244 |
initializePayment(pipe, merchantPaymentId, amount, false);
|
| 2391 |
chandransh |
245 |
} catch (ShoppingCartException e1) {
|
|
|
246 |
log.error("Error while creating hdfc payment.", e1);
|
|
|
247 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
|
|
248 |
} catch (TException e1) {
|
|
|
249 |
log.error("Error while creating hdfc payment.", e1);
|
|
|
250 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
List<Attribute> attributes = null;
|
|
|
254 |
try {
|
|
|
255 |
attributes = getAttributesAndSetUdfs(pipe, payment.getMerchantTxnId());
|
|
|
256 |
} catch (TransactionServiceException e1) {
|
|
|
257 |
log.error("Error while setting udfs to payment.", e1);
|
|
|
258 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
|
|
259 |
} catch (TException e1) {
|
|
|
260 |
log.error("Error while setting udfs to payment.", e1);
|
|
|
261 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
try {
|
|
|
265 |
if(pipe.performPaymentInitialization() != e24PaymentPipe.SUCCESS) {
|
|
|
266 |
log.error("Error sending Payment Initialization Request: ");
|
|
|
267 |
handler.updatePaymentDetails(merchantPaymentId, null, "", "", pipe.getErrorMsg(), "", "", "", "", PaymentStatus.INIT, "", attributes);
|
|
|
268 |
} else {
|
|
|
269 |
log.info("Payment Initialization Request processed successfully for payment Id: " + merchantPaymentId);
|
|
|
270 |
String paymentID = pipe.getPaymentId();
|
|
|
271 |
handler.updatePaymentDetails(merchantPaymentId, paymentID, "", "", "", "", "", "", "", PaymentStatus.INIT, "", attributes);
|
|
|
272 |
|
|
|
273 |
String payURL = pipe.getPaymentPage();
|
| 3046 |
chandransh |
274 |
return payURL + "?PaymentID=" + paymentID;
|
| 2391 |
chandransh |
275 |
}
|
|
|
276 |
} catch (NotEnoughDataException e) {
|
|
|
277 |
log.error("Error while initializing payment.", e);
|
|
|
278 |
}catch (Exception e) {
|
|
|
279 |
log.error("Error while initializing payment.", e);
|
|
|
280 |
}
|
| 3046 |
chandransh |
281 |
//If the code reaches here, the payment initialization was not successful and we've not returned the redirect URL.
|
|
|
282 |
//Throw the exception so that any failovers can happen.
|
|
|
283 |
throw new PaymentException(115, "Unable to initialize HDFC payment");
|
| 2391 |
chandransh |
284 |
}
|
|
|
285 |
|
|
|
286 |
private static List<Attribute> getAttributesAndSetUdfs(e24PaymentPipe pipe, long txnId) throws TransactionServiceException, TException{
|
|
|
287 |
StringBuilder orderDetails = new StringBuilder();
|
|
|
288 |
StringBuilder billingAddress = new StringBuilder();
|
|
|
289 |
String email = "";
|
|
|
290 |
String contactNumber = "";
|
|
|
291 |
|
|
|
292 |
//get udfs
|
|
|
293 |
Transaction transaction;
|
| 3128 |
rajveer |
294 |
TransactionClient transactionServiceClient = null;
|
| 2391 |
chandransh |
295 |
try {
|
| 3128 |
rajveer |
296 |
transactionServiceClient = new TransactionClient();
|
| 2391 |
chandransh |
297 |
} catch (Exception e) {
|
|
|
298 |
log.error("Unable to get transaction details", e);
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
|
|
|
302 |
transaction = txnClient.getTransaction(txnId);
|
|
|
303 |
orderDetails.append(transaction.getOrdersSize() + " ");
|
|
|
304 |
for (Order order : transaction.getOrders()) {
|
|
|
305 |
contactNumber= order.getCustomer_mobilenumber();
|
|
|
306 |
email = order.getCustomer_email();
|
|
|
307 |
billingAddress.append(" ");
|
|
|
308 |
if(order.getCustomer_pincode()!=null){
|
|
|
309 |
billingAddress.append(order.getCustomer_pincode());
|
|
|
310 |
}
|
|
|
311 |
if(order.getCustomer_city()!=null){
|
|
|
312 |
billingAddress.append(" " + order.getCustomer_city());
|
|
|
313 |
}
|
|
|
314 |
if(order.getCustomer_address1()!=null){
|
|
|
315 |
billingAddress.append(" " + order.getCustomer_address1());
|
|
|
316 |
}
|
|
|
317 |
if(order.getCustomer_address2()!=null){
|
|
|
318 |
billingAddress.append(" " + order.getCustomer_address2());
|
|
|
319 |
}
|
|
|
320 |
if(order.getCustomer_state()!=null){
|
|
|
321 |
billingAddress.append(" " + order.getCustomer_state());
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
for(LineItem line: order.getLineitems()){
|
|
|
326 |
if(line.getBrand() != null){
|
|
|
327 |
orderDetails.append(line.getBrand());
|
|
|
328 |
}
|
|
|
329 |
if(line.getModel_name() != null){
|
|
|
330 |
orderDetails.append(line.getModel_name());
|
|
|
331 |
}
|
|
|
332 |
if(line.getModel_number() != null){
|
|
|
333 |
orderDetails.append(line.getModel_number());
|
|
|
334 |
}
|
|
|
335 |
if(line.getColor() != null){
|
|
|
336 |
orderDetails.append(line.getColor());
|
|
|
337 |
}
|
|
|
338 |
orderDetails.append(" ");
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
Random random = new Random();
|
|
|
344 |
String merchantInfo = ""+random.nextLong();
|
|
|
345 |
|
|
|
346 |
String udf1 = formatUdf(orderDetails.toString());
|
|
|
347 |
String udf2 = formatUdf(email);
|
|
|
348 |
String udf3 = formatUdf(contactNumber);
|
|
|
349 |
String udf4 = formatUdf(billingAddress.toString());
|
|
|
350 |
String udf5 = merchantInfo;
|
|
|
351 |
|
|
|
352 |
log.info("udf1:" + udf1);
|
|
|
353 |
log.info("udf2:" + udf2);
|
|
|
354 |
log.info("udf3:" + udf3);
|
|
|
355 |
log.info("udf4:" + udf4);
|
|
|
356 |
log.info("udf5:" + udf5);
|
|
|
357 |
|
|
|
358 |
|
|
|
359 |
pipe.setUdf1(udf1); // UDF 1 - Order details
|
|
|
360 |
pipe.setUdf2(udf2); // UDF 2 - Email ID
|
|
|
361 |
pipe.setUdf3(udf3); // UDF 3 - Contact Number.
|
|
|
362 |
pipe.setUdf4(udf4); // UDF 4 - Billing Address
|
|
|
363 |
pipe.setUdf5(udf5); // UDF 5 - Merchant specific
|
|
|
364 |
|
|
|
365 |
List<Attribute> attributes = new ArrayList<Attribute>();
|
|
|
366 |
Attribute attribute1 = new Attribute("udf1",udf1);
|
|
|
367 |
Attribute attribute2 = new Attribute("udf2",udf2);
|
|
|
368 |
Attribute attribute3 = new Attribute("udf3",udf3);
|
|
|
369 |
Attribute attribute4 = new Attribute("udf4",udf4);
|
|
|
370 |
Attribute attribute5 = new Attribute("udf5",udf5);
|
|
|
371 |
|
|
|
372 |
attributes.add(attribute1);
|
|
|
373 |
attributes.add(attribute2);
|
|
|
374 |
attributes.add(attribute3);
|
|
|
375 |
attributes.add(attribute4);
|
|
|
376 |
attributes.add(attribute5);
|
|
|
377 |
|
|
|
378 |
return attributes;
|
|
|
379 |
}
|
|
|
380 |
|
| 6050 |
anupam.sin |
381 |
private static void initializePayment(e24PaymentPipe pipe, long merchantPaymentId, double amounta, boolean isDigital) throws ShoppingCartException, TException{
|
| 2391 |
chandransh |
382 |
String amount = (new Double(amounta)).toString();
|
|
|
383 |
|
|
|
384 |
//Following is the code which initilize e24PaymentPipe with proper value
|
| 4641 |
rajveer |
385 |
pipe.setResourcePath(resourceDirPath); //mandatory
|
| 2391 |
chandransh |
386 |
String as = pipe.getResourcePath();
|
|
|
387 |
log.info("Resource= " +as);
|
|
|
388 |
|
|
|
389 |
pipe.setAlias(aliasName); //mandatory
|
|
|
390 |
String ab=pipe.getAlias();
|
|
|
391 |
log.info("Alias= " +ab);
|
|
|
392 |
|
| 6091 |
anupam.sin |
393 |
|
| 2391 |
chandransh |
394 |
String ac=pipe.getAction();
|
|
|
395 |
log.info("Action= " +ac);
|
| 6050 |
anupam.sin |
396 |
|
|
|
397 |
if(isDigital) {
|
| 6091 |
anupam.sin |
398 |
pipe.setAction(ActionType.PURCHASE.value()); //mandatory
|
| 6050 |
anupam.sin |
399 |
pipe.setResponseURL( responseURLforRecharge ); //mandatory
|
|
|
400 |
pipe.setErrorURL( errorURLforRecharge); //mandatory
|
|
|
401 |
} else {
|
| 6091 |
anupam.sin |
402 |
pipe.setAction(ActionType.AUTH.value()); //mandatory
|
| 6050 |
anupam.sin |
403 |
pipe.setResponseURL( responseURL );
|
|
|
404 |
pipe.setErrorURL( errorURL);
|
|
|
405 |
}
|
| 2391 |
chandransh |
406 |
String at=pipe.getResponseURL();
|
|
|
407 |
log.info("ResponseURL= "+at);
|
|
|
408 |
|
|
|
409 |
//pipe.setErrorURL( errorURL + "?paymentId=" + merchantPaymentId ); //mandatory
|
|
|
410 |
String ak=pipe.getErrorURL();
|
|
|
411 |
log.info("ErrorURL= " + ak);
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
pipe.setAmt(amount);
|
|
|
415 |
String ap=pipe.getAmt();
|
|
|
416 |
log.info("Amt= " + ap);
|
|
|
417 |
|
| 2761 |
chandransh |
418 |
pipe.setCurrency(currencyCode);
|
| 2391 |
chandransh |
419 |
String a=pipe.getCurrency();
|
|
|
420 |
log.info("Currency= " + a);
|
|
|
421 |
|
|
|
422 |
pipe.setLanguage("USA");
|
|
|
423 |
String p=pipe.getLanguage();
|
|
|
424 |
log.info("Language= "+ p);
|
|
|
425 |
|
|
|
426 |
pipe.setTrackId((new Long(merchantPaymentId)).toString());
|
|
|
427 |
}
|
|
|
428 |
|
|
|
429 |
private static String formatUdf(String udfString){
|
|
|
430 |
udfString = udfString.replaceAll(regex, replacement);
|
|
|
431 |
if(udfString.length() > MAX_UDF_LENGTH){
|
|
|
432 |
udfString = udfString.substring(0, MAX_UDF_LENGTH);
|
|
|
433 |
}
|
|
|
434 |
return udfString;
|
|
|
435 |
}
|
| 6050 |
anupam.sin |
436 |
|
|
|
437 |
public static String initializeHdfcPayment(in.shop2020.payment.domain.Payment payment, RechargeOrder rechargeOrder,
|
| 6228 |
anupam.sin |
438 |
String phone, PaymentServiceHandler paymentServiceHandler) throws Exception {
|
| 6233 |
anupam.sin |
439 |
Long merchantPaymentId = payment.getId();
|
| 6050 |
anupam.sin |
440 |
double amount = payment.getAmount();
|
|
|
441 |
e24PaymentPipe pipe = new e24PaymentPipe();
|
|
|
442 |
|
|
|
443 |
try {
|
|
|
444 |
initializePayment(pipe, merchantPaymentId, amount, true);
|
|
|
445 |
} catch (ShoppingCartException e1) {
|
|
|
446 |
log.error("Error while creating hdfc payment.", e1);
|
|
|
447 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
|
|
448 |
} catch (TException e1) {
|
|
|
449 |
log.error("Error while creating hdfc payment.", e1);
|
|
|
450 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
|
|
451 |
}
|
|
|
452 |
|
|
|
453 |
List<Attribute> attributes = null;
|
|
|
454 |
try {
|
| 6233 |
anupam.sin |
455 |
attributes = getAttributesAndSetUdfs(pipe, rechargeOrder, merchantPaymentId.toString(), phone);
|
| 6050 |
anupam.sin |
456 |
} catch (TransactionServiceException e1) {
|
|
|
457 |
log.error("Error while setting udfs to payment.", e1);
|
|
|
458 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
|
|
459 |
} catch (TException e1) {
|
|
|
460 |
log.error("Error while setting udfs to payment.", e1);
|
|
|
461 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
try {
|
|
|
465 |
if(pipe.performPaymentInitialization() != e24PaymentPipe.SUCCESS) {
|
|
|
466 |
log.error("Error sending Payment Initialization Request: ");
|
|
|
467 |
paymentServiceHandler.updatePaymentDetails(merchantPaymentId, null, "", "", pipe.getErrorMsg(), "", "", "", "", PaymentStatus.INIT, "", attributes);
|
|
|
468 |
} else {
|
|
|
469 |
log.info("Payment Initialization Request processed successfully for payment Id: " + merchantPaymentId);
|
|
|
470 |
String paymentID = pipe.getPaymentId();
|
|
|
471 |
paymentServiceHandler.updatePaymentDetails(merchantPaymentId, paymentID, "", "", "", "", "", "", "", PaymentStatus.INIT, "", attributes);
|
|
|
472 |
|
|
|
473 |
String payURL = pipe.getPaymentPage();
|
|
|
474 |
return payURL + "?PaymentID=" + paymentID;
|
|
|
475 |
}
|
|
|
476 |
} catch (NotEnoughDataException e) {
|
|
|
477 |
log.error("Error while initializing payment.", e);
|
|
|
478 |
}catch (Exception e) {
|
|
|
479 |
log.error("Error while initializing payment.", e);
|
|
|
480 |
}
|
|
|
481 |
//If the code reaches here, the payment initialization was not successful and we've not returned the redirect URL.
|
|
|
482 |
//Throw the exception so that any failovers can happen.
|
|
|
483 |
throw new PaymentException(115, "Unable to initialize HDFC payment");
|
|
|
484 |
}
|
|
|
485 |
|
| 6233 |
anupam.sin |
486 |
private static List<Attribute> getAttributesAndSetUdfs(e24PaymentPipe pipe, RechargeOrder rechargeOrder, String merchantPaymentId, String phone) throws TransactionServiceException, TException {
|
| 6228 |
anupam.sin |
487 |
|
| 6050 |
anupam.sin |
488 |
StringBuilder orderDetails = new StringBuilder();
|
|
|
489 |
StringBuilder billingAddress = new StringBuilder();
|
|
|
490 |
String email = "";
|
|
|
491 |
String contactNumber = "";
|
| 6228 |
anupam.sin |
492 |
Address address = null;
|
| 6050 |
anupam.sin |
493 |
//get udfs
|
| 6233 |
anupam.sin |
494 |
if (!(phone == null) && !(phone.isEmpty())) {
|
| 6228 |
anupam.sin |
495 |
//Remember in RechargePaymentController we kept phone set only for a specific case.
|
| 6233 |
anupam.sin |
496 |
//This is the case where we don't need to get the address and can safely set the phone number only.
|
| 6228 |
anupam.sin |
497 |
|
|
|
498 |
contactNumber = phone;
|
|
|
499 |
email = rechargeOrder.getUserEmailId();
|
|
|
500 |
billingAddress.append(" ");
|
|
|
501 |
billingAddress.append("110001");
|
|
|
502 |
billingAddress.append(" " + "Delhi");//city
|
| 6233 |
anupam.sin |
503 |
billingAddress.append(" " + merchantPaymentId);//line1
|
|
|
504 |
billingAddress.append(" " + merchantPaymentId);//line2
|
|
|
505 |
billingAddress.append(" " + merchantPaymentId);//state
|
| 6228 |
anupam.sin |
506 |
} else {
|
|
|
507 |
try {
|
|
|
508 |
UserClient userClient = new UserClient();
|
|
|
509 |
address = userClient.getClient().getAddressById(userClient.getClient().getDefaultAddressId(rechargeOrder.getUserId()));
|
|
|
510 |
} catch (Exception e) {
|
|
|
511 |
log.error("Unable to get transaction details", e);
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
|
|
|
515 |
contactNumber= address.getPhone();
|
|
|
516 |
email = rechargeOrder.getUserEmailId();
|
|
|
517 |
billingAddress.append(" ");
|
|
|
518 |
if(address.getPin()!=null){
|
|
|
519 |
billingAddress.append(address.getPin());
|
|
|
520 |
}
|
|
|
521 |
if(address.getCity()!=null){
|
|
|
522 |
billingAddress.append(" " + address.getCity());
|
|
|
523 |
}
|
|
|
524 |
if(address.getLine1()!=null){
|
|
|
525 |
billingAddress.append(" " + address.getLine1());
|
|
|
526 |
}
|
|
|
527 |
if(address.getLine2()!=null){
|
|
|
528 |
billingAddress.append(" " + address.getLine2());
|
|
|
529 |
}
|
|
|
530 |
if(address.getState()!=null){
|
|
|
531 |
billingAddress.append(" " + address.getState());
|
|
|
532 |
}
|
|
|
533 |
|
| 6050 |
anupam.sin |
534 |
}
|
|
|
535 |
orderDetails.append("Recharge : " + rechargeOrder.getDisplayId());
|
|
|
536 |
orderDetails.append(" ");
|
|
|
537 |
|
|
|
538 |
Random random = new Random();
|
|
|
539 |
String merchantInfo = ""+random.nextLong();
|
|
|
540 |
|
|
|
541 |
String udf1 = formatUdf(orderDetails.toString());
|
|
|
542 |
String udf2 = formatUdf(email);
|
|
|
543 |
String udf3 = formatUdf(contactNumber);
|
|
|
544 |
String udf4 = formatUdf(billingAddress.toString());
|
|
|
545 |
String udf5 = merchantInfo;
|
|
|
546 |
|
|
|
547 |
log.info("udf1:" + udf1);
|
|
|
548 |
log.info("udf2:" + udf2);
|
|
|
549 |
log.info("udf3:" + udf3);
|
|
|
550 |
log.info("udf4:" + udf4);
|
|
|
551 |
log.info("udf5:" + udf5);
|
|
|
552 |
|
|
|
553 |
|
|
|
554 |
pipe.setUdf1(udf1); // UDF 1 - Order details
|
|
|
555 |
pipe.setUdf2(udf2); // UDF 2 - Email ID
|
|
|
556 |
pipe.setUdf3(udf3); // UDF 3 - Contact Number.
|
|
|
557 |
pipe.setUdf4(udf4); // UDF 4 - Billing Address
|
|
|
558 |
pipe.setUdf5(udf5); // UDF 5 - Merchant specific
|
|
|
559 |
|
|
|
560 |
List<Attribute> attributes = new ArrayList<Attribute>();
|
|
|
561 |
Attribute attribute1 = new Attribute("udf1",udf1);
|
|
|
562 |
Attribute attribute2 = new Attribute("udf2",udf2);
|
|
|
563 |
Attribute attribute3 = new Attribute("udf3",udf3);
|
|
|
564 |
Attribute attribute4 = new Attribute("udf4",udf4);
|
|
|
565 |
Attribute attribute5 = new Attribute("udf5",udf5);
|
|
|
566 |
|
|
|
567 |
attributes.add(attribute1);
|
|
|
568 |
attributes.add(attribute2);
|
|
|
569 |
attributes.add(attribute3);
|
|
|
570 |
attributes.add(attribute4);
|
|
|
571 |
attributes.add(attribute5);
|
|
|
572 |
|
|
|
573 |
return attributes;
|
|
|
574 |
}
|
| 2391 |
chandransh |
575 |
}
|