Source:
private void handle(SmartpayNotification notification) { if (shouldIgnore(notification)) { logger.info("{} notification ignored", PAYMENT_GATEWAY_NAME, notification); return; } logger.info("Verifying notification {}", PAYMENT_GATEWAY_NAME, notification); if (isBlank(notification.getTransactionId())) { logger.error("{} notification failed verification because it has no transaction ID", PAYMENT_GATEWAY_NAME, notification); return; } logger.info("Evaluating notification {}", PAYMENT_GATEWAY_NAME, notification); Optional<Charge> maybeCharge = chargeService.findByProviderAndTransactionIdFromDbOrLedger(PAYMENT_GATEWAY_NAME, notification.getOriginalReference()); if (maybeCharge.isEmpty()) { logger.warn("{} notification could not be evaluated (associated charge entity not found)", PAYMENT_GATEWAY_NAME, notification); return; } Charge charge = maybeCharge.get(); GatewayAccountEntity gatewayAccountEntity = gatewayAccountService.getGatewayAccount(charge.getGatewayAccountId()).get(); InterpretedStatus interpretedStatus = interpretStatus(notification, charge.getStatus()); if (interpretedStatus instanceof MappedChargeStatus) { chargeNotificationProcessor.invoke( notification.getOriginalReference(), charge, interpretedStatus.getChargeStatus(), notification.getEventDate() ); } else if (interpretedStatus instanceof MappedRefundStatus) { refundNotificationProcessor.invoke( SMARTPAY, interpretedStatus.getRefundStatus(), gatewayAccountEntity, notification.getPspReference(), notification.getOriginalReference(), charge ); } else { logger.error("{} notification unknown", PAYMENT_GATEWAY_NAME, notification); } }

Target:
private void handle(SmartpayNotification notification) { if (shouldIgnore(notification)) { logger.info("{} notification ignored", PAYMENT_GATEWAY_NAME, notification); return; } logger.info("Verifying notification {}", PAYMENT_GATEWAY_NAME, notification); if (isBlank(notification.getTransactionId())) { logger.error("{} notification failed verification because it has no transaction ID", PAYMENT_GATEWAY_NAME, notification); return; } logger.info("Evaluating notification {}", PAYMENT_GATEWAY_NAME, notification); Optional<Charge> maybeCharge = chargeService.findByProviderAndTransactionIdFromDbOrLedger(PAYMENT_GATEWAY_NAME, notification.getOriginalReference()); if (maybeCharge.isEmpty()) { logger.warn("{} notification could not be evaluated (associated charge entity not found)", PAYMENT_GATEWAY_NAME, notification); return; } Charge charge = maybeCharge.get(); GatewayAccountEntity gatewayAccountEntity = gatewayAccountService.getGatewayAccount(charge.getGatewayAccountId()).get(); InterpretedStatus interpretedStatus = interpretStatus(notification); if (interpretedStatus instanceof MappedChargeStatus) { chargeNotificationProcessor.invoke( notification.getOriginalReference(), charge, interpretedStatus.getChargeStatus(), notification.getEventDate() ); } else if (interpretedStatus instanceof MappedRefundStatus) { refundNotificationProcessor.invoke( SMARTPAY, interpretedStatus.getRefundStatus(), gatewayAccountEntity, notification.getPspReference(), notification.getOriginalReference(), charge ); } else { logger.error("{} notification unknown", PAYMENT_GATEWAY_NAME, notification); } }