diff --git a/pom.xml b/pom.xml
index b8887d15..208ce5a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -177,7 +177,7 @@
dev.vality
damsel
- 1.695-25e75a5
+ 1.696-b07c077
dev.vality
diff --git a/src/main/java/dev/vality/daway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentCreatedHandler.java b/src/main/java/dev/vality/daway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentCreatedHandler.java
index f77112de..41e867c6 100644
--- a/src/main/java/dev/vality/daway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentCreatedHandler.java
+++ b/src/main/java/dev/vality/daway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentCreatedHandler.java
@@ -98,6 +98,11 @@ public void handle(InvoiceChange invoiceChange, MachineEvent event, Integer chan
invoicePaymentAdjustmentState.getStatusChange().getScenario().getTargetStatus(),
PaymentStatus.class);
adjustment.setPaymentStatus(paymentStatus);
+ } else if (invoicePaymentAdjustmentState.isSetTransactionInfo()) {
+ var transactionInfo = invoicePaymentAdjustmentState.getTransactionInfo().getScenario().getTrx();
+ if (transactionInfo.isSetAdditionalInfo()) {
+ adjustment.setTransactionInfoRrn(transactionInfo.getAdditionalInfo().getRrn());
+ }
}
}
diff --git a/src/main/java/dev/vality/daway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentStatusChangedHandler.java b/src/main/java/dev/vality/daway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentStatusChangedHandler.java
index 934d9018..910cf28a 100644
--- a/src/main/java/dev/vality/daway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentStatusChangedHandler.java
+++ b/src/main/java/dev/vality/daway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentStatusChangedHandler.java
@@ -6,12 +6,15 @@
import dev.vality.damsel.payment_processing.InvoicePaymentChange;
import dev.vality.daway.dao.invoicing.iface.AdjustmentDao;
import dev.vality.daway.dao.invoicing.iface.CashFlowDao;
+import dev.vality.daway.dao.invoicing.iface.PaymentAdditionalInfoDao;
import dev.vality.daway.domain.enums.AdjustmentCashFlowType;
import dev.vality.daway.domain.enums.AdjustmentStatus;
import dev.vality.daway.domain.tables.pojos.Adjustment;
import dev.vality.daway.domain.tables.pojos.CashFlow;
+import dev.vality.daway.domain.tables.pojos.PaymentAdditionalInfo;
import dev.vality.daway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.daway.handler.event.stock.impl.invoicing.InvoicingHandler;
+import dev.vality.daway.model.InvoicingKey;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
@@ -27,6 +30,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
+import java.util.Set;
@Slf4j
@Component
@@ -35,6 +39,7 @@ public class InvoicePaymentAdjustmentStatusChangedHandler implements InvoicingHa
private final AdjustmentDao adjustmentDao;
private final CashFlowDao cashFlowDao;
+ private final PaymentAdditionalInfoDao paymentAdditionalInfoDao;
private final MachineEventCopyFactory machineEventCopyFactory;
@Getter
@@ -92,6 +97,11 @@ public void handle(InvoiceChange invoiceChange, MachineEvent event, Integer chan
pcf.setObjId(id);
});
cashFlowDao.save(oldCashFlows);
+ applyTransactionInfoAdjustment(
+ adjustmentOld,
+ invoicePaymentAdjustmentStatus,
+ event,
+ changeId);
log.info("Adjustment status change has been saved, " +
"sequenceId={}, invoiceId={}, paymentId={}, adjustmentId={}",
sequenceId, invoiceId, paymentId, adjustmentId);
@@ -102,4 +112,30 @@ public void handle(InvoiceChange invoiceChange, MachineEvent event, Integer chan
sequenceId, invoiceId, paymentId, adjustmentId));
}
+ private void applyTransactionInfoAdjustment(
+ Adjustment adjustment,
+ InvoicePaymentAdjustmentStatus status,
+ MachineEvent event,
+ int changeId) {
+ if (!status.isSetCaptured() || adjustment.getTransactionInfoRrn() == null) {
+ return;
+ }
+ var invoiceId = adjustment.getInvoiceId();
+ var paymentId = adjustment.getPaymentId();
+ var key = InvoicingKey.buildKey(invoiceId, paymentId);
+ var currentAdditionalInfo = paymentAdditionalInfoDao.safeGet(invoiceId, paymentId);
+ var additionalInfo = currentAdditionalInfo == null
+ ? new PaymentAdditionalInfo()
+ : new PaymentAdditionalInfo(currentAdditionalInfo);
+ additionalInfo.setId(null);
+ additionalInfo.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
+ additionalInfo.setInvoiceId(invoiceId);
+ additionalInfo.setPaymentId(paymentId);
+ additionalInfo.setRrn(adjustment.getTransactionInfoRrn());
+ additionalInfo.setSequenceId(event.getEventId());
+ additionalInfo.setChangeId(changeId);
+ paymentAdditionalInfoDao.saveBatch(List.of(additionalInfo));
+ paymentAdditionalInfoDao.switchCurrent(Set.of(key));
+ }
+
}
diff --git a/src/main/resources/db/migration/V53__add_transaction_info_rrn_to_adjustment.sql b/src/main/resources/db/migration/V53__add_transaction_info_rrn_to_adjustment.sql
new file mode 100644
index 00000000..1e82fce0
--- /dev/null
+++ b/src/main/resources/db/migration/V53__add_transaction_info_rrn_to_adjustment.sql
@@ -0,0 +1,2 @@
+ALTER TABLE dw.adjustment
+ ADD COLUMN transaction_info_rrn CHARACTER VARYING;
diff --git a/src/test/java/dev/vality/daway/IntegrationTest.java b/src/test/java/dev/vality/daway/IntegrationTest.java
index 297f43a7..2e2d0db8 100644
--- a/src/test/java/dev/vality/daway/IntegrationTest.java
+++ b/src/test/java/dev/vality/daway/IntegrationTest.java
@@ -235,6 +235,54 @@ void test() {
assertDuplication();
}
+ @Test
+ void transactionInfoAdjustmentIsAppliedOnlyWhenCaptured() {
+ cleanUpTables();
+ invoicingService.handleEvents(getInitialInvoicePaymentEvents(invoiceId, paymentId));
+
+ var transactionInfo = new TransactionInfo()
+ .setId("adjustedTrxId")
+ .setExtra(Map.of("source", "dispute"))
+ .setAdditionalInfo(new AdditionalTransactionInfo().setRrn("adjustedRrn"));
+ invoicingService.handleEvents(List.of(createTransactionInfoAdjustmentCreatedEvent(2, transactionInfo)));
+ assertEquals("adjustedRrn", jdbcTemplate.queryForObject(
+ "SELECT transaction_info_rrn FROM dw.adjustment WHERE current",
+ String.class));
+ assertCurrentTransactionInfo("trxId", null);
+
+ invoicingService.handleEvents(List.of(createAdjustmentStatusChangedEvent(
+ 3,
+ InvoicePaymentAdjustmentStatus.processed(new InvoicePaymentAdjustmentProcessed()))));
+ assertCurrentTransactionInfo("trxId", null);
+
+ invoicingService.handleEvents(List.of(createAdjustmentStatusChangedEvent(
+ 4,
+ InvoicePaymentAdjustmentStatus.captured(
+ new InvoicePaymentAdjustmentCaptured().setAt("2026-07-13T14:00:00Z")))));
+ assertCurrentTransactionInfo("trxId", "adjustedRrn");
+ }
+
+ @Test
+ void cancelledTransactionInfoAdjustmentIsNotApplied() {
+ cleanUpTables();
+ invoicingService.handleEvents(getInitialInvoicePaymentEvents(invoiceId, paymentId));
+
+ var transactionInfo = new TransactionInfo()
+ .setId("cancelledTrxId")
+ .setExtra(Map.of())
+ .setAdditionalInfo(new AdditionalTransactionInfo().setRrn("cancelledRrn"));
+ invoicingService.handleEvents(List.of(createTransactionInfoAdjustmentCreatedEvent(2, transactionInfo)));
+ invoicingService.handleEvents(List.of(createAdjustmentStatusChangedEvent(
+ 3,
+ InvoicePaymentAdjustmentStatus.processed(new InvoicePaymentAdjustmentProcessed()))));
+ invoicingService.handleEvents(List.of(createAdjustmentStatusChangedEvent(
+ 4,
+ InvoicePaymentAdjustmentStatus.cancelled(
+ new InvoicePaymentAdjustmentCancelled().setAt("2026-07-13T14:00:00Z")))));
+
+ assertCurrentTransactionInfo("trxId", null);
+ }
+
@NotNull
private List getInitialInvoicePaymentEvents(String invoiceId, String paymentId) {
return List.of(
@@ -396,6 +444,54 @@ private List getInvoicePaymentFailedChange(String invoiceId, Strin
);
}
+ private MachineEvent createTransactionInfoAdjustmentCreatedEvent(long eventId, TransactionInfo transactionInfo) {
+ var adjustment = new InvoicePaymentAdjustment()
+ .setId("transactionInfoAdjustment")
+ .setStatus(InvoicePaymentAdjustmentStatus.pending(
+ new dev.vality.damsel.domain.InvoicePaymentAdjustmentPending()))
+ .setCreatedAt("2026-07-13T14:00:00Z")
+ .setDomainRevision(1)
+ .setReason("providerCallbackId=test")
+ .setNewCashFlow(List.of())
+ .setOldCashFlowInverse(List.of())
+ .setState(InvoicePaymentAdjustmentState.transaction_info(
+ new InvoicePaymentAdjustmentTransactionInfoState()
+ .setScenario(new InvoicePaymentAdjustmentTransactionInfo(transactionInfo))));
+ var payload = InvoicePaymentChangePayload.invoice_payment_adjustment_change(
+ new InvoicePaymentAdjustmentChange()
+ .setId(adjustment.getId())
+ .setPayload(InvoicePaymentAdjustmentChangePayload.invoice_payment_adjustment_created(
+ new InvoicePaymentAdjustmentCreated(adjustment))));
+ return createPaymentChangeEvent(eventId, payload);
+ }
+
+ private MachineEvent createAdjustmentStatusChangedEvent(
+ long eventId,
+ InvoicePaymentAdjustmentStatus status) {
+ var payload = InvoicePaymentChangePayload.invoice_payment_adjustment_change(
+ new InvoicePaymentAdjustmentChange()
+ .setId("transactionInfoAdjustment")
+ .setPayload(InvoicePaymentAdjustmentChangePayload.invoice_payment_adjustment_status_changed(
+ new InvoicePaymentAdjustmentStatusChanged(status))));
+ return createPaymentChangeEvent(eventId, payload);
+ }
+
+ private MachineEvent createPaymentChangeEvent(long eventId, InvoicePaymentChangePayload payload) {
+ var change = InvoiceChange.invoice_payment_change(
+ new InvoicePaymentChange().setId(paymentId).setPayload(payload));
+ return new MachineEvent()
+ .setSourceId(invoiceId)
+ .setEventId(eventId)
+ .setCreatedAt("2026-07-13T14:00:00Z")
+ .setData(Value.bin(serializer.serialize(EventPayload.invoice_changes(List.of(change)))));
+ }
+
+ private void assertCurrentTransactionInfo(String transactionId, String rrn) {
+ var paymentAdditionalInfo = paymentAdditionalInfoDao.get(invoiceId, paymentId);
+ assertEquals(transactionId, paymentAdditionalInfo.getTransactionId());
+ assertEquals(rrn, paymentAdditionalInfo.getRrn());
+ }
+
private void cleanUpTables() {
jdbcTemplate.execute("truncate table dw.invoice cascade");
jdbcTemplate.execute("truncate table dw.invoice_status_info cascade");
@@ -410,6 +506,7 @@ private void cleanUpTables() {
jdbcTemplate.execute("truncate table dw.payment_route cascade");
jdbcTemplate.execute("truncate table dw.cash_flow_link cascade");
jdbcTemplate.execute("truncate table dw.cash_flow cascade");
+ jdbcTemplate.execute("truncate table dw.adjustment cascade");
}
private void assertDuplication() {