mirror of
https://github.com/valitydev/hooker.git
synced 2024-11-06 00:05:17 +00:00
JD-169 bump damsel (#141)
* JD-169 bump damsel * JD-169 bump damsel Co-authored-by: ElenaKushchenko <e.kushchenko@rbkmoney.com>
This commit is contained in:
parent
aeffeedb13
commit
c31b6440bd
21
Jenkinsfile
vendored
21
Jenkinsfile
vendored
@ -1,18 +1,17 @@
|
||||
#!groovy
|
||||
build('hooker', 'java-maven') {
|
||||
checkoutRepo()
|
||||
loadBuildUtils()
|
||||
loadBuildUtils()
|
||||
|
||||
def javaServicePipeline
|
||||
runStage('load JavaService pipeline') {
|
||||
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaService.groovy")
|
||||
}
|
||||
def javaServicePipeline
|
||||
runStage('load JavaService pipeline') {
|
||||
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaService.groovy")
|
||||
}
|
||||
|
||||
def serviceName = env.REPO_NAME
|
||||
def mvnArgs = '-DjvmArgs="-Xmx256m"'
|
||||
def useJava11 = true
|
||||
def registry = 'dr2.rbkmoney.com'
|
||||
def registryCredsId = 'jenkins_harbor'
|
||||
def serviceName = env.REPO_NAME
|
||||
def mvnArgs = '-DjvmArgs="-Xmx256m"'
|
||||
def useJava11 = true
|
||||
def registry = 'dr2.rbkmoney.com'
|
||||
|
||||
javaServicePipeline(serviceName, useJava11, mvnArgs)
|
||||
javaServicePipeline(serviceName, useJava11, mvnArgs)
|
||||
}
|
||||
|
13
README.md
13
README.md
@ -1,16 +1,19 @@
|
||||
# webhooker (hooker)
|
||||
|
||||
Сервис вебхуков
|
||||
|
||||
[![Build Status](http://ci.rbkmoney.com/buildStatus/icon?job=rbkmoney_private/hooker/master)](http://ci.rbkmoney.com/job/rbkmoney_private/job/hooker/job/master/)
|
||||
|
||||
1. Сервис предоставляет интерфейс для CAPI для создания, удаления вебхуков, установки/редактирования опций вебхука (таких как url, public/private keys - они генерируются сервисом, типы событий).
|
||||
1. Сервис предоставляет интерфейс для CAPI для создания, удаления вебхуков, установки/редактирования опций вебхука (
|
||||
таких как url, public/private keys - они генерируются сервисом, типы событий).
|
||||
2. Сервис поллит bustermaze на появление событий, по которым должны отправляться сообщения мерчантам
|
||||
|
||||
Интерфейс для capi доступен по пути /hook
|
||||
|
||||
Для более подробного ознакомления со структурой объектов можно воспользоваться ссылкой на сам объект [webhooker.thrift][1]
|
||||
Для более подробного ознакомления со структурой объектов можно воспользоваться ссылкой на сам
|
||||
объект [webhooker.thrift][1]
|
||||
|
||||
Подробная информация по протоколу отправки сообщений мерчантам описана в [swagger-спецификации][2]
|
||||
Подробная информация по протоколу отправки сообщений мерчантам описана в [swagger-спецификации][2]
|
||||
|
||||
#### Пример запроса к мерчанту
|
||||
|
||||
@ -22,7 +25,9 @@ curl -v -X POST
|
||||
' https://{host}:{port}/{path}
|
||||
```
|
||||
|
||||
Мерчант, используя публичный ключ и имея в распоряжении тело запроса, подпись, алгоритм подписи и хэширования, может произвести проверку подписи
|
||||
Мерчант, используя публичный ключ и имея в распоряжении тело запроса, подпись, алгоритм подписи и хэширования, может
|
||||
произвести проверку подписи
|
||||
|
||||
[1]: https://github.com/rbkmoney/damsel/blob/master/proto/webhooker.thrift
|
||||
|
||||
[2]: https://github.com/rbkmoney/swag-webhook-events/blob/master/spec/swagger.yaml
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 29cb2775d05d9c18c3aa74a629459cde84a2d42e
|
||||
Subproject commit 56606f5cacec1c30ca11088c575e9c285f1f2f40
|
16
pom.xml
16
pom.xml
@ -12,8 +12,8 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.8</version>
|
||||
<artifactId>service-parent-pom</artifactId>
|
||||
<version>1.0.9</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@ -24,8 +24,6 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<dockerfile.base.service.tag>c0612d6052ac049496b72a23a04acb142035f249</dockerfile.base.service.tag>
|
||||
<dockerfile.registry>${env.REGISTRY}</dockerfile.registry>
|
||||
<damsel.version>1.475-bde841f</damsel.version>
|
||||
<shared.resources.version>0.3.8</shared.resources.version>
|
||||
|
||||
<db.host.name>localhost</db.host.name>
|
||||
<db.host.port>5432</db.host.port>
|
||||
@ -35,8 +33,7 @@
|
||||
<db.password>postgres</db.password>
|
||||
<db.schema>hook</db.schema>
|
||||
|
||||
<geck.version>0.6.11</geck.version>
|
||||
<testcontainers.version>1.14.3</testcontainers.version>
|
||||
<testcontainers.version>1.15.0</testcontainers.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -105,12 +102,10 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney.geck</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>${geck.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney.geck</groupId>
|
||||
<artifactId>filter</artifactId>
|
||||
<version>${geck.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
@ -168,7 +163,6 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>damsel</artifactId>
|
||||
<version>${damsel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
@ -183,7 +177,6 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>shared-resources</artifactId>
|
||||
<version>${shared.resources.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney.geck</groupId>
|
||||
@ -198,7 +191,6 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>custom-metrics-spring-boot-starter</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
@ -322,7 +314,7 @@
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<resourceBundles>
|
||||
<resourceBundle>com.rbkmoney:shared-resources:${shared.resources.version}</resourceBundle>
|
||||
<resourceBundle>com.rbkmoney:shared-resources:${shared-resources.version}</resourceBundle>
|
||||
</resourceBundles>
|
||||
<attachToMain>false</attachToMain>
|
||||
<attachToTest>false</attachToTest>
|
||||
|
@ -13,11 +13,17 @@ import com.rbkmoney.hooker.dao.impl.CustomerQueueDao;
|
||||
import com.rbkmoney.hooker.dao.impl.CustomerTaskDao;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingQueueDao;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingTaskDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.CustomerMessage;
|
||||
import com.rbkmoney.hooker.model.CustomerQueue;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingQueue;
|
||||
import com.rbkmoney.hooker.retry.RetryPoliciesService;
|
||||
import com.rbkmoney.hooker.scheduler.MessageScheduler;
|
||||
import com.rbkmoney.hooker.scheduler.MessageSender;
|
||||
import com.rbkmoney.hooker.service.*;
|
||||
import com.rbkmoney.hooker.service.CustomerEventService;
|
||||
import com.rbkmoney.hooker.service.FaultDetectorService;
|
||||
import com.rbkmoney.hooker.service.InvoicingEventService;
|
||||
import com.rbkmoney.hooker.service.MessageProcessor;
|
||||
import com.rbkmoney.hooker.service.crypt.Signer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -52,54 +58,48 @@ public class AppConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageSender<InvoicingMessage, InvoicingQueue> invoicngMessageSender(Signer signer,
|
||||
InvoicingEventService eventService,
|
||||
ObjectMapper objectMapper,
|
||||
FaultDetectorService faultDetector) {
|
||||
public MessageSender<InvoicingMessage, InvoicingQueue> invoicngMessageSender(
|
||||
Signer signer, InvoicingEventService eventService,
|
||||
ObjectMapper objectMapper, FaultDetectorService faultDetector) {
|
||||
return new MessageSender<>(invoicingThreadPoolSize, timeout, signer, eventService, objectMapper, faultDetector);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageSender<CustomerMessage, CustomerQueue> customerMessageSender(Signer signer,
|
||||
CustomerEventService eventService,
|
||||
ObjectMapper objectMapper,
|
||||
FaultDetectorService faultDetector) {
|
||||
public MessageSender<CustomerMessage, CustomerQueue> customerMessageSender(
|
||||
Signer signer, CustomerEventService eventService,
|
||||
ObjectMapper objectMapper, FaultDetectorService faultDetector) {
|
||||
return new MessageSender<>(customerThreadPoolSize, timeout, signer, eventService, objectMapper, faultDetector);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageProcessor<InvoicingMessage, InvoicingQueue> invoicingMessageProcessor(HookDao hookDao,
|
||||
InvoicingTaskDao taskDao,
|
||||
InvoicingQueueDao queueDao,
|
||||
InvoicingMessageDao messageDao,
|
||||
RetryPoliciesService retryPoliciesService,
|
||||
TransactionTemplate transactionTemplate,
|
||||
FaultDetectorService faultDetector,
|
||||
MessageSender<InvoicingMessage, InvoicingQueue> invoicngMessageSender) {
|
||||
return new MessageProcessor<>(hookDao, taskDao, queueDao, messageDao, retryPoliciesService, transactionTemplate, faultDetector, invoicngMessageSender);
|
||||
public MessageProcessor<InvoicingMessage, InvoicingQueue> invoicingMessageProcessor(
|
||||
HookDao hookDao, InvoicingTaskDao taskDao, InvoicingQueueDao queueDao, InvoicingMessageDao messageDao,
|
||||
RetryPoliciesService retryPoliciesService, TransactionTemplate transactionTemplate,
|
||||
FaultDetectorService faultDetector, MessageSender<InvoicingMessage, InvoicingQueue> invoicngMessageSender) {
|
||||
return new MessageProcessor<>(hookDao, taskDao, queueDao, messageDao, retryPoliciesService, transactionTemplate,
|
||||
faultDetector, invoicngMessageSender);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageProcessor<CustomerMessage, CustomerQueue> customerMessageProcessor(HookDao hookDao,
|
||||
CustomerTaskDao taskDao,
|
||||
CustomerQueueDao queueDao,
|
||||
CustomerDao messageDao,
|
||||
RetryPoliciesService retryPoliciesService,
|
||||
TransactionTemplate transactionTemplate,
|
||||
FaultDetectorService faultDetector,
|
||||
MessageSender<CustomerMessage, CustomerQueue> customerMessageSender) {
|
||||
return new MessageProcessor<>(hookDao, taskDao, queueDao, messageDao, retryPoliciesService, transactionTemplate, faultDetector, customerMessageSender);
|
||||
public MessageProcessor<CustomerMessage, CustomerQueue> customerMessageProcessor(
|
||||
HookDao hookDao, CustomerTaskDao taskDao, CustomerQueueDao queueDao, CustomerDao messageDao,
|
||||
RetryPoliciesService retryPoliciesService, TransactionTemplate transactionTemplate,
|
||||
FaultDetectorService faultDetector, MessageSender<CustomerMessage, CustomerQueue> customerMessageSender) {
|
||||
return new MessageProcessor<>(hookDao, taskDao, queueDao, messageDao, retryPoliciesService, transactionTemplate,
|
||||
faultDetector, customerMessageSender);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageScheduler<InvoicingMessage, InvoicingQueue> invoicingMessageScheduler(MessageProcessor<InvoicingMessage, InvoicingQueue> invoicingMessageProcessor,
|
||||
ThreadPoolTaskScheduler taskScheduler) {
|
||||
public MessageScheduler<InvoicingMessage, InvoicingQueue> invoicingMessageScheduler(
|
||||
MessageProcessor<InvoicingMessage, InvoicingQueue> invoicingMessageProcessor,
|
||||
ThreadPoolTaskScheduler taskScheduler) {
|
||||
return new MessageScheduler<>(invoicingThreadPoolSize, delayMillis, invoicingMessageProcessor, taskScheduler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageScheduler<CustomerMessage, CustomerQueue> cuustomerMessageScheduler(MessageProcessor<CustomerMessage, CustomerQueue> customerMessageProcessor,
|
||||
ThreadPoolTaskScheduler taskScheduler) {
|
||||
public MessageScheduler<CustomerMessage, CustomerQueue> cuustomerMessageScheduler(
|
||||
MessageProcessor<CustomerMessage, CustomerQueue> customerMessageProcessor,
|
||||
ThreadPoolTaskScheduler taskScheduler) {
|
||||
return new MessageScheduler<>(customerThreadPoolSize, delayMillis, customerMessageProcessor, taskScheduler);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class CacheConfig {
|
||||
|
||||
@Bean
|
||||
public Cache<InvoicingMessageKey, InvoicingMessage> invoiceDataCache(@Value("${cache.invoice.size}") int cacheSize) {
|
||||
public Cache<InvoicingMessageKey, InvoicingMessage> invoiceDataCache(
|
||||
@Value("${cache.invoice.size}") int cacheSize) {
|
||||
return Caffeine.newBuilder()
|
||||
.maximumSize(cacheSize)
|
||||
.build();
|
||||
|
@ -14,7 +14,8 @@ public class FaultDetectorConfig {
|
||||
|
||||
@Bean
|
||||
public FaultDetectorSrv.Iface faultDetectorClient(@Value("${service.fault-detector.url}") Resource resource,
|
||||
@Value("${service.fault-detector.networkTimeout}") int networkTimeout) throws IOException {
|
||||
@Value("${service.fault-detector.networkTimeout}")
|
||||
int networkTimeout) throws IOException {
|
||||
|
||||
return new THSpawnClientBuilder()
|
||||
.withNetworkTimeout(networkTimeout)
|
||||
|
@ -17,7 +17,8 @@ import java.util.List;
|
||||
public class HgConfig {
|
||||
@Bean
|
||||
public InvoicingSrv.Iface invoicingClient(@Value("${service.invoicing.url}") Resource resource,
|
||||
@Value("${service.invoicing.networkTimeout}") int networkTimeout) throws IOException {
|
||||
@Value("${service.invoicing.networkTimeout}") int networkTimeout)
|
||||
throws IOException {
|
||||
return new THSpawnClientBuilder()
|
||||
.withNetworkTimeout(networkTimeout)
|
||||
.withAddress(resource.getURI()).build(InvoicingSrv.Iface.class);
|
||||
@ -25,7 +26,8 @@ public class HgConfig {
|
||||
|
||||
@Bean
|
||||
public CustomerManagementSrv.Iface customerClient(@Value("${service.customer.url}") Resource resource,
|
||||
@Value("${service.customer.networkTimeout}") int networkTimeout) throws IOException {
|
||||
@Value("${service.customer.networkTimeout}") int networkTimeout)
|
||||
throws IOException {
|
||||
return new THSpawnClientBuilder()
|
||||
.withMetaExtensions(List.of(
|
||||
UserIdentityIdExtensionKit.INSTANCE,
|
||||
|
@ -79,11 +79,13 @@ public class KafkaConfig {
|
||||
private void configureSsl(Map<String, Object> props) {
|
||||
if (kafkaSslProperties.isEnabled()) {
|
||||
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, SecurityProtocol.SSL.name());
|
||||
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, new File(kafkaSslProperties.getTrustStoreLocation()).getAbsolutePath());
|
||||
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG,
|
||||
new File(kafkaSslProperties.getTrustStoreLocation()).getAbsolutePath());
|
||||
props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, kafkaSslProperties.getTrustStorePassword());
|
||||
props.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, kafkaSslProperties.getKeyStoreType());
|
||||
props.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, kafkaSslProperties.getTrustStoreType());
|
||||
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, new File(kafkaSslProperties.getKeyStoreLocation()).getAbsolutePath());
|
||||
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG,
|
||||
new File(kafkaSslProperties.getKeyStoreLocation()).getAbsolutePath());
|
||||
props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, kafkaSslProperties.getKeyStorePassword());
|
||||
props.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, kafkaSslProperties.getKeyPassword());
|
||||
}
|
||||
@ -95,10 +97,12 @@ public class KafkaConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("LineLength")
|
||||
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, MachineEvent>> kafkaListenerContainerFactory(
|
||||
ConsumerFactory<String, MachineEvent> consumerFactory
|
||||
) {
|
||||
ConcurrentKafkaListenerContainerFactory<String, MachineEvent> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
ConcurrentKafkaListenerContainerFactory<String, MachineEvent> factory =
|
||||
new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory);
|
||||
factory.setBatchListener(true);
|
||||
factory.getContainerProperties().setAckOnError(false);
|
||||
@ -109,10 +113,12 @@ public class KafkaConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("LineLength")
|
||||
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, MachineEvent>> customerListenerContainerFactory(
|
||||
ConsumerFactory<String, MachineEvent> consumerFactory
|
||||
) {
|
||||
ConcurrentKafkaListenerContainerFactory<String, MachineEvent> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
ConcurrentKafkaListenerContainerFactory<String, MachineEvent> factory =
|
||||
new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory);
|
||||
factory.setBatchListener(false);
|
||||
factory.getContainerProperties().setAckOnError(false);
|
||||
|
@ -12,20 +12,24 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerBindingConverter implements Converter<com.rbkmoney.damsel.payment_processing.CustomerBinding, CustomerBinding> {
|
||||
public class CustomerBindingConverter
|
||||
implements Converter<com.rbkmoney.damsel.payment_processing.CustomerBinding, CustomerBinding> {
|
||||
|
||||
@Override
|
||||
public CustomerBinding convert(com.rbkmoney.damsel.payment_processing.CustomerBinding source) {
|
||||
DisposablePaymentResource paymentResource = source.getPaymentResource();
|
||||
return new CustomerBinding()
|
||||
.status(CustomerBinding.StatusEnum.fromValue(source.getStatus().getSetField().getFieldName()))
|
||||
.error(source.getStatus().isSetFailed() ? ErrorUtils.getCustomerBindingError(source.getStatus().getFailed().getFailure()) : null)
|
||||
.error(source.getStatus().isSetFailed()
|
||||
? ErrorUtils.getCustomerBindingError(source.getStatus().getFailed().getFailure()) : null)
|
||||
.id(source.getId())
|
||||
.paymentResource(new PaymentResource()
|
||||
.paymentSession(paymentResource.getPaymentSessionId())
|
||||
.clientInfo(new ClientInfo()
|
||||
.ip(paymentResource.isSetClientInfo() ? paymentResource.getClientInfo().getIpAddress() : null)
|
||||
.fingerprint(paymentResource.isSetClientInfo() ? paymentResource.getClientInfo().getFingerprint() : null))
|
||||
.ip(paymentResource.isSetClientInfo()
|
||||
? paymentResource.getClientInfo().getIpAddress() : null)
|
||||
.fingerprint(paymentResource.isSetClientInfo()
|
||||
? paymentResource.getClientInfo().getFingerprint() : null))
|
||||
.paymentToolDetails(PaymentToolUtils.getPaymentToolDetails(paymentResource.getPaymentTool())));
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,10 @@ public class InvoiceConverter implements Converter<com.rbkmoney.damsel.domain.In
|
||||
.price(l.getPrice().getAmount())
|
||||
.quantity((long) l.getQuantity())
|
||||
.cost(l.getPrice().getAmount() * l.getQuantity())
|
||||
.taxMode(l.getMetadata() != null && l.getMetadata().get("TaxMode") != null ?
|
||||
new InvoiceCartLineTaxMode()
|
||||
.rate(InvoiceCartLineTaxMode.RateEnum.fromValue(l.getMetadata().get("TaxMode").getStr()))
|
||||
.taxMode(l.getMetadata() != null && l.getMetadata().get("TaxMode") != null
|
||||
? new InvoiceCartLineTaxMode()
|
||||
.rate(InvoiceCartLineTaxMode.RateEnum
|
||||
.fromValue(l.getMetadata().get("TaxMode").getStr()))
|
||||
: null))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class MetadataDeserializer {
|
||||
}
|
||||
}
|
||||
|
||||
public Object deserialize(Value value){
|
||||
public Object deserialize(Value value) {
|
||||
if (!value.isSetObj()) {
|
||||
throw new IllegalArgumentException("Wrong metadata format. It should be obj: " + value);
|
||||
}
|
||||
@ -34,7 +34,8 @@ public class MetadataDeserializer {
|
||||
|
||||
private Object deserializeValue(Value value) {
|
||||
if (value.isSetObj()) {
|
||||
return value.getObj().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> deserializeValue(e.getValue())));
|
||||
return value.getObj().entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> deserializeValue(e.getValue())));
|
||||
} else if (value.isSetArr()) {
|
||||
return value.getArr().stream().map(this::deserializeValue).collect(Collectors.toList());
|
||||
} else if (value.isSetNl()) {
|
||||
|
@ -10,7 +10,14 @@ import com.rbkmoney.hooker.utils.CashFlowUtils;
|
||||
import com.rbkmoney.hooker.utils.ErrorUtils;
|
||||
import com.rbkmoney.hooker.utils.PaymentToolUtils;
|
||||
import com.rbkmoney.hooker.utils.TimeUtils;
|
||||
import com.rbkmoney.swag_webhook_events.model.*;
|
||||
import com.rbkmoney.swag_webhook_events.model.ClientInfo;
|
||||
import com.rbkmoney.swag_webhook_events.model.ContactInfo;
|
||||
import com.rbkmoney.swag_webhook_events.model.CustomerPayer;
|
||||
import com.rbkmoney.swag_webhook_events.model.Payment;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentContactInfo;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentRecurrentParent;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentResourcePayer;
|
||||
import com.rbkmoney.swag_webhook_events.model.RecurrentPayer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -57,7 +64,8 @@ public class PaymentConverter implements Converter<InvoicePayment, Payment> {
|
||||
}
|
||||
|
||||
private Long getFee(InvoicePayment sourceWrapper) {
|
||||
return sourceWrapper.isSetCashFlow() ? CashFlowUtils.getFees(sourceWrapper.getCashFlow()).getOrDefault(FeeType.FEE, 0L) : 0L;
|
||||
return sourceWrapper.isSetCashFlow()
|
||||
? CashFlowUtils.getFees(sourceWrapper.getCashFlow()).getOrDefault(FeeType.FEE, 0L) : 0L;
|
||||
}
|
||||
|
||||
private String getRrn(InvoicePayment sourceWrapper) {
|
||||
@ -94,8 +102,10 @@ public class PaymentConverter implements Converter<InvoicePayment, Payment> {
|
||||
.email(payerOrigin.getContactInfo().getEmail())
|
||||
.phoneNumber(payerOrigin.getContactInfo().getPhoneNumber()))
|
||||
.clientInfo(new ClientInfo()
|
||||
.ip(resourceOrigin.isSetClientInfo() ? resourceOrigin.getClientInfo().getIpAddress() : null)
|
||||
.fingerprint(resourceOrigin.isSetClientInfo() ? resourceOrigin.getClientInfo().getFingerprint() : null))
|
||||
.ip(resourceOrigin.isSetClientInfo() ? resourceOrigin.getClientInfo().getIpAddress() :
|
||||
null)
|
||||
.fingerprint(resourceOrigin.isSetClientInfo()
|
||||
? resourceOrigin.getClientInfo().getFingerprint() : null))
|
||||
.paymentToolDetails(PaymentToolUtils.getPaymentToolDetails(paymentTool)));
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,11 @@ public abstract class AbstractTaskDao implements TaskDao {
|
||||
|
||||
@Override
|
||||
public void remove(long queueId, long messageId) throws DaoException {
|
||||
final String sql = "DELETE FROM hook.scheduled_task where queue_id=:queue_id and message_id=:message_id and message_type=CAST(:message_type as hook.message_topic)";
|
||||
final String sql =
|
||||
"DELETE FROM hook.scheduled_task " +
|
||||
" where queue_id=:queue_id " +
|
||||
" and message_id=:message_id " +
|
||||
" and message_type=CAST(:message_type as hook.message_topic)";
|
||||
try {
|
||||
jdbcTemplate.update(sql, new MapSqlParameterSource("queue_id", queueId)
|
||||
.addValue("message_id", messageId)
|
||||
@ -43,9 +47,11 @@ public abstract class AbstractTaskDao implements TaskDao {
|
||||
|
||||
@Override
|
||||
public void removeAll(long queueId) throws DaoException {
|
||||
final String sql = "DELETE FROM hook.scheduled_task where queue_id=:queue_id and message_type=CAST(:message_type as hook.message_topic)";
|
||||
final String sql = "DELETE FROM hook.scheduled_task " +
|
||||
"where queue_id=:queue_id and message_type=CAST(:message_type as hook.message_topic)";
|
||||
try {
|
||||
jdbcTemplate.update(sql, new MapSqlParameterSource("queue_id", queueId).addValue("message_type", getMessageTopic()));
|
||||
jdbcTemplate.update(sql,
|
||||
new MapSqlParameterSource("queue_id", queueId).addValue("message_type", getMessageTopic()));
|
||||
} catch (NestedRuntimeException e) {
|
||||
log.warn("Fail to delete tasks for hook:" + queueId, e);
|
||||
throw new DaoException(e);
|
||||
|
@ -5,7 +5,6 @@ import com.rbkmoney.hooker.model.Hook;
|
||||
import com.rbkmoney.hooker.model.PartyMetadata;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by inal on 28.11.2016.
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.rbkmoney.hooker.dao;
|
||||
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Created by inalarsanukaev on 18.04.17.
|
||||
|
@ -16,21 +16,21 @@ public class CleanTablesDao {
|
||||
|
||||
public int cleanInvocing(int daysAgo) {
|
||||
final String sql =
|
||||
" with excluded_ids as (" +
|
||||
" select queue_id from hook.scheduled_task st " +
|
||||
" where message_type = CAST(:message_type as hook.message_topic)), " +
|
||||
" ids as (" +
|
||||
" select iq.id as queue_id from hook.invoicing_queue iq \n" +
|
||||
" where iq.wtime < (now() at time zone 'utc' - (interval '1 days') * :days_ago) " +
|
||||
" and iq.id not in (select excluded_ids.queue_id from excluded_ids) " +
|
||||
" and iq.enabled), " +
|
||||
" delete_simple_retry_policy as (" +
|
||||
" delete from hook.simple_retry_policy srp " +
|
||||
" using ids where srp.queue_id = ids.queue_id " +
|
||||
" and srp.message_type = CAST(:message_type as hook.message_topic) " +
|
||||
" returning *) " +
|
||||
" delete from hook.invoicing_queue iq " +
|
||||
" using ids where iq.id = ids.queue_id;";
|
||||
" with excluded_ids as (" +
|
||||
" select queue_id from hook.scheduled_task st " +
|
||||
" where message_type = CAST(:message_type as hook.message_topic)), " +
|
||||
" ids as (" +
|
||||
" select iq.id as queue_id from hook.invoicing_queue iq \n" +
|
||||
" where iq.wtime < (now() at time zone 'utc' - (interval '1 days') * :days_ago) " +
|
||||
" and iq.id not in (select excluded_ids.queue_id from excluded_ids) " +
|
||||
" and iq.enabled), " +
|
||||
" delete_simple_retry_policy as (" +
|
||||
" delete from hook.simple_retry_policy srp " +
|
||||
" using ids where srp.queue_id = ids.queue_id " +
|
||||
" and srp.message_type = CAST(:message_type as hook.message_topic) " +
|
||||
" returning *) " +
|
||||
" delete from hook.invoicing_queue iq " +
|
||||
" using ids where iq.id = ids.queue_id;";
|
||||
try {
|
||||
return jdbcTemplate.update(sql, new MapSqlParameterSource("days_ago", daysAgo)
|
||||
.addValue("message_type", Event.TopicEnum.INVOICESTOPIC.getValue()));
|
||||
|
@ -64,7 +64,8 @@ public class CustomerDaoImpl implements CustomerDao {
|
||||
final String sql = "SELECT * FROM hook.customer_message " +
|
||||
"WHERE customer_id =:customer_id AND type=CAST(:type as hook.customer_message_type) " +
|
||||
"ORDER BY id DESC LIMIT 1";
|
||||
MapSqlParameterSource params = new MapSqlParameterSource(CUSTOMER_ID, customerId).addValue(TYPE, type.getValue());
|
||||
MapSqlParameterSource params =
|
||||
new MapSqlParameterSource(CUSTOMER_ID, customerId).addValue(TYPE, type.getValue());
|
||||
try {
|
||||
result = jdbcTemplate.queryForObject(sql, params, messageRowMapper);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
@ -127,7 +128,8 @@ public class CustomerDaoImpl implements CustomerDao {
|
||||
}
|
||||
final String sql = "SELECT * FROM hook.customer_message WHERE id in (:ids)";
|
||||
try {
|
||||
List<CustomerMessage> messagesFromDb = jdbcTemplate.query(sql, new MapSqlParameterSource("ids", messageIds), messageRowMapper);
|
||||
List<CustomerMessage> messagesFromDb =
|
||||
jdbcTemplate.query(sql, new MapSqlParameterSource("ids", messageIds), messageRowMapper);
|
||||
log.debug("messagesFromDb {}", messagesFromDb);
|
||||
return messagesFromDb;
|
||||
} catch (NestedRuntimeException e) {
|
||||
|
@ -51,10 +51,12 @@ public class CustomerQueueDao implements QueueDao<CustomerQueue> {
|
||||
" insert into hook.customer_queue(hook_id, customer_id)" +
|
||||
" select w.id, m.customer_id" +
|
||||
" from hook.customer_message m" +
|
||||
" join hook.webhook w on m.party_id = w.party_id and w.enabled and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook w on m.party_id = w.party_id " +
|
||||
" and w.enabled and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" where m.id = :id " +
|
||||
" on conflict(hook_id, customer_id) do nothing returning *) " +
|
||||
"insert into hook.simple_retry_policy(queue_id, message_type) select id, CAST(:message_type as hook.message_topic) from queue";
|
||||
" insert into hook.simple_retry_policy(queue_id, message_type) " +
|
||||
" select id, CAST(:message_type as hook.message_topic) from queue";
|
||||
try {
|
||||
int count = jdbcTemplate.update(sql, new MapSqlParameterSource("id", messageId)
|
||||
.addValue("message_type", getMessagesTopic()));
|
||||
@ -68,11 +70,15 @@ public class CustomerQueueDao implements QueueDao<CustomerQueue> {
|
||||
@Override
|
||||
public List<CustomerQueue> getWithPolicies(Collection<Long> ids) throws DaoException {
|
||||
final String sql =
|
||||
" select q.id, q.hook_id, q.customer_id, wh.party_id, wh.url, k.pub_key, k.priv_key, wh.enabled, wh.retry_policy, srp.fail_count, srp.last_fail_time, srp.next_fire_time_ms, srp.message_type " +
|
||||
" select q.id, q.hook_id, q.customer_id, wh.party_id, wh.url, k.pub_key, k.priv_key, wh.enabled, " +
|
||||
" wh.retry_policy, srp.fail_count, srp.last_fail_time, " +
|
||||
" srp.next_fire_time_ms, srp.message_type " +
|
||||
" from hook.customer_queue q " +
|
||||
" join hook.webhook wh on wh.id = q.hook_id and wh.enabled and wh.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook wh on wh.id = q.hook_id " +
|
||||
" and wh.enabled and wh.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.party_data k on k.party_id = wh.party_id " +
|
||||
" left join hook.simple_retry_policy srp on q.id = srp.queue_id and srp.message_type=CAST(:message_type as hook.message_topic)" +
|
||||
" left join hook.simple_retry_policy srp on q.id = srp.queue_id " +
|
||||
" and srp.message_type=CAST(:message_type as hook.message_topic)" +
|
||||
" where q.id in (:ids) and q.enabled";
|
||||
final MapSqlParameterSource params = new MapSqlParameterSource("ids", ids)
|
||||
.addValue("message_type", getMessagesTopic());
|
||||
|
@ -31,7 +31,8 @@ public class CustomerTaskDao extends AbstractTaskDao {
|
||||
" insert into hook.scheduled_task(message_id, queue_id, message_type)" +
|
||||
" select m.id, q.id, w.topic" +
|
||||
" from hook.customer_message m" +
|
||||
" join hook.webhook w on m.party_id = w.party_id and w.enabled and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook w on m.party_id = w.party_id " +
|
||||
" and w.enabled and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook_to_events wte on wte.hook_id = w.id" +
|
||||
" join hook.customer_queue q on q.hook_id=w.id and q.enabled and q.customer_id=m.customer_id" +
|
||||
" where m.id = :message_id " +
|
||||
@ -53,7 +54,7 @@ public class CustomerTaskDao extends AbstractTaskDao {
|
||||
" select m.id, q.id, w.topic" +
|
||||
" from hook.customer_message m" +
|
||||
" join hook.webhook w on m.party_id = w.party_id " +
|
||||
" and w.id = :hook_id "+
|
||||
" and w.id = :hook_id " +
|
||||
" and w.enabled " +
|
||||
" and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook_to_events wte on wte.hook_id = w.id" +
|
||||
|
@ -21,7 +21,11 @@ import org.springframework.jdbc.support.KeyHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -229,11 +233,13 @@ public class HookDaoImpl implements HookDao {
|
||||
batchValues.add(mapSqlParameterSource.getValues());
|
||||
}
|
||||
|
||||
final String sql = "INSERT INTO hook.webhook_to_events(hook_id, event_type, invoice_shop_id, invoice_status, invoice_payment_status, invoice_payment_refund_status) VALUES (:hook_id, CAST(:event_type AS hook.eventtype)," +
|
||||
" :invoice_shop_id, :invoice_status, :invoice_payment_status, :invoice_payment_refund_status)";
|
||||
final String sql = "INSERT INTO hook.webhook_to_events(hook_id, event_type, invoice_shop_id, invoice_status, " +
|
||||
"invoice_payment_status, invoice_payment_refund_status) VALUES " +
|
||||
"(:hook_id, CAST(:event_type AS hook.eventtype), :invoice_shop_id, :invoice_status, " +
|
||||
":invoice_payment_status, :invoice_payment_refund_status)";
|
||||
|
||||
try {
|
||||
int updateCount[] = jdbcTemplate.batchUpdate(sql, batchValues.toArray(new Map[size]));
|
||||
int[] updateCount = jdbcTemplate.batchUpdate(sql, batchValues.toArray(new Map[size]));
|
||||
if (updateCount.length != size) {
|
||||
throw new DaoException("Couldn't insert relation between hook and events.");
|
||||
}
|
||||
@ -246,8 +252,10 @@ public class HookDaoImpl implements HookDao {
|
||||
@Override
|
||||
public void delete(long id) throws DaoException {
|
||||
final String sql =
|
||||
" DELETE FROM hook.scheduled_task st USING hook.invoicing_queue q WHERE st.queue_id = q.id AND q.hook_id=:id; " +
|
||||
" DELETE FROM hook.scheduled_task st USING hook.customer_queue q WHERE st.queue_id = q.id AND q.hook_id=:id; " +
|
||||
" DELETE FROM hook.scheduled_task st USING hook.invoicing_queue q " +
|
||||
" WHERE st.queue_id = q.id AND q.hook_id=:id; " +
|
||||
" DELETE FROM hook.scheduled_task st USING hook.customer_queue q " +
|
||||
" WHERE st.queue_id = q.id AND q.hook_id=:id; " +
|
||||
" UPDATE hook.webhook SET enabled = FALSE where id=:id;";
|
||||
try {
|
||||
jdbcTemplate.update(sql, new MapSqlParameterSource("id", id));
|
||||
@ -303,4 +311,4 @@ public class HookDaoImpl implements HookDao {
|
||||
rs.getString("invoice_status"),
|
||||
rs.getString("invoice_payment_status"),
|
||||
rs.getString("invoice_payment_refund_status")));
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,21 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.*;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.CHANGE_ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.EVENT_TIME;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.EVENT_TYPE;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.INVOICE_ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.INVOICE_STATUS;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.NEW_EVENT_ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.PARTY_ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.PAYMENT_ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.PAYMENT_STATUS;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.REFUND_ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.REFUND_STATUS;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.SEQUENCE_ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.SHOP_ID;
|
||||
import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.TYPE;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@ -38,7 +52,8 @@ public class InvoicingMessageDaoImpl implements InvoicingMessageDao {
|
||||
int[] batchMessagesResult = saveBatchMessages(messages);
|
||||
log.info("Batch messages saved info {}",
|
||||
IntStream.range(0, messages.size())
|
||||
.mapToObj(i -> "(" + i + " : " + batchMessagesResult[i] + " : " + messages.get(i).getId() + " : " + messages.get(i).getInvoiceId() + ")")
|
||||
.mapToObj(i -> "(" + i + " : " + batchMessagesResult[i] + " : " + messages.get(i).getId() +
|
||||
" : " + messages.get(i).getInvoiceId() + ")")
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@ -50,8 +65,9 @@ public class InvoicingMessageDaoImpl implements InvoicingMessageDao {
|
||||
"(id, new_event_id, event_time, sequence_id, change_id, type, party_id, event_type, " +
|
||||
"invoice_id, shop_id, invoice_status, payment_id, payment_status, refund_id, refund_status) " +
|
||||
"VALUES " +
|
||||
"(:id, :new_event_id, :event_time, :sequence_id, :change_id, :type, :party_id, CAST(:event_type as hook.eventtype), " +
|
||||
":invoice_id, :shop_id, :invoice_status, :payment_id, :payment_status, :refund_id, :refund_status) " +
|
||||
"(:id, :new_event_id, :event_time, :sequence_id, :change_id, :type, :party_id, " +
|
||||
"CAST(:event_type as hook.eventtype), :invoice_id, :shop_id, :invoice_status, :payment_id, " +
|
||||
":payment_status, :refund_id, :refund_status) " +
|
||||
"ON CONFLICT (invoice_id, sequence_id, change_id) DO NOTHING ";
|
||||
|
||||
MapSqlParameterSource[] sqlParameterSources = messages.stream()
|
||||
@ -68,9 +84,11 @@ public class InvoicingMessageDaoImpl implements InvoicingMessageDao {
|
||||
.addValue(SHOP_ID, message.getShopId())
|
||||
.addValue(INVOICE_STATUS, message.getInvoiceStatus().getValue())
|
||||
.addValue(PAYMENT_ID, message.getPaymentId())
|
||||
.addValue(PAYMENT_STATUS, message.getPaymentStatus() != null ? message.getPaymentStatus().getValue() : null)
|
||||
.addValue(PAYMENT_STATUS,
|
||||
message.getPaymentStatus() != null ? message.getPaymentStatus().getValue() : null)
|
||||
.addValue(REFUND_ID, message.getRefundId())
|
||||
.addValue(REFUND_STATUS, message.getRefundStatus() != null ? message.getRefundStatus().getValue() : null))
|
||||
.addValue(REFUND_STATUS,
|
||||
message.getRefundStatus() != null ? message.getRefundStatus().getValue() : null))
|
||||
.toArray(MapSqlParameterSource[]::new);
|
||||
return jdbcTemplate.batchUpdate(sql, sqlParameterSources);
|
||||
} catch (NestedRuntimeException e) {
|
||||
|
@ -1,6 +1,11 @@
|
||||
package com.rbkmoney.hooker.dao.impl;
|
||||
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoiceStatusEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import com.rbkmoney.hooker.model.RefundStatusEnum;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
@ -39,11 +44,11 @@ public class InvoicingMessageRowMapper implements RowMapper<InvoicingMessage> {
|
||||
message.setInvoiceId(rs.getString(INVOICE_ID));
|
||||
message.setInvoiceStatus(InvoiceStatusEnum.lookup(rs.getString(INVOICE_STATUS)));
|
||||
message.setPaymentId(rs.getString(PAYMENT_ID));
|
||||
message.setPaymentStatus(rs.getString(PAYMENT_STATUS) != null ?
|
||||
PaymentStatusEnum.lookup(rs.getString(PAYMENT_STATUS)) : null);
|
||||
message.setPaymentStatus(rs.getString(PAYMENT_STATUS) != null
|
||||
? PaymentStatusEnum.lookup(rs.getString(PAYMENT_STATUS)) : null);
|
||||
message.setRefundId(rs.getString(REFUND_ID));
|
||||
message.setRefundStatus(rs.getString(REFUND_STATUS) != null ?
|
||||
RefundStatusEnum.lookup(rs.getString(REFUND_STATUS)) : null);
|
||||
message.setRefundStatus(rs.getString(REFUND_STATUS) != null
|
||||
? RefundStatusEnum.lookup(rs.getString(REFUND_STATUS)) : null);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
@ -49,10 +49,12 @@ public class InvoicingQueueDao implements QueueDao<InvoicingQueue> {
|
||||
" insert into hook.invoicing_queue(hook_id, invoice_id)" +
|
||||
" select w.id , m.invoice_id" +
|
||||
" from hook.message m" +
|
||||
" join hook.webhook w on m.party_id = w.party_id and w.enabled and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook w on m.party_id = w.party_id " +
|
||||
" and w.enabled and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" where m.id = :id " +
|
||||
" on conflict(hook_id, invoice_id) do nothing returning *) " +
|
||||
"insert into hook.simple_retry_policy(queue_id, message_type) select id, CAST(:message_type as hook.message_topic) from queue";
|
||||
" insert into hook.simple_retry_policy(queue_id, message_type) " +
|
||||
" select id, CAST(:message_type as hook.message_topic) from queue";
|
||||
MapSqlParameterSource[] sqlParameterSources = messageIds
|
||||
.stream()
|
||||
.map(id -> new MapSqlParameterSource()
|
||||
@ -69,11 +71,15 @@ public class InvoicingQueueDao implements QueueDao<InvoicingQueue> {
|
||||
@Override
|
||||
public List<InvoicingQueue> getWithPolicies(Collection<Long> ids) {
|
||||
final String sql =
|
||||
" select q.id, q.hook_id, q.invoice_id, wh.party_id, wh.url, k.pub_key, k.priv_key, wh.enabled, wh.retry_policy, srp.fail_count, srp.last_fail_time, srp.next_fire_time_ms, srp.message_type " +
|
||||
" select q.id, q.hook_id, q.invoice_id, wh.party_id, wh.url, k.pub_key, k.priv_key, wh.enabled, " +
|
||||
" wh.retry_policy, srp.fail_count, srp.last_fail_time, " +
|
||||
" srp.next_fire_time_ms, srp.message_type " +
|
||||
" from hook.invoicing_queue q " +
|
||||
" join hook.webhook wh on wh.id = q.hook_id and wh.enabled and wh.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook wh on wh.id = q.hook_id " +
|
||||
" and wh.enabled and wh.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.party_data k on k.party_id = wh.party_id " +
|
||||
" left join hook.simple_retry_policy srp on q.id = srp.queue_id and srp.message_type=CAST(:message_type as hook.message_topic)" +
|
||||
" left join hook.simple_retry_policy srp on q.id = srp.queue_id " +
|
||||
" and srp.message_type=CAST(:message_type as hook.message_topic)" +
|
||||
" where q.id in (:ids) and q.enabled";
|
||||
final MapSqlParameterSource params = new MapSqlParameterSource("ids", ids)
|
||||
.addValue("message_type", getMessagesTopic());
|
||||
|
@ -38,7 +38,8 @@ public class InvoicingTaskDao extends AbstractTaskDao {
|
||||
" insert into hook.scheduled_task(message_id, queue_id, message_type)" +
|
||||
" select m.id, q.id, w.topic" +
|
||||
" from hook.message m" +
|
||||
" join hook.webhook w on m.party_id = w.party_id and w.enabled and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook w on m.party_id = w.party_id " +
|
||||
" and w.enabled and w.topic=CAST(:message_type as hook.message_topic)" +
|
||||
" join hook.webhook_to_events wte on wte.hook_id = w.id" +
|
||||
" join hook.invoicing_queue q on q.hook_id=w.id and q.enabled and q.invoice_id=m.invoice_id" +
|
||||
" where m.id in (:message_ids) " +
|
||||
@ -46,7 +47,8 @@ public class InvoicingTaskDao extends AbstractTaskDao {
|
||||
" and (m.shop_id = wte.invoice_shop_id or wte.invoice_shop_id is null) " +
|
||||
" and (m.invoice_status = wte.invoice_status or wte.invoice_status is null) " +
|
||||
" and (m.payment_status = wte.invoice_payment_status or wte.invoice_payment_status is null)" +
|
||||
" and (m.refund_status = wte.invoice_payment_refund_status or wte.invoice_payment_refund_status is null)" +
|
||||
" and (m.refund_status = wte.invoice_payment_refund_status " +
|
||||
" or wte.invoice_payment_refund_status is null)" +
|
||||
" ON CONFLICT (message_id, queue_id, message_type) DO NOTHING";
|
||||
|
||||
final MapSqlParameterSource sqlParameterSources = new MapSqlParameterSource("message_ids", messageIds)
|
||||
@ -77,7 +79,8 @@ public class InvoicingTaskDao extends AbstractTaskDao {
|
||||
" and (m.shop_id = wte.invoice_shop_id or wte.invoice_shop_id is null) " +
|
||||
" and (m.invoice_status = wte.invoice_status or wte.invoice_status is null) " +
|
||||
" and (m.payment_status = wte.invoice_payment_status or wte.invoice_payment_status is null)" +
|
||||
" and (m.refund_status = wte.invoice_payment_refund_status or wte.invoice_payment_refund_status is null)" +
|
||||
" and (m.refund_status = wte.invoice_payment_refund_status " +
|
||||
" or wte.invoice_payment_refund_status is null)" +
|
||||
" ON CONFLICT (message_id, queue_id, message_type) DO NOTHING";
|
||||
|
||||
final MapSqlParameterSource sqlParameterSources = new MapSqlParameterSource("hook_id", hookId)
|
||||
|
@ -18,7 +18,9 @@ public class SimpleRetryPolicyDaoImpl implements SimpleRetryPolicyDao {
|
||||
@Override
|
||||
public void update(SimpleRetryPolicyRecord record) throws DaoException {
|
||||
final String sql = "update hook.simple_retry_policy " +
|
||||
" set last_fail_time = :last_fail_time, fail_count = :fail_count, next_fire_time_ms = :next_fire_time_ms" +
|
||||
" set last_fail_time = :last_fail_time, " +
|
||||
" fail_count = :fail_count, " +
|
||||
" next_fire_time_ms = :next_fire_time_ms" +
|
||||
" where queue_id = :queue_id and message_type=CAST(:message_type as hook.message_topic)";
|
||||
try {
|
||||
jdbcTemplate.update(sql, new MapSqlParameterSource("queue_id", record.getQueueId())
|
||||
|
@ -8,8 +8,14 @@ import com.rbkmoney.woody.thrift.impl.http.event.ServiceEventLogListener;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.GenericServlet;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet("/hook")
|
||||
|
@ -8,8 +8,14 @@ import com.rbkmoney.woody.thrift.impl.http.event.ServiceEventLogListener;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.GenericServlet;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet("/message")
|
||||
|
@ -17,7 +17,8 @@ public class NotFoundException extends RuntimeException {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
protected NotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
protected NotFoundException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ public class RemoteHostException extends RuntimeException {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
protected RemoteHostException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
protected RemoteHostException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ public class CustomerBindingFailedHandler extends NeedReadCustomerEventHandler {
|
||||
|
||||
private EventType eventType = EventType.CUSTOMER_BINDING_FAILED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public CustomerBindingFailedHandler(CustomerDaoImpl customerDao,
|
||||
CustomerQueueDao customerQueueDao,
|
||||
|
@ -22,7 +22,8 @@ public class CustomerBindingStartedHandler extends NeedReadCustomerEventHandler
|
||||
|
||||
private EventType eventType = EventType.CUSTOMER_BINDING_STARTED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public CustomerBindingStartedHandler(CustomerDaoImpl customerDao,
|
||||
CustomerQueueDao customerQueueDao,
|
||||
|
@ -19,7 +19,8 @@ public class CustomerBindingSucceededHandler extends NeedReadCustomerEventHandle
|
||||
|
||||
private EventType eventType = EventType.CUSTOMER_BINDING_SUCCEEDED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public CustomerBindingSucceededHandler(CustomerDaoImpl customerDao,
|
||||
CustomerQueueDao customerQueueDao,
|
||||
|
@ -9,7 +9,10 @@ import com.rbkmoney.hooker.dao.impl.CustomerDaoImpl;
|
||||
import com.rbkmoney.hooker.dao.impl.CustomerQueueDao;
|
||||
import com.rbkmoney.hooker.dao.impl.CustomerTaskDao;
|
||||
import com.rbkmoney.hooker.exception.DaoException;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.CustomerMessage;
|
||||
import com.rbkmoney.hooker.model.CustomerMessageEnum;
|
||||
import com.rbkmoney.hooker.model.EventInfo;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -22,7 +25,8 @@ public class CustomerCreatedHandler extends AbstractCustomerEventHandler {
|
||||
|
||||
private EventType eventType = EventType.CUSTOMER_CREATED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
private final CustomerDaoImpl customerDao;
|
||||
|
||||
|
@ -19,7 +19,8 @@ public class CustomerDeletedHandler extends NeedReadCustomerEventHandler {
|
||||
|
||||
private EventType eventType = EventType.CUSTOMER_DELETED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public CustomerDeletedHandler(CustomerDaoImpl customerDao,
|
||||
CustomerQueueDao customerQueueDao,
|
||||
|
@ -19,7 +19,8 @@ public class CustomerReadyHandler extends NeedReadCustomerEventHandler {
|
||||
|
||||
private EventType eventType = EventType.CUSTOMER_READY;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public CustomerReadyHandler(CustomerDaoImpl customerDao,
|
||||
CustomerQueueDao customerQueueDao,
|
||||
|
@ -12,9 +12,12 @@ import java.util.Map;
|
||||
public abstract class AbstractInvoiceEventMapper implements Mapper<InvoiceChange, InvoicingMessage> {
|
||||
|
||||
@Override
|
||||
public InvoicingMessage handle(InvoiceChange ic, EventInfo eventInfo, Map<InvoicingMessageKey, InvoicingMessage> storage) throws DaoException {
|
||||
public InvoicingMessage handle(InvoiceChange ic, EventInfo eventInfo,
|
||||
Map<InvoicingMessageKey, InvoicingMessage> storage) throws DaoException {
|
||||
return buildEvent(ic, eventInfo, storage);
|
||||
}
|
||||
|
||||
protected abstract InvoicingMessage buildEvent(InvoiceChange ic, EventInfo eventInfo, Map<InvoicingMessageKey, InvoicingMessage> storage) throws DaoException;
|
||||
protected abstract InvoicingMessage buildEvent(InvoiceChange ic, EventInfo eventInfo,
|
||||
Map<InvoicingMessageKey, InvoicingMessage> storage)
|
||||
throws DaoException;
|
||||
}
|
||||
|
@ -7,7 +7,11 @@ import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import com.rbkmoney.hooker.service.HellgateInvoicingService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -7,7 +7,12 @@ import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.exception.DaoException;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventInfo;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoiceStatusEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -18,11 +23,13 @@ public class InvoiceCreatedMapper extends AbstractInvoiceEventMapper {
|
||||
|
||||
private EventType eventType = EventType.INVOICE_CREATED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public InvoicingMessage buildEvent(InvoiceChange ic, EventInfo eventInfo, Map<InvoicingMessageKey, InvoicingMessage> storage) throws DaoException {
|
||||
public InvoicingMessage buildEvent(InvoiceChange ic, EventInfo eventInfo,
|
||||
Map<InvoicingMessageKey, InvoicingMessage> storage) throws DaoException {
|
||||
Invoice invoiceOrigin = ic.getInvoiceCreated().getInvoice();
|
||||
InvoicingMessage message = new InvoicingMessage();
|
||||
message.setEventTime(eventInfo.getEventCreatedAt());
|
||||
|
@ -8,7 +8,11 @@ import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import com.rbkmoney.hooker.model.RefundStatusEnum;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ -16,7 +20,8 @@ public class InvoicePaymentRefundStartedMapper extends NeedReadInvoiceEventMappe
|
||||
|
||||
private EventType eventType = EventType.INVOICE_PAYMENT_REFUND_STARTED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public InvoicePaymentRefundStartedMapper(InvoicingMessageDao messageDao) {
|
||||
super(messageDao);
|
||||
@ -48,8 +53,9 @@ public class InvoicePaymentRefundStartedMapper extends NeedReadInvoiceEventMappe
|
||||
|
||||
@Override
|
||||
protected void modifyMessage(InvoiceChange ic, InvoicingMessage message) {
|
||||
InvoicePaymentRefundCreated refundCreated = ic.getInvoicePaymentChange().getPayload().getInvoicePaymentRefundChange()
|
||||
.getPayload().getInvoicePaymentRefundCreated();
|
||||
InvoicePaymentRefundCreated refundCreated =
|
||||
ic.getInvoicePaymentChange().getPayload().getInvoicePaymentRefundChange()
|
||||
.getPayload().getInvoicePaymentRefundCreated();
|
||||
InvoicePaymentRefund refundOrigin = refundCreated.getRefund();
|
||||
message.setRefundId(refundOrigin.getId());
|
||||
message.setRefundStatus(RefundStatusEnum.lookup(refundOrigin.getStatus().getSetField().getFieldName()));
|
||||
|
@ -6,7 +6,11 @@ import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import com.rbkmoney.hooker.model.RefundStatusEnum;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ -14,7 +18,8 @@ public class InvoicePaymentRefundStatusChangedMapper extends NeedReadInvoiceEven
|
||||
|
||||
private EventType eventType = EventType.INVOICE_PAYMENT_REFUND_STATUS_CHANGED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public InvoicePaymentRefundStatusChangedMapper(InvoicingMessageDao messageDao) {
|
||||
super(messageDao);
|
||||
@ -47,7 +52,8 @@ public class InvoicePaymentRefundStatusChangedMapper extends NeedReadInvoiceEven
|
||||
|
||||
@Override
|
||||
protected void modifyMessage(InvoiceChange ic, InvoicingMessage message) {
|
||||
message.setRefundStatus(RefundStatusEnum.lookup(ic.getInvoicePaymentChange().getPayload().getInvoicePaymentRefundChange()
|
||||
.getPayload().getInvoicePaymentRefundStatusChanged().getStatus().getSetField().getFieldName()));
|
||||
message.setRefundStatus(
|
||||
RefundStatusEnum.lookup(ic.getInvoicePaymentChange().getPayload().getInvoicePaymentRefundChange()
|
||||
.getPayload().getInvoicePaymentRefundStatusChanged().getStatus().getSetField().getFieldName()));
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,11 @@ import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ -15,7 +19,8 @@ public class InvoicePaymentStartedMapper extends NeedReadInvoiceEventMapper {
|
||||
|
||||
private EventType eventType = EventType.INVOICE_PAYMENT_STARTED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public InvoicePaymentStartedMapper(InvoicingMessageDao messageDao) {
|
||||
super(messageDao);
|
||||
@ -38,7 +43,8 @@ public class InvoicePaymentStartedMapper extends NeedReadInvoiceEventMapper {
|
||||
|
||||
@Override
|
||||
protected void modifyMessage(InvoiceChange ic, InvoicingMessage message) {
|
||||
InvoicePayment paymentOrigin = ic.getInvoicePaymentChange().getPayload().getInvoicePaymentStarted().getPayment();
|
||||
InvoicePayment paymentOrigin =
|
||||
ic.getInvoicePaymentChange().getPayload().getInvoicePaymentStarted().getPayment();
|
||||
message.setPaymentId(paymentOrigin.getId());
|
||||
message.setPaymentStatus(PaymentStatusEnum.lookup(paymentOrigin.getStatus().getSetField().getFieldName()));
|
||||
}
|
||||
|
@ -6,7 +6,11 @@ import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ -14,7 +18,8 @@ public class InvoicePaymentStatusChangedMapper extends NeedReadInvoiceEventMappe
|
||||
|
||||
private EventType eventType = EventType.INVOICE_PAYMENT_STATUS_CHANGED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public InvoicePaymentStatusChangedMapper(InvoicingMessageDao messageDao) {
|
||||
super(messageDao);
|
||||
@ -52,7 +57,8 @@ public class InvoicePaymentStatusChangedMapper extends NeedReadInvoiceEventMappe
|
||||
|
||||
@Override
|
||||
public boolean accept(InvoiceChange change) {
|
||||
return getFilter().match(change) &&
|
||||
!change.getInvoicePaymentChange().getPayload().getInvoicePaymentStatusChanged().getStatus().isSetChargedBack();
|
||||
return getFilter().match(change)
|
||||
&& !change.getInvoicePaymentChange().getPayload().getInvoicePaymentStatusChanged().getStatus()
|
||||
.isSetChargedBack();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,11 @@ import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoiceStatusEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ -14,7 +18,8 @@ public class InvoiceStatusChangedMapper extends NeedReadInvoiceEventMapper {
|
||||
|
||||
private EventType eventType = EventType.INVOICE_STATUS_CHANGED;
|
||||
|
||||
private Filter filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
public InvoiceStatusChangedMapper(InvoicingMessageDao messageDao) {
|
||||
super(messageDao);
|
||||
@ -45,6 +50,7 @@ public class InvoiceStatusChangedMapper extends NeedReadInvoiceEventMapper {
|
||||
|
||||
@Override
|
||||
protected void modifyMessage(InvoiceChange ic, InvoicingMessage message) {
|
||||
message.setInvoiceStatus(InvoiceStatusEnum.lookup(ic.getInvoiceStatusChanged().getStatus().getSetField().getFieldName()));
|
||||
message.setInvoiceStatus(
|
||||
InvoiceStatusEnum.lookup(ic.getInvoiceStatusChanged().getStatus().getSetField().getFieldName()));
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,11 @@ import com.rbkmoney.damsel.payment_processing.InvoiceChange;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.exception.DaoException;
|
||||
import com.rbkmoney.hooker.exception.NotFoundException;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventInfo;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -17,7 +21,8 @@ public abstract class NeedReadInvoiceEventMapper extends AbstractInvoiceEventMap
|
||||
private final InvoicingMessageDao messageDao;
|
||||
|
||||
@Override
|
||||
protected InvoicingMessage buildEvent(InvoiceChange ic, EventInfo eventInfo, Map<InvoicingMessageKey, InvoicingMessage> storage) throws DaoException {
|
||||
protected InvoicingMessage buildEvent(InvoiceChange ic, EventInfo eventInfo,
|
||||
Map<InvoicingMessageKey, InvoicingMessage> storage) throws DaoException {
|
||||
InvoicingMessage message;
|
||||
InvoicingMessageKey messageKey = getMessageKey(eventInfo.getSourceId(), ic);
|
||||
try {
|
||||
@ -41,7 +46,8 @@ public abstract class NeedReadInvoiceEventMapper extends AbstractInvoiceEventMap
|
||||
|
||||
protected abstract InvoicingMessageEnum getMessageType();
|
||||
|
||||
protected abstract InvoicingMessageKey getMessageKey(String invoiceId, InvoiceChange ic) throws NotFoundException, DaoException;
|
||||
protected abstract InvoicingMessageKey getMessageKey(String invoiceId, InvoiceChange ic)
|
||||
throws NotFoundException, DaoException;
|
||||
|
||||
protected abstract EventType getEventType();
|
||||
|
||||
|
@ -23,6 +23,7 @@ public class InvoicingEventKafkaListener {
|
||||
invoicingMachineEventHandler.handle(messages.stream()
|
||||
.map(m -> m.value().getEvent())
|
||||
.collect(Collectors.toList()), ack);
|
||||
log.info("Batch has been committed, size={}, {}", messages.size(), LogUtil.toSummaryStringWithSinkEventValues(messages));
|
||||
log.info("Batch has been committed, size={}, {}", messages.size(),
|
||||
LogUtil.toSummaryStringWithSinkEventValues(messages));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,15 @@
|
||||
package com.rbkmoney.hooker.logging;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import okhttp3.Connection;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.http.HttpHeaders;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
@ -105,7 +113,9 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
||||
* Change the level at which this interceptor logs.
|
||||
*/
|
||||
public HttpLoggingInterceptor setLevel(Level level) {
|
||||
if (level == null) throw new NullPointerException("level == null. Use Level.NONE instead.");
|
||||
if (level == null) {
|
||||
throw new NullPointerException("level == null. Use Level.NONE instead.");
|
||||
}
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
@ -204,7 +214,8 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
||||
.append(response.code())
|
||||
.append(response.message().isEmpty() ? "" : " " + response.message())
|
||||
.append(' ').append(response.request().url())
|
||||
.append(" (").append(tookMs).append("ms").append((!logHeaders ? ", " + bodySize + " body" : "") + ')').append('\n');
|
||||
.append(" (").append(tookMs).append("ms").append((!logHeaders ? ", " + bodySize + " body" : "") + ')')
|
||||
.append('\n');
|
||||
|
||||
if (logHeaders) {
|
||||
Headers headers = response.headers();
|
||||
|
@ -3,6 +3,7 @@ package com.rbkmoney.hooker.model;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@SuppressWarnings("LineLength")
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum EventType {
|
||||
|
@ -1,6 +1,10 @@
|
||||
package com.rbkmoney.hooker.model;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -8,6 +8,7 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class PaymentToolDetailsDigitalWallet extends com.rbkmoney.swag_webhook_events.model.PaymentToolDetailsDigitalWallet {
|
||||
public class PaymentToolDetailsDigitalWallet
|
||||
extends com.rbkmoney.swag_webhook_events.model.PaymentToolDetailsDigitalWallet {
|
||||
private DigitalWalletDetails digitalWalletDetails;
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ public class RetryPoliciesService {
|
||||
if (RetryPolicyType.SIMPLE.equals(record.getType())) {
|
||||
simpleRetryPolicyDao.update((SimpleRetryPolicyRecord) record);
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Retry policy DAO for type: " + record.getType().toString() + " not found");
|
||||
throw new UnsupportedOperationException(
|
||||
"Retry policy DAO for type: " + record.getType().toString() + " not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,11 @@ package com.rbkmoney.hooker.retry.impl.simple;
|
||||
|
||||
import com.rbkmoney.hooker.retry.RetryPolicyRecord;
|
||||
import com.rbkmoney.hooker.retry.RetryPolicyType;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
|
@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@Slf4j
|
||||
@ -21,6 +22,6 @@ public class MessageScheduler<M extends Message, Q extends Queue> {
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
IntStream.range(0, threadPoolSize).forEach(i ->
|
||||
executorService.scheduleWithFixedDelay(messageProcessor, delayMillis));
|
||||
executorService.scheduleWithFixedDelay(messageProcessor, delayMillis));
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import com.rbkmoney.hooker.model.QueueStatus;
|
||||
import com.rbkmoney.hooker.model.Task;
|
||||
import com.rbkmoney.hooker.service.EventService;
|
||||
import com.rbkmoney.hooker.service.FaultDetectorService;
|
||||
import com.rbkmoney.hooker.service.FaultDetectorServiceImpl;
|
||||
import com.rbkmoney.hooker.service.PostSender;
|
||||
import com.rbkmoney.hooker.service.crypt.Signer;
|
||||
import com.rbkmoney.hooker.service.err.PostRequestException;
|
||||
@ -30,7 +29,8 @@ public class MessageSender<M extends Message, Q extends Queue> {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final FaultDetectorService faultDetector;
|
||||
|
||||
public List<QueueStatus> send(Map<Long, List<Task>> scheduledTasks, Map<Long, Q> queuesMap, Map<Long, M> messagesMap) {
|
||||
public List<QueueStatus> send(Map<Long, List<Task>> scheduledTasks, Map<Long, Q> queuesMap,
|
||||
Map<Long, M> messagesMap) {
|
||||
PostSender postSender = new PostSender(connectionPoolSize, timeout);
|
||||
List<QueueStatus> queueStatuses = new ArrayList<>();
|
||||
for (Map.Entry<Long, List<Task>> entry : scheduledTasks.entrySet()) {
|
||||
@ -49,9 +49,12 @@ public class MessageSender<M extends Message, Q extends Queue> {
|
||||
final String messageJson = objectMapper.writeValueAsString(event);
|
||||
final String signature = signer.sign(messageJson, queue.getHook().getPrivKey());
|
||||
faultDetector.startRequest(queue.getHook().getId(), message.getEventId());
|
||||
int statusCode = postSender.doPost(queue.getHook().getUrl(), message.getId(), messageJson, signature);
|
||||
int statusCode =
|
||||
postSender.doPost(queue.getHook().getUrl(), message.getId(), messageJson, signature);
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
String wrongCodeMessage = String.format("Wrong status code: %d from merchant, we'll try to resend it. Message with id: %d %s", statusCode, message.getId(), message);
|
||||
String wrongCodeMessage = String.format(
|
||||
"Wrong status code: %d from merchant, we'll try to resend it. Message with id: %d %s",
|
||||
statusCode, message.getId(), message);
|
||||
log.info(wrongCodeMessage);
|
||||
faultDetector.errorRequest(queue.getHook().getId(), message.getEventId());
|
||||
throw new PostRequestException(wrongCodeMessage);
|
||||
@ -61,12 +64,14 @@ public class MessageSender<M extends Message, Q extends Queue> {
|
||||
}
|
||||
queueStatus.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
if (currentMessage != null)
|
||||
log.warn("Couldn't send message with id {} {} to hook {}. We'll try to resend it", currentMessage.getId(), currentMessage, queue.getHook(), e);
|
||||
if (currentMessage != null) {
|
||||
log.warn("Couldn't send message with id {} {} to hook {}. We'll try to resend it",
|
||||
currentMessage.getId(), currentMessage, queue.getHook(), e);
|
||||
}
|
||||
queueStatus.setSuccess(false);
|
||||
}
|
||||
queueStatuses.add(queueStatus);
|
||||
}
|
||||
return queueStatuses;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,13 @@ import com.rbkmoney.hooker.exception.RemoteHostException;
|
||||
import com.rbkmoney.hooker.model.CustomerMessage;
|
||||
import com.rbkmoney.hooker.utils.HellgateUtils;
|
||||
import com.rbkmoney.hooker.utils.TimeUtils;
|
||||
import com.rbkmoney.swag_webhook_events.model.*;
|
||||
import com.rbkmoney.swag_webhook_events.model.CustomerBindingFailed;
|
||||
import com.rbkmoney.swag_webhook_events.model.CustomerBindingStarted;
|
||||
import com.rbkmoney.swag_webhook_events.model.CustomerBindingSucceeded;
|
||||
import com.rbkmoney.swag_webhook_events.model.CustomerCreated;
|
||||
import com.rbkmoney.swag_webhook_events.model.CustomerDeleted;
|
||||
import com.rbkmoney.swag_webhook_events.model.CustomerReady;
|
||||
import com.rbkmoney.swag_webhook_events.model.Event;
|
||||
import com.rbkmoney.woody.api.flow.WFlow;
|
||||
import com.rbkmoney.woody.api.trace.ContextUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -25,12 +31,12 @@ public class CustomerEventService implements EventService<CustomerMessage> {
|
||||
private final CustomerManagementSrv.Iface customerClient;
|
||||
private final CustomerConverter customerConverter;
|
||||
private final CustomerBindingConverter customerBindingConverter;
|
||||
private final WFlow wFlow = new WFlow();
|
||||
private final WFlow woodyFlow = new WFlow();
|
||||
|
||||
@Override
|
||||
public Event getEventByMessage(CustomerMessage message) {
|
||||
try {
|
||||
Customer customer = wFlow.createServiceFork(() -> {
|
||||
Customer customer = woodyFlow.createServiceFork(() -> {
|
||||
addWoodyContext();
|
||||
return customerClient.get(message.getCustomerId(),
|
||||
HellgateUtils.getEventRange(message.getSequenceId().intValue()));
|
||||
@ -48,7 +54,7 @@ public class CustomerEventService implements EventService<CustomerMessage> {
|
||||
}
|
||||
}
|
||||
|
||||
private void addWoodyContext(){
|
||||
private void addWoodyContext() {
|
||||
ContextUtils.setCustomMetadataValue(UserIdentityIdExtensionKit.KEY, "hooker");
|
||||
ContextUtils.setCustomMetadataValue(UserIdentityRealmExtensionKit.KEY, "service");
|
||||
}
|
||||
@ -78,7 +84,8 @@ public class CustomerEventService implements EventService<CustomerMessage> {
|
||||
}
|
||||
}
|
||||
|
||||
private com.rbkmoney.damsel.payment_processing.CustomerBinding extractBinding(CustomerMessage message, Customer customer) {
|
||||
private com.rbkmoney.damsel.payment_processing.CustomerBinding extractBinding(CustomerMessage message,
|
||||
Customer customer) {
|
||||
return customer.getBindings().stream()
|
||||
.filter(b -> b.getId().equals(message.getBindingId()))
|
||||
.findFirst()
|
||||
|
@ -3,8 +3,11 @@ package com.rbkmoney.hooker.service;
|
||||
public interface FaultDetectorService {
|
||||
|
||||
double getRate(long hookId);
|
||||
|
||||
void startRequest(long hookId, long eventId);
|
||||
|
||||
void finishRequest(long hookId, long eventId);
|
||||
|
||||
void errorRequest(long hookId, long eventId);
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,13 @@
|
||||
package com.rbkmoney.hooker.service;
|
||||
|
||||
import com.rbkmoney.damsel.fault_detector.*;
|
||||
import com.rbkmoney.damsel.fault_detector.Error;
|
||||
import com.rbkmoney.damsel.fault_detector.FaultDetectorSrv;
|
||||
import com.rbkmoney.damsel.fault_detector.Finish;
|
||||
import com.rbkmoney.damsel.fault_detector.Operation;
|
||||
import com.rbkmoney.damsel.fault_detector.OperationState;
|
||||
import com.rbkmoney.damsel.fault_detector.ServiceConfig;
|
||||
import com.rbkmoney.damsel.fault_detector.ServiceStatistics;
|
||||
import com.rbkmoney.damsel.fault_detector.Start;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -9,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.List;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.rbkmoney.hooker.service;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.*;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoiceNotFound;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoicePayment;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoicingSrv;
|
||||
import com.rbkmoney.hooker.converter.InvoiceConverter;
|
||||
import com.rbkmoney.hooker.converter.PaymentConverter;
|
||||
import com.rbkmoney.hooker.converter.RefundConverter;
|
||||
@ -11,15 +13,29 @@ import com.rbkmoney.hooker.utils.HellgateUtils;
|
||||
import com.rbkmoney.hooker.utils.TimeUtils;
|
||||
import com.rbkmoney.swag_webhook_events.model.Event;
|
||||
import com.rbkmoney.swag_webhook_events.model.Invoice;
|
||||
import com.rbkmoney.swag_webhook_events.model.InvoiceCancelled;
|
||||
import com.rbkmoney.swag_webhook_events.model.InvoiceCreated;
|
||||
import com.rbkmoney.swag_webhook_events.model.*;
|
||||
import com.rbkmoney.swag_webhook_events.model.InvoiceFulfilled;
|
||||
import com.rbkmoney.swag_webhook_events.model.InvoicePaid;
|
||||
import com.rbkmoney.swag_webhook_events.model.Payment;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentCancelled;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentCaptured;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentFailed;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentProcessed;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentRefunded;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentStarted;
|
||||
import com.rbkmoney.swag_webhook_events.model.Refund;
|
||||
import com.rbkmoney.swag_webhook_events.model.RefundCreated;
|
||||
import com.rbkmoney.swag_webhook_events.model.RefundFailed;
|
||||
import com.rbkmoney.swag_webhook_events.model.RefundSucceeded;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class InvoicingEventService implements EventService<InvoicingMessage>, HellgateInvoicingService<InvoicingMessage> {
|
||||
public class InvoicingEventService
|
||||
implements EventService<InvoicingMessage>, HellgateInvoicingService<InvoicingMessage> {
|
||||
|
||||
private final InvoicingSrv.Iface invoicingClient;
|
||||
private final InvoiceConverter invoiceConverter;
|
||||
@ -83,7 +99,8 @@ public class InvoicingEventService implements EventService<InvoicingMessage>, He
|
||||
return invoiceConverter.convert(invoiceInfo.getInvoice());
|
||||
}
|
||||
|
||||
private Event resolveInvoiceStatusChanged(InvoicingMessage message, com.rbkmoney.damsel.payment_processing.Invoice invoiceInfo) {
|
||||
private Event resolveInvoiceStatusChanged(InvoicingMessage message,
|
||||
com.rbkmoney.damsel.payment_processing.Invoice invoiceInfo) {
|
||||
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
|
||||
switch (message.getInvoiceStatus()) {
|
||||
case UNPAID:
|
||||
@ -105,18 +122,21 @@ public class InvoicingEventService implements EventService<InvoicingMessage>, He
|
||||
return paymentConverter.convert(damselPayment);
|
||||
}
|
||||
|
||||
private InvoicePayment extractPayment(InvoicingMessage message, com.rbkmoney.damsel.payment_processing.Invoice invoiceInfo) {
|
||||
private InvoicePayment extractPayment(InvoicingMessage message,
|
||||
com.rbkmoney.damsel.payment_processing.Invoice invoiceInfo) {
|
||||
return invoiceInfo.getPayments().stream()
|
||||
.filter(p -> p.getPayment().getId().equals(message.getPaymentId()))
|
||||
.findFirst()
|
||||
.orElseThrow(
|
||||
() -> new NotFoundException(
|
||||
String.format("Payment not found, invoiceId=%s, paymentId=%s", message.getInvoiceId(), message.getPaymentId())
|
||||
String.format("Payment not found, invoiceId=%s, paymentId=%s", message.getInvoiceId(),
|
||||
message.getPaymentId())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private Event resolvePaymentStatusChanged(InvoicingMessage message, com.rbkmoney.damsel.payment_processing.Invoice invoiceInfo) {
|
||||
private Event resolvePaymentStatusChanged(InvoicingMessage message,
|
||||
com.rbkmoney.damsel.payment_processing.Invoice invoiceInfo) {
|
||||
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
|
||||
Payment swagPayment = getSwagPayment(message, invoiceInfo);
|
||||
switch (message.getPaymentStatus()) {
|
||||
@ -149,7 +169,8 @@ public class InvoicingEventService implements EventService<InvoicingMessage>, He
|
||||
return swagRefund;
|
||||
}
|
||||
|
||||
private com.rbkmoney.damsel.payment_processing.InvoicePaymentRefund extractRefund(InvoicingMessage m, InvoicePayment damselPayment) {
|
||||
private com.rbkmoney.damsel.payment_processing.InvoicePaymentRefund extractRefund(InvoicingMessage m,
|
||||
InvoicePayment damselPayment) {
|
||||
return damselPayment.getRefunds().stream()
|
||||
.filter(invoicePaymentRefund -> invoicePaymentRefund.getRefund().getId().equals(m.getRefundId()))
|
||||
.findFirst()
|
||||
@ -163,7 +184,8 @@ public class InvoicingEventService implements EventService<InvoicingMessage>, He
|
||||
);
|
||||
}
|
||||
|
||||
private Event resolveRefundStatusChanged(InvoicingMessage message, com.rbkmoney.damsel.payment_processing.Invoice invoiceInfo) {
|
||||
private Event resolveRefundStatusChanged(InvoicingMessage message,
|
||||
com.rbkmoney.damsel.payment_processing.Invoice invoiceInfo) {
|
||||
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
|
||||
Payment swagPayment = getSwagPayment(message, invoiceInfo);
|
||||
Refund swagRefund = getSwagRefund(message, invoiceInfo);
|
||||
|
@ -5,7 +5,10 @@ import com.rbkmoney.hooker.dao.MessageDao;
|
||||
import com.rbkmoney.hooker.dao.QueueDao;
|
||||
import com.rbkmoney.hooker.dao.TaskDao;
|
||||
import com.rbkmoney.hooker.exception.DaoException;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.Message;
|
||||
import com.rbkmoney.hooker.model.Queue;
|
||||
import com.rbkmoney.hooker.model.QueueStatus;
|
||||
import com.rbkmoney.hooker.model.Task;
|
||||
import com.rbkmoney.hooker.retry.RetryPoliciesService;
|
||||
import com.rbkmoney.hooker.retry.RetryPolicy;
|
||||
import com.rbkmoney.hooker.retry.RetryPolicyRecord;
|
||||
@ -22,7 +25,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class MessageProcessor<M extends Message, Q extends Queue> implements Runnable {
|
||||
public class MessageProcessor<M extends Message, Q extends Queue> implements Runnable {
|
||||
|
||||
private static final double UPDATE_PROBABILITY = 0.25;
|
||||
private final HookDao hookDao;
|
||||
@ -50,9 +53,12 @@ public class MessageProcessor<M extends Message, Q extends Queue> implements Run
|
||||
}
|
||||
|
||||
Set<Long> queueIds = scheduledTasks.keySet();
|
||||
Map<Long, Q> queuesMap = queueDao.getWithPolicies(queueIds).stream().collect(Collectors.toMap(Queue::getId, q -> q));
|
||||
Set<Long> messageIds = scheduledTasks.values().stream().flatMap(Collection::stream).map(Task::getMessageId).collect(Collectors.toSet());
|
||||
Map<Long, M> messagesMap = messageDao.getBy(messageIds).stream().collect(Collectors.toMap(Message::getId, m -> m));
|
||||
Map<Long, Q> queuesMap =
|
||||
queueDao.getWithPolicies(queueIds).stream().collect(Collectors.toMap(Queue::getId, q -> q));
|
||||
Set<Long> messageIds = scheduledTasks.values().stream().flatMap(Collection::stream).map(Task::getMessageId)
|
||||
.collect(Collectors.toSet());
|
||||
Map<Long, M> messagesMap =
|
||||
messageDao.getBy(messageIds).stream().collect(Collectors.toMap(Message::getId, m -> m));
|
||||
|
||||
List<QueueStatus> queueStatuses = messageSender.send(scheduledTasks, queuesMap, messagesMap);
|
||||
queueStatuses.forEach(queueStatus -> {
|
||||
@ -65,7 +71,8 @@ public class MessageProcessor<M extends Message, Q extends Queue> implements Run
|
||||
fail(queue);
|
||||
}
|
||||
} catch (DaoException e) {
|
||||
log.error("DaoException error when remove sent messages. It's not a big deal, but some messages may be re-sent: {}",
|
||||
log.error("DaoException error when remove sent messages. " +
|
||||
"It's not a big deal, but some messages may be re-sent: {}",
|
||||
queueStatus.getMessagesDone(), e);
|
||||
}
|
||||
});
|
||||
|
@ -2,8 +2,12 @@ package com.rbkmoney.hooker.service;
|
||||
|
||||
import com.rbkmoney.hooker.logging.HttpLoggingInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -45,7 +49,8 @@ public class PostSender {
|
||||
.build();
|
||||
|
||||
try (Response response = httpClient.newCall(request).execute()) {
|
||||
log.info("Response from hook: messageId: {}, code: {}; body: {}", messageId, response.code(), response.body() != null ? response.peekBody(RESPONSE_MAX_LENGTH).string() : "<empty>");
|
||||
log.info("Response from hook: messageId: {}, code: {}; body: {}", messageId, response.code(),
|
||||
response.body() != null ? response.peekBody(RESPONSE_MAX_LENGTH).string() : "<empty>");
|
||||
return response.code();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
package com.rbkmoney.hooker.service;
|
||||
|
||||
import com.rbkmoney.damsel.webhooker.*;
|
||||
import com.rbkmoney.damsel.webhooker.LimitExceeded;
|
||||
import com.rbkmoney.damsel.webhooker.Webhook;
|
||||
import com.rbkmoney.damsel.webhooker.WebhookManagerSrv;
|
||||
import com.rbkmoney.damsel.webhooker.WebhookNotFound;
|
||||
import com.rbkmoney.damsel.webhooker.WebhookParams;
|
||||
import com.rbkmoney.hooker.dao.HookDao;
|
||||
import com.rbkmoney.hooker.model.Hook;
|
||||
import com.rbkmoney.hooker.utils.HookConverter;
|
||||
|
@ -3,12 +3,10 @@ package com.rbkmoney.hooker.service;
|
||||
import com.rbkmoney.damsel.webhooker.SourceNotFound;
|
||||
import com.rbkmoney.damsel.webhooker.WebhookMessageServiceSrv;
|
||||
import com.rbkmoney.damsel.webhooker.WebhookNotFound;
|
||||
import com.rbkmoney.hooker.dao.CustomerDao;
|
||||
import com.rbkmoney.hooker.dao.HookDao;
|
||||
import com.rbkmoney.hooker.dao.InvoicingMessageDao;
|
||||
import com.rbkmoney.hooker.dao.impl.CustomerTaskDao;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingTaskDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.Hook;
|
||||
import com.rbkmoney.swag_webhook_events.model.Event;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -4,7 +4,13 @@ import com.rbkmoney.hooker.service.err.UnknownCryptoException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.*;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Signature;
|
||||
import java.security.SignatureException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
|
@ -90,8 +90,9 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
private static SubError getSubErrorTree(String[] codes) {
|
||||
if (codes.length == 1)
|
||||
if (codes.length == 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<SubError> subErrors = Arrays.stream(codes)
|
||||
.map(code -> new SubError().code(code))
|
||||
|
@ -1,6 +1,28 @@
|
||||
package com.rbkmoney.hooker.utils;
|
||||
|
||||
import com.rbkmoney.damsel.webhooker.*;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerBindingEvent;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerBindingFailed;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerBindingStarted;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerBindingSucceeded;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerCreated;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerDeleted;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerEventFilter;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerEventType;
|
||||
import com.rbkmoney.damsel.webhooker.CustomerStatusReady;
|
||||
import com.rbkmoney.damsel.webhooker.EventFilter;
|
||||
import com.rbkmoney.damsel.webhooker.InvoiceCreated;
|
||||
import com.rbkmoney.damsel.webhooker.InvoiceEventFilter;
|
||||
import com.rbkmoney.damsel.webhooker.InvoiceEventType;
|
||||
import com.rbkmoney.damsel.webhooker.InvoicePaymentCreated;
|
||||
import com.rbkmoney.damsel.webhooker.InvoicePaymentEventType;
|
||||
import com.rbkmoney.damsel.webhooker.InvoicePaymentRefundChange;
|
||||
import com.rbkmoney.damsel.webhooker.InvoicePaymentRefundCreated;
|
||||
import com.rbkmoney.damsel.webhooker.InvoicePaymentRefundStatus;
|
||||
import com.rbkmoney.damsel.webhooker.InvoicePaymentRefundStatusChanged;
|
||||
import com.rbkmoney.damsel.webhooker.InvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.webhooker.InvoicePaymentStatusChanged;
|
||||
import com.rbkmoney.damsel.webhooker.InvoiceStatus;
|
||||
import com.rbkmoney.damsel.webhooker.InvoiceStatusChanged;
|
||||
import com.rbkmoney.hooker.dao.WebhookAdditionalFilter;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.swag_webhook_events.model.Event;
|
||||
@ -43,58 +65,78 @@ public class EventFilterUtils {
|
||||
InvoiceStatus value = new InvoiceStatus();
|
||||
InvoiceStatus._Fields fields = InvoiceStatus._Fields.findByName(status);
|
||||
try {
|
||||
Object tBase = ((StructMetaData) value.getFieldMetaData().get(fields).valueMetaData).structClass.newInstance();
|
||||
value.setFieldValue(fields, tBase);
|
||||
Object thriftBase = ((StructMetaData) value.getFieldMetaData()
|
||||
.get(fields).valueMetaData).structClass.newInstance();
|
||||
value.setFieldValue(fields, thriftBase);
|
||||
invoiceStatusChanged.setValue(value);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new UnsupportedOperationException("Unknown status " + status + "; must be one of these: " + Arrays.toString(InvoiceStatus._Fields.values()));
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown status " + status + "; must be one of these: " +
|
||||
Arrays.toString(InvoiceStatus._Fields.values()));
|
||||
}
|
||||
invoiceStatusChanged.setValue(value);
|
||||
}
|
||||
invoiceEventTypes.add(InvoiceEventType.status_changed(invoiceStatusChanged));
|
||||
break;
|
||||
case INVOICE_PAYMENT_STARTED:
|
||||
invoiceEventTypes.add(InvoiceEventType.payment(InvoicePaymentEventType.created(new InvoicePaymentCreated())));
|
||||
invoiceEventTypes.add(InvoiceEventType
|
||||
.payment(InvoicePaymentEventType.created(new InvoicePaymentCreated())));
|
||||
break;
|
||||
case INVOICE_PAYMENT_STATUS_CHANGED:
|
||||
InvoicePaymentStatusChanged invoicePaymentStatusChanged = new InvoicePaymentStatusChanged();
|
||||
String invoicePaymentStatus = webhookAdditionalFilter.getInvoicePaymentStatus();
|
||||
if (invoicePaymentStatus != null) {
|
||||
InvoicePaymentStatus value1 = new InvoicePaymentStatus();
|
||||
InvoicePaymentStatus._Fields fields = InvoicePaymentStatus._Fields.findByName(invoicePaymentStatus);
|
||||
InvoicePaymentStatus._Fields fields =
|
||||
InvoicePaymentStatus._Fields.findByName(invoicePaymentStatus);
|
||||
try {
|
||||
Object tBase = ((StructMetaData) value1.getFieldMetaData().get(fields).valueMetaData).structClass.newInstance();
|
||||
value1.setFieldValue(fields, tBase);
|
||||
Object triftBase = ((StructMetaData) value1.getFieldMetaData()
|
||||
.get(fields).valueMetaData).structClass.newInstance();
|
||||
value1.setFieldValue(fields, triftBase);
|
||||
invoicePaymentStatusChanged.setValue(value1);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new UnsupportedOperationException("Unknown status " + invoicePaymentStatus + "; must be one of these: " + Arrays.toString(InvoicePaymentStatus._Fields.values()));
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown status " + invoicePaymentStatus + "; must be one of these: " +
|
||||
Arrays.toString(InvoicePaymentStatus._Fields.values()));
|
||||
}
|
||||
invoicePaymentStatusChanged.setValue(value1);
|
||||
}
|
||||
invoiceEventTypes.add(InvoiceEventType.payment(InvoicePaymentEventType.status_changed(invoicePaymentStatusChanged)));
|
||||
invoiceEventTypes.add(InvoiceEventType
|
||||
.payment(InvoicePaymentEventType.status_changed(invoicePaymentStatusChanged)));
|
||||
break;
|
||||
case INVOICE_PAYMENT_REFUND_STARTED:
|
||||
invoiceEventTypes.add(InvoiceEventType.payment(InvoicePaymentEventType.invoice_payment_refund_change(InvoicePaymentRefundChange.invoice_payment_refund_created(new InvoicePaymentRefundCreated()))));
|
||||
invoiceEventTypes.add(InvoiceEventType.payment(InvoicePaymentEventType
|
||||
.invoice_payment_refund_change(InvoicePaymentRefundChange
|
||||
.invoice_payment_refund_created(new InvoicePaymentRefundCreated()))));
|
||||
break;
|
||||
case INVOICE_PAYMENT_REFUND_STATUS_CHANGED:
|
||||
InvoicePaymentRefundStatusChanged invoicePaymentRefundStatusChanged = new InvoicePaymentRefundStatusChanged();
|
||||
InvoicePaymentRefundStatusChanged invoicePaymentRefundStatusChanged =
|
||||
new InvoicePaymentRefundStatusChanged();
|
||||
String invoicePaymentRefundStatus = webhookAdditionalFilter.getInvoicePaymentRefundStatus();
|
||||
if (invoicePaymentRefundStatus != null) {
|
||||
InvoicePaymentRefundStatus value1 = new InvoicePaymentRefundStatus();
|
||||
InvoicePaymentRefundStatus._Fields fields = InvoicePaymentRefundStatus._Fields.findByName(invoicePaymentRefundStatus);
|
||||
InvoicePaymentRefundStatus._Fields fields =
|
||||
InvoicePaymentRefundStatus._Fields.findByName(invoicePaymentRefundStatus);
|
||||
try {
|
||||
Object tBase = ((StructMetaData) value1.getFieldMetaData().get(fields).valueMetaData).structClass.newInstance();
|
||||
value1.setFieldValue(fields, tBase);
|
||||
Object thriftBase = ((StructMetaData) value1.getFieldMetaData()
|
||||
.get(fields).valueMetaData).structClass.newInstance();
|
||||
value1.setFieldValue(fields, thriftBase);
|
||||
invoicePaymentRefundStatusChanged.setValue(value1);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new UnsupportedOperationException("Unknown status " + invoicePaymentRefundStatus + "; must be one of these: " + Arrays.toString(InvoicePaymentRefundStatus._Fields.values()));
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown status " + invoicePaymentRefundStatus + "; must be one of these: " +
|
||||
Arrays.toString(InvoicePaymentRefundStatus._Fields.values()));
|
||||
}
|
||||
invoicePaymentRefundStatusChanged.setValue(value1);
|
||||
}
|
||||
invoiceEventTypes.add(InvoiceEventType.payment(InvoicePaymentEventType.invoice_payment_refund_change(InvoicePaymentRefundChange.invoice_payment_refund_status_changed(invoicePaymentRefundStatusChanged))));
|
||||
invoiceEventTypes.add(InvoiceEventType.payment(InvoicePaymentEventType
|
||||
.invoice_payment_refund_change(InvoicePaymentRefundChange
|
||||
.invoice_payment_refund_status_changed(invoicePaymentRefundStatusChanged))));
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown event code " + eventTypeCode + "; must be one of these: " + Arrays.toString(EventType.values()));
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown event code " + eventTypeCode + "; must be one of these: " +
|
||||
Arrays.toString(EventType.values()));
|
||||
}
|
||||
}
|
||||
} else if (firstEventType.isCustomerEvent()) {
|
||||
@ -119,20 +161,27 @@ public class EventFilterUtils {
|
||||
customerEventTypes.add(CustomerEventType.ready(new CustomerStatusReady()));
|
||||
break;
|
||||
case CUSTOMER_BINDING_STARTED:
|
||||
customerEventTypes.add(CustomerEventType.binding(CustomerBindingEvent.started(new CustomerBindingStarted())));
|
||||
customerEventTypes.add(CustomerEventType
|
||||
.binding(CustomerBindingEvent.started(new CustomerBindingStarted())));
|
||||
break;
|
||||
case CUSTOMER_BINDING_SUCCEEDED:
|
||||
customerEventTypes.add(CustomerEventType.binding(CustomerBindingEvent.succeeded(new CustomerBindingSucceeded())));
|
||||
customerEventTypes.add(CustomerEventType
|
||||
.binding(CustomerBindingEvent.succeeded(new CustomerBindingSucceeded())));
|
||||
break;
|
||||
case CUSTOMER_BINDING_FAILED:
|
||||
customerEventTypes.add(CustomerEventType.binding(CustomerBindingEvent.failed(new CustomerBindingFailed())));
|
||||
customerEventTypes.add(CustomerEventType
|
||||
.binding(CustomerBindingEvent.failed(new CustomerBindingFailed())));
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown event code " + eventTypeCode + "; must be one of these: " + Arrays.toString(EventType.values()));
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown event code " + eventTypeCode + "; must be one of these: " +
|
||||
Arrays.toString(EventType.values()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unknown event code " + firstEventType + "; must be one of these: " + Arrays.toString(EventType.values()));
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown event code " + firstEventType + "; must be one of these: " +
|
||||
Arrays.toString(EventType.values()));
|
||||
}
|
||||
return eventFilter;
|
||||
}
|
||||
@ -152,7 +201,8 @@ public class EventFilterUtils {
|
||||
} else if (invoiceEventType.isSetStatusChanged()) {
|
||||
webhookAdditionalFilter.setEventType(EventType.INVOICE_STATUS_CHANGED);
|
||||
if (invoiceEventType.getStatusChanged().isSetValue()) {
|
||||
webhookAdditionalFilter.setInvoiceStatus(invoiceEventType.getStatusChanged().getValue().getSetField().getFieldName());
|
||||
webhookAdditionalFilter.setInvoiceStatus(
|
||||
invoiceEventType.getStatusChanged().getValue().getSetField().getFieldName());
|
||||
}
|
||||
} else if (invoiceEventType.isSetPayment()) {
|
||||
InvoicePaymentEventType payment = invoiceEventType.getPayment();
|
||||
@ -161,7 +211,8 @@ public class EventFilterUtils {
|
||||
} else if (payment.isSetStatusChanged()) {
|
||||
webhookAdditionalFilter.setEventType(EventType.INVOICE_PAYMENT_STATUS_CHANGED);
|
||||
if (payment.getStatusChanged().isSetValue()) {
|
||||
webhookAdditionalFilter.setInvoicePaymentStatus(payment.getStatusChanged().getValue().getSetField().getFieldName());
|
||||
webhookAdditionalFilter.setInvoicePaymentStatus(
|
||||
payment.getStatusChanged().getValue().getSetField().getFieldName());
|
||||
}
|
||||
} else if (payment.isSetInvoicePaymentRefundChange()) {
|
||||
InvoicePaymentRefundChange refundChange = payment.getInvoicePaymentRefundChange();
|
||||
@ -170,7 +221,9 @@ public class EventFilterUtils {
|
||||
} else if (refundChange.isSetInvoicePaymentRefundStatusChanged()) {
|
||||
webhookAdditionalFilter.setEventType(EventType.INVOICE_PAYMENT_REFUND_STATUS_CHANGED);
|
||||
if (refundChange.getInvoicePaymentRefundStatusChanged().isSetValue()) {
|
||||
webhookAdditionalFilter.setInvoicePaymentRefundStatus(refundChange.getInvoicePaymentRefundStatusChanged().getValue().getSetField().getFieldName());
|
||||
webhookAdditionalFilter.setInvoicePaymentRefundStatus(
|
||||
refundChange.getInvoicePaymentRefundStatusChanged().getValue().getSetField()
|
||||
.getFieldName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,6 +265,7 @@ public class EventFilterUtils {
|
||||
if (eventFilter.isSetCustomer()) {
|
||||
return Event.TopicEnum.CUSTOMERSTOPIC.getValue();
|
||||
}
|
||||
throw new UnsupportedOperationException("Unknown topic; must be one of these: " + Arrays.toString(Event.TopicEnum.values()));
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown topic; must be one of these: " + Arrays.toString(Event.TopicEnum.values()));
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,13 @@ import com.rbkmoney.damsel.domain.DigitalWalletProvider;
|
||||
import com.rbkmoney.damsel.domain.MobilePhone;
|
||||
import com.rbkmoney.damsel.domain.PaymentTool;
|
||||
import com.rbkmoney.hooker.model.PaymentToolDetailsDigitalWallet;
|
||||
import com.rbkmoney.swag_webhook_events.model.*;
|
||||
import com.rbkmoney.swag_webhook_events.model.CryptoCurrency;
|
||||
import com.rbkmoney.swag_webhook_events.model.DigitalWalletDetailsQIWI;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentToolDetails;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentToolDetailsBankCard;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentToolDetailsCryptoWallet;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentToolDetailsMobileCommerce;
|
||||
import com.rbkmoney.swag_webhook_events.model.PaymentToolDetailsPaymentTerminal;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
@ -24,15 +30,19 @@ public class PaymentToolUtils {
|
||||
return new PaymentToolDetailsBankCard()
|
||||
.bin(paymentTool.getBankCard().getBin())
|
||||
.lastDigits(paymentTool.getBankCard().getLastDigits())
|
||||
.cardNumberMask(paymentTool.getBankCard().getBin() + "******" + paymentTool.getBankCard().getLastDigits())
|
||||
.tokenProvider(paymentTool.getBankCard().isSetTokenProvider() ?
|
||||
PaymentToolDetailsBankCard.TokenProviderEnum.fromValue(paymentTool.getBankCard().getTokenProvider().name()) : null)
|
||||
.cardNumberMask(
|
||||
paymentTool.getBankCard().getBin() + "******" + paymentTool.getBankCard().getLastDigits())
|
||||
.tokenProvider(paymentTool.getBankCard().isSetTokenProvider()
|
||||
? PaymentToolDetailsBankCard.TokenProviderEnum
|
||||
.fromValue(paymentTool.getBankCard().getTokenProvider().name()) : null)
|
||||
.paymentSystem(paymentTool.getBankCard().getPaymentSystem().name())
|
||||
.issuerCountry(paymentTool.getBankCard().getIssuerCountry() != null ? paymentTool.getBankCard().getIssuerCountry().name() : null)
|
||||
.issuerCountry(paymentTool.getBankCard().getIssuerCountry() != null
|
||||
? paymentTool.getBankCard().getIssuerCountry().name() : null)
|
||||
.bankName(paymentTool.getBankCard().getBankName());
|
||||
} else if (paymentTool.isSetPaymentTerminal()) {
|
||||
return new PaymentToolDetailsPaymentTerminal()
|
||||
.provider(PaymentToolDetailsPaymentTerminal.ProviderEnum.fromValue(paymentTool.getPaymentTerminal().getTerminalType().name()));
|
||||
.provider(PaymentToolDetailsPaymentTerminal.ProviderEnum
|
||||
.fromValue(paymentTool.getPaymentTerminal().getTerminalType().name()));
|
||||
} else if (paymentTool.isSetDigitalWallet()) {
|
||||
if (paymentTool.getDigitalWallet().getProvider() == DigitalWalletProvider.qiwi) {
|
||||
return new PaymentToolDetailsDigitalWallet(new DigitalWalletDetailsQIWI()
|
||||
@ -45,23 +55,25 @@ public class PaymentToolUtils {
|
||||
.cryptoCurrency(CryptoCurrency.fromValue(paymentTool.getCryptoCurrency().name()));
|
||||
} else if (paymentTool.isSetMobileCommerce()) {
|
||||
return new PaymentToolDetailsMobileCommerce()
|
||||
.phoneNumber(paymentTool.getMobileCommerce().getPhone().getCc() + paymentTool.getMobileCommerce().getPhone().getCtn());
|
||||
.phoneNumber(paymentTool.getMobileCommerce().getPhone().getCc() +
|
||||
paymentTool.getMobileCommerce().getPhone().getCtn());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unknown payment tool type. Must be bank card, terminal or digital wallet");
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown payment tool type. Must be bank card, terminal or digital wallet");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPaymentToolToken(PaymentTool paymentTool) {
|
||||
ObjectNode rootNode = mapper.createObjectNode();
|
||||
if (paymentTool.isSetBankCard()) {
|
||||
BankCard pCard = paymentTool.getBankCard();
|
||||
BankCard paymentCard = paymentTool.getBankCard();
|
||||
rootNode.put("type", "bank_card");
|
||||
rootNode.put("token", pCard.getToken());
|
||||
rootNode.put("payment_system", pCard.getPaymentSystem().toString());
|
||||
rootNode.put("bin", pCard.getBin());
|
||||
rootNode.put("masked_pan", pCard.getLastDigits());
|
||||
if (pCard.isSetTokenProvider()) {
|
||||
rootNode.put("token_provider", pCard.getTokenProvider().name());
|
||||
rootNode.put("token", paymentCard.getToken());
|
||||
rootNode.put("payment_system", paymentCard.getPaymentSystem().toString());
|
||||
rootNode.put("bin", paymentCard.getBin());
|
||||
rootNode.put("masked_pan", paymentCard.getLastDigits());
|
||||
if (paymentCard.isSetTokenProvider()) {
|
||||
rootNode.put("token_provider", paymentCard.getTokenProvider().name());
|
||||
}
|
||||
} else if (paymentTool.isSetPaymentTerminal()) {
|
||||
rootNode.put("type", "payment_terminal");
|
||||
@ -78,7 +90,8 @@ public class PaymentToolUtils {
|
||||
MobilePhone mobilePhone = paymentTool.getMobileCommerce().getPhone();
|
||||
rootNode.put("mobile_commerce", mobilePhone.getCc() + mobilePhone.getCtn());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unknown payment tool type. Must be bank card, terminal or digital wallet");
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown payment tool type. Must be bank card, terminal or digital wallet");
|
||||
}
|
||||
return Base64.getUrlEncoder().encodeToString(rootNode.toString().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
server:
|
||||
port: @server.port@
|
||||
port: '@server.port@'
|
||||
management:
|
||||
security:
|
||||
flag: false
|
||||
server:
|
||||
port: @management.port@
|
||||
port: '@management.port@'
|
||||
metrics:
|
||||
export:
|
||||
statsd:
|
||||
flavor: etsy
|
||||
enabled: false
|
||||
prometheus:
|
||||
enabled: false
|
||||
endpoint:
|
||||
@ -64,10 +61,10 @@ kafka:
|
||||
concurrency: 1
|
||||
|
||||
info:
|
||||
version: @version@
|
||||
version: '@version@'
|
||||
responsible: Inal Arsanukaev
|
||||
stage: dev
|
||||
damsel.version: @damsel.version@
|
||||
damsel.version: '@damsel.version@'
|
||||
|
||||
service:
|
||||
invoicing:
|
||||
@ -96,9 +93,9 @@ limit:
|
||||
spring.datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: org.postgresql.Driver
|
||||
url: @db.url@
|
||||
username: @db.user@
|
||||
password: @db.password@
|
||||
url: '@db.url@'
|
||||
username: '@db.user@'
|
||||
password: '@db.password@'
|
||||
hikari:
|
||||
maximum-pool-size: 20
|
||||
idle-timeout: 30000
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.rbkmoney.hooker;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -27,12 +26,12 @@ public abstract class AbstractIntegrationTest {
|
||||
|
||||
@ClassRule
|
||||
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6")
|
||||
.withStartupTimeout(Duration.ofMinutes(5));
|
||||
.withStartupTimeout(Duration.ofMinutes(5));
|
||||
|
||||
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
log.info("Postgres URL: "+ postgres.getJdbcUrl());
|
||||
log.info("Postgres URL: " + postgres.getJdbcUrl());
|
||||
TestPropertyValues.of(
|
||||
"spring.datasource.url=" + postgres.getJdbcUrl(),
|
||||
"spring.datasource.username=" + postgres.getUsername(),
|
||||
@ -44,6 +43,7 @@ public abstract class AbstractIntegrationTest {
|
||||
.applyTo(configurableApplicationContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Value("${local.server.port}")
|
||||
protected int port;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.rbkmoney.hooker;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -24,7 +23,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
@ContextConfiguration(classes = HookerApplication.class, initializers = AbstractKafkaIntegrationTest.Initializer.class)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@Slf4j
|
||||
public abstract class AbstractKafkaIntegrationTest {
|
||||
public abstract class AbstractKafkaIntegrationTest {
|
||||
public static final String SOURCE_ID = "source_id";
|
||||
public static final String SOURCE_NS = "source_ns";
|
||||
|
||||
@ -35,12 +34,12 @@ public abstract class AbstractKafkaIntegrationTest {
|
||||
|
||||
@ClassRule
|
||||
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6")
|
||||
.withStartupTimeout(Duration.ofMinutes(5));
|
||||
.withStartupTimeout(Duration.ofMinutes(5));
|
||||
|
||||
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
log.info("Postgres URL: "+ postgres.getJdbcUrl());
|
||||
log.info("Postgres URL: " + postgres.getJdbcUrl());
|
||||
TestPropertyValues.of(
|
||||
"spring.datasource.url=" + postgres.getJdbcUrl(),
|
||||
"spring.datasource.username=" + postgres.getUsername(),
|
||||
@ -60,6 +59,7 @@ public abstract class AbstractKafkaIntegrationTest {
|
||||
.applyTo(configurableApplicationContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Value("${local.server.port}")
|
||||
protected int port;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CustomerBindingConverterTest extends AbstractIntegrationTest {
|
||||
|
||||
@ -24,10 +24,12 @@ public class CustomerBindingConverterTest extends AbstractIntegrationTest {
|
||||
MockTBaseProcessor mockTBaseProcessor = new MockTBaseProcessor(MockMode.RANDOM, 15, 1);
|
||||
CustomerBinding source = mockTBaseProcessor
|
||||
.process(new CustomerBinding(), new TBaseHandler<>(CustomerBinding.class));
|
||||
source.getPaymentResource().setPaymentTool(PaymentTool.bank_card(mockTBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))));
|
||||
source.getPaymentResource().setPaymentTool(
|
||||
PaymentTool.bank_card(mockTBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))));
|
||||
com.rbkmoney.swag_webhook_events.model.CustomerBinding target = converter.convert(source);
|
||||
assertEquals(source.getId(), target.getId());
|
||||
assertEquals(source.getPaymentResource().getPaymentSessionId(), target.getPaymentResource().getPaymentSession());
|
||||
assertEquals(source.getPaymentResource().getPaymentSessionId(),
|
||||
target.getPaymentResource().getPaymentSession());
|
||||
assertEquals(source.getStatus().getSetField().getFieldName(), target.getStatus().getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CustomerConverterTest extends AbstractIntegrationTest {
|
||||
|
||||
@ -29,4 +29,4 @@ public class CustomerConverterTest extends AbstractIntegrationTest {
|
||||
assertEquals(source.getShopId(), target.getShopID());
|
||||
assertEquals(source.getStatus().getSetField().getFieldName(), target.getStatus().getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class InvoiceConverterTest extends AbstractIntegrationTest {
|
||||
|
||||
@ -32,4 +32,4 @@ public class InvoiceConverterTest extends AbstractIntegrationTest {
|
||||
assertEquals(source.getDetails().getCart().getLines().size(), target.getCart().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ import org.junit.Test;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MetadataDeserializerTest {
|
||||
|
||||
|
@ -33,27 +33,34 @@ public class PaymentConverterTest extends AbstractIntegrationTest {
|
||||
source.setCreatedAt("2016-03-22T06:12:27Z");
|
||||
if (source.getPayer().isSetPaymentResource()) {
|
||||
source.getPayer().getPaymentResource().getResource()
|
||||
.setPaymentTool(PaymentTool.bank_card(mockTBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))));
|
||||
.setPaymentTool(PaymentTool
|
||||
.bank_card(mockTBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))));
|
||||
}
|
||||
Payment target = converter.convert(new com.rbkmoney.damsel.payment_processing.InvoicePayment(source, of(), of(), of(), of()));
|
||||
Payment target = converter
|
||||
.convert(new com.rbkmoney.damsel.payment_processing.InvoicePayment(source, of(), of(), of(), of()));
|
||||
assertEquals(source.getId(), target.getId());
|
||||
assertEquals(source.getStatus().getSetField().getFieldName(), target.getStatus().getValue());
|
||||
if (source.getStatus().isSetCaptured() && source.getStatus().getCaptured().isSetCost()) {
|
||||
assertEquals(source.getStatus().getCaptured().getCost().getAmount(), target.getAmount().longValue());
|
||||
assertEquals(source.getStatus().getCaptured().getCost().getCurrency().getSymbolicCode(), target.getCurrency());
|
||||
assertEquals(source.getStatus().getCaptured().getCost().getCurrency().getSymbolicCode(),
|
||||
target.getCurrency());
|
||||
} else {
|
||||
assertEquals(source.getCost().getAmount(), target.getAmount().longValue());
|
||||
assertEquals(source.getCost().getCurrency().getSymbolicCode(), target.getCurrency());
|
||||
}
|
||||
if (source.getPayer().isSetCustomer()) {
|
||||
assertTrue(target.getPayer() instanceof CustomerPayer);
|
||||
assertEquals(source.getPayer().getCustomer().getCustomerId(), ((CustomerPayer) target.getPayer()).getCustomerID());
|
||||
assertEquals(source.getPayer().getCustomer().getCustomerId(),
|
||||
((CustomerPayer) target.getPayer()).getCustomerID());
|
||||
}
|
||||
if (source.getPayer().isSetPaymentResource()) {
|
||||
assertTrue(target.getPayer() instanceof PaymentResourcePayer);
|
||||
assertEquals(source.getPayer().getPaymentResource().getContactInfo().getEmail(), ((PaymentResourcePayer) target.getPayer()).getContactInfo().getEmail());
|
||||
assertEquals(source.getPayer().getPaymentResource().getContactInfo().getPhoneNumber(), ((PaymentResourcePayer) target.getPayer()).getContactInfo().getPhoneNumber());
|
||||
assertEquals(source.getPayer().getPaymentResource().getResource().getPaymentSessionId(), ((PaymentResourcePayer) target.getPayer()).getPaymentSession());
|
||||
assertEquals(source.getPayer().getPaymentResource().getContactInfo().getEmail(),
|
||||
((PaymentResourcePayer) target.getPayer()).getContactInfo().getEmail());
|
||||
assertEquals(source.getPayer().getPaymentResource().getContactInfo().getPhoneNumber(),
|
||||
((PaymentResourcePayer) target.getPayer()).getContactInfo().getPhoneNumber());
|
||||
assertEquals(source.getPayer().getPaymentResource().getResource().getPaymentSessionId(),
|
||||
((PaymentResourcePayer) target.getPayer()).getPaymentSession());
|
||||
} else if (source.getPayer().isSetRecurrent()) {
|
||||
assertTrue(target.getPayer() instanceof RecurrentPayer);
|
||||
assertEquals(source.getPayer().getRecurrent().getRecurrentParent().getInvoiceId(),
|
||||
|
@ -24,7 +24,8 @@ public class RefundConverterTest extends AbstractIntegrationTest {
|
||||
InvoicePaymentRefund source = new MockTBaseProcessor(MockMode.RANDOM, 15, 1)
|
||||
.process(new InvoicePaymentRefund(), new TBaseHandler<>(InvoicePaymentRefund.class));
|
||||
source.setCreatedAt("2016-03-22T06:12:27Z");
|
||||
Refund target = converter.convert(new com.rbkmoney.damsel.payment_processing.InvoicePaymentRefund(source, of()));
|
||||
Refund target =
|
||||
converter.convert(new com.rbkmoney.damsel.payment_processing.InvoicePaymentRefund(source, of()));
|
||||
assertEquals(source.getId(), target.getId());
|
||||
assertEquals(source.getStatus().getSetField().getFieldName(), target.getStatus().getValue());
|
||||
assertEquals(source.getReason(), target.getReason());
|
||||
|
@ -34,8 +34,10 @@ public class CustomerMessageDaoImplTest extends AbstractIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if(!messagesCreated){
|
||||
CustomerMessage message = buildCustomerMessage(1L, "1234", EventType.CUSTOMER_CREATED, CustomerMessageEnum.CUSTOMER, "124", "4356");
|
||||
if (!messagesCreated) {
|
||||
CustomerMessage message =
|
||||
buildCustomerMessage(1L, "1234", EventType.CUSTOMER_CREATED, CustomerMessageEnum.CUSTOMER, "124",
|
||||
"4356");
|
||||
message.setSequenceId(1L);
|
||||
message.setChangeId(1);
|
||||
messageDao.create(message);
|
||||
@ -45,7 +47,9 @@ public class CustomerMessageDaoImplTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testDuplication() {
|
||||
CustomerMessage message = buildCustomerMessage(1L, "1234", EventType.CUSTOMER_CREATED, CustomerMessageEnum.CUSTOMER, "124", "4356");
|
||||
CustomerMessage message =
|
||||
buildCustomerMessage(1L, "1234", EventType.CUSTOMER_CREATED, CustomerMessageEnum.CUSTOMER, "124",
|
||||
"4356");
|
||||
message.setSequenceId(1L);
|
||||
message.setChangeId(1);
|
||||
messageDao.create(message);
|
||||
|
@ -5,7 +5,6 @@ import com.rbkmoney.damsel.webhooker.WebhookParams;
|
||||
import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.Hook;
|
||||
import com.rbkmoney.hooker.model.HooksLimit;
|
||||
import com.rbkmoney.hooker.model.PartyMetadata;
|
||||
import com.rbkmoney.hooker.utils.EventFilterUtils;
|
||||
import com.rbkmoney.hooker.utils.HookConverter;
|
||||
@ -17,17 +16,19 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Created by inalarsanukaev on 08.04.17.
|
||||
@ -47,31 +48,41 @@ public class HookDaoImplTest extends AbstractIntegrationTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Set<WebhookAdditionalFilter> webhookAdditionalFilters = new HashSet<>();
|
||||
webhookAdditionalFilters.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "cancelled", null));
|
||||
webhookAdditionalFilters
|
||||
.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "cancelled",
|
||||
null));
|
||||
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_CREATED).build());
|
||||
EventFilter eventFilterByCode = EventFilterUtils.getEventFilter(webhookAdditionalFilters);
|
||||
eventFilterByCode.getInvoice().setShopId("1");
|
||||
WebhookParams webhookParams = new WebhookParams("123", eventFilterByCode, "https://google.com");
|
||||
Hook hook = hookDao.create(HookConverter.convert(webhookParams));
|
||||
ids.add(hook.getId());
|
||||
webhookAdditionalFilters.clear();
|
||||
webhookAdditionalFilters
|
||||
.add(new WebhookAdditionalFilter(EventType.INVOICE_STATUS_CHANGED, "78", "unpaid", null, null));
|
||||
webhookAdditionalFilters
|
||||
.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_STARTED).shopId("78")
|
||||
.build());
|
||||
webhookParams = new WebhookParams("999", EventFilterUtils.getEventFilter(webhookAdditionalFilters),
|
||||
"https://yandex.ru");
|
||||
hook = hookDao.create(HookConverter.convert(webhookParams));
|
||||
ids.add(hook.getId());
|
||||
webhookAdditionalFilters.clear();
|
||||
webhookAdditionalFilters
|
||||
.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_STATUS_CHANGED).build());
|
||||
webhookParams =
|
||||
new WebhookParams("123", EventFilterUtils.getEventFilter(webhookAdditionalFilters), "https://2ch.hk/b");
|
||||
hook = hookDao.create(HookConverter.convert(webhookParams));
|
||||
ids.add(hook.getId());
|
||||
String pubKey1 = hook.getPubKey();
|
||||
ids.add(hook.getId());
|
||||
webhookAdditionalFilters.clear();
|
||||
webhookAdditionalFilters.add(new WebhookAdditionalFilter(EventType.INVOICE_STATUS_CHANGED, "78", "unpaid", null, null));
|
||||
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_STARTED).shopId("78").build());
|
||||
webhookParams = new WebhookParams("999", EventFilterUtils.getEventFilter(webhookAdditionalFilters), "https://yandex.ru");
|
||||
hook = hookDao.create(HookConverter.convert(webhookParams));
|
||||
ids.add(hook.getId());
|
||||
webhookAdditionalFilters.clear();
|
||||
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_STATUS_CHANGED).build());
|
||||
webhookParams = new WebhookParams("123", EventFilterUtils.getEventFilter(webhookAdditionalFilters), "https://2ch.hk/b");
|
||||
hook = hookDao.create(HookConverter.convert(webhookParams));
|
||||
String pubKey2 = hook.getPubKey();
|
||||
ids.add(hook.getId());
|
||||
Assert.assertEquals(pubKey1, pubKey2);
|
||||
webhookAdditionalFilters.clear();
|
||||
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_CREATED).build());
|
||||
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_BINDING_SUCCEEDED).build());
|
||||
webhookParams = new WebhookParams("123", EventFilterUtils.getEventFilter(webhookAdditionalFilters), "https://2ch.hk/b");
|
||||
webhookAdditionalFilters
|
||||
.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_BINDING_SUCCEEDED).build());
|
||||
webhookParams =
|
||||
new WebhookParams("123", EventFilterUtils.getEventFilter(webhookAdditionalFilters), "https://2ch.hk/b");
|
||||
hook = hookDao.create(HookConverter.convert(webhookParams));
|
||||
}
|
||||
|
||||
@ -88,19 +99,26 @@ public class HookDaoImplTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstraint(){
|
||||
public void testConstraint() {
|
||||
Set<WebhookAdditionalFilter> webhookAdditionalFilters = new HashSet<>();
|
||||
webhookAdditionalFilters.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "failed", "succeeded"));
|
||||
webhookAdditionalFilters.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "pending", null));
|
||||
WebhookParams webhookParams = new WebhookParams("123", EventFilterUtils.getEventFilter(webhookAdditionalFilters), "https://2ch.hk/b");
|
||||
webhookAdditionalFilters
|
||||
.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "failed",
|
||||
"succeeded"));
|
||||
webhookAdditionalFilters
|
||||
.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "pending",
|
||||
null));
|
||||
WebhookParams webhookParams =
|
||||
new WebhookParams("123", EventFilterUtils.getEventFilter(webhookAdditionalFilters), "https://2ch.hk/b");
|
||||
Hook hook = hookDao.create(HookConverter.convert(webhookParams));
|
||||
ids.add(hook.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPartyWebhooks() throws Exception {
|
||||
assertEquals(hookDao.getPartyHooks("123").stream().filter(Hook::isEnabled).collect(Collectors.toList()).size(), 3);
|
||||
Assert.assertTrue(hookDao.getPartyHooks("88888").stream().filter(Hook::isEnabled).collect(Collectors.toList()).isEmpty());
|
||||
assertEquals(hookDao.getPartyHooks("123").stream().filter(Hook::isEnabled).collect(Collectors.toList()).size(),
|
||||
3);
|
||||
Assert.assertTrue(
|
||||
hookDao.getPartyHooks("88888").stream().filter(Hook::isEnabled).collect(Collectors.toList()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -125,25 +143,27 @@ public class HookDaoImplTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getShopHooksCountTest(){
|
||||
public void getShopHooksCountTest() {
|
||||
assertEquals(1, hookDao.getShopHooksCount("123", "1"));
|
||||
assertEquals(0, hookDao.getShopHooksCount("kekekekekeke", "1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPartyHooksCountTest(){
|
||||
public void getPartyHooksCountTest() {
|
||||
assertEquals(2, hookDao.getPartyHooksCount("123"));
|
||||
assertEquals(0, hookDao.getPartyHooksCount("keke"));
|
||||
}
|
||||
|
||||
public static Hook buildHook(String partyId, String url){
|
||||
public static Hook buildHook(String partyId, String url) {
|
||||
Hook hook = new Hook();
|
||||
hook.setPartyId(partyId);
|
||||
hook.setUrl(url);
|
||||
hook.setTopic(Event.TopicEnum.INVOICESTOPIC.getValue());
|
||||
|
||||
Set<WebhookAdditionalFilter> webhookAdditionalFilters = new HashSet<>();
|
||||
webhookAdditionalFilters.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "cancelled", "failed"));
|
||||
webhookAdditionalFilters
|
||||
.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "cancelled",
|
||||
"failed"));
|
||||
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_CREATED).build());
|
||||
hook.setFilters(webhookAdditionalFilters);
|
||||
|
||||
@ -157,7 +177,7 @@ public class HookDaoImplTest extends AbstractIntegrationTest {
|
||||
hookDao.getPartyHooks("123").forEach(h -> assertEquals(availability, h.getAvailability(), 0.000000000001));
|
||||
}
|
||||
|
||||
public static Hook buildCustomerHook(String partyId, String url){
|
||||
public static Hook buildCustomerHook(String partyId, String url) {
|
||||
Hook hook = new Hook();
|
||||
hook.setPartyId(partyId);
|
||||
hook.setUrl(url);
|
||||
|
@ -1,8 +1,17 @@
|
||||
package com.rbkmoney.hooker.dao;
|
||||
|
||||
import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.dao.impl.*;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.dao.impl.CustomerDaoImpl;
|
||||
import com.rbkmoney.hooker.dao.impl.CustomerQueueDao;
|
||||
import com.rbkmoney.hooker.dao.impl.CustomerTaskDao;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingQueueDao;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingTaskDao;
|
||||
import com.rbkmoney.hooker.model.CustomerMessageEnum;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.Hook;
|
||||
import com.rbkmoney.hooker.model.InvoiceStatusEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import com.rbkmoney.hooker.service.BatchService;
|
||||
import com.rbkmoney.hooker.utils.BuildUtils;
|
||||
import org.junit.Test;
|
||||
@ -15,7 +24,10 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.rbkmoney.hooker.utils.BuildUtils.buildCustomerMessage;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@ -45,27 +57,31 @@ public class HookDeleteDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testDelete() {
|
||||
Long hookId = hookDao.create(HookDaoImplTest.buildHook("partyId", "fake.url")).getId();
|
||||
Long hookId2 = hookDao.create(HookDaoImplTest.buildHook("partyId2", "fake2.url")).getId();
|
||||
batchService.process(Collections.singletonList(BuildUtils.buildMessage(InvoicingMessageEnum.INVOICE.getValue(),"2345", "partyId", EventType.INVOICE_CREATED, InvoiceStatusEnum.FULFILLED, PaymentStatusEnum.CAPTURED)));
|
||||
Hook hook1 = hookDao.create(HookDaoImplTest.buildHook("partyId", "fake.url"));
|
||||
Hook hook2 = hookDao.create(HookDaoImplTest.buildHook("partyId2", "fake2.url"));
|
||||
batchService.process(Collections.singletonList(BuildUtils
|
||||
.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "2345", hook1.getPartyId(),
|
||||
EventType.INVOICE_CREATED, InvoiceStatusEnum.FULFILLED, PaymentStatusEnum.CAPTURED)));
|
||||
assertEquals(queueDao.getWithPolicies(taskDao.getScheduled().keySet()).size(), 1);
|
||||
hookDao.delete(hookId2);
|
||||
|
||||
hookDao.delete(hook2.getId());
|
||||
assertNotEquals(queueDao.getWithPolicies(taskDao.getScheduled().keySet()).size(), 0);
|
||||
hookDao.delete(hookId);
|
||||
hookDao.delete(hook1.getId());
|
||||
assertTrue(taskDao.getScheduled().keySet().isEmpty());
|
||||
assertFalse(hookDao.getHookById(hookId).isEnabled());
|
||||
assertFalse(hookDao.getHookById(hookId2).isEnabled());
|
||||
assertFalse(hookDao.getHookById(hook1.getId()).isEnabled());
|
||||
assertFalse(hookDao.getHookById(hook2.getId()).isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomerHooks() {
|
||||
Long hookId = hookDao.create(HookDaoImplTest.buildCustomerHook("partyId", "fake.url")).getId();
|
||||
Long messageId = customerDaoImpl.create(buildCustomerMessage(1L, "partyId", EventType.CUSTOMER_CREATED, CustomerMessageEnum.CUSTOMER, "124", "4356"));
|
||||
Hook hook = hookDao.create(HookDaoImplTest.buildCustomerHook("partyId", "fake.url"));
|
||||
Long messageId = customerDaoImpl.create(buildCustomerMessage(1L, hook.getPartyId(), EventType.CUSTOMER_CREATED,
|
||||
CustomerMessageEnum.CUSTOMER, "124", "4356"));
|
||||
customerQueueDao.createWithPolicy(messageId);
|
||||
customerTaskDao.create(messageId);
|
||||
assertEquals(customerQueueDao.getWithPolicies(customerTaskDao.getScheduled().keySet()).size(), 1);
|
||||
hookDao.delete(hookId);
|
||||
hookDao.delete(hook.getId());
|
||||
assertTrue(customerTaskDao.getScheduled().keySet().isEmpty());
|
||||
assertFalse(hookDao.getHookById(hookId).isEnabled());
|
||||
assertFalse(hookDao.getHookById(hook.getId()).isEnabled());
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,12 @@ package com.rbkmoney.hooker.dao;
|
||||
import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingMessageDaoImpl;
|
||||
import com.rbkmoney.hooker.exception.NotFoundException;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoiceStatusEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@ -18,7 +23,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.rbkmoney.hooker.utils.BuildUtils.buildMessage;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by inalarsanukaev on 09.04.17.
|
||||
@ -37,16 +42,20 @@ public class InvoicingMessageDaoImplTest extends AbstractIntegrationTest {
|
||||
public void setUp() throws Exception {
|
||||
if (!messagesCreated) {
|
||||
messageDao.saveBatch(Arrays.asList(
|
||||
buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "1234", "56678", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED),
|
||||
buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "1235", "56678", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED),
|
||||
buildMessage(InvoicingMessageEnum.PAYMENT.getValue(), "1236", "56678", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED)));
|
||||
buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "1234", "56678", EventType.INVOICE_CREATED,
|
||||
InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED),
|
||||
buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "1235", "56678", EventType.INVOICE_CREATED,
|
||||
InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED),
|
||||
buildMessage(InvoicingMessageEnum.PAYMENT.getValue(), "1236", "56678", EventType.INVOICE_CREATED,
|
||||
InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED)));
|
||||
messagesCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void get() throws Exception {
|
||||
InvoicingMessage message = messageDao.getInvoicingMessage(InvoicingMessageKey.builder().invoiceId("1235").type(InvoicingMessageEnum.INVOICE).build());
|
||||
InvoicingMessage message = messageDao.getInvoicingMessage(
|
||||
InvoicingMessageKey.builder().invoiceId("1235").type(InvoicingMessageEnum.INVOICE).build());
|
||||
assertEquals(message.getInvoiceId(), "1235");
|
||||
assertEquals(message.getInvoiceStatus(), InvoiceStatusEnum.PAID);
|
||||
|
||||
@ -54,13 +63,16 @@ public class InvoicingMessageDaoImplTest extends AbstractIntegrationTest {
|
||||
assertEquals(1, messages.size());
|
||||
assertEquals(messages.get(0).getPartyId(), "56678");
|
||||
|
||||
InvoicingMessage payment = messageDao.getInvoicingMessage(InvoicingMessageKey.builder().invoiceId("1236").paymentId("123").type(InvoicingMessageEnum.PAYMENT).build());
|
||||
InvoicingMessage payment = messageDao.getInvoicingMessage(
|
||||
InvoicingMessageKey.builder().invoiceId("1236").paymentId("123").type(InvoicingMessageEnum.PAYMENT)
|
||||
.build());
|
||||
assertEquals("123", payment.getPaymentId());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test(expected = NotFoundException.class)
|
||||
public void testNotFound(){
|
||||
messageDao.getInvoicingMessage(InvoicingMessageKey.builder().invoiceId("kek").paymentId("lol").refundId("kk").build());
|
||||
public void testNotFound() {
|
||||
messageDao.getInvoicingMessage(
|
||||
InvoicingMessageKey.builder().invoiceId("kek").paymentId("lol").refundId("kk").build());
|
||||
}
|
||||
}
|
||||
|
@ -4,27 +4,35 @@ import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingMessageDaoImpl;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingQueueDao;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingTaskDao;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.Hook;
|
||||
import com.rbkmoney.hooker.model.InvoiceStatusEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import com.rbkmoney.hooker.model.Message;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import com.rbkmoney.hooker.model.Task;
|
||||
import com.rbkmoney.hooker.utils.BuildUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by jeckep on 17.04.17.
|
||||
@ -61,13 +69,19 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
jdbcTemplate.update("truncate hook.scheduled_task, hook.invoicing_queue, hook.message, hook.webhook_to_events, hook.webhook", new HashMap<>());
|
||||
jdbcTemplate.update(
|
||||
"truncate hook.scheduled_task, hook.invoicing_queue, " +
|
||||
" hook.message, hook.webhook_to_events, hook.webhook",
|
||||
new HashMap<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDeleteGet() {
|
||||
messageDao.saveBatch(Collections.singletonList(BuildUtils.buildMessage(InvoicingMessageEnum.INVOICE.getValue(),"2345", "partyId", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED)));
|
||||
messageId = messageDao.getInvoicingMessage(InvoicingMessageKey.builder().invoiceId("2345").type(InvoicingMessageEnum.INVOICE).build()).getId();
|
||||
messageDao.saveBatch(Collections.singletonList(BuildUtils
|
||||
.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "2345", "partyId", EventType.INVOICE_CREATED,
|
||||
InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED)));
|
||||
messageId = messageDao.getInvoicingMessage(
|
||||
InvoicingMessageKey.builder().invoiceId("2345").type(InvoicingMessageEnum.INVOICE).build()).getId();
|
||||
queueDao.saveBatchWithPolicies(Collections.singletonList(messageId));
|
||||
taskDao.save(Collections.singletonList(messageId));
|
||||
Map<Long, List<Task>> scheduled = taskDao.getScheduled();
|
||||
@ -77,9 +91,12 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveWithHookIdAndInvoiceId(){
|
||||
messageDao.saveBatch(Collections.singletonList(BuildUtils.buildMessage(InvoicingMessageEnum.INVOICE.getValue(),"2345", "partyId", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED)));
|
||||
messageId = messageDao.getInvoicingMessage(InvoicingMessageKey.builder().invoiceId("2345").type(InvoicingMessageEnum.INVOICE).build()).getId();
|
||||
public void testSaveWithHookIdAndInvoiceId() {
|
||||
messageDao.saveBatch(Collections.singletonList(BuildUtils
|
||||
.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "2345", "partyId", EventType.INVOICE_CREATED,
|
||||
InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED)));
|
||||
messageId = messageDao.getInvoicingMessage(
|
||||
InvoicingMessageKey.builder().invoiceId("2345").type(InvoicingMessageEnum.INVOICE).build()).getId();
|
||||
queueDao.saveBatchWithPolicies(Collections.singletonList(messageId));
|
||||
int count = taskDao.save(hookId, "2345");
|
||||
assertEquals(1, count);
|
||||
@ -90,10 +107,9 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
int cnt = 20;
|
||||
|
||||
List<InvoicingMessage> messagesOne = IntStream.range(0, cnt).mapToObj(i -> BuildUtils.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "invoice_id1", "partyId", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<InvoicingMessage> messagesSecond = IntStream.range(0, cnt).mapToObj(i -> BuildUtils.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "invoice_id2", "partyId", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED))
|
||||
List<InvoicingMessage> messagesOne = IntStream.range(0, cnt).mapToObj(i -> BuildUtils
|
||||
.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "invoice_id1", "partyId",
|
||||
EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
messageDao.saveBatch(messagesOne);
|
||||
@ -101,6 +117,11 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
queueDao.saveBatchWithPolicies(messageIdsOne);
|
||||
taskDao.save(messageIdsOne);
|
||||
|
||||
List<InvoicingMessage> messagesSecond = IntStream.range(0, cnt).mapToObj(i -> BuildUtils
|
||||
.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "invoice_id2", "partyId",
|
||||
EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
messageDao.saveBatch(messagesSecond);
|
||||
List<Long> messageIdsSecond = messagesSecond.stream().map(Message::getId).collect(Collectors.toList());
|
||||
queueDao.saveBatchWithPolicies(messageIdsSecond);
|
||||
@ -108,7 +129,8 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
Set<Long> scheduledOne = new HashSet<>();
|
||||
new Thread(() -> transactionTemplate.execute(tr -> {
|
||||
scheduledOne.addAll(taskDao.getScheduled().values().stream().flatMap(List::stream).map(Task::getMessageId).collect(Collectors.toSet()));
|
||||
scheduledOne.addAll(taskDao.getScheduled().values().stream().flatMap(List::stream).map(Task::getMessageId)
|
||||
.collect(Collectors.toSet()));
|
||||
System.out.println("scheduledOne: " + scheduledOne);
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
@ -124,7 +146,8 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
Set<Long> scheduledTwo = new HashSet<>();
|
||||
new Thread(() -> transactionTemplate.execute(tr -> {
|
||||
scheduledTwo.addAll(taskDao.getScheduled().values().stream().flatMap(List::stream).map(Task::getMessageId).collect(Collectors.toSet()));
|
||||
scheduledTwo.addAll(taskDao.getScheduled().values().stream().flatMap(List::stream).map(Task::getMessageId)
|
||||
.collect(Collectors.toSet()));
|
||||
System.out.println("scheduledTwo :" + scheduledTwo);
|
||||
return 1;
|
||||
})).start();
|
||||
@ -142,7 +165,9 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
hookDao.create(HookDaoImplTest.buildHook("partyId", "fake2.url"));
|
||||
|
||||
InvoicingMessage message = BuildUtils.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "1", "partyId", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED);
|
||||
InvoicingMessage message = BuildUtils
|
||||
.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "1", "partyId", EventType.INVOICE_CREATED,
|
||||
InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED);
|
||||
|
||||
messageDao.saveBatch(List.of(message));
|
||||
queueDao.saveBatchWithPolicies(List.of(message.getId()));
|
||||
@ -150,7 +175,8 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
Set<String> scheduledOne = new HashSet<>();
|
||||
new Thread(() -> transactionTemplate.execute(tr -> {
|
||||
scheduledOne.addAll(taskDao.getScheduled().values().stream().flatMap(List::stream).map(t -> t.getMessageId() + " " + t.getQueueId()).collect(Collectors.toSet()));
|
||||
scheduledOne.addAll(taskDao.getScheduled().values().stream().flatMap(List::stream)
|
||||
.map(t -> t.getMessageId() + " " + t.getQueueId()).collect(Collectors.toSet()));
|
||||
System.out.println("scheduledOne: " + scheduledOne);
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
@ -166,7 +192,8 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
Set<String> scheduledTwo = new HashSet<>();
|
||||
new Thread(() -> transactionTemplate.execute(tr -> {
|
||||
scheduledTwo.addAll(taskDao.getScheduled().values().stream().flatMap(List::stream).map(t -> t.getMessageId() + " " + t.getQueueId()).collect(Collectors.toSet()));
|
||||
scheduledTwo.addAll(taskDao.getScheduled().values().stream().flatMap(List::stream)
|
||||
.map(t -> t.getMessageId() + " " + t.getQueueId()).collect(Collectors.toSet()));
|
||||
System.out.println("scheduledTwo :" + scheduledTwo);
|
||||
return 1;
|
||||
})).start();
|
||||
@ -182,11 +209,15 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
Hook hook1 = HookDaoImplTest.buildHook("partyId_1", "fake1.url");
|
||||
hookDao.create(hook1);
|
||||
hookDao.updateAvailability(hookDao.getPartyHooks("partyId_1").get(0).getId(), 0.1);
|
||||
InvoicingMessage message1 = BuildUtils.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "1", "partyId_1", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED);
|
||||
InvoicingMessage message1 = BuildUtils
|
||||
.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "1", "partyId_1", EventType.INVOICE_CREATED,
|
||||
InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED);
|
||||
|
||||
Hook hook2 = HookDaoImplTest.buildHook("partyId_2", "fake2.url");
|
||||
hookDao.create(hook2);
|
||||
InvoicingMessage message2 = BuildUtils.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "2", "partyId_2", EventType.INVOICE_CREATED, InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED);
|
||||
InvoicingMessage message2 = BuildUtils
|
||||
.buildMessage(InvoicingMessageEnum.INVOICE.getValue(), "2", "partyId_2", EventType.INVOICE_CREATED,
|
||||
InvoiceStatusEnum.PAID, PaymentStatusEnum.CAPTURED);
|
||||
|
||||
messageDao.saveBatch(List.of(message1, message2));
|
||||
queueDao.saveBatchWithPolicies(List.of(message1.getId(), message2.getId()));
|
||||
|
@ -10,7 +10,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
|
@ -8,7 +8,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CleanTablesDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
@ -30,7 +30,7 @@ public class CleanTablesDaoTest extends AbstractIntegrationTest {
|
||||
int countOldRecords = 1000;
|
||||
IntStream.range(0, countOldRecords).forEach(i -> {
|
||||
jdbcTemplate.update(sql, new MapSqlParameterSource("invoice_id", "old" + i)
|
||||
.addValue("days_ago", 11));
|
||||
.addValue("days_ago", 11));
|
||||
});
|
||||
|
||||
|
||||
@ -44,7 +44,8 @@ public class CleanTablesDaoTest extends AbstractIntegrationTest {
|
||||
int count = cleanTablesDao.cleanInvocing(10);
|
||||
assertEquals(count, countOldRecords);
|
||||
|
||||
long newRecordsCount = jdbcTemplate.queryForObject("select count(*) from hook.invoicing_queue", new MapSqlParameterSource(), Long.class);
|
||||
long newRecordsCount = jdbcTemplate
|
||||
.queryForObject("select count(*) from hook.invoicing_queue", new MapSqlParameterSource(), Long.class);
|
||||
assertEquals(newRecordsCount, countNewRecords);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.rbkmoney.hooker.dao.impl;
|
||||
|
||||
import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.dao.CustomerDao;
|
||||
import com.rbkmoney.hooker.dao.CustomerMessageDaoImplTest;
|
||||
import com.rbkmoney.hooker.dao.HookDao;
|
||||
import com.rbkmoney.hooker.dao.HookDaoImplTest;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.CustomerMessageEnum;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.Task;
|
||||
import com.rbkmoney.hooker.utils.BuildUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -16,12 +16,11 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@ -49,13 +48,16 @@ public class CustomerTaskDaoTest extends AbstractIntegrationTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
hookId = hookDao.create(HookDaoImplTest.buildCustomerHook("partyId", "fake.url")).getId();
|
||||
customerDao.create(BuildUtils.buildCustomerMessage(1L, "partyId", EventType.CUSTOMER_CREATED, CustomerMessageEnum.CUSTOMER, custId, "4356"));
|
||||
customerDao.create(BuildUtils
|
||||
.buildCustomerMessage(1L, "partyId", EventType.CUSTOMER_CREATED, CustomerMessageEnum.CUSTOMER, custId,
|
||||
"4356"));
|
||||
messageId = customerDao.getAny(custId, CustomerMessageEnum.CUSTOMER).getId();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
jdbcTemplate.update("truncate hook.scheduled_task, hook.customer_queue, hook.customer_message, hook.webhook_to_events, hook.webhook", new HashMap<>());
|
||||
jdbcTemplate.update("truncate hook.scheduled_task, hook.customer_queue, hook.customer_message, " +
|
||||
"hook.webhook_to_events, hook.webhook", new HashMap<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -69,7 +71,7 @@ public class CustomerTaskDaoTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveWithHookIdAndCustomerId(){
|
||||
public void testSaveWithHookIdAndCustomerId() {
|
||||
queueDao.createWithPolicy(messageId);
|
||||
int count = taskDao.create(hookId, custId);
|
||||
assertEquals(1, count);
|
||||
|
@ -2,13 +2,16 @@ package com.rbkmoney.hooker.kafka;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.EventPayload;
|
||||
import com.rbkmoney.hooker.AbstractKafkaIntegrationTest;
|
||||
import com.rbkmoney.hooker.listener.*;
|
||||
import com.rbkmoney.sink.common.parser.impl.MachineEventParser;
|
||||
import com.rbkmoney.hooker.listener.CustomerEventKafkaListener;
|
||||
import com.rbkmoney.hooker.listener.CustomerMachineEventHandler;
|
||||
import com.rbkmoney.hooker.listener.InvoicingEventKafkaListener;
|
||||
import com.rbkmoney.hooker.listener.InvoicingMachineEventHandler;
|
||||
import com.rbkmoney.hooker.service.HandlerManager;
|
||||
import com.rbkmoney.kafka.common.serialization.ThriftSerializer;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.machinegun.eventsink.SinkEvent;
|
||||
import com.rbkmoney.machinegun.msgpack.Value;
|
||||
import com.rbkmoney.sink.common.parser.impl.MachineEventParser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
@ -20,7 +23,6 @@ import org.mockito.Mockito;
|
||||
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
@ -69,19 +69,22 @@ public class CustomerMachineEventHandlerTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
private static List<CustomerChange> createCustomerChangeList(String customerId) {
|
||||
List<CustomerChange> changes = new ArrayList<>();
|
||||
CustomerChange change = new CustomerChange();
|
||||
ContactInfo contactInfo = new ContactInfo();
|
||||
contactInfo.setEmail("1@1.ru");
|
||||
contactInfo.setPhoneNumber("88005553535");
|
||||
|
||||
CustomerCreated created = new CustomerCreated();
|
||||
created.setCustomerId(customerId);
|
||||
created.setOwnerId("PartyId");
|
||||
created.setShopId("ShopId");
|
||||
created.setMetadata(null);
|
||||
ContactInfo contactInfo = new ContactInfo();
|
||||
contactInfo.setEmail("1@1.ru");
|
||||
contactInfo.setPhoneNumber("88005553535");
|
||||
created.setContactInfo(contactInfo);
|
||||
created.setCreatedAt(TypeUtil.temporalToString(LocalDateTime.now()));
|
||||
|
||||
CustomerChange change = new CustomerChange();
|
||||
change.setCustomerCreated(created);
|
||||
|
||||
List<CustomerChange> changes = new ArrayList<>();
|
||||
changes.add(change);
|
||||
return changes;
|
||||
}
|
||||
|
@ -71,13 +71,14 @@ public class InvoicingMachineEventHandlerTest {
|
||||
|
||||
@Test
|
||||
public void listenChanges() {
|
||||
MachineEvent message = new MachineEvent();
|
||||
Event event = new Event();
|
||||
EventPayload payload = new EventPayload();
|
||||
ArrayList<InvoiceChange> invoiceChanges = new ArrayList<>();
|
||||
invoiceChanges.add(new InvoiceChange());
|
||||
EventPayload payload = new EventPayload();
|
||||
payload.setInvoiceChanges(invoiceChanges);
|
||||
Event event = new Event();
|
||||
event.setPayload(payload);
|
||||
MachineEvent message = new MachineEvent();
|
||||
|
||||
Mockito.when(eventParser.parse(message)).thenReturn(payload);
|
||||
Mockito.when(handlerManager.getHandler(any())).thenReturn(java.util.Optional.of(handler));
|
||||
|
||||
|
@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class InvoicingMessageKeyTest {
|
||||
|
||||
|
@ -1,28 +1,64 @@
|
||||
package com.rbkmoney.hooker.service;
|
||||
|
||||
import com.rbkmoney.damsel.base.Content;
|
||||
import com.rbkmoney.damsel.domain.*;
|
||||
import com.rbkmoney.damsel.domain.BankCard;
|
||||
import com.rbkmoney.damsel.domain.BankCardPaymentSystem;
|
||||
import com.rbkmoney.damsel.domain.Cash;
|
||||
import com.rbkmoney.damsel.domain.ClientInfo;
|
||||
import com.rbkmoney.damsel.domain.ContactInfo;
|
||||
import com.rbkmoney.damsel.domain.CurrencyRef;
|
||||
import com.rbkmoney.damsel.domain.DisposablePaymentResource;
|
||||
import com.rbkmoney.damsel.domain.Invoice;
|
||||
import com.rbkmoney.damsel.domain.InvoiceCart;
|
||||
import com.rbkmoney.damsel.domain.InvoiceDetails;
|
||||
import com.rbkmoney.damsel.domain.InvoiceLine;
|
||||
import com.rbkmoney.damsel.domain.InvoicePayment;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentFlow;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentPending;
|
||||
import com.rbkmoney.damsel.payment_processing.*;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentProcessed;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.InvoiceStatus;
|
||||
import com.rbkmoney.damsel.domain.InvoiceUnpaid;
|
||||
import com.rbkmoney.damsel.domain.Payer;
|
||||
import com.rbkmoney.damsel.domain.PaymentResourcePayer;
|
||||
import com.rbkmoney.damsel.domain.PaymentTool;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoiceChange;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoiceCreated;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoicePaymentChange;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoicePaymentChangePayload;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoicePaymentStarted;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoicePaymentStatusChanged;
|
||||
import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.dao.HookDao;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingMessageDaoImpl;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingQueueDao;
|
||||
import com.rbkmoney.hooker.dao.impl.InvoicingTaskDao;
|
||||
import com.rbkmoney.hooker.handler.poller.invoicing.AbstractInvoiceEventMapper;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventInfo;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageKey;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import com.rbkmoney.hooker.utils.BuildUtils;
|
||||
import com.rbkmoney.hooker.utils.KeyUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BatchProcessingTest extends AbstractIntegrationTest {
|
||||
|
||||
@ -46,15 +82,12 @@ public class BatchProcessingTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testBatchProcess() {
|
||||
|
||||
hookDao.create(BuildUtils.buildHook("partyId", "www.kek.ru", EventType.INVOICE_CREATED));
|
||||
|
||||
|
||||
LinkedHashMap<InvoicingMessageKey, InvoicingMessage> storage = new LinkedHashMap<>();
|
||||
List<InvoicingMessage> messages = new ArrayList<>();
|
||||
|
||||
InvoiceChange ic = getInvoiceCreated();
|
||||
EventInfo eventInfo = new EventInfo(null, "2016-03-22T06:12:27Z", "invoiceId",1L,1);
|
||||
EventInfo eventInfo = new EventInfo(null, "2016-03-22T06:12:27Z", "invoiceId", 1L, 1);
|
||||
Optional<AbstractInvoiceEventMapper> eventMapperOptional = handlerManager.getHandler(ic);
|
||||
assertTrue(eventMapperOptional.isPresent());
|
||||
AbstractInvoiceEventMapper invoiceEventMapper = eventMapperOptional.get();
|
||||
@ -63,30 +96,39 @@ public class BatchProcessingTest extends AbstractIntegrationTest {
|
||||
assertEquals("invoiceId", invoiceCreated.getInvoiceId());
|
||||
assertEquals(InvoicingMessageEnum.INVOICE, invoiceCreated.getType());
|
||||
storage.put(KeyUtils.key(invoiceCreated), invoiceCreated);
|
||||
messages.add(invoiceCreated);
|
||||
|
||||
InvoiceChange icPaymentStarted = getInvoicePaymentStarted();
|
||||
EventInfo eventInfoPaymentStarted = new EventInfo(null, "2016-03-22T06:12:27Z", "invoiceId",1L,2);
|
||||
Optional<AbstractInvoiceEventMapper> eventMapperPaymentStartedOptional = handlerManager.getHandler(icPaymentStarted);
|
||||
Optional<AbstractInvoiceEventMapper> eventMapperPaymentStartedOptional =
|
||||
handlerManager.getHandler(icPaymentStarted);
|
||||
assertTrue(eventMapperPaymentStartedOptional.isPresent());
|
||||
AbstractInvoiceEventMapper invoicePaymentStartedEventMapper = eventMapperPaymentStartedOptional.get();
|
||||
InvoicingMessage paymentStarted = invoicePaymentStartedEventMapper.handle(icPaymentStarted, eventInfoPaymentStarted, storage);
|
||||
InvoicingMessage paymentStarted =
|
||||
invoicePaymentStartedEventMapper.handle(icPaymentStarted, eventInfoPaymentStarted, storage);
|
||||
assertNotNull(paymentStarted);
|
||||
assertEquals(InvoicingMessageEnum.PAYMENT, paymentStarted.getType());
|
||||
assertEquals("partyId", paymentStarted.getPartyId());
|
||||
assertNotEquals(invoiceCreated.getChangeId(), paymentStarted.getChangeId());
|
||||
|
||||
List<InvoicingMessage> messages = new ArrayList<>();
|
||||
|
||||
storage.put(KeyUtils.key(invoiceCreated), invoiceCreated);
|
||||
storage.put(KeyUtils.key(paymentStarted), paymentStarted);
|
||||
messages.add(invoiceCreated);
|
||||
messages.add(paymentStarted);
|
||||
|
||||
assertEquals(2, storage.size());
|
||||
assertEquals(2, messages.size());
|
||||
|
||||
InvoiceChange icStatusChanged = getInvoicePaymentChangeStatus();
|
||||
EventInfo eventInfoPaymentStatusChanged = new EventInfo(null, "2016-03-22T06:12:27Z", "invoiceId",1L,3);
|
||||
Optional<AbstractInvoiceEventMapper> eventMapperPaymentStatusChangedOptional = handlerManager.getHandler(icStatusChanged);
|
||||
EventInfo eventInfoPaymentStatusChanged = new EventInfo(null, "2016-03-22T06:12:27Z", "invoiceId", 1L, 3);
|
||||
Optional<AbstractInvoiceEventMapper> eventMapperPaymentStatusChangedOptional =
|
||||
handlerManager.getHandler(icStatusChanged);
|
||||
assertTrue(eventMapperPaymentStatusChangedOptional.isPresent());
|
||||
AbstractInvoiceEventMapper invoicePaymentStatusChangedEventMapper = eventMapperPaymentStatusChangedOptional.get();
|
||||
InvoicingMessage statusChanged = invoicePaymentStatusChangedEventMapper.handle(icStatusChanged, eventInfoPaymentStatusChanged, storage);
|
||||
AbstractInvoiceEventMapper invoicePaymentStatusChangedEventMapper =
|
||||
eventMapperPaymentStatusChangedOptional.get();
|
||||
InvoicingMessage statusChanged =
|
||||
invoicePaymentStatusChangedEventMapper.handle(icStatusChanged, eventInfoPaymentStatusChanged, storage);
|
||||
assertNotNull(statusChanged);
|
||||
assertEquals("partyId", statusChanged.getPartyId());
|
||||
assertEquals(PaymentStatusEnum.PROCESSED, statusChanged.getPaymentStatus());
|
||||
@ -98,13 +140,17 @@ public class BatchProcessingTest extends AbstractIntegrationTest {
|
||||
assertEquals(3, messages.size());
|
||||
|
||||
// not found message
|
||||
InvoiceChange icStatusNFChanged = getInvoicePaymentChangeStatus();
|
||||
EventInfo eventInfoPaymentStatusNFChanged = new EventInfo(null, "2016-03-22T06:12:27Z", "not_found",1L,3);
|
||||
Optional<AbstractInvoiceEventMapper> eventMapperPaymentStatusNFChangedOptional = handlerManager.getHandler(icStatusNFChanged);
|
||||
InvoiceChange icStatusNotFoundChanged = getInvoicePaymentChangeStatus();
|
||||
EventInfo eventInfoPaymentStatusNotFoundChanged =
|
||||
new EventInfo(null, "2016-03-22T06:12:27Z", "not_found", 1L, 3);
|
||||
Optional<AbstractInvoiceEventMapper> eventMapperPaymentStatusNotFoundChangedOptional =
|
||||
handlerManager.getHandler(icStatusNotFoundChanged);
|
||||
assertTrue(eventMapperPaymentStatusChangedOptional.isPresent());
|
||||
AbstractInvoiceEventMapper invoicePaymentStatusNFChangedEventMapper = eventMapperPaymentStatusNFChangedOptional.get();
|
||||
InvoicingMessage statusNFChanged = invoicePaymentStatusNFChangedEventMapper.handle(icStatusNFChanged, eventInfoPaymentStatusNFChanged, storage);
|
||||
assertNull(statusNFChanged);
|
||||
AbstractInvoiceEventMapper invoicePaymentStatusNotFoundChangedEventMapper =
|
||||
eventMapperPaymentStatusNotFoundChangedOptional.get();
|
||||
InvoicingMessage statusNotFoundChanged = invoicePaymentStatusNotFoundChangedEventMapper
|
||||
.handle(icStatusNotFoundChanged, eventInfoPaymentStatusNotFoundChanged, storage);
|
||||
assertNull(statusNotFoundChanged);
|
||||
|
||||
batchService.process(messages);
|
||||
//
|
||||
@ -132,31 +178,33 @@ public class BatchProcessingTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
private InvoiceChange getInvoicePaymentStarted() {
|
||||
InvoicePayment payment = new InvoicePayment()
|
||||
.setId("1")
|
||||
.setCreatedAt("2016-03-22T06:12:27Z")
|
||||
.setStatus(InvoicePaymentStatus.pending(new InvoicePaymentPending()))
|
||||
.setPayer(Payer.payment_resource(
|
||||
new PaymentResourcePayer()
|
||||
.setResource(new DisposablePaymentResource()
|
||||
.setPaymentTool(PaymentTool.bank_card(new BankCard()
|
||||
.setToken("token")
|
||||
.setPaymentSystem(BankCardPaymentSystem.amex)
|
||||
.setBin("bin")
|
||||
.setLastDigits("masked")))
|
||||
.setClientInfo(new ClientInfo()))
|
||||
.setContactInfo(new ContactInfo())))
|
||||
.setCost(new Cash()
|
||||
.setAmount(123L)
|
||||
.setCurrency(new CurrencyRef()
|
||||
.setSymbolicCode("RUB")))
|
||||
.setFlow(new InvoicePaymentFlow());
|
||||
|
||||
return InvoiceChange.invoice_payment_change(
|
||||
new InvoicePaymentChange()
|
||||
.setId("1")
|
||||
.setPayload(InvoicePaymentChangePayload.invoice_payment_started(
|
||||
new InvoicePaymentStarted()
|
||||
.setPayment(new InvoicePayment()
|
||||
.setId("1")
|
||||
.setCreatedAt("2016-03-22T06:12:27Z")
|
||||
.setStatus(InvoicePaymentStatus.pending(new InvoicePaymentPending()))
|
||||
.setPayer(Payer.payment_resource(
|
||||
new PaymentResourcePayer()
|
||||
.setResource(new DisposablePaymentResource()
|
||||
.setPaymentTool(PaymentTool.bank_card(new BankCard()
|
||||
.setToken("token")
|
||||
.setPaymentSystem(BankCardPaymentSystem.amex)
|
||||
.setBin("bin")
|
||||
.setLastDigits("masked")))
|
||||
.setClientInfo(new ClientInfo()))
|
||||
.setContactInfo(new ContactInfo())))
|
||||
.setCost(new Cash()
|
||||
.setAmount(123L)
|
||||
.setCurrency(new CurrencyRef()
|
||||
.setSymbolicCode("RUB")))
|
||||
.setFlow(new InvoicePaymentFlow())))
|
||||
));
|
||||
.setPayload(
|
||||
InvoicePaymentChangePayload.invoice_payment_started(
|
||||
new InvoicePaymentStarted().setPayment(payment)
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,7 +4,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rbkmoney.damsel.payment_processing.CustomerManagementSrv;
|
||||
import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.CustomerMessage;
|
||||
import com.rbkmoney.hooker.model.CustomerMessageEnum;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.utils.BuildUtils;
|
||||
import com.rbkmoney.swag_webhook_events.model.CustomerBindingSucceeded;
|
||||
import com.rbkmoney.swag_webhook_events.model.Event;
|
||||
@ -15,7 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import static io.github.benas.randombeans.api.EnhancedRandom.random;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
public class CustomerEventServiceTest extends AbstractIntegrationTest {
|
||||
@ -61,4 +64,4 @@ public class CustomerEventServiceTest extends AbstractIntegrationTest {
|
||||
String json = objectMapper.writeValueAsString(event);
|
||||
assertTrue(json.contains("2016-03-22T06:12:27Z"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
package com.rbkmoney.hooker.service;
|
||||
|
||||
import com.rbkmoney.damsel.webhooker.*;
|
||||
import com.rbkmoney.damsel.webhooker.EventFilter;
|
||||
import com.rbkmoney.damsel.webhooker.InvoiceCreated;
|
||||
import com.rbkmoney.damsel.webhooker.InvoiceEventFilter;
|
||||
import com.rbkmoney.damsel.webhooker.InvoiceEventType;
|
||||
import com.rbkmoney.damsel.webhooker.WebhookParams;
|
||||
import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.dao.HookDao;
|
||||
import com.rbkmoney.hooker.utils.HookConverter;
|
||||
@ -10,11 +14,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class HooksLimitServiceTest extends AbstractIntegrationTest {
|
||||
|
||||
@ -39,7 +43,7 @@ public class HooksLimitServiceTest extends AbstractIntegrationTest {
|
||||
public void isShopLimitExceededTrueTest() {
|
||||
WebhookParams webhookParams = buildWebhookParams();
|
||||
|
||||
IntStream.range(1, 11).forEach( x -> hookDao.create(HookConverter.convert(webhookParams)));
|
||||
IntStream.range(1, 11).forEach(x -> hookDao.create(HookConverter.convert(webhookParams)));
|
||||
assertTrue(hooksLimitService.isLimitExceeded(webhookParams));
|
||||
}
|
||||
|
||||
@ -47,7 +51,7 @@ public class HooksLimitServiceTest extends AbstractIntegrationTest {
|
||||
public void isShopLimitExceededFalseTest() {
|
||||
WebhookParams webhookParams = buildWebhookParams();
|
||||
|
||||
IntStream.range(1, 11).forEach( x -> hookDao.create(HookConverter.convert(webhookParams)));
|
||||
IntStream.range(1, 11).forEach(x -> hookDao.create(HookConverter.convert(webhookParams)));
|
||||
jdbcTemplate.update("update hook.party_data set metadata =:metadata where party_id=:party_id",
|
||||
new MapSqlParameterSource("party_id", "party_id")
|
||||
.addValue("metadata", "{\"hooksLimit\":{\"perShop\":{\"shop_id\":22},\"perParty\":15}}"));
|
||||
@ -59,14 +63,13 @@ public class HooksLimitServiceTest extends AbstractIntegrationTest {
|
||||
WebhookParams webhookParams = buildWebhookParams();
|
||||
webhookParams.getEventFilter().getInvoice().setShopId(null);
|
||||
|
||||
IntStream.range(1, 6).forEach( x -> hookDao.create(HookConverter.convert(webhookParams)));
|
||||
IntStream.range(1, 6).forEach(x -> hookDao.create(HookConverter.convert(webhookParams)));
|
||||
assertTrue(hooksLimitService.isLimitExceeded(webhookParams));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@After
|
||||
public void after(){
|
||||
public void after() {
|
||||
jdbcTemplate.update("truncate hook.webhook cascade", new MapSqlParameterSource());
|
||||
jdbcTemplate.update("truncate hook.party_data cascade", new MapSqlParameterSource());
|
||||
}
|
||||
@ -81,4 +84,4 @@ public class HooksLimitServiceTest extends AbstractIntegrationTest {
|
||||
.setTypes(Set.of(InvoiceEventType.created(new InvoiceCreated())))));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,11 @@ import com.rbkmoney.damsel.domain.InvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.InvoiceStatus;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoicingSrv;
|
||||
import com.rbkmoney.hooker.AbstractIntegrationTest;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import com.rbkmoney.hooker.model.RefundStatusEnum;
|
||||
import com.rbkmoney.hooker.utils.BuildUtils;
|
||||
import com.rbkmoney.swag_webhook_events.model.Event;
|
||||
import com.rbkmoney.swag_webhook_events.model.RefundSucceeded;
|
||||
@ -38,7 +42,8 @@ public class InvoicingEventServiceTest extends AbstractIntegrationTest {
|
||||
public void setUp() throws Exception {
|
||||
Mockito.when(invoicingClient.get(any(), any(), any()))
|
||||
.thenReturn(BuildUtils.buildInvoice("partyId", "invoiceId", "1", "1",
|
||||
InvoiceStatus.paid(new InvoicePaid()), InvoicePaymentStatus.pending(new InvoicePaymentPending())));
|
||||
InvoiceStatus.paid(new InvoicePaid()),
|
||||
InvoicePaymentStatus.pending(new InvoicePaymentPending())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -73,4 +78,4 @@ public class InvoicingEventServiceTest extends AbstractIntegrationTest {
|
||||
String json = objectMapper.writeValueAsString(event);
|
||||
assertTrue(json.contains("\"payment_id\":271771960"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PostSenderTest {
|
||||
|
||||
@Test
|
||||
public void doPost() throws Exception {
|
||||
PostSender postSender = new PostSender(1,1);
|
||||
PostSender postSender = new PostSender(1, 1);
|
||||
MockWebServer server = new MockWebServer();
|
||||
HttpUrl httpUrl = server.url("/");
|
||||
|
||||
|
@ -20,7 +20,17 @@ public class AsymSignerTest {
|
||||
public void test() throws Exception {
|
||||
AsymSigner asymSigner = new AsymSigner();
|
||||
KeyPair keyPair = asymSigner.generateKeys();
|
||||
String data = "{\"eventID\":27,\"occuredAt\":\"2017-05-16T13:49:34.935099Z\",\"topic\":\"InvoicesTopic\",\"eventType\":\"PaymentCaptured\",\"invoice\":{\"id\":\"qXMiygTqb2\",\"shopID\":1,\"createdAt\":\"2017-05-16T13:49:32.753723Z\",\"status\":\"unpaid\",\"reason\":null,\"dueDate\":\"2017-05-16T13:59:32Z\",\"amount\":100000,\"currency\":\"RUB\",\"metadata\":{\"type\":\"application/json\",\"data\":\"eyJpbnZvaWNlX2R1bW15X2NvbnRleHQiOiJ0ZXN0X3ZhbHVlIn0=\"},\"product\":\"test_product\",\"description\":\"test_invoice_description\"},\"payment\":{\"id\":\"1\",\"createdAt\":\"2017-05-16T13:49:33.182195Z\",\"status\":\"captured\",\"error\":null,\"amount\":100000,\"currency\":\"RUB\",\"paymentToolToken\":\"5Gz2nhE1eleFGBAcGe9SrA\",\"paymentSession\":\"2nTYVgk6h85O7vIVV9j4pA\",\"contactInfo\":{\"email\":\"bla@bla.ru\",\"phoneNumber\":null},\"ip\":\"10.100.2.1\",\"fingerprint\":\"test fingerprint\"}}";
|
||||
String data = "{\"eventID\":27,\"occuredAt\":\"2017-05-16T13:49:34.935099Z\",\"topic\":\"InvoicesTopic\"," +
|
||||
"\"eventType\":\"PaymentCaptured\",\"invoice\":{\"id\":\"qXMiygTqb2\",\"shopID\":1," +
|
||||
"\"createdAt\":\"2017-05-16T13:49:32.753723Z\",\"status\":\"unpaid\",\"reason\":null," +
|
||||
"\"dueDate\":\"2017-05-16T13:59:32Z\",\"amount\":100000,\"currency\":\"RUB\"," +
|
||||
"\"metadata\":{\"type\":\"application/json\"," +
|
||||
"\"data\":\"eyJpbnZvaWNlX2R1bW15X2NvbnRleHQiOiJ0ZXN0X3ZhbHVlIn0=\"},\"product\":\"test_product\"," +
|
||||
"\"description\":\"test_invoice_description\"},\"payment\":{\"id\":\"1\"," +
|
||||
"\"createdAt\":\"2017-05-16T13:49:33.182195Z\",\"status\":\"captured\",\"error\":null," +
|
||||
"\"amount\":100000,\"currency\":\"RUB\",\"paymentToolToken\":\"5Gz2nhE1eleFGBAcGe9SrA\"," +
|
||||
"\"paymentSession\":\"2nTYVgk6h85O7vIVV9j4pA\",\"contactInfo\":{\"email\":\"bla@bla.ru\"," +
|
||||
"\"phoneNumber\":null},\"ip\":\"10.100.2.1\",\"fingerprint\":\"test fingerprint\"}}";
|
||||
String sign = asymSigner.sign(data, keyPair.getPrivKey());
|
||||
byte[] sigBytes = Base64.getUrlDecoder().decode(sign);
|
||||
|
||||
|
@ -1,7 +1,14 @@
|
||||
package com.rbkmoney.hooker.utils;
|
||||
|
||||
import com.rbkmoney.damsel.base.Content;
|
||||
import com.rbkmoney.damsel.domain.*;
|
||||
import com.rbkmoney.damsel.domain.AdditionalTransactionInfo;
|
||||
import com.rbkmoney.damsel.domain.BankCard;
|
||||
import com.rbkmoney.damsel.domain.Invoice;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentRefund;
|
||||
import com.rbkmoney.damsel.domain.InvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.InvoiceStatus;
|
||||
import com.rbkmoney.damsel.domain.PaymentTool;
|
||||
import com.rbkmoney.damsel.domain.TransactionInfo;
|
||||
import com.rbkmoney.damsel.json.Value;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoicePayment;
|
||||
import com.rbkmoney.damsel.payment_processing.InvoiceRefundSession;
|
||||
@ -9,21 +16,38 @@ import com.rbkmoney.geck.serializer.kit.mock.MockMode;
|
||||
import com.rbkmoney.geck.serializer.kit.mock.MockTBaseProcessor;
|
||||
import com.rbkmoney.geck.serializer.kit.tbase.TBaseHandler;
|
||||
import com.rbkmoney.hooker.dao.WebhookAdditionalFilter;
|
||||
import com.rbkmoney.hooker.model.*;
|
||||
import com.rbkmoney.hooker.model.CustomerMessage;
|
||||
import com.rbkmoney.hooker.model.CustomerMessageEnum;
|
||||
import com.rbkmoney.hooker.model.EventType;
|
||||
import com.rbkmoney.hooker.model.Hook;
|
||||
import com.rbkmoney.hooker.model.InvoiceStatusEnum;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessage;
|
||||
import com.rbkmoney.hooker.model.InvoicingMessageEnum;
|
||||
import com.rbkmoney.hooker.model.PaymentStatusEnum;
|
||||
import com.rbkmoney.hooker.model.RefundStatusEnum;
|
||||
import com.rbkmoney.swag_webhook_events.model.Event;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BuildUtils {
|
||||
private static int messageId = 1;
|
||||
|
||||
public static InvoicingMessage buildMessage(String type, String invoiceId, String partyId, EventType eventType, InvoiceStatusEnum invoiceStatus, PaymentStatusEnum paymentStatus) {
|
||||
public static InvoicingMessage buildMessage(String type, String invoiceId, String partyId, EventType eventType,
|
||||
InvoiceStatusEnum invoiceStatus, PaymentStatusEnum paymentStatus) {
|
||||
return buildMessage(type, invoiceId, partyId, eventType, invoiceStatus, paymentStatus, null, 0);
|
||||
}
|
||||
|
||||
public static InvoicingMessage buildMessage(String type, String invoiceId, String partyId, EventType eventType, InvoiceStatusEnum invoiceStatus, PaymentStatusEnum paymentStatus, Long sequenceId, Integer changeId) {
|
||||
public static InvoicingMessage buildMessage(String type, String invoiceId, String partyId, EventType eventType,
|
||||
InvoiceStatusEnum invoiceStatus, PaymentStatusEnum paymentStatus,
|
||||
Long sequenceId, Integer changeId) {
|
||||
InvoicingMessage message = new InvoicingMessage();
|
||||
message.setId((long) messageId++);
|
||||
message.setEventId((long) messageId++);
|
||||
@ -48,36 +72,50 @@ public class BuildUtils {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static com.rbkmoney.damsel.payment_processing.Customer buildCustomer(String customerId, String bindingId) throws IOException {
|
||||
MockTBaseProcessor tBaseProcessor = new MockTBaseProcessor(MockMode.RANDOM, 15, 1);
|
||||
com.rbkmoney.damsel.payment_processing.Customer customer = tBaseProcessor.process(new com.rbkmoney.damsel.payment_processing.Customer(),
|
||||
new TBaseHandler<>(com.rbkmoney.damsel.payment_processing.Customer.class))
|
||||
.setId(customerId)
|
||||
public static com.rbkmoney.damsel.payment_processing.Customer buildCustomer(String customerId, String bindingId)
|
||||
throws IOException {
|
||||
MockTBaseProcessor thriftBaseProcessor = new MockTBaseProcessor(MockMode.RANDOM, 15, 1);
|
||||
com.rbkmoney.damsel.payment_processing.Customer customer = thriftBaseProcessor.process(
|
||||
new com.rbkmoney.damsel.payment_processing.Customer(),
|
||||
new TBaseHandler<>(com.rbkmoney.damsel.payment_processing.Customer.class)
|
||||
);
|
||||
com.rbkmoney.damsel.payment_processing.CustomerBinding customerBinding = thriftBaseProcessor.process(
|
||||
new com.rbkmoney.damsel.payment_processing.CustomerBinding(),
|
||||
new TBaseHandler<>(com.rbkmoney.damsel.payment_processing.CustomerBinding.class)
|
||||
).setId(bindingId);
|
||||
|
||||
customer.setId(customerId)
|
||||
.setCreatedAt("2016-03-22T06:12:27Z")
|
||||
.setMetadata(Value.obj(new HashMap<>()))
|
||||
.setBindings(Collections.singletonList(
|
||||
tBaseProcessor.process(new com.rbkmoney.damsel.payment_processing.CustomerBinding(),
|
||||
new TBaseHandler<>(com.rbkmoney.damsel.payment_processing.CustomerBinding.class))
|
||||
.setId(bindingId)));
|
||||
customer.getBindings().get(0).getPaymentResource().setPaymentTool(PaymentTool.bank_card(tBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))));
|
||||
.setBindings(Collections.singletonList(customerBinding));
|
||||
|
||||
customer.getBindings().get(0).getPaymentResource().setPaymentTool(
|
||||
PaymentTool.bank_card(thriftBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))));
|
||||
return customer;
|
||||
}
|
||||
|
||||
public static com.rbkmoney.damsel.payment_processing.Invoice buildInvoice(String partyId, String invoiceId, String paymentId, String refundId,
|
||||
InvoiceStatus invoiceStatus, InvoicePaymentStatus paymentStatus) throws IOException {
|
||||
MockTBaseProcessor tBaseProcessor = new MockTBaseProcessor(MockMode.RANDOM, 15, 1);
|
||||
public static com.rbkmoney.damsel.payment_processing.Invoice buildInvoice(String partyId, String invoiceId,
|
||||
String paymentId, String refundId,
|
||||
InvoiceStatus invoiceStatus,
|
||||
InvoicePaymentStatus paymentStatus)
|
||||
throws IOException {
|
||||
MockTBaseProcessor thriftBaseProcessor = new MockTBaseProcessor(MockMode.RANDOM, 15, 1);
|
||||
com.rbkmoney.damsel.payment_processing.Invoice invoice = new com.rbkmoney.damsel.payment_processing.Invoice()
|
||||
.setInvoice(buildInvoice(partyId, invoiceId, invoiceStatus, tBaseProcessor))
|
||||
.setPayments(buildPayments(partyId, paymentId, refundId, paymentStatus, tBaseProcessor));
|
||||
.setInvoice(buildInvoice(partyId, invoiceId, invoiceStatus, thriftBaseProcessor))
|
||||
.setPayments(buildPayments(partyId, paymentId, refundId, paymentStatus, thriftBaseProcessor));
|
||||
if (invoice.getPayments().get(0).getPayment().getPayer().isSetPaymentResource()) {
|
||||
PaymentTool paymentTool = PaymentTool.bank_card(
|
||||
thriftBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))
|
||||
);
|
||||
invoice.getPayments().get(0).getPayment().getPayer().getPaymentResource().getResource()
|
||||
.setPaymentTool(PaymentTool.bank_card(tBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))));
|
||||
.setPaymentTool(paymentTool);
|
||||
}
|
||||
return invoice;
|
||||
}
|
||||
|
||||
private static Invoice buildInvoice(String partyId, String invoiceId, InvoiceStatus invoiceStatus, MockTBaseProcessor tBaseProcessor) throws IOException {
|
||||
return tBaseProcessor.process(
|
||||
private static Invoice buildInvoice(String partyId, String invoiceId, InvoiceStatus invoiceStatus,
|
||||
MockTBaseProcessor thriftBaseProcessor) throws IOException {
|
||||
return thriftBaseProcessor.process(
|
||||
new Invoice(),
|
||||
new TBaseHandler<>(Invoice.class)
|
||||
)
|
||||
@ -89,18 +127,23 @@ public class BuildUtils {
|
||||
.setStatus(invoiceStatus);
|
||||
}
|
||||
|
||||
private static List<InvoicePayment> buildPayments(String partyId, String paymentId, String refundId, InvoicePaymentStatus paymentStatus, MockTBaseProcessor tBaseProcessor) throws IOException {
|
||||
private static List<InvoicePayment> buildPayments(String partyId, String paymentId, String refundId,
|
||||
InvoicePaymentStatus paymentStatus,
|
||||
MockTBaseProcessor thriftBaseProcessor) throws IOException {
|
||||
return Collections.singletonList(
|
||||
new InvoicePayment()
|
||||
.setAdjustments(Collections.emptyList())
|
||||
.setPayment(buildPayment(partyId, paymentId, paymentStatus, tBaseProcessor))
|
||||
.setRefunds(buildRefunds(refundId, tBaseProcessor))
|
||||
.setPayment(buildPayment(partyId, paymentId, paymentStatus, thriftBaseProcessor))
|
||||
.setRefunds(buildRefunds(refundId, thriftBaseProcessor))
|
||||
.setSessions(Collections.emptyList())
|
||||
);
|
||||
}
|
||||
|
||||
private static com.rbkmoney.damsel.domain.InvoicePayment buildPayment(String partyId, String paymentId, InvoicePaymentStatus paymentStatus, MockTBaseProcessor tBaseProcessor) throws IOException {
|
||||
return tBaseProcessor.process(
|
||||
private static com.rbkmoney.damsel.domain.InvoicePayment buildPayment(String partyId, String paymentId,
|
||||
InvoicePaymentStatus paymentStatus,
|
||||
MockTBaseProcessor thriftBaseProcessor)
|
||||
throws IOException {
|
||||
return thriftBaseProcessor.process(
|
||||
new com.rbkmoney.damsel.domain.InvoicePayment(),
|
||||
new TBaseHandler<>(com.rbkmoney.damsel.domain.InvoicePayment.class)
|
||||
)
|
||||
@ -110,17 +153,23 @@ public class BuildUtils {
|
||||
.setStatus(paymentStatus);
|
||||
}
|
||||
|
||||
private static List<com.rbkmoney.damsel.payment_processing.InvoicePaymentRefund> buildRefunds(String refundId, MockTBaseProcessor tBaseProcessor) throws IOException {
|
||||
private static List<com.rbkmoney.damsel.payment_processing.InvoicePaymentRefund> buildRefunds(
|
||||
String refundId,
|
||||
MockTBaseProcessor thriftBaseProcessor
|
||||
) throws IOException {
|
||||
return Collections.singletonList(
|
||||
new com.rbkmoney.damsel.payment_processing.InvoicePaymentRefund(
|
||||
buildRefund(refundId, tBaseProcessor),
|
||||
buildRefund(refundId, thriftBaseProcessor),
|
||||
Collections.singletonList(new InvoiceRefundSession().setTransactionInfo(getTransactionInfo()))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static InvoicePaymentRefund buildRefund(String refundId, MockTBaseProcessor tBaseProcessor) throws IOException {
|
||||
return tBaseProcessor.process(
|
||||
private static InvoicePaymentRefund buildRefund(
|
||||
String refundId,
|
||||
MockTBaseProcessor thriftBaseProcessor
|
||||
) throws IOException {
|
||||
return thriftBaseProcessor.process(
|
||||
new InvoicePaymentRefund(),
|
||||
new TBaseHandler<>(InvoicePaymentRefund.class)
|
||||
)
|
||||
@ -141,7 +190,8 @@ public class BuildUtils {
|
||||
.setRrn("chicken-teriyaki");
|
||||
}
|
||||
|
||||
public static CustomerMessage buildCustomerMessage(Long eventId, String partyId, EventType eventType, CustomerMessageEnum type, String custId, String shopId) {
|
||||
public static CustomerMessage buildCustomerMessage(Long eventId, String partyId, EventType eventType,
|
||||
CustomerMessageEnum type, String custId, String shopId) {
|
||||
CustomerMessage customerMessage = new CustomerMessage();
|
||||
customerMessage.setEventId(eventId);
|
||||
customerMessage.setPartyId(partyId);
|
||||
|
@ -1,6 +1,11 @@
|
||||
package com.rbkmoney.hooker.utils;
|
||||
|
||||
import com.rbkmoney.damsel.domain.*;
|
||||
import com.rbkmoney.damsel.domain.Cash;
|
||||
import com.rbkmoney.damsel.domain.CashFlowAccount;
|
||||
import com.rbkmoney.damsel.domain.FinalCashFlowAccount;
|
||||
import com.rbkmoney.damsel.domain.FinalCashFlowPosting;
|
||||
import com.rbkmoney.damsel.domain.MerchantCashFlowAccount;
|
||||
import com.rbkmoney.damsel.domain.SystemCashFlowAccount;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -19,8 +24,10 @@ public class CashFlowUtilsTest {
|
||||
Cash cash = new Cash();
|
||||
cash.setAmount(10);
|
||||
firstFinalCashFlowPosting.setVolume(cash);
|
||||
firstFinalCashFlowPosting.setSource(new FinalCashFlowAccount().setAccountType(CashFlowAccount.merchant(MerchantCashFlowAccount.settlement)));
|
||||
firstFinalCashFlowPosting.setDestination(new FinalCashFlowAccount().setAccountType(CashFlowAccount.system(SystemCashFlowAccount.settlement)));
|
||||
firstFinalCashFlowPosting.setSource(new FinalCashFlowAccount()
|
||||
.setAccountType(CashFlowAccount.merchant(MerchantCashFlowAccount.settlement)));
|
||||
firstFinalCashFlowPosting.setDestination(
|
||||
new FinalCashFlowAccount().setAccountType(CashFlowAccount.system(SystemCashFlowAccount.settlement)));
|
||||
FinalCashFlowPosting secondFinalCashFlowPosting = firstFinalCashFlowPosting.deepCopy();
|
||||
return List.of(firstFinalCashFlowPosting, secondFinalCashFlowPosting);
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ public class ErrorUtilsTest {
|
||||
|
||||
@Test
|
||||
public void toPaymentError() {
|
||||
assertEquals("test", ErrorUtils.toPaymentError("code:sub_code:test", "message").getSubError().getSubError().getCode());
|
||||
assertEquals("test",
|
||||
ErrorUtils.toPaymentError("code:sub_code:test", "message").getSubError().getSubError().getCode());
|
||||
assertEquals("sub_code", ErrorUtils.toPaymentError("code:sub_code", "message").getSubError().getCode());
|
||||
assertNull(ErrorUtils.toPaymentError("code:sub_code", "message").getSubError().getSubError());
|
||||
assertEquals("code", ErrorUtils.toPaymentError("code", "message").getCode());
|
||||
|
@ -22,18 +22,24 @@ public class EventFilterUtilsTest {
|
||||
private EventFilter getEventFilter() {
|
||||
Collection<WebhookAdditionalFilter> eventTypeCodeSet = new HashSet<>();
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_CREATED).build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_STARTED).shopId("77").build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_STATUS_CHANGED).build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_STARTED).shopId("77")
|
||||
.build());
|
||||
eventTypeCodeSet
|
||||
.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_STATUS_CHANGED).build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_STATUS_CHANGED).build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_REFUND_STARTED).build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_REFUND_STATUS_CHANGED).build());
|
||||
eventTypeCodeSet
|
||||
.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_REFUND_STARTED).build());
|
||||
eventTypeCodeSet
|
||||
.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_PAYMENT_REFUND_STATUS_CHANGED)
|
||||
.build());
|
||||
return EventFilterUtils.getEventFilter(eventTypeCodeSet);
|
||||
}
|
||||
|
||||
private EventFilter getCustomerEventFilter() {
|
||||
Collection<WebhookAdditionalFilter> eventTypeCodeSet = new HashSet<>();
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_CREATED).build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_DELETED).shopId("77").build());
|
||||
eventTypeCodeSet
|
||||
.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_DELETED).shopId("77").build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_READY).build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_BINDING_STARTED).build());
|
||||
eventTypeCodeSet.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_BINDING_SUCCEEDED).build());
|
||||
|
@ -3,7 +3,13 @@ package com.rbkmoney.hooker.utils;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rbkmoney.damsel.domain.*;
|
||||
import com.rbkmoney.damsel.domain.BankCard;
|
||||
import com.rbkmoney.damsel.domain.CryptoCurrency;
|
||||
import com.rbkmoney.damsel.domain.DigitalWallet;
|
||||
import com.rbkmoney.damsel.domain.DigitalWalletProvider;
|
||||
import com.rbkmoney.damsel.domain.PaymentTerminal;
|
||||
import com.rbkmoney.damsel.domain.PaymentTool;
|
||||
import com.rbkmoney.damsel.domain.TerminalPaymentProvider;
|
||||
import com.rbkmoney.geck.serializer.kit.mock.MockMode;
|
||||
import com.rbkmoney.geck.serializer.kit.mock.MockTBaseProcessor;
|
||||
import com.rbkmoney.geck.serializer.kit.tbase.TBaseHandler;
|
||||
@ -15,7 +21,9 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PaymentToolUtilsTest {
|
||||
|
||||
@ -25,15 +33,20 @@ public class PaymentToolUtilsTest {
|
||||
PaymentToolDetails paymentToolDetails = PaymentToolUtils.getPaymentToolDetails(paymentTool);
|
||||
assertTrue(paymentToolDetails instanceof PaymentToolDetailsCryptoWallet);
|
||||
assertNull(paymentToolDetails.getDetailsType());
|
||||
assertEquals(com.rbkmoney.swag_webhook_events.model.CryptoCurrency.BITCOIN.getValue(), ((PaymentToolDetailsCryptoWallet)paymentToolDetails).getCryptoCurrency().getValue());
|
||||
assertEquals(com.rbkmoney.swag_webhook_events.model.CryptoCurrency.BITCOIN.getValue(),
|
||||
((PaymentToolDetailsCryptoWallet) paymentToolDetails).getCryptoCurrency().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDigitalWalletJson() throws JsonProcessingException {
|
||||
PaymentTool paymentTool = PaymentTool.digital_wallet(new DigitalWallet(DigitalWalletProvider.qiwi, "kke"));
|
||||
PaymentToolDetails paymentToolDetails = PaymentToolUtils.getPaymentToolDetails(paymentTool);
|
||||
String json = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY).writeValueAsString(paymentToolDetails);
|
||||
assertEquals("{\"detailsType\":\"PaymentToolDetailsDigitalWallet\",\"digitalWalletDetails\":{\"digitalWalletDetailsType\":\"DigitalWalletDetailsQIWI\",\"phoneNumberMask\":\"kke\"}}", json);
|
||||
String json = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||
.writeValueAsString(paymentToolDetails);
|
||||
assertEquals(
|
||||
"{\"detailsType\":\"PaymentToolDetailsDigitalWallet\",\"digitalWalletDetails\":" +
|
||||
"{\"digitalWalletDetailsType\":\"DigitalWalletDetailsQIWI\",\"phoneNumberMask\":\"kke\"}}",
|
||||
json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -44,7 +57,8 @@ public class PaymentToolUtilsTest {
|
||||
PaymentToolDetails paymentToolDetails = PaymentToolUtils.getPaymentToolDetails(paymentTool);
|
||||
assertTrue(paymentToolDetails instanceof PaymentToolDetailsPaymentTerminal);
|
||||
assertNull(paymentToolDetails.getDetailsType());
|
||||
assertEquals(PaymentToolDetailsPaymentTerminal.ProviderEnum.ALIPAY.getValue(), ((PaymentToolDetailsPaymentTerminal) paymentToolDetails).getProvider().getValue());
|
||||
assertEquals(PaymentToolDetailsPaymentTerminal.ProviderEnum.ALIPAY.getValue(),
|
||||
((PaymentToolDetailsPaymentTerminal) paymentToolDetails).getProvider().getValue());
|
||||
|
||||
paymentTool = PaymentTool.payment_terminal(new PaymentTerminal()
|
||||
.setTerminalType(TerminalPaymentProvider.wechat)
|
||||
@ -52,16 +66,18 @@ public class PaymentToolUtilsTest {
|
||||
paymentToolDetails = PaymentToolUtils.getPaymentToolDetails(paymentTool);
|
||||
assertTrue(paymentToolDetails instanceof PaymentToolDetailsPaymentTerminal);
|
||||
assertNull(paymentToolDetails.getDetailsType());
|
||||
assertEquals(PaymentToolDetailsPaymentTerminal.ProviderEnum.WECHAT.getValue(), ((PaymentToolDetailsPaymentTerminal) paymentToolDetails).getProvider().getValue());
|
||||
assertEquals(PaymentToolDetailsPaymentTerminal.ProviderEnum.WECHAT.getValue(),
|
||||
((PaymentToolDetailsPaymentTerminal) paymentToolDetails).getProvider().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPaymentToolDetailsBankCard() throws IOException {
|
||||
PaymentTool paymentTool = PaymentTool.bank_card(new MockTBaseProcessor(MockMode.RANDOM, 15, 2).process(new BankCard(), new TBaseHandler<>(BankCard.class)));
|
||||
PaymentTool paymentTool = PaymentTool.bank_card(new MockTBaseProcessor(MockMode.RANDOM, 15, 2)
|
||||
.process(new BankCard(), new TBaseHandler<>(BankCard.class)));
|
||||
PaymentToolDetails paymentToolDetails = PaymentToolUtils.getPaymentToolDetails(paymentTool);
|
||||
assertTrue(paymentToolDetails instanceof PaymentToolDetailsBankCard);
|
||||
assertNull(paymentToolDetails.getDetailsType());
|
||||
assertEquals(paymentTool.getBankCard().getBin(), ((PaymentToolDetailsBankCard)paymentToolDetails).getBin());
|
||||
assertEquals(paymentTool.getBankCard().getBin(), ((PaymentToolDetailsBankCard) paymentToolDetails).getBin());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user