diff --git a/pom.xml b/pom.xml index 0e12608..5630357 100644 --- a/pom.xml +++ b/pom.xml @@ -26,9 +26,9 @@ 11 ${server.port} 0.6.4 - 1.395-dca168e + 1.399-dfc81d0 1.36-683822a - 1.9-9c79023 + 1.13-f4f401b 2.2.3.RELEASE diff --git a/src/main/java/com/rbkmoney/cashier/config/CashRegConfig.java b/src/main/java/com/rbkmoney/cashier/config/CashRegConfig.java index 84917a3..083a7aa 100644 --- a/src/main/java/com/rbkmoney/cashier/config/CashRegConfig.java +++ b/src/main/java/com/rbkmoney/cashier/config/CashRegConfig.java @@ -1,6 +1,6 @@ package com.rbkmoney.cashier.config; -import com.rbkmoney.damsel.cashreg_processing.ManagementSrv; +import com.rbkmoney.damsel.cashreg.processing.ManagementSrv; import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -13,9 +13,9 @@ import java.io.IOException; public class CashRegConfig { @Bean - public ManagementSrv.Iface cashRegClient( - @Value("${client.cash-reg.url}") Resource url, - @Value("${client.cash-reg.timeout}") int timeout) throws IOException { + public ManagementSrv.Iface cashregClient( + @Value("${client.cashreg.url}") Resource url, + @Value("${client.cashreg.timeout}") int timeout) throws IOException { return new THSpawnClientBuilder() .withAddress(url.getURI()) .withNetworkTimeout(timeout) diff --git a/src/main/java/com/rbkmoney/cashier/handler/events/PaymentCancelledHandler.java b/src/main/java/com/rbkmoney/cashier/handler/events/PaymentCancelledHandler.java index 8eb6e0d..9725c70 100644 --- a/src/main/java/com/rbkmoney/cashier/handler/events/PaymentCancelledHandler.java +++ b/src/main/java/com/rbkmoney/cashier/handler/events/PaymentCancelledHandler.java @@ -1,32 +1,35 @@ package com.rbkmoney.cashier.handler.events; +import com.rbkmoney.cashier.domain.CashRegister; import com.rbkmoney.cashier.domain.InvoiceChangeWithMetadata; import com.rbkmoney.cashier.handler.events.iface.AbstractEventHandler; +import com.rbkmoney.cashier.repository.CashRegisterRepository; import com.rbkmoney.cashier.repository.InvoiceAggregateRepository; -import com.rbkmoney.cashier.repository.ProviderRepository; -import com.rbkmoney.cashier.service.CashRegService; -import com.rbkmoney.damsel.cashreg_processing.CashRegParams; +import com.rbkmoney.cashier.service.CashregService; +import com.rbkmoney.damsel.cashreg.processing.ReceiptParams; import com.rbkmoney.damsel.payment_processing.Invoice; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @Service public class PaymentCancelledHandler extends AbstractEventHandler { private final InvoiceAggregateRepository invoiceAggregateRepository; - private final ProviderRepository providerRepository; - private final CashRegService cashRegService; + private final CashRegisterRepository cashRegisterRepository; + private final CashregService cashRegService; public PaymentCancelledHandler( @Value("${events.path.payment-cancelled}") String path, InvoiceAggregateRepository invoiceAggregateRepository, - ProviderRepository providerRepository, - CashRegService cashRegService) { + CashRegisterRepository cashRegisterRepository, + CashregService cashRegService) { super(path); this.invoiceAggregateRepository = invoiceAggregateRepository; - this.providerRepository = providerRepository; + this.cashRegisterRepository = cashRegisterRepository; this.cashRegService = cashRegService; } @@ -41,10 +44,12 @@ public class PaymentCancelledHandler extends AbstractEventHandler { invoiceId, eventId); - String providerId = providerRepository.findBy(); + List cashRegisters = cashRegisterRepository.findByPartyIdAndShopId( + aggregate.getInvoice().getOwnerId(), + aggregate.getInvoice().getShopId()); - CashRegParams refundDebitForInvoice = cashRegService.refundDebitForInvoice( - providerId, + ReceiptParams refundDebitForInvoice = cashRegService.refundDebitForInvoice( + cashRegisters, aggregate); cashRegService.send(refundDebitForInvoice); diff --git a/src/main/java/com/rbkmoney/cashier/handler/events/PaymentCapturedHandler.java b/src/main/java/com/rbkmoney/cashier/handler/events/PaymentCapturedHandler.java index 6919f56..749b1f0 100644 --- a/src/main/java/com/rbkmoney/cashier/handler/events/PaymentCapturedHandler.java +++ b/src/main/java/com/rbkmoney/cashier/handler/events/PaymentCapturedHandler.java @@ -1,33 +1,36 @@ package com.rbkmoney.cashier.handler.events; +import com.rbkmoney.cashier.domain.CashRegister; import com.rbkmoney.cashier.domain.InvoiceChangeWithMetadata; import com.rbkmoney.cashier.handler.events.iface.AbstractEventHandler; +import com.rbkmoney.cashier.repository.CashRegisterRepository; import com.rbkmoney.cashier.repository.InvoiceAggregateRepository; -import com.rbkmoney.cashier.repository.ProviderRepository; -import com.rbkmoney.cashier.service.CashRegService; -import com.rbkmoney.damsel.cashreg_processing.CashRegParams; +import com.rbkmoney.cashier.service.CashregService; +import com.rbkmoney.damsel.cashreg.processing.ReceiptParams; import com.rbkmoney.damsel.domain.InvoicePaymentCaptured; import com.rbkmoney.damsel.payment_processing.Invoice; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @Service public class PaymentCapturedHandler extends AbstractEventHandler { private final InvoiceAggregateRepository invoiceAggregateRepository; - private final ProviderRepository providerRepository; - private final CashRegService cashRegService; + private final CashRegisterRepository cashRegisterRepository; + private final CashregService cashRegService; public PaymentCapturedHandler( @Value("${events.path.payment-captured}") String path, InvoiceAggregateRepository invoiceAggregateRepository, - ProviderRepository providerRepository, - CashRegService cashRegService) { + CashRegisterRepository cashRegisterRepository, + CashregService cashRegService) { super(path); this.invoiceAggregateRepository = invoiceAggregateRepository; - this.providerRepository = providerRepository; + this.cashRegisterRepository = cashRegisterRepository; this.cashRegService = cashRegService; } @@ -56,14 +59,16 @@ public class PaymentCapturedHandler extends AbstractEventHandler { invoiceId, eventId); - String providerId = providerRepository.findBy(); + List cashRegisters = cashRegisterRepository.findByPartyIdAndShopId( + aggregate.getInvoice().getOwnerId(), + aggregate.getInvoice().getShopId()); - CashRegParams refundDebitForInvoice = cashRegService.refundDebitForInvoice( - providerId, + ReceiptParams refundDebitForInvoice = cashRegService.refundDebitForInvoice( + cashRegisters, aggregate); - CashRegParams debitForPartialCapture = cashRegService.debitForPartialCapture( - providerId, + ReceiptParams debitForPartialCapture = cashRegService.debitForPartialCapture( + cashRegisters, aggregate, capturedPayment); diff --git a/src/main/java/com/rbkmoney/cashier/handler/events/PaymentFailedHandler.java b/src/main/java/com/rbkmoney/cashier/handler/events/PaymentFailedHandler.java index 175d763..eb5c01e 100644 --- a/src/main/java/com/rbkmoney/cashier/handler/events/PaymentFailedHandler.java +++ b/src/main/java/com/rbkmoney/cashier/handler/events/PaymentFailedHandler.java @@ -1,32 +1,35 @@ package com.rbkmoney.cashier.handler.events; +import com.rbkmoney.cashier.domain.CashRegister; import com.rbkmoney.cashier.domain.InvoiceChangeWithMetadata; import com.rbkmoney.cashier.handler.events.iface.AbstractEventHandler; +import com.rbkmoney.cashier.repository.CashRegisterRepository; import com.rbkmoney.cashier.repository.InvoiceAggregateRepository; -import com.rbkmoney.cashier.repository.ProviderRepository; -import com.rbkmoney.cashier.service.CashRegService; -import com.rbkmoney.damsel.cashreg_processing.CashRegParams; +import com.rbkmoney.cashier.service.CashregService; +import com.rbkmoney.damsel.cashreg.processing.ReceiptParams; import com.rbkmoney.damsel.payment_processing.Invoice; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @Service public class PaymentFailedHandler extends AbstractEventHandler { private final InvoiceAggregateRepository invoiceAggregateRepository; - private final ProviderRepository providerRepository; - private final CashRegService cashRegService; + private final CashRegisterRepository cashRegisterRepository; + private final CashregService cashRegService; public PaymentFailedHandler( @Value("${events.path.payment-failed}") String path, InvoiceAggregateRepository invoiceAggregateRepository, - ProviderRepository providerRepository, - CashRegService cashRegService) { + CashRegisterRepository cashRegisterRepository, + CashregService cashRegService) { super(path); this.invoiceAggregateRepository = invoiceAggregateRepository; - this.providerRepository = providerRepository; + this.cashRegisterRepository = cashRegisterRepository; this.cashRegService = cashRegService; } @@ -41,10 +44,12 @@ public class PaymentFailedHandler extends AbstractEventHandler { invoiceId, eventId); - String providerId = providerRepository.findBy(); + List cashRegisters = cashRegisterRepository.findByPartyIdAndShopId( + aggregate.getInvoice().getOwnerId(), + aggregate.getInvoice().getShopId()); - CashRegParams refundDebitForInvoice = cashRegService.refundDebitForInvoice( - providerId, + ReceiptParams refundDebitForInvoice = cashRegService.refundDebitForInvoice( + cashRegisters, aggregate); cashRegService.send(refundDebitForInvoice); diff --git a/src/main/java/com/rbkmoney/cashier/handler/events/PaymentProcessedHandler.java b/src/main/java/com/rbkmoney/cashier/handler/events/PaymentProcessedHandler.java index 3b568bc..7ebd5b6 100644 --- a/src/main/java/com/rbkmoney/cashier/handler/events/PaymentProcessedHandler.java +++ b/src/main/java/com/rbkmoney/cashier/handler/events/PaymentProcessedHandler.java @@ -1,32 +1,35 @@ package com.rbkmoney.cashier.handler.events; +import com.rbkmoney.cashier.domain.CashRegister; import com.rbkmoney.cashier.domain.InvoiceChangeWithMetadata; import com.rbkmoney.cashier.handler.events.iface.AbstractEventHandler; +import com.rbkmoney.cashier.repository.CashRegisterRepository; import com.rbkmoney.cashier.repository.InvoiceAggregateRepository; -import com.rbkmoney.cashier.repository.ProviderRepository; -import com.rbkmoney.cashier.service.CashRegService; -import com.rbkmoney.damsel.cashreg_processing.CashRegParams; +import com.rbkmoney.cashier.service.CashregService; +import com.rbkmoney.damsel.cashreg.processing.ReceiptParams; import com.rbkmoney.damsel.payment_processing.Invoice; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @Service public class PaymentProcessedHandler extends AbstractEventHandler { private final InvoiceAggregateRepository invoiceAggregateRepository; - private final ProviderRepository providerRepository; - private final CashRegService cashRegService; + private final CashRegisterRepository cashRegisterRepository; + private final CashregService cashRegService; public PaymentProcessedHandler( @Value("${events.path.payment-processed}") String path, InvoiceAggregateRepository repository, - ProviderRepository providerRepository, - CashRegService cashRegService) { + CashRegisterRepository cashRegisterRepository, + CashregService cashRegService) { super(path); this.invoiceAggregateRepository = repository; - this.providerRepository = providerRepository; + this.cashRegisterRepository = cashRegisterRepository; this.cashRegService = cashRegService; } @@ -41,10 +44,12 @@ public class PaymentProcessedHandler extends AbstractEventHandler { invoiceId, eventId); - String providerId = providerRepository.findBy(); + List cashRegisters = cashRegisterRepository.findByPartyIdAndShopId( + aggregate.getInvoice().getOwnerId(), + aggregate.getInvoice().getShopId()); - CashRegParams debitForInvoice = cashRegService.debitForInvoice( - providerId, + ReceiptParams debitForInvoice = cashRegService.debitForInvoice( + cashRegisters, aggregate); cashRegService.send(debitForInvoice); diff --git a/src/main/java/com/rbkmoney/cashier/handler/events/RefundSucceededHandler.java b/src/main/java/com/rbkmoney/cashier/handler/events/RefundSucceededHandler.java index 8accb92..a81a7ac 100644 --- a/src/main/java/com/rbkmoney/cashier/handler/events/RefundSucceededHandler.java +++ b/src/main/java/com/rbkmoney/cashier/handler/events/RefundSucceededHandler.java @@ -1,11 +1,12 @@ package com.rbkmoney.cashier.handler.events; +import com.rbkmoney.cashier.domain.CashRegister; import com.rbkmoney.cashier.domain.InvoiceChangeWithMetadata; import com.rbkmoney.cashier.handler.events.iface.AbstractEventHandler; +import com.rbkmoney.cashier.repository.CashRegisterRepository; import com.rbkmoney.cashier.repository.InvoiceAggregateRepository; -import com.rbkmoney.cashier.repository.ProviderRepository; -import com.rbkmoney.cashier.service.CashRegService; -import com.rbkmoney.damsel.cashreg_processing.CashRegParams; +import com.rbkmoney.cashier.service.CashregService; +import com.rbkmoney.damsel.cashreg.processing.ReceiptParams; import com.rbkmoney.damsel.domain.InvoicePaymentRefund; import com.rbkmoney.damsel.payment_processing.Invoice; import com.rbkmoney.damsel.payment_processing.InvoicePayment; @@ -22,17 +23,17 @@ import java.util.stream.Stream; public class RefundSucceededHandler extends AbstractEventHandler { private final InvoiceAggregateRepository invoiceAggregateRepository; - private final ProviderRepository providerRepository; - private final CashRegService cashRegService; + private final CashRegisterRepository cashRegisterRepository; + private final CashregService cashRegService; public RefundSucceededHandler( @Value("${events.path.refund-succeeded}") String path, InvoiceAggregateRepository invoiceAggregateRepository, - ProviderRepository providerRepository, - CashRegService cashRegService) { + CashRegisterRepository cashRegisterRepository, + CashregService cashRegService) { super(path); this.invoiceAggregateRepository = invoiceAggregateRepository; - this.providerRepository = providerRepository; + this.cashRegisterRepository = cashRegisterRepository; this.cashRegService = cashRegService; } @@ -47,7 +48,9 @@ public class RefundSucceededHandler extends AbstractEventHandler { invoiceId, eventId); - String providerId = providerRepository.findBy(); + List cashRegisters = cashRegisterRepository.findByPartyIdAndShopId( + aggregate.getInvoice().getOwnerId(), + aggregate.getInvoice().getShopId()); String currentRefundId = invoiceChangeWithMetadata .getInvoiceChange() @@ -63,8 +66,8 @@ public class RefundSucceededHandler extends AbstractEventHandler { if (currentPartialRefund.isPresent()) { log.debug("Current refund is partial"); - CashRegParams debitForPartialRefund = cashRegService.debitForPartialRefund( - providerId, + ReceiptParams debitForPartialRefund = cashRegService.debitForPartialRefund( + cashRegisters, aggregate, currentPartialRefund.get()); @@ -73,16 +76,16 @@ public class RefundSucceededHandler extends AbstractEventHandler { log.debug("Current refund is NOT partial"); } - CashRegParams refundDebit = refundDebitForPreviousPartialRefund(providerId, aggregate, currentRefundId) - .orElse(cashRegService.refundDebitForInvoice(providerId, aggregate)); + ReceiptParams refundDebit = refundDebitForPreviousPartialRefund(cashRegisters, aggregate, currentRefundId) + .orElse(cashRegService.refundDebitForInvoice(cashRegisters, aggregate)); cashRegService.send(refundDebit); log.debug("Finished handling RefundSucceeded event: invoiceId={}, eventId={}", invoiceId, eventId); } - private Optional refundDebitForPreviousPartialRefund( - String providerId, + private Optional refundDebitForPreviousPartialRefund( + List cashRegisters, Invoice aggregate, String currentRefundId) { log.debug("Looking for previous successful refunds..."); @@ -108,7 +111,7 @@ public class RefundSucceededHandler extends AbstractEventHandler { log.debug("Previous successful partial refund was found"); return Optional.of( cashRegService.refundDebitForPreviousPartialRefund( - providerId, + cashRegisters, aggregate, previousPartialRefund.get())); } diff --git a/src/main/java/com/rbkmoney/cashier/service/CartTransformer.java b/src/main/java/com/rbkmoney/cashier/service/CartTransformer.java index 8c15dcc..160c20f 100644 --- a/src/main/java/com/rbkmoney/cashier/service/CartTransformer.java +++ b/src/main/java/com/rbkmoney/cashier/service/CartTransformer.java @@ -1,6 +1,6 @@ package com.rbkmoney.cashier.service; -import com.rbkmoney.damsel.cashreg.ItemsLine; +import com.rbkmoney.damsel.cashreg.receipt.ItemsLine; import com.rbkmoney.damsel.domain.InvoiceCart; import com.rbkmoney.damsel.domain.InvoiceLine; import com.rbkmoney.damsel.msgpack.Value; diff --git a/src/main/java/com/rbkmoney/cashier/service/CashRegService.java b/src/main/java/com/rbkmoney/cashier/service/CashregService.java similarity index 71% rename from src/main/java/com/rbkmoney/cashier/service/CashRegService.java rename to src/main/java/com/rbkmoney/cashier/service/CashregService.java index 4210a8f..8bd18c8 100644 --- a/src/main/java/com/rbkmoney/cashier/service/CashRegService.java +++ b/src/main/java/com/rbkmoney/cashier/service/CashregService.java @@ -1,13 +1,14 @@ package com.rbkmoney.cashier.service; -import com.rbkmoney.damsel.cashreg.Cart; -import com.rbkmoney.damsel.cashreg.ItemsLine; -import com.rbkmoney.damsel.cashreg.type.Debit; -import com.rbkmoney.damsel.cashreg.type.RefundDebit; -import com.rbkmoney.damsel.cashreg.type.Type; -import com.rbkmoney.damsel.cashreg_domain.PaymentInfo; -import com.rbkmoney.damsel.cashreg_processing.CashRegParams; -import com.rbkmoney.damsel.cashreg_processing.ManagementSrv; +import com.rbkmoney.cashier.domain.CashRegister; +import com.rbkmoney.damsel.cashreg.domain.PaymentInfo; +import com.rbkmoney.damsel.cashreg.processing.ManagementSrv; +import com.rbkmoney.damsel.cashreg.processing.ReceiptParams; +import com.rbkmoney.damsel.cashreg.receipt.Cart; +import com.rbkmoney.damsel.cashreg.receipt.ItemsLine; +import com.rbkmoney.damsel.cashreg.receipt.type.Debit; +import com.rbkmoney.damsel.cashreg.receipt.type.RefundDebit; +import com.rbkmoney.damsel.cashreg.receipt.type.Type; import com.rbkmoney.damsel.domain.Cash; import com.rbkmoney.damsel.domain.CurrencyRef; import com.rbkmoney.damsel.domain.InvoicePaymentCaptured; @@ -27,34 +28,34 @@ import java.util.UUID; @Slf4j @Service @RequiredArgsConstructor -public class CashRegService { +public class CashregService { @Setter - @Value("${client.cash-reg.enabled}") + @Value("${client.cashreg.enabled}") private boolean isReceiptsSendingEnabled; private final CartTransformer cartTransformer; private final EmailExtractor emailExtractor; - private final ManagementSrv.Iface cashRegClient; + private final ManagementSrv.Iface cashregClient; - public void send(CashRegParams... receipts) { + public void send(ReceiptParams... receipts) { if (!isReceiptsSendingEnabled) { - log.debug("Sending receipts to cashReg is disabled!"); + log.debug("Sending receipts to cashreg is disabled!"); return; } - for (CashRegParams receipt : receipts) { + for (ReceiptParams receipt : receipts) { try { - log.debug("Sending receipt={} to cashReg...", receipt); - cashRegClient.create(receipt); + log.debug("Sending receipt={} to cashreg...", receipt); + cashregClient.create(receipt); } catch (TException e) { - log.error("CashRegClient exception for receipt={}: ", receipt, e); + log.error("CashregClient exception for receipt={}: ", receipt, e); } } } - public CashRegParams debitForInvoice( - String providerId, + public ReceiptParams debitForInvoice( + List cashRegisters, Invoice aggregate) { log.debug("Creating new DEBIT receipt for invoice..."); @@ -62,15 +63,15 @@ public class CashRegService { List items = cartTransformer.transform(aggregate.getInvoice().getDetails().getCart()); return receipt( - providerId, + cashRegisters, aggregate, Type.debit(new Debit()), cash, items); } - public CashRegParams debitForPartialCapture( - String providerId, + public ReceiptParams debitForPartialCapture( + List cashRegisters, Invoice aggregate, InvoicePaymentCaptured capturedPayment) { log.debug("Creating new DEBIT receipt for partial capture..."); @@ -79,15 +80,15 @@ public class CashRegService { List items = cartTransformer.transform(capturedPayment.getCart()); return receipt( - providerId, + cashRegisters, aggregate, Type.debit(new Debit()), cash, items); } - public CashRegParams debitForPartialRefund( - String providerId, + public ReceiptParams debitForPartialRefund( + List cashRegisters, Invoice aggregate, InvoicePaymentRefund refund) { log.debug("Creating new DEBIT receipt for partial refund..."); @@ -96,15 +97,15 @@ public class CashRegService { List items = cartTransformer.transform(refund.getCart()); return receipt( - providerId, + cashRegisters, aggregate, Type.debit(new Debit()), cash, items); } - public CashRegParams refundDebitForInvoice( - String providerId, + public ReceiptParams refundDebitForInvoice( + List cashRegisters, Invoice aggregate) { log.debug("Creating new REFUND_DEBIT receipt for invoice..."); @@ -112,15 +113,15 @@ public class CashRegService { List items = cartTransformer.transform(aggregate.getInvoice().getDetails().getCart()); return receipt( - providerId, + cashRegisters, aggregate, Type.refund_debit(new RefundDebit()), cash, items); } - public CashRegParams refundDebitForPreviousPartialRefund( - String providerId, + public ReceiptParams refundDebitForPreviousPartialRefund( + List cashRegisters, Invoice aggregate, InvoicePaymentRefund refund) { log.debug("Creating new REFUND_DEBIT receipt for previous partial refund..."); @@ -129,15 +130,15 @@ public class CashRegService { List items = cartTransformer.transform(refund.getCart()); return receipt( - providerId, + cashRegisters, aggregate, Type.refund_debit(new RefundDebit()), cash, items); } - private CashRegParams receipt( - String providerId, + private ReceiptParams receipt( + List cashRegisters, Invoice aggregate, Type type, Cash cash, @@ -151,12 +152,12 @@ public class CashRegService { String shopId = invoice.getShopId(); String email = emailExtractor.extract(payments); - CashRegParams receipt = new CashRegParams() - .setCashregId(id) - .setCashregProviderId(providerId) + ReceiptParams receipt = new ReceiptParams() + .setReceiptId(id) .setPartyId(partyId) .setShopId(shopId) .setType(type) + .setProviders(List.of()) // TODO [a.romanov]: map .setPaymentInfo( new PaymentInfo() .setEmail(email) @@ -188,7 +189,7 @@ public class CashRegService { .getCart() .getLines() .stream() - .mapToLong(line -> line.getPrice().getAmount()) + .mapToLong(item -> item.getPrice().getAmount()) .sum(); return new Cash(amount, currency); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 932afa0..5b17607 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -37,7 +37,7 @@ info: version: @project.version@ client: - cash-reg: + cashreg: enabled: true url: http://changeit:8080 timeout: 5000 diff --git a/src/test/java/com/rbkmoney/cashier/IntegrationTestWithNoKafka.java b/src/test/java/com/rbkmoney/cashier/IntegrationTestWithNoKafka.java index 8de5315..3253c2e 100644 --- a/src/test/java/com/rbkmoney/cashier/IntegrationTestWithNoKafka.java +++ b/src/test/java/com/rbkmoney/cashier/IntegrationTestWithNoKafka.java @@ -3,8 +3,7 @@ package com.rbkmoney.cashier; import com.rbkmoney.cashier.handler.EventsHandler; import com.rbkmoney.cashier.repository.CashRegisterRepository; import com.rbkmoney.cashier.repository.InvoiceAggregateRepository; -import com.rbkmoney.cashier.repository.ProviderRepository; -import com.rbkmoney.damsel.cashreg_processing.ManagementSrv; +import com.rbkmoney.damsel.cashreg.processing.ManagementSrv; import com.rbkmoney.damsel.domain.*; import com.rbkmoney.damsel.payment_processing.Invoice; import com.rbkmoney.damsel.payment_processing.InvoicePayment; @@ -50,14 +49,11 @@ public class IntegrationTestWithNoKafka { @MockBean private InvoiceAggregateRepository invoiceAggregateRepository; - @MockBean - private ProviderRepository providerRepository; - @MockBean private CashRegisterRepository cashRegisterRepository; @MockBean - private ManagementSrv.Iface cashRegClient; + private ManagementSrv.Iface cashregClient; public static class Initializer implements ApplicationContextInitializer { @@ -93,15 +89,15 @@ public class IntegrationTestWithNoKafka { when(invoiceAggregateRepository.findByInvoiceIdAndEventId("invoiceId", 0L)) .thenReturn(aggregate); - when(providerRepository.findBy()) - .thenReturn("providerId"); + when(cashRegisterRepository.findByPartyIdAndShopId(anyString(), anyString())) + .thenReturn(List.of()); } @Test public void shouldSendReceiptsToCashReg() throws TException { eventsHandler.handle(List.of(machineEvent())); - verify(cashRegClient, times(7)) + verify(cashregClient, times(7)) .create(any()); } diff --git a/src/test/java/com/rbkmoney/cashier/handler/events/RefundSucceededHandlerTest.java b/src/test/java/com/rbkmoney/cashier/handler/events/RefundSucceededHandlerTest.java index 7b65e24..27ae95f 100644 --- a/src/test/java/com/rbkmoney/cashier/handler/events/RefundSucceededHandlerTest.java +++ b/src/test/java/com/rbkmoney/cashier/handler/events/RefundSucceededHandlerTest.java @@ -1,10 +1,10 @@ package com.rbkmoney.cashier.handler.events; import com.rbkmoney.cashier.domain.InvoiceChangeWithMetadata; +import com.rbkmoney.cashier.repository.CashRegisterRepository; import com.rbkmoney.cashier.repository.InvoiceAggregateRepository; -import com.rbkmoney.cashier.repository.ProviderRepository; -import com.rbkmoney.cashier.service.CashRegService; -import com.rbkmoney.damsel.cashreg_processing.CashRegParams; +import com.rbkmoney.cashier.service.CashregService; +import com.rbkmoney.damsel.cashreg.processing.ReceiptParams; import com.rbkmoney.damsel.domain.InvoiceCart; import com.rbkmoney.damsel.domain.InvoicePaymentRefundStatus; import com.rbkmoney.damsel.domain.InvoicePaymentRefundSucceeded; @@ -19,24 +19,24 @@ import static org.mockito.Mockito.*; public class RefundSucceededHandlerTest { private InvoiceAggregateRepository invoiceAggregateRepository; - private CashRegService cashRegService; + private CashregService cashregService; private RefundSucceededHandler handler; @Before public void setUp() { invoiceAggregateRepository = mock(InvoiceAggregateRepository.class); - cashRegService = mock(CashRegService.class); - ProviderRepository providerRepository = mock(ProviderRepository.class); + cashregService = mock(CashregService.class); + CashRegisterRepository cashRegisterRepository = mock(CashRegisterRepository.class); - when(providerRepository.findBy()) - .thenReturn("providerId"); + when(cashRegisterRepository.findByPartyIdAndShopId(anyString(), anyString())) + .thenReturn(List.of()); handler = new RefundSucceededHandler( "", invoiceAggregateRepository, - providerRepository, - cashRegService); + cashRegisterRepository, + cashregService); } @Test @@ -69,9 +69,9 @@ public class RefundSucceededHandlerTest { handler.handle(invoiceChangeWithMetadata); // Then - verify(cashRegService, times(1)) + verify(cashregService, times(1)) .refundDebitForInvoice(any(), any()); - verify(cashRegService, times(1)) + verify(cashregService, times(1)) .send(any()); } @@ -105,8 +105,8 @@ public class RefundSucceededHandlerTest { .setRefund(new com.rbkmoney.damsel.domain.InvoicePaymentRefund() .setId("refundId")))))); - when(cashRegService.refundDebitForPreviousPartialRefund(any(), any(), any())) - .thenReturn(new CashRegParams()); + when(cashregService.refundDebitForPreviousPartialRefund(any(), any(), any())) + .thenReturn(new ReceiptParams()); when(invoiceAggregateRepository.findByInvoiceIdAndEventId("invoiceId", 0L)) .thenReturn(aggregate); @@ -114,9 +114,9 @@ public class RefundSucceededHandlerTest { handler.handle(invoiceChangeWithMetadata); // Then - verify(cashRegService, times(1)) + verify(cashregService, times(1)) .refundDebitForPreviousPartialRefund(any(), any(), any()); - verify(cashRegService, times(1)) + verify(cashregService, times(1)) .send(any()); } @@ -151,11 +151,11 @@ public class RefundSucceededHandlerTest { handler.handle(invoiceChangeWithMetadata); // Then - verify(cashRegService, times(1)) + verify(cashregService, times(1)) .refundDebitForInvoice(any(), any()); - verify(cashRegService, times(1)) + verify(cashregService, times(1)) .debitForPartialRefund(any(), any(), any()); - verify(cashRegService, times(2)) + verify(cashregService, times(2)) .send(any()); } } \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/cashier/service/CartTransformerTest.java b/src/test/java/com/rbkmoney/cashier/service/CartTransformerTest.java index ae420f1..7e5aadf 100644 --- a/src/test/java/com/rbkmoney/cashier/service/CartTransformerTest.java +++ b/src/test/java/com/rbkmoney/cashier/service/CartTransformerTest.java @@ -1,6 +1,6 @@ package com.rbkmoney.cashier.service; -import com.rbkmoney.damsel.cashreg.ItemsLine; +import com.rbkmoney.damsel.cashreg.receipt.ItemsLine; import com.rbkmoney.damsel.domain.Cash; import com.rbkmoney.damsel.domain.CurrencyRef; import com.rbkmoney.damsel.domain.InvoiceCart; diff --git a/src/test/java/com/rbkmoney/cashier/service/CashRegServiceTest.java b/src/test/java/com/rbkmoney/cashier/service/CashregServiceTest.java similarity index 89% rename from src/test/java/com/rbkmoney/cashier/service/CashRegServiceTest.java rename to src/test/java/com/rbkmoney/cashier/service/CashregServiceTest.java index 8396165..64b45df 100644 --- a/src/test/java/com/rbkmoney/cashier/service/CashRegServiceTest.java +++ b/src/test/java/com/rbkmoney/cashier/service/CashregServiceTest.java @@ -1,11 +1,11 @@ package com.rbkmoney.cashier.service; -import com.rbkmoney.damsel.cashreg.ItemsLine; -import com.rbkmoney.damsel.cashreg.type.Debit; -import com.rbkmoney.damsel.cashreg.type.RefundDebit; -import com.rbkmoney.damsel.cashreg.type.Type; -import com.rbkmoney.damsel.cashreg_processing.CashRegParams; -import com.rbkmoney.damsel.cashreg_processing.ManagementSrv; +import com.rbkmoney.damsel.cashreg.processing.ManagementSrv; +import com.rbkmoney.damsel.cashreg.processing.ReceiptParams; +import com.rbkmoney.damsel.cashreg.receipt.ItemsLine; +import com.rbkmoney.damsel.cashreg.receipt.type.Debit; +import com.rbkmoney.damsel.cashreg.receipt.type.RefundDebit; +import com.rbkmoney.damsel.cashreg.receipt.type.Type; import com.rbkmoney.damsel.domain.*; import com.rbkmoney.damsel.payment_processing.Invoice; import com.rbkmoney.damsel.payment_processing.InvoicePayment; @@ -24,21 +24,21 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) -public class CashRegServiceTest { +public class CashregServiceTest { @Mock private CartTransformer cartTransformer; @Mock private EmailExtractor emailExtractor; @Mock - private ManagementSrv.Iface cashRegClient; + private ManagementSrv.Iface cashregClient; @InjectMocks - private CashRegService cashRegService; + private CashregService cashregService; @Before public void setUp() { - cashRegService.setReceiptsSendingEnabled(true); + cashregService.setReceiptsSendingEnabled(true); when(cartTransformer.transform(any())) .thenReturn(List.of(new ItemsLine())); @@ -49,13 +49,13 @@ public class CashRegServiceTest { @Test public void shouldSendReceipts() throws TException { // Given - When - cashRegService.send( - new CashRegParams(), - new CashRegParams(), - new CashRegParams()); + cashregService.send( + new ReceiptParams(), + new ReceiptParams(), + new ReceiptParams()); // Then - verify(cashRegClient, times(3)) + verify(cashregClient, times(3)) .create(any()); } @@ -78,8 +78,8 @@ public class CashRegServiceTest { .setId("paymentId")))); // When - CashRegParams receipt = cashRegService.debitForInvoice( - "providerId", + ReceiptParams receipt = cashregService.debitForInvoice( + List.of(), aggregate); // Then @@ -118,8 +118,8 @@ public class CashRegServiceTest { .setSymbolicCode("RUB"))); // When - CashRegParams receipt = cashRegService.debitForPartialCapture( - "providerId", + ReceiptParams receipt = cashregService.debitForPartialCapture( + List.of(), aggregate, capturedPayment); @@ -164,8 +164,8 @@ public class CashRegServiceTest { .setSymbolicCode("RUB"))); // When - CashRegParams receipt = cashRegService.debitForPartialRefund( - "providerId", + ReceiptParams receipt = cashregService.debitForPartialRefund( + List.of(), aggregate, refund); @@ -198,8 +198,8 @@ public class CashRegServiceTest { .setId("paymentId")))); // When - CashRegParams receipt = cashRegService.refundDebitForInvoice( - "providerId", + ReceiptParams receipt = cashregService.refundDebitForInvoice( + List.of(), aggregate); // Then @@ -243,8 +243,8 @@ public class CashRegServiceTest { .setSymbolicCode("RUB"))); // When - CashRegParams receipt = cashRegService.refundDebitForPreviousPartialRefund( - "providerId", + ReceiptParams receipt = cashregService.refundDebitForPreviousPartialRefund( + List.of(), aggregate, refund);