| Line 56... |
Line 56... |
| 56 |
|
56 |
|
| 57 |
public static final long PAYMENT_NOT_CREATED = -1;
|
57 |
public static final long PAYMENT_NOT_CREATED = -1;
|
| 58 |
|
58 |
|
| 59 |
private static final long HDFC_GATEWAY_ID = 1;
|
59 |
private static final long HDFC_GATEWAY_ID = 1;
|
| 60 |
private static final long EBS_GATEWAY_ID = 2;
|
60 |
private static final long EBS_GATEWAY_ID = 2;
|
| - |
|
61 |
private static final long HDFC_EMI_GATEWAY_ID = 5;
|
| 61 |
|
62 |
|
| 62 |
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
|
63 |
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
|
| 63 |
PaymentHandler paymentHandler = (PaymentHandler) context.getBean("paymentHandler");
|
64 |
PaymentHandler paymentHandler = (PaymentHandler) context.getBean("paymentHandler");
|
| 64 |
PaymentGatewayHandler paymentGatewayHandler = (PaymentGatewayHandler) context.getBean("paymentGatewayHandler");
|
65 |
PaymentGatewayHandler paymentGatewayHandler = (PaymentGatewayHandler) context.getBean("paymentGatewayHandler");
|
| 65 |
RefundHandler refundHandler = (RefundHandler) context.getBean("refundHandler");
|
66 |
RefundHandler refundHandler = (RefundHandler) context.getBean("refundHandler");
|
| Line 195... |
Line 196... |
| 195 |
}
|
196 |
}
|
| 196 |
return redirectURL;
|
197 |
return redirectURL;
|
| 197 |
}
|
198 |
}
|
| 198 |
|
199 |
|
| 199 |
@Override
|
200 |
@Override
|
| 200 |
public Map<String, String> captureHdfcPayment(long merchantPaymentId) throws PaymentException, TException {
|
- |
|
| 201 |
logger.info("Capturing HDFC payment with id: " + merchantPaymentId);
|
- |
|
| 202 |
in.shop2020.payment.domain.Payment payment = paymentHandler.getPayment(merchantPaymentId);
|
- |
|
| 203 |
return HdfcPaymentHandler.capturePayment(payment);
|
- |
|
| 204 |
}
|
- |
|
| 205 |
|
- |
|
| 206 |
@Override
|
- |
|
| 207 |
public Map<String, String> captureEbsPayment(long merchantPaymentId) throws PaymentException, TException {
|
- |
|
| 208 |
logger.info("Capturing EBS payment with id: " + merchantPaymentId);
|
- |
|
| 209 |
in.shop2020.payment.domain.Payment payment = paymentHandler.getPayment(merchantPaymentId);
|
- |
|
| 210 |
return EbsPaymentHandler.capturePayment(payment);
|
- |
|
| 211 |
}
|
- |
|
| 212 |
|
- |
|
| 213 |
@Override
|
- |
|
| 214 |
public long createRefund(long orderId, long merchantTxnId, double amount) throws PaymentException, TException{
|
201 |
public long createRefund(long orderId, long merchantTxnId, double amount) throws PaymentException, TException{
|
| 215 |
logger.info("Attempting to create a refund for order: " + orderId);
|
202 |
logger.info("Attempting to create a refund for order: " + orderId);
|
| 216 |
List<in.shop2020.payment.domain.Payment> payments = paymentHandler.getPaymentForTxn(merchantTxnId);
|
203 |
List<in.shop2020.payment.domain.Payment> payments = paymentHandler.getPaymentForTxn(merchantTxnId);
|
| 217 |
if(payments ==null || payments.isEmpty())
|
204 |
if(payments ==null || payments.isEmpty())
|
| 218 |
throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
|
205 |
throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
|
| Line 262... |
Line 249... |
| 262 |
//Capture and update the HDFC payment
|
249 |
//Capture and update the HDFC payment
|
| 263 |
return captureAndUpdateHdfcPayment(payment);
|
250 |
return captureAndUpdateHdfcPayment(payment);
|
| 264 |
} else if (gatewayId == EBS_GATEWAY_ID){
|
251 |
} else if (gatewayId == EBS_GATEWAY_ID){
|
| 265 |
//Capture and update the EBS payment
|
252 |
//Capture and update the EBS payment
|
| 266 |
return captureAndUpdateEbsPayment(payment);
|
253 |
return captureAndUpdateEbsPayment(payment);
|
| - |
|
254 |
} else if (gatewayId == HDFC_EMI_GATEWAY_ID){
|
| - |
|
255 |
//Capture and update the HDFC EMI payment
|
| - |
|
256 |
return captureAndUpdateHdfcEmiPayment(payment);
|
| 267 |
}
|
257 |
}
|
| 268 |
|
258 |
|
| 269 |
logger.error("We have an authorized payment from unknown gateway: " + gatewayId);
|
259 |
logger.error("We have an authorized payment from unknown gateway: " + gatewayId);
|
| 270 |
return false;
|
260 |
return false;
|
| 271 |
}
|
261 |
}
|
| Line 320... |
Line 310... |
| 320 |
return true;
|
310 |
return true;
|
| 321 |
}
|
311 |
}
|
| 322 |
}
|
312 |
}
|
| 323 |
|
313 |
|
| 324 |
/**
|
314 |
/**
|
| - |
|
315 |
* Capture the HDFC EMI payment represented by the given payment object. If
|
| - |
|
316 |
* the capture attempt is not successful, we mark this payment as failed. We
|
| - |
|
317 |
* don't retry or anything. We'll add the support of multiple attempts later
|
| - |
|
318 |
* on.
|
| - |
|
319 |
*
|
| - |
|
320 |
* @param payment
|
| - |
|
321 |
* The payment which has to be captured.
|
| - |
|
322 |
* @return True if the payment attempt is successful, false if not.
|
| - |
|
323 |
*/
|
| - |
|
324 |
private boolean captureAndUpdateHdfcEmiPayment(in.shop2020.payment.domain.Payment payment){
|
| - |
|
325 |
long merchantPaymentId = payment.getId();
|
| - |
|
326 |
logger.info("Capturing HDFC payment with id: " + merchantPaymentId);
|
| - |
|
327 |
Map<String, String> captureResult = HdfcEmiPaymentHandler.capturePayment(payment);
|
| - |
|
328 |
String captureStatus = captureResult.get(IPaymentHandler.STATUS);
|
| - |
|
329 |
String gatewayStatus = captureResult.get(IPaymentHandler.GATEWAY_STATUS);
|
| - |
|
330 |
|
| - |
|
331 |
Map<String, String> attrMap = new HashMap<String, String>();
|
| - |
|
332 |
if (!captureStatus.trim().equals("0")
|
| - |
|
333 |
|| !HdfcPaymentReturnStatus.CAPTURED.value().equals(gatewayStatus)) {
|
| - |
|
334 |
// Failure
|
| - |
|
335 |
logger.info("Capture attempt failed for HDFC payment with id: " + merchantPaymentId);
|
| - |
|
336 |
String description = captureResult.get(IPaymentHandler.ERROR);
|
| - |
|
337 |
String errorCode = captureResult.get(IPaymentHandler.ERR_CODE);
|
| - |
|
338 |
|
| - |
|
339 |
payment.setDescription(description);
|
| - |
|
340 |
payment.setErrorCode(errorCode);
|
| - |
|
341 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
| - |
|
342 |
payment.setErrorTimestamp(new Date());
|
| - |
|
343 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
344 |
createTicketForFailedPayment(payment);
|
| - |
|
345 |
return false;
|
| - |
|
346 |
} else {
|
| - |
|
347 |
// Success
|
| - |
|
348 |
logger.error("Capture attempt successful for HDFC payment with id: " + merchantPaymentId);
|
| - |
|
349 |
payment.setDescription("Payment Captured");
|
| - |
|
350 |
payment.setGatewayTxnStatus(gatewayStatus);
|
| - |
|
351 |
payment.setStatus(PaymentStatus.SUCCESS.getValue());
|
| - |
|
352 |
payment.setSuccessTimestamp(new Date());
|
| - |
|
353 |
|
| - |
|
354 |
attrMap.put(IPaymentHandler.CAPTURE_TXN_ID, captureResult.get(IPaymentHandler.CAPTURE_TXN_ID));
|
| - |
|
355 |
attrMap.put(IPaymentHandler.CAPTURE_REF_ID, captureResult.get(IPaymentHandler.CAPTURE_REF_ID));
|
| - |
|
356 |
attrMap.put(IPaymentHandler.CAPTURE_AUTH_ID, captureResult.get(IPaymentHandler.CAPTURE_AUTH_ID));
|
| - |
|
357 |
|
| - |
|
358 |
SimpleDateFormat captureTimeDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| - |
|
359 |
attrMap.put(HdfcPaymentHandler.CAPTURE_TIME, captureTimeDateFormatter.format(new Date()));
|
| - |
|
360 |
|
| - |
|
361 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
362 |
return true;
|
| - |
|
363 |
}
|
| - |
|
364 |
}
|
| - |
|
365 |
|
| - |
|
366 |
/**
|
| 325 |
* Capture the EBS payment represented by the given payment object. If the
|
367 |
* Capture the EBS payment represented by the given payment object. If the
|
| 326 |
* capture attempt is not successful, we mark this payment as failed. We
|
368 |
* capture attempt is not successful, we mark this payment as failed. We
|
| 327 |
* don't retry or anything. We'll add the support of multiple attempts later
|
369 |
* don't retry or anything. We'll add the support of multiple attempts later
|
| 328 |
* on.
|
370 |
* on.
|
| 329 |
*
|
371 |
*
|