Source:
<code>public void invoke(PaymentGatewayName gatewayName, RefundStatus newStatus, GatewayAccountEntity gatewayAccountEntity, String gatewayTransactionId, String transactionId, Charge charge) { if (isBlank(gatewayTransactionId)) { logger.warn("{} refund notification could not be used to update charge (missing reference)", gatewayName, charge.getExternalId()); return; } Optional<RefundEntity> optionalRefundEntity = refundService.findByChargeExternalIdAndGatewayTransactionId(charge.getExternalId(), gatewayTransactionId); if (optionalRefundEntity.isEmpty()) { Optional<Refund> mayBeHistoricRefund = refundService.findHistoricRefundByChargeExternalIdAndGatewayTransactionId(charge, gatewayTransactionId); mayBeHistoricRefund.ifPresentOrElse( refund -> logger.warn("{} notification could not be processed as refund has been expunged from connector", gatewayName, refund.getExternalId(), <START> kv(REFUND_EXTERNAL_ID, refund.getExternalId()), kv(PAYMENT_EXTERNAL_ID, charge.getExternalId())), <END> () -> logger.warn("{} notification '{}' could not be used to update refund (associated refund entity not found) for charge [{}]", gatewayName, gatewayTransactionId, charge.getExternalId())); return; } RefundEntity refundEntity = optionalRefundEntity.get(); RefundStatus oldStatus = refundEntity.getStatus(); refundService.transitionRefundState(refundEntity, newStatus); if (RefundStatus.REFUNDED.equals(newStatus)) { userNotificationService.sendRefundIssuedEmail(refundEntity, charge, gatewayAccountEntity); } logger.info("Notification received for refund. Updating refund - charge_external_id={}, refund_reference={}, transaction_id={}, status={}, " + "status_to={}, account_id={}, provider={}, provider_type={}", refundEntity.getChargeExternalId(), gatewayTransactionId, transactionId, oldStatus, newStatus, gatewayAccountEntity.getId(), gatewayAccountEntity.getGatewayName(), gatewayAccountEntity.getType()); }</code><technical_language>log gatewayName a structured argument PROVIDER key? useful</technical_language>

Target:
public void invoke(PaymentGatewayName gatewayName, RefundStatus newStatus, GatewayAccountEntity gatewayAccountEntity, String gatewayTransactionId, String transactionId, Charge charge) { if (isBlank(gatewayTransactionId)) { logger.warn("{} refund notification could not be used to update charge (missing reference)", gatewayName, charge.getExternalId()); return; } Optional<RefundEntity> optionalRefundEntity = refundService.findByChargeExternalIdAndGatewayTransactionId(charge.getExternalId(), gatewayTransactionId); if (optionalRefundEntity.isEmpty()) { Optional<Refund> mayBeHistoricRefund = refundService.findHistoricRefundByChargeExternalIdAndGatewayTransactionId(charge, gatewayTransactionId); mayBeHistoricRefund.ifPresentOrElse( refund -> logger.warn("{} notification could not be processed as refund has been expunged from connector", gatewayName, refund.getExternalId(), kv(REFUND_EXTERNAL_ID, refund.getExternalId()), kv(PAYMENT_EXTERNAL_ID, charge.getExternalId()), kv(PROVIDER, gatewayName)), () -> logger.warn("{} notification '{}' could not be used to update refund (associated refund entity not found) for charge [{}]", gatewayName, gatewayTransactionId, charge.getExternalId(), kv(PAYMENT_EXTERNAL_ID, charge.getExternalId()), kv(PROVIDER, gatewayName), kv("provider_refund_id", gatewayTransactionId)) ); return; } RefundEntity refundEntity = optionalRefundEntity.get(); RefundStatus oldStatus = refundEntity.getStatus(); refundService.transitionRefundState(refundEntity, newStatus); if (RefundStatus.REFUNDED.equals(newStatus)) { userNotificationService.sendRefundIssuedEmail(refundEntity, charge, gatewayAccountEntity); } logger.info("Notification received for refund. Updating refund - charge_external_id={}, refund_reference={}, transaction_id={}, status={}, " + "status_to={}, account_id={}, provider={}, provider_type={}", refundEntity.getChargeExternalId(), gatewayTransactionId, transactionId, oldStatus, newStatus, gatewayAccountEntity.getId(), gatewayAccountEntity.getGatewayName(), gatewayAccountEntity.getType()); }