|
16 | 16 | import dev.vality.hooker.utils.TimeUtils; |
17 | 17 | import dev.vality.swag_webhook_events.model.*; |
18 | 18 | import lombok.RequiredArgsConstructor; |
| 19 | +import lombok.extern.slf4j.Slf4j; |
19 | 20 | import org.apache.thrift.TException; |
20 | 21 | import org.springframework.stereotype.Service; |
21 | 22 |
|
| 23 | +@Slf4j |
22 | 24 | @Service |
23 | 25 | @RequiredArgsConstructor |
24 | 26 | public class InvoicingEventService |
@@ -51,7 +53,14 @@ public InvoicePaymentAdjustment getAdjustmentByMessage(InvoicingMessage message, |
51 | 53 | @Override |
52 | 54 | public dev.vality.damsel.payment_processing.Invoice getInvoiceByMessage(InvoicingMessage message) { |
53 | 55 | try { |
54 | | - return invoicingClient.get(message.getSourceId(), getEventRange(message)); |
| 56 | + dev.vality.damsel.payment_processing.Invoice invoice = |
| 57 | + invoicingClient.get(message.getSourceId(), getEventRange(message)); |
| 58 | + if (invoice.getLatestEventId() != message.getSequenceId().intValue()) { |
| 59 | + log.warn("Event not need version: {} but come: {}", message.getSequenceId(), |
| 60 | + invoice.getLatestEventId()); |
| 61 | + throw new RemoteHostException("Event not need version!"); |
| 62 | + } |
| 63 | + return invoice; |
55 | 64 | } catch (InvoiceNotFound e) { |
56 | 65 | throw new NotFoundException("Invoice not found, invoiceId=" + message.getSourceId()); |
57 | 66 | } catch (TException e) { |
@@ -157,7 +166,7 @@ private static InvoicePaymentAdjustment findAdjustmentInPayment(InvoicingMessage |
157 | 166 | } |
158 | 167 | return invoicePayment.getAdjustments().stream() |
159 | 168 | .filter(invoicePaymentAdjustment -> invoicePaymentAdjustment.isSetId() |
160 | | - && invoicePaymentAdjustment.getId().equals(adjustmentId)) |
| 169 | + && invoicePaymentAdjustment.getId().equals(adjustmentId)) |
161 | 170 | .findFirst() |
162 | 171 | .orElseThrow(() -> new NotFoundException( |
163 | 172 | String.format("Adjustment not found, invoiceId=%s, paymentId=%s, adjustmentId=%s", |
|
0 commit comments