mirror of
https://github.com/valitydev/cashier.git
synced 2024-11-06 09:55:17 +00:00
BJ-852: Update cashreg integration
This commit is contained in:
parent
f977fd0192
commit
cae834b861
4
pom.xml
4
pom.xml
@ -26,9 +26,9 @@
|
||||
<java.version>11</java.version>
|
||||
<exposed.ports>${server.port}</exposed.ports>
|
||||
<geck.version>0.6.4</geck.version>
|
||||
<damsel.version>1.395-dca168e</damsel.version>
|
||||
<damsel.version>1.399-dfc81d0</damsel.version>
|
||||
<fistful-proto.version>1.36-683822a</fistful-proto.version>
|
||||
<cashreg-proto.version>1.9-9c79023</cashreg-proto.version>
|
||||
<cashreg-proto.version>1.13-f4f401b</cashreg-proto.version>
|
||||
<spring.kafka.version>2.2.3.RELEASE</spring.kafka.version>
|
||||
</properties>
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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<CashRegister> cashRegisters = cashRegisterRepository.findByPartyIdAndShopId(
|
||||
aggregate.getInvoice().getOwnerId(),
|
||||
aggregate.getInvoice().getShopId());
|
||||
|
||||
CashRegParams refundDebitForInvoice = cashRegService.refundDebitForInvoice(
|
||||
providerId,
|
||||
ReceiptParams refundDebitForInvoice = cashRegService.refundDebitForInvoice(
|
||||
cashRegisters,
|
||||
aggregate);
|
||||
|
||||
cashRegService.send(refundDebitForInvoice);
|
||||
|
@ -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<CashRegister> 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);
|
||||
|
||||
|
@ -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<CashRegister> cashRegisters = cashRegisterRepository.findByPartyIdAndShopId(
|
||||
aggregate.getInvoice().getOwnerId(),
|
||||
aggregate.getInvoice().getShopId());
|
||||
|
||||
CashRegParams refundDebitForInvoice = cashRegService.refundDebitForInvoice(
|
||||
providerId,
|
||||
ReceiptParams refundDebitForInvoice = cashRegService.refundDebitForInvoice(
|
||||
cashRegisters,
|
||||
aggregate);
|
||||
|
||||
cashRegService.send(refundDebitForInvoice);
|
||||
|
@ -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<CashRegister> cashRegisters = cashRegisterRepository.findByPartyIdAndShopId(
|
||||
aggregate.getInvoice().getOwnerId(),
|
||||
aggregate.getInvoice().getShopId());
|
||||
|
||||
CashRegParams debitForInvoice = cashRegService.debitForInvoice(
|
||||
providerId,
|
||||
ReceiptParams debitForInvoice = cashRegService.debitForInvoice(
|
||||
cashRegisters,
|
||||
aggregate);
|
||||
|
||||
cashRegService.send(debitForInvoice);
|
||||
|
@ -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<CashRegister> 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<CashRegParams> refundDebitForPreviousPartialRefund(
|
||||
String providerId,
|
||||
private Optional<ReceiptParams> refundDebitForPreviousPartialRefund(
|
||||
List<CashRegister> 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()));
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<CashRegister> cashRegisters,
|
||||
Invoice aggregate) {
|
||||
log.debug("Creating new DEBIT receipt for invoice...");
|
||||
|
||||
@ -62,15 +63,15 @@ public class CashRegService {
|
||||
List<ItemsLine> 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<CashRegister> cashRegisters,
|
||||
Invoice aggregate,
|
||||
InvoicePaymentCaptured capturedPayment) {
|
||||
log.debug("Creating new DEBIT receipt for partial capture...");
|
||||
@ -79,15 +80,15 @@ public class CashRegService {
|
||||
List<ItemsLine> 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<CashRegister> cashRegisters,
|
||||
Invoice aggregate,
|
||||
InvoicePaymentRefund refund) {
|
||||
log.debug("Creating new DEBIT receipt for partial refund...");
|
||||
@ -96,15 +97,15 @@ public class CashRegService {
|
||||
List<ItemsLine> 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<CashRegister> cashRegisters,
|
||||
Invoice aggregate) {
|
||||
log.debug("Creating new REFUND_DEBIT receipt for invoice...");
|
||||
|
||||
@ -112,15 +113,15 @@ public class CashRegService {
|
||||
List<ItemsLine> 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<CashRegister> cashRegisters,
|
||||
Invoice aggregate,
|
||||
InvoicePaymentRefund refund) {
|
||||
log.debug("Creating new REFUND_DEBIT receipt for previous partial refund...");
|
||||
@ -129,15 +130,15 @@ public class CashRegService {
|
||||
List<ItemsLine> 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<CashRegister> 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);
|
@ -37,7 +37,7 @@ info:
|
||||
version: @project.version@
|
||||
|
||||
client:
|
||||
cash-reg:
|
||||
cashreg:
|
||||
enabled: true
|
||||
url: http://changeit:8080
|
||||
timeout: 5000
|
||||
|
@ -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<ConfigurableApplicationContext> {
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user