| Line 146... |
Line 146... |
| 146 |
payment.setStatus(status.getValue());
|
146 |
payment.setStatus(status.getValue());
|
| 147 |
if(status.equals(PaymentStatus.SUCCESS))
|
147 |
if(status.equals(PaymentStatus.SUCCESS))
|
| 148 |
payment.setSuccessTimestamp(new Date());
|
148 |
payment.setSuccessTimestamp(new Date());
|
| 149 |
else if(status.equals(PaymentStatus.FAILED)) {
|
149 |
else if(status.equals(PaymentStatus.FAILED)) {
|
| 150 |
payment.setErrorTimestamp(new Date());
|
150 |
payment.setErrorTimestamp(new Date());
|
| 151 |
persistPaymentRequiringExtraProcessing(payment);
|
151 |
persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
| - |
|
152 |
}
|
| - |
|
153 |
else if (status.equals(PaymentStatus.PROVISIONALLY_CAPTURED)) {
|
| - |
|
154 |
// FIXME different column to note provisional capture timestamp
|
| - |
|
155 |
// FIXME Requires extra processing at Crm end for actual manual capture
|
| - |
|
156 |
payment.setProvisionalCaptureTimestamp(new Date());
|
| - |
|
157 |
persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.PENDING_CAPTURE);
|
| 152 |
}
|
158 |
}
|
| 153 |
}
|
159 |
}
|
| 154 |
|
160 |
|
| 155 |
payment.setGatewayTxnDate(gatewayTxnDate);
|
161 |
payment.setGatewayTxnDate(gatewayTxnDate);
|
| 156 |
|
162 |
|
| Line 169... |
Line 175... |
| 169 |
* Persists a given payment Id in another table for future processing by CRM etc.
|
175 |
* Persists a given payment Id in another table for future processing by CRM etc.
|
| 170 |
* Failed payments generally require a follow-up to help customers through our
|
176 |
* Failed payments generally require a follow-up to help customers through our
|
| 171 |
* CRM-Outbound team.
|
177 |
* CRM-Outbound team.
|
| 172 |
*
|
178 |
*
|
| 173 |
* @param payment the payment object that failed.
|
179 |
* @param payment the payment object that failed.
|
| - |
|
180 |
* @param type TODO
|
| 174 |
*/
|
181 |
*/
|
| 175 |
private void persistPaymentRequiringExtraProcessing(in.shop2020.payment.domain.Payment payment) {
|
182 |
private void persistPaymentRequiringExtraProcessing(in.shop2020.payment.domain.Payment payment, ExtraPaymentProcessingType type) {
|
| 176 |
try {
|
183 |
try {
|
| 177 |
paymentRequiringExtraProcessingHandler.insert(payment.getId(), ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
184 |
paymentRequiringExtraProcessingHandler.insert(payment.getId(), type);
|
| 178 |
} catch (Exception e) {
|
185 |
} catch (Exception e) {
|
| 179 |
logger.error("Could not persist payment: " + payment.getId(), e);
|
186 |
logger.error("Could not persist payment: " + payment.getId(), e);
|
| 180 |
}
|
187 |
}
|
| 181 |
}
|
188 |
}
|
| 182 |
|
189 |
|
| Line 250... |
Line 257... |
| 250 |
return false;
|
257 |
return false;
|
| 251 |
case INIT:
|
258 |
case INIT:
|
| 252 |
logger.warn("Attempt to capture a non-authorized payment");
|
259 |
logger.warn("Attempt to capture a non-authorized payment");
|
| 253 |
return false;
|
260 |
return false;
|
| 254 |
case AUTHORIZED:
|
261 |
case AUTHORIZED:
|
| - |
|
262 |
case CAPTURE_IN_PROCESS:
|
| 255 |
//Actual work to be done in this case. Let the call proceed.
|
263 |
//Actual work to be done in this case. Let the call proceed.
|
| 256 |
break;
|
264 |
break;
|
| - |
|
265 |
case PROVISIONALLY_CAPTURED:
|
| - |
|
266 |
logger.info("Attempting to capture a payment that is provisonally captured but we can let the client proceed.");
|
| - |
|
267 |
return true;
|
| 257 |
case SUCCESS:
|
268 |
case SUCCESS:
|
| 258 |
logger.warn("Attempting to capture an already captured payment but we can let the client proceed.");
|
269 |
logger.warn("Attempting to capture an already captured payment but we can let the client proceed.");
|
| 259 |
return true;
|
270 |
return true;
|
| 260 |
case FAILED:
|
271 |
case FAILED:
|
| 261 |
logger.error("Attempting to capture a failed payment");
|
272 |
logger.error("Attempting to capture a failed payment");
|
| Line 317... |
Line 328... |
| 317 |
* don't retry or anything. We'll add the support of multiple attempts later
|
328 |
* don't retry or anything. We'll add the support of multiple attempts later
|
| 318 |
* on.
|
329 |
* on.
|
| 319 |
*
|
330 |
*
|
| 320 |
* @param payment The payment which has to be captured.
|
331 |
* @param payment The payment which has to be captured.
|
| 321 |
* @return True if the payment attempt is successful, false if not.
|
332 |
* @return True if the payment attempt is successful, false if not.
|
| - |
|
333 |
* @throws PaymentException
|
| 322 |
*/
|
334 |
*/
|
| 323 |
private boolean captureAndUpdateHdfcPayment(in.shop2020.payment.domain.Payment payment){
|
335 |
private boolean captureAndUpdateHdfcPayment(in.shop2020.payment.domain.Payment payment) throws PaymentException {
|
| 324 |
long merchantPaymentId = payment.getId();
|
336 |
long merchantPaymentId = payment.getId();
|
| 325 |
logger.info("Capturing HDFC payment with id: " + merchantPaymentId);
|
337 |
logger.info("Capturing HDFC payment with id: " + merchantPaymentId);
|
| 326 |
Map<String, String> captureResult = HdfcPaymentHandler.capturePayment(payment);
|
338 |
Map<String, String> captureResult = HdfcPaymentHandler.capturePayment(payment);
|
| 327 |
String captureStatus = captureResult.get(IPaymentHandler.STATUS);
|
339 |
String captureStatus = captureResult.get(IPaymentHandler.STATUS);
|
| 328 |
String gatewayStatus = captureResult.get(IPaymentHandler.GATEWAY_STATUS);
|
340 |
String gatewayStatus = captureResult.get(IPaymentHandler.GATEWAY_STATUS);
|
| Line 335... |
Line 347... |
| 335 |
String description = captureResult.get(IPaymentHandler.ERROR);
|
347 |
String description = captureResult.get(IPaymentHandler.ERROR);
|
| 336 |
String errorCode = captureResult.get(IPaymentHandler.ERR_CODE);
|
348 |
String errorCode = captureResult.get(IPaymentHandler.ERR_CODE);
|
| 337 |
|
349 |
|
| 338 |
payment.setDescription(description);
|
350 |
payment.setDescription(description);
|
| 339 |
payment.setErrorCode(errorCode);
|
351 |
payment.setErrorCode(errorCode);
|
| 340 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
- |
|
| 341 |
payment.setErrorTimestamp(new Date());
|
352 |
payment.setErrorTimestamp(new Date());
|
| - |
|
353 |
|
| - |
|
354 |
if (IPaymentHandler.Errors.CONN_FAILURE.code.equals(errorCode)) {
|
| - |
|
355 |
payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());
|
| 342 |
paymentHandler.updatePayment(payment, attrMap);
|
356 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
357 |
throw new PaymentException(106, "Could not capture due to connection issue");
|
| - |
|
358 |
}
|
| - |
|
359 |
else {
|
| - |
|
360 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
| - |
|
361 |
paymentHandler.updatePayment(payment, attrMap);
|
| 343 |
persistPaymentRequiringExtraProcessing(payment);
|
362 |
persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
| - |
|
363 |
}
|
| - |
|
364 |
|
| 344 |
return false;
|
365 |
return false;
|
| 345 |
} else {
|
366 |
} else {
|
| 346 |
// Success
|
367 |
// Success
|
| 347 |
logger.info("Capture attempt successful for HDFC payment with id: " + merchantPaymentId);
|
368 |
logger.info("Capture attempt successful for HDFC payment with id: " + merchantPaymentId);
|
| 348 |
payment.setDescription("Payment Captured");
|
369 |
payment.setDescription("Payment Captured");
|
| Line 369... |
Line 390... |
| 369 |
* on.
|
390 |
* on.
|
| 370 |
*
|
391 |
*
|
| 371 |
* @param payment
|
392 |
* @param payment
|
| 372 |
* The payment which has to be captured.
|
393 |
* The payment which has to be captured.
|
| 373 |
* @return True if the payment attempt is successful, false if not.
|
394 |
* @return True if the payment attempt is successful, false if not.
|
| - |
|
395 |
* @throws PaymentException
|
| 374 |
*/
|
396 |
*/
|
| 375 |
private boolean captureAndUpdateHdfcEmiPayment(in.shop2020.payment.domain.Payment payment){
|
397 |
private boolean captureAndUpdateHdfcEmiPayment(in.shop2020.payment.domain.Payment payment) throws PaymentException{
|
| 376 |
long merchantPaymentId = payment.getId();
|
398 |
long merchantPaymentId = payment.getId();
|
| 377 |
logger.info("Capturing HDFC payment with id: " + merchantPaymentId);
|
399 |
logger.info("Capturing HDFC payment with id: " + merchantPaymentId);
|
| 378 |
Map<String, String> captureResult = HdfcEmiPaymentHandler.capturePayment(payment);
|
400 |
Map<String, String> captureResult = HdfcEmiPaymentHandler.capturePayment(payment);
|
| 379 |
String captureStatus = captureResult.get(IPaymentHandler.STATUS);
|
401 |
String captureStatus = captureResult.get(IPaymentHandler.STATUS);
|
| 380 |
String gatewayStatus = captureResult.get(IPaymentHandler.GATEWAY_STATUS);
|
402 |
String gatewayStatus = captureResult.get(IPaymentHandler.GATEWAY_STATUS);
|
| Line 387... |
Line 409... |
| 387 |
String description = captureResult.get(IPaymentHandler.ERROR);
|
409 |
String description = captureResult.get(IPaymentHandler.ERROR);
|
| 388 |
String errorCode = captureResult.get(IPaymentHandler.ERR_CODE);
|
410 |
String errorCode = captureResult.get(IPaymentHandler.ERR_CODE);
|
| 389 |
|
411 |
|
| 390 |
payment.setDescription(description);
|
412 |
payment.setDescription(description);
|
| 391 |
payment.setErrorCode(errorCode);
|
413 |
payment.setErrorCode(errorCode);
|
| - |
|
414 |
payment.setErrorTimestamp(new Date());
|
| - |
|
415 |
|
| - |
|
416 |
// Not marking payments as failed in case of connection issues
|
| - |
|
417 |
if (IPaymentHandler.Errors.CONN_FAILURE.code.equals(errorCode)) {
|
| 392 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
418 |
payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());
|
| - |
|
419 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
420 |
throw new PaymentException(106, "Could not capture due to connection issue");
|
| - |
|
421 |
}
|
| - |
|
422 |
else {
|
| 393 |
payment.setErrorTimestamp(new Date());
|
423 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
| 394 |
paymentHandler.updatePayment(payment, attrMap);
|
424 |
paymentHandler.updatePayment(payment, attrMap);
|
| 395 |
persistPaymentRequiringExtraProcessing(payment);
|
425 |
persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
| - |
|
426 |
}
|
| - |
|
427 |
|
| 396 |
return false;
|
428 |
return false;
|
| 397 |
} else {
|
429 |
} else {
|
| 398 |
// Success
|
430 |
// Success
|
| 399 |
logger.info("Capture attempt successful for HDFC payment with id: " + merchantPaymentId);
|
431 |
logger.info("Capture attempt successful for HDFC payment with id: " + merchantPaymentId);
|
| 400 |
payment.setDescription("Payment Captured");
|
432 |
payment.setDescription("Payment Captured");
|
| 401 |
payment.setGatewayTxnStatus(gatewayStatus);
|
433 |
payment.setGatewayTxnStatus(gatewayStatus);
|
| 402 |
payment.setStatus(PaymentStatus.SUCCESS.getValue());
|
434 |
payment.setStatus(PaymentStatus.SUCCESS.getValue());
|
| 403 |
payment.setSuccessTimestamp(new Date());
|
435 |
payment.setSuccessTimestamp(new Date());
|
| 404 |
|
436 |
|
| 405 |
attrMap.put(IPaymentHandler.CAPTURE_TXN_ID, captureResult.get(IPaymentHandler.CAPTURE_TXN_ID));
|
437 |
attrMap.put(IPaymentHandler.CAPTURE_TXN_ID, captureResult.get(IPaymentHandler.CAPTURE_TXN_ID));
|
| 406 |
attrMap.put(IPaymentHandler.CAPTURE_REF_ID, captureResult.get(IPaymentHandler.CAPTURE_REF_ID));
|
438 |
attrMap.put(IPaymentHandler.CAPTURE_REF_ID, captureResult.get(IPaymentHandler.CAPTURE_REF_ID));
|
| 407 |
attrMap.put(IPaymentHandler.CAPTURE_AUTH_ID, captureResult.get(IPaymentHandler.CAPTURE_AUTH_ID));
|
439 |
attrMap.put(IPaymentHandler.CAPTURE_AUTH_ID, captureResult.get(IPaymentHandler.CAPTURE_AUTH_ID));
|
| 408 |
|
440 |
|
| Line 420... |
Line 452... |
| 420 |
* don't retry or anything. We'll add the support of multiple attempts later
|
452 |
* don't retry or anything. We'll add the support of multiple attempts later
|
| 421 |
* on.
|
453 |
* on.
|
| 422 |
*
|
454 |
*
|
| 423 |
* @param payment The payment which has to be captured.
|
455 |
* @param payment The payment which has to be captured.
|
| 424 |
* @return True if the payment attempt is successful, false if not.
|
456 |
* @return True if the payment attempt is successful, false if not.
|
| - |
|
457 |
* @throws PaymentException
|
| 425 |
*/
|
458 |
*/
|
| 426 |
private boolean captureAndUpdateEbsPayment(in.shop2020.payment.domain.Payment payment){
|
459 |
private boolean captureAndUpdateEbsPayment(in.shop2020.payment.domain.Payment payment) throws PaymentException{
|
| 427 |
Map<String, String> captureResult = EbsPaymentHandler.capturePayment(payment);
|
460 |
Map<String, String> captureResult = EbsPaymentHandler.capturePayment(payment);
|
| 428 |
String captureStatus = captureResult.get(EbsPaymentHandler.STATUS);
|
461 |
String captureStatus = captureResult.get(EbsPaymentHandler.STATUS);
|
| 429 |
|
462 |
|
| 430 |
Map<String, String> attrMap = new HashMap<String, String>();
|
463 |
Map<String, String> attrMap = new HashMap<String, String>();
|
| 431 |
if("".equals(captureStatus)){
|
464 |
if("".equals(captureStatus)){
|
| 432 |
//Failure
|
465 |
//Failure
|
| 433 |
logger.error("Capture attempt failed for EBS payment with id: " + payment.getId());
|
466 |
logger.error("Capture attempt failed for EBS payment with id: " + payment.getId());
|
| 434 |
String description = captureResult.get(EbsPaymentHandler.ERROR);
|
467 |
String description = captureResult.get(EbsPaymentHandler.ERROR);
|
| 435 |
String errorCode = captureResult.get(EbsPaymentHandler.ERR_CODE);
|
468 |
String errorCode = captureResult.get(EbsPaymentHandler.ERR_CODE);
|
| 436 |
|
469 |
|
| 437 |
payment.setDescription(description);
|
470 |
payment.setDescription(description);
|
| 438 |
payment.setErrorCode(errorCode);
|
471 |
payment.setErrorCode(errorCode);
|
| 439 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
- |
|
| 440 |
payment.setErrorTimestamp(new Date());
|
472 |
payment.setErrorTimestamp(new Date());
|
| - |
|
473 |
|
| - |
|
474 |
if (IPaymentHandler.Errors.CONN_FAILURE.code.equals(errorCode)) {
|
| - |
|
475 |
payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());
|
| 441 |
paymentHandler.updatePayment(payment, attrMap);
|
476 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
477 |
throw new PaymentException(106, "Could not capture due to connection issue");
|
| - |
|
478 |
}
|
| - |
|
479 |
else {
|
| - |
|
480 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
| - |
|
481 |
paymentHandler.updatePayment(payment, attrMap);
|
| 442 |
persistPaymentRequiringExtraProcessing(payment);
|
482 |
persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
| - |
|
483 |
}
|
| - |
|
484 |
|
| 443 |
return false;
|
485 |
return false;
|
| 444 |
}else{
|
486 |
}else{
|
| 445 |
//Success
|
487 |
//Success
|
| 446 |
logger.info("Capture attempt successful for EBS payment with id: " + payment.getId());
|
488 |
logger.info("Capture attempt successful for EBS payment with id: " + payment.getId());
|
| 447 |
payment.setGatewayTxnStatus(captureStatus);
|
489 |
payment.setGatewayTxnStatus(captureStatus);
|