mirror of
https://github.com/valitydev/disputes-api.git
synced 2024-11-06 00:55:23 +00:00
bump proto ProviderPaymentsCallbackHandler
This commit is contained in:
parent
b3200e2914
commit
13121d130a
2
pom.xml
2
pom.xml
@ -47,7 +47,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.vality</groupId>
|
||||
<artifactId>disputes-proto</artifactId>
|
||||
<version>1.28-38cc0c1</version>
|
||||
<version>1.31-9ee58cd</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.vality</groupId>
|
||||
|
@ -1,143 +0,0 @@
|
||||
package dev.vality.disputes.callback;
|
||||
|
||||
import dev.vality.disputes.api.model.PaymentParams;
|
||||
import dev.vality.disputes.api.service.PaymentParamsBuilder;
|
||||
import dev.vality.disputes.dao.DisputeDao;
|
||||
import dev.vality.disputes.dao.ProviderCallbackDao;
|
||||
import dev.vality.disputes.domain.tables.pojos.Dispute;
|
||||
import dev.vality.disputes.domain.tables.pojos.ProviderCallback;
|
||||
import dev.vality.disputes.provider.TransactionContext;
|
||||
import dev.vality.disputes.schedule.service.ProviderDataService;
|
||||
import dev.vality.disputes.schedule.service.ProviderIfaceBuilder;
|
||||
import dev.vality.disputes.schedule.service.ProviderRouting;
|
||||
import dev.vality.disputes.security.AccessData;
|
||||
import dev.vality.disputes.security.AccessService;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static dev.vality.disputes.api.service.ApiDisputesService.DISPUTE_PENDING;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@SuppressWarnings({"ParameterName", "LineLength", "MissingSwitchDefault"})
|
||||
public class ProviderDisputesCallbackHandler implements ProviderDisputesCallbackServiceSrv.Iface {
|
||||
|
||||
private final DisputeDao disputeDao;
|
||||
private final AccessService accessService;
|
||||
private final PaymentParamsBuilder paymentParamsBuilder;
|
||||
private final ProviderDataService providerDataService;
|
||||
private final ProviderRouting providerRouting;
|
||||
private final ProviderIfaceBuilder providerIfaceBuilder;
|
||||
private final ProviderCallbackDao providerCallbackDao;
|
||||
|
||||
@Value("${dispute.isProviderCallbackEnabled}")
|
||||
private boolean enabled;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void createAdjustmentIfPaymentSuccess(DisputeCallbackParams disputeCallbackParams) throws TException {
|
||||
log.info("disputeCallbackParams {}", disputeCallbackParams);
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
var invoiceData = disputeCallbackParams.getDisputeID()
|
||||
.map(s -> disputeDao.getDisputeForUpdateSkipLocked(UUID.fromString(s)))
|
||||
.map(dispute -> InvoiceData.builder()
|
||||
.invoiceId(dispute.getInvoiceId())
|
||||
.paymentId(dispute.getPaymentId())
|
||||
.dispute(dispute)
|
||||
.build())
|
||||
.or(() -> disputeCallbackParams.getInvoiceId()
|
||||
.map(s -> disputeDao.getDisputesForUpdateSkipLocked(s, disputeCallbackParams.getPaymentId().get()))
|
||||
.flatMap(disputes -> disputes.stream()
|
||||
.filter(dispute -> DISPUTE_PENDING.contains(dispute.getStatus()))
|
||||
.findFirst())
|
||||
.map(dispute -> InvoiceData.builder()
|
||||
.invoiceId(dispute.getInvoiceId())
|
||||
.paymentId(dispute.getPaymentId())
|
||||
.dispute(dispute)
|
||||
.build())
|
||||
.or(() -> disputeCallbackParams.getInvoiceId()
|
||||
.map(s -> InvoiceData.builder()
|
||||
.invoiceId(s)
|
||||
.paymentId(disputeCallbackParams.getPaymentId().get())
|
||||
.build())))
|
||||
.orElse(null);
|
||||
log.info("invoiceData {}", invoiceData);
|
||||
if (invoiceData == null || invoiceData.getInvoiceId() == null) {
|
||||
return;
|
||||
}
|
||||
var accessData = getAccessData(invoiceData);
|
||||
if (accessData == null) {
|
||||
return;
|
||||
}
|
||||
if (!accessData.getPayment().getPayment().getStatus().isSetFailed()) {
|
||||
return;
|
||||
}
|
||||
var paymentParams = getPaymentParams(accessData);
|
||||
if (paymentParams == null) {
|
||||
return;
|
||||
}
|
||||
var providerData = providerDataService.getProviderData(paymentParams.getProviderId(), paymentParams.getTerminalId());
|
||||
providerRouting.initRouteUrl(providerData);
|
||||
var remoteClient = providerIfaceBuilder.buildTHSpawnClient(providerData.getRouteUrl());
|
||||
var transactionContext = new TransactionContext();
|
||||
transactionContext.setProviderTrxId(paymentParams.getProviderTrxId());
|
||||
transactionContext.setInvoiceId(paymentParams.getInvoiceId());
|
||||
transactionContext.setPaymentId(paymentParams.getPaymentId());
|
||||
transactionContext.setTerminalOptions(paymentParams.getOptions());
|
||||
log.info("call remoteClient.isPaymentSuccess {}", transactionContext);
|
||||
try {
|
||||
var paymentStatusResult = remoteClient.checkPaymentStatus(transactionContext);
|
||||
if (paymentStatusResult.isSuccess()) {
|
||||
var providerCallback = new ProviderCallback();
|
||||
providerCallback.setInvoiceId(paymentParams.getInvoiceId());
|
||||
providerCallback.setPaymentId(paymentParams.getPaymentId());
|
||||
providerCallback.setChangedAmount(paymentStatusResult.getChangedAmount().orElse(null));
|
||||
providerCallbackDao.save(providerCallback);
|
||||
log.info("providerCallback {}", providerCallback);
|
||||
}
|
||||
} catch (TException e) {
|
||||
log.warn("remoteClient.isPaymentSuccess error", e);
|
||||
}
|
||||
}
|
||||
|
||||
private AccessData getAccessData(InvoiceData invoiceData) {
|
||||
try {
|
||||
var accessData = accessService.approveUserAccess(invoiceData.getInvoiceId(), invoiceData.getPaymentId(), false);
|
||||
log.info("accessData {}", accessData);
|
||||
return accessData;
|
||||
} catch (Throwable e) {
|
||||
log.warn("accessData error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private PaymentParams getPaymentParams(AccessData accessData) {
|
||||
try {
|
||||
var paymentParams = paymentParamsBuilder.buildGeneralPaymentContext(accessData);
|
||||
log.info("paymentParams {}", paymentParams);
|
||||
return paymentParams;
|
||||
} catch (Throwable e) {
|
||||
log.warn("paymentParams error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public static class InvoiceData {
|
||||
private String invoiceId;
|
||||
private String paymentId;
|
||||
private Dispute dispute;
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package dev.vality.disputes.callback;
|
||||
|
||||
import dev.vality.damsel.domain.Currency;
|
||||
import dev.vality.disputes.api.model.PaymentParams;
|
||||
import dev.vality.disputes.api.service.PaymentParamsBuilder;
|
||||
import dev.vality.disputes.dao.DisputeDao;
|
||||
import dev.vality.disputes.dao.ProviderCallbackDao;
|
||||
import dev.vality.disputes.domain.tables.pojos.Dispute;
|
||||
import dev.vality.disputes.domain.tables.pojos.ProviderCallback;
|
||||
import dev.vality.disputes.schedule.service.ProviderDataService;
|
||||
import dev.vality.disputes.security.AccessService;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static dev.vality.disputes.api.service.ApiDisputesService.DISPUTE_PENDING;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@SuppressWarnings({"ParameterName", "LineLength", "MissingSwitchDefault"})
|
||||
public class ProviderPaymentsCallbackHandler implements ProviderPaymentsCallbackServiceSrv.Iface {
|
||||
|
||||
private final DisputeDao disputeDao;
|
||||
private final AccessService accessService;
|
||||
private final PaymentParamsBuilder paymentParamsBuilder;
|
||||
private final ProviderDataService providerDataService;
|
||||
private final ProviderPaymentsRouting providerPaymentsRouting;
|
||||
private final ProviderPaymentsIfaceBuilder providerPaymentsIfaceBuilder;
|
||||
private final ProviderCallbackDao providerCallbackDao;
|
||||
|
||||
@Value("${dispute.isProviderCallbackEnabled}")
|
||||
private boolean enabled;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void createAdjustmentWhenFailedPaymentSuccess(ProviderPaymentsCallbackParams providerPaymentsCallbackParams) throws TException {
|
||||
log.info("disputeCallbackParams {}", providerPaymentsCallbackParams);
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var invoiceData = providerPaymentsCallbackParams.getDisputeID()
|
||||
.map(s -> disputeDao.getDisputeForUpdateSkipLocked(UUID.fromString(s)))
|
||||
.map(dispute -> InvoiceData.builder()
|
||||
.invoiceId(dispute.getInvoiceId())
|
||||
.paymentId(dispute.getPaymentId())
|
||||
.dispute(dispute)
|
||||
.build())
|
||||
.or(() -> providerPaymentsCallbackParams.getInvoiceId()
|
||||
.map(s -> disputeDao.getDisputesForUpdateSkipLocked(s, providerPaymentsCallbackParams.getPaymentId().get()))
|
||||
.flatMap(disputes -> disputes.stream()
|
||||
.filter(dispute -> DISPUTE_PENDING.contains(dispute.getStatus()))
|
||||
.findFirst())
|
||||
.map(dispute -> InvoiceData.builder()
|
||||
.invoiceId(dispute.getInvoiceId())
|
||||
.paymentId(dispute.getPaymentId())
|
||||
.dispute(dispute)
|
||||
.build())
|
||||
.or(() -> providerPaymentsCallbackParams.getInvoiceId()
|
||||
.map(s -> InvoiceData.builder()
|
||||
.invoiceId(s)
|
||||
.paymentId(providerPaymentsCallbackParams.getPaymentId().get())
|
||||
.build())))
|
||||
.orElse(null);
|
||||
log.info("invoiceData {}", invoiceData);
|
||||
if (invoiceData == null || invoiceData.getInvoiceId() == null) {
|
||||
return;
|
||||
}
|
||||
var accessData = accessService.approveUserAccess(invoiceData.getInvoiceId(), invoiceData.getPaymentId(), false);
|
||||
log.info("accessData {}", accessData);
|
||||
if (!accessData.getPayment().getPayment().getStatus().isSetFailed()) {
|
||||
return;
|
||||
}
|
||||
var paymentParams = paymentParamsBuilder.buildGeneralPaymentContext(accessData);
|
||||
log.info("paymentParams {}", paymentParams);
|
||||
var providerData = providerDataService.getProviderData(paymentParams.getProviderId(), paymentParams.getTerminalId());
|
||||
providerPaymentsRouting.initRouteUrl(providerData);
|
||||
var transactionContext = getTransactionContext(paymentParams);
|
||||
var remoteClient = providerPaymentsIfaceBuilder.buildTHSpawnClient(providerData.getRouteUrl());
|
||||
log.info("call remoteClient.isPaymentSuccess {}", transactionContext);
|
||||
var paymentStatusResult = remoteClient.checkPaymentStatus(transactionContext, getCurrency(paymentParams));
|
||||
if (paymentStatusResult.isSuccess()) {
|
||||
var providerCallback = new ProviderCallback();
|
||||
providerCallback.setInvoiceId(paymentParams.getInvoiceId());
|
||||
providerCallback.setPaymentId(paymentParams.getPaymentId());
|
||||
providerCallback.setChangedAmount(paymentStatusResult.getChangedAmount().orElse(null));
|
||||
providerCallbackDao.save(providerCallback);
|
||||
log.info("providerCallback {}", providerCallback);
|
||||
}
|
||||
} catch (TException e) {
|
||||
log.warn("remoteClient.isPaymentSuccess error", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static TransactionContext getTransactionContext(PaymentParams paymentParams) {
|
||||
var transactionContext = new TransactionContext();
|
||||
transactionContext.setProviderTrxId(paymentParams.getProviderTrxId());
|
||||
transactionContext.setInvoiceId(paymentParams.getInvoiceId());
|
||||
transactionContext.setPaymentId(paymentParams.getPaymentId());
|
||||
transactionContext.setTerminalOptions(paymentParams.getOptions());
|
||||
return transactionContext;
|
||||
}
|
||||
|
||||
private static Currency getCurrency(PaymentParams paymentParams) {
|
||||
var currency = new Currency();
|
||||
currency.setName(paymentParams.getCurrencyName());
|
||||
currency.setSymbolicCode(paymentParams.getCurrencySymbolicCode());
|
||||
currency.setNumericCode(paymentParams.getCurrencyNumericCode().shortValue());
|
||||
currency.setExponent(paymentParams.getCurrencyExponent().shortValue());
|
||||
return currency;
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public static class InvoiceData {
|
||||
private String invoiceId;
|
||||
private String paymentId;
|
||||
private Dispute dispute;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package dev.vality.disputes.callback;
|
||||
|
||||
import dev.vality.disputes.config.properties.AdaptersConnectionProperties;
|
||||
import dev.vality.woody.thrift.impl.http.THSpawnClientBuilder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@SuppressWarnings({"AbbreviationAsWordInName", "LineLength"})
|
||||
public class ProviderPaymentsIfaceBuilder {
|
||||
|
||||
private final AdaptersConnectionProperties adaptersConnectionProperties;
|
||||
|
||||
@Cacheable(value = "providersPayments", key = "#root.args[0]", cacheManager = "providersPaymentsCacheManager")
|
||||
public ProviderPaymentsServiceSrv.Iface buildTHSpawnClient(String routeUrl) {
|
||||
log.info("Creating new client for url: {}", routeUrl);
|
||||
return new THSpawnClientBuilder()
|
||||
.withNetworkTimeout((int) TimeUnit.SECONDS.toMillis(adaptersConnectionProperties.getTimeoutSec()))
|
||||
.withAddress(URI.create(routeUrl))
|
||||
.build(ProviderPaymentsServiceSrv.Iface.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package dev.vality.disputes.callback;
|
||||
|
||||
import dev.vality.disputes.exception.RoutingException;
|
||||
import dev.vality.disputes.schedule.model.ProviderData;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProviderPaymentsRouting {
|
||||
|
||||
private static final String PAYMENTS_URL_POSTFIX_DEFAULT = "payments";
|
||||
private static final String OPTION_PROVIDER_PAYMENTS_URL_FIELD_NAME = "provider_payments_url";
|
||||
|
||||
public void initRouteUrl(ProviderData providerData) {
|
||||
var url = providerData.getOptions().get(OPTION_PROVIDER_PAYMENTS_URL_FIELD_NAME);
|
||||
if (ObjectUtils.isEmpty(url)) {
|
||||
url = createDefaultRouteUrl(providerData.getDefaultProviderUrl());
|
||||
}
|
||||
providerData.setRouteUrl(url);
|
||||
}
|
||||
|
||||
private String createDefaultRouteUrl(String defaultProviderUrl) {
|
||||
log.debug("Creating url by appending postfix");
|
||||
try {
|
||||
return UriComponentsBuilder.fromUri(URI.create(defaultProviderUrl))
|
||||
.pathSegment(PAYMENTS_URL_POSTFIX_DEFAULT)
|
||||
.encode()
|
||||
.build()
|
||||
.toUriString();
|
||||
} catch (Exception e) {
|
||||
throw new RoutingException("Unable to create default provider url: ", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -26,10 +26,18 @@ public class CacheConfig {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public CacheManager adaptersCacheManager() {
|
||||
public CacheManager providersDisputesCacheManager() {
|
||||
var caffeineCacheManager = new CaffeineCacheManager();
|
||||
caffeineCacheManager.setCaffeine(adaptersConnectionsCacheConfig());
|
||||
caffeineCacheManager.setCacheNames(List.of("adapters"));
|
||||
caffeineCacheManager.setCacheNames(List.of("providersDisputes"));
|
||||
return caffeineCacheManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheManager providersPaymentsCacheManager() {
|
||||
var caffeineCacheManager = new CaffeineCacheManager();
|
||||
caffeineCacheManager.setCaffeine(adaptersConnectionsCacheConfig());
|
||||
caffeineCacheManager.setCacheNames(List.of("providersPayments"));
|
||||
return caffeineCacheManager;
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,8 @@ import dev.vality.disputes.provider.DisputeStatusResult;
|
||||
import dev.vality.disputes.schedule.converter.DisputeContextConverter;
|
||||
import dev.vality.disputes.schedule.converter.DisputeParamsConverter;
|
||||
import dev.vality.disputes.schedule.model.ProviderData;
|
||||
import dev.vality.disputes.schedule.service.ProviderIfaceBuilder;
|
||||
import dev.vality.disputes.schedule.service.ProviderRouting;
|
||||
import dev.vality.disputes.schedule.service.ProviderDisputesIfaceBuilder;
|
||||
import dev.vality.disputes.schedule.service.ProviderDisputesRouting;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -23,16 +23,16 @@ import java.util.List;
|
||||
@SuppressWarnings({"ParameterName", "LineLength"})
|
||||
public class RemoteClient {
|
||||
|
||||
private final ProviderRouting providerRouting;
|
||||
private final ProviderIfaceBuilder providerIfaceBuilder;
|
||||
private final ProviderDisputesRouting providerDisputesRouting;
|
||||
private final ProviderDisputesIfaceBuilder providerDisputesIfaceBuilder;
|
||||
private final DisputeParamsConverter disputeParamsConverter;
|
||||
private final DisputeContextConverter disputeContextConverter;
|
||||
|
||||
@SneakyThrows
|
||||
public DisputeCreatedResult createDispute(Dispute dispute, List<Attachment> attachments, ProviderData providerData) {
|
||||
providerRouting.initRouteUrl(providerData);
|
||||
providerDisputesRouting.initRouteUrl(providerData);
|
||||
log.debug("Trying to call ProviderIfaceBuilder {}", dispute.getId());
|
||||
var remoteClient = providerIfaceBuilder.buildTHSpawnClient(providerData.getRouteUrl());
|
||||
var remoteClient = providerDisputesIfaceBuilder.buildTHSpawnClient(providerData.getRouteUrl());
|
||||
log.debug("Trying to build disputeParams {}", dispute.getId());
|
||||
var disputeParams = disputeParamsConverter.convert(dispute, attachments, providerData.getOptions());
|
||||
log.debug("Trying to routed remote provider's createDispute() call {}", dispute.getId());
|
||||
@ -43,9 +43,9 @@ public class RemoteClient {
|
||||
|
||||
@SneakyThrows
|
||||
public DisputeStatusResult checkDisputeStatus(Dispute dispute, ProviderDispute providerDispute, ProviderData providerData) {
|
||||
providerRouting.initRouteUrl(providerData);
|
||||
providerDisputesRouting.initRouteUrl(providerData);
|
||||
log.debug("Trying to call ProviderIfaceBuilder {}", dispute.getId());
|
||||
var remoteClient = providerIfaceBuilder.buildTHSpawnClient(providerData.getRouteUrl());
|
||||
var remoteClient = providerDisputesIfaceBuilder.buildTHSpawnClient(providerData.getRouteUrl());
|
||||
log.debug("Trying to build disputeContext {}", dispute.getId());
|
||||
var disputeContext = disputeContextConverter.convert(dispute, providerDispute, providerData.getOptions());
|
||||
log.debug("Trying to routed remote provider's checkDisputeStatus() call {}", dispute.getId());
|
||||
|
@ -20,7 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
public class ExternalGatewayChecker {
|
||||
|
||||
private final CloseableHttpClient httpClient;
|
||||
private final ProviderRouting providerRouting;
|
||||
private final ProviderDisputesRouting providerDisputesRouting;
|
||||
|
||||
public boolean isProvidersDisputesUnexpectedResultMapping(WRuntimeException e) {
|
||||
return e.getErrorDefinition() != null
|
||||
@ -45,7 +45,7 @@ public class ExternalGatewayChecker {
|
||||
}
|
||||
|
||||
private String getRouteUrl(ProviderData providerData) {
|
||||
providerRouting.initRouteUrl(providerData);
|
||||
providerDisputesRouting.initRouteUrl(providerData);
|
||||
log.debug("Check adapter connection, routeUrl={}", providerData.getRouteUrl());
|
||||
return providerData.getRouteUrl();
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ import java.util.concurrent.TimeUnit;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@SuppressWarnings({"AbbreviationAsWordInName", "LineLength"})
|
||||
public class ProviderIfaceBuilder {
|
||||
public class ProviderDisputesIfaceBuilder {
|
||||
|
||||
private final AdaptersConnectionProperties adaptersConnectionProperties;
|
||||
|
||||
@Cacheable(value = "adapters", key = "#root.args[0]", cacheManager = "adaptersCacheManager")
|
||||
@Cacheable(value = "providersDisputes", key = "#root.args[0]", cacheManager = "providersDisputesCacheManager")
|
||||
public ProviderDisputesServiceSrv.Iface buildTHSpawnClient(String routeUrl) {
|
||||
log.info("Creating new client for url: {}", routeUrl);
|
||||
return new THSpawnClientBuilder()
|
@ -13,7 +13,7 @@ import java.net.URI;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProviderRouting {
|
||||
public class ProviderDisputesRouting {
|
||||
|
||||
private static final String DISPUTES_URL_POSTFIX_DEFAULT = "disputes";
|
||||
private static final String OPTION_DISPUTES_URL_FIELD_NAME = "disputes_url";
|
@ -1,6 +1,6 @@
|
||||
package dev.vality.disputes.servlet;
|
||||
|
||||
import dev.vality.disputes.callback.ProviderDisputesCallbackServiceSrv;
|
||||
import dev.vality.disputes.callback.ProviderPaymentsCallbackServiceSrv;
|
||||
import dev.vality.woody.thrift.impl.http.THServiceBuilder;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
@ -12,7 +12,7 @@ import java.io.IOException;
|
||||
public class ProviderDisputesCallbackServlet extends GenericServlet {
|
||||
|
||||
@Autowired
|
||||
private ProviderDisputesCallbackServiceSrv.Iface providerDisputesCallbackHandler;
|
||||
private ProviderPaymentsCallbackServiceSrv.Iface providerPaymentsCallbackHandler;
|
||||
|
||||
private Servlet servlet;
|
||||
|
||||
@ -20,7 +20,7 @@ public class ProviderDisputesCallbackServlet extends GenericServlet {
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
servlet = new THServiceBuilder()
|
||||
.build(ProviderDisputesCallbackServiceSrv.Iface.class, providerDisputesCallbackHandler);
|
||||
.build(ProviderPaymentsCallbackServiceSrv.Iface.class, providerPaymentsCallbackHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,8 +3,8 @@ package dev.vality.disputes.api;
|
||||
import dev.vality.damsel.payment_processing.InvoicingSrv;
|
||||
import dev.vality.disputes.admin.AdminManagementServiceSrv;
|
||||
import dev.vality.disputes.admin.CancelParamsRequest;
|
||||
import dev.vality.disputes.callback.DisputeCallbackParams;
|
||||
import dev.vality.disputes.callback.ProviderDisputesCallbackServiceSrv;
|
||||
import dev.vality.disputes.callback.ProviderPaymentsCallbackParams;
|
||||
import dev.vality.disputes.callback.ProviderPaymentsCallbackServiceSrv;
|
||||
import dev.vality.disputes.config.WireMockSpringBootITest;
|
||||
import dev.vality.disputes.merchant.DisputeParams;
|
||||
import dev.vality.disputes.merchant.MerchantDisputesServiceSrv;
|
||||
@ -71,12 +71,12 @@ public class ServletTest {
|
||||
var iface = new THSpawnClientBuilder()
|
||||
.withAddress(new URI("http://127.0.0.1:" + serverPort + CALLBACK))
|
||||
.withNetworkTimeout(5000)
|
||||
.build(ProviderDisputesCallbackServiceSrv.Iface.class);
|
||||
.build(ProviderPaymentsCallbackServiceSrv.Iface.class);
|
||||
var request = DamselUtil.fillRequiredTBaseObject(
|
||||
new DisputeCallbackParams(),
|
||||
DisputeCallbackParams.class
|
||||
new ProviderPaymentsCallbackParams(),
|
||||
ProviderPaymentsCallbackParams.class
|
||||
);
|
||||
iface.createAdjustmentIfPaymentSuccess(request);
|
||||
iface.createAdjustmentWhenFailedPaymentSuccess(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
|
||||
public class CreatedDisputesServiceTest {
|
||||
|
||||
@Autowired
|
||||
private ProviderIfaceBuilder providerIfaceBuilder;
|
||||
private ProviderDisputesIfaceBuilder providerDisputesIfaceBuilder;
|
||||
@Autowired
|
||||
private DominantService dominantService;
|
||||
@Autowired
|
||||
@ -125,7 +125,7 @@ public class CreatedDisputesServiceTest {
|
||||
when(dominantService.getProxy(any())).thenReturn(createProxy().get());
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.createDispute(any())).thenReturn(createDisputeCreatedFailResult());
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
createdDisputesService.callCreateDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.failed, disputeDao.get(disputeId).get().getStatus());
|
||||
@ -150,7 +150,7 @@ public class CreatedDisputesServiceTest {
|
||||
var disputeCreatedFailResult = createDisputeCreatedFailResult();
|
||||
disputeCreatedFailResult.getFailResult().getFailure().setCode(DISPUTES_UNKNOWN_MAPPING);
|
||||
when(providerMock.createDispute(any())).thenReturn(disputeCreatedFailResult);
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
createdDisputesService.callCreateDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.manual_created, disputeDao.get(disputeId).get().getStatus());
|
||||
@ -176,7 +176,7 @@ public class CreatedDisputesServiceTest {
|
||||
when(dominantService.getProxy(any())).thenReturn(createProxyWithRealAddress(serverPort).get());
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.createDispute(any())).thenThrow(getUnexpectedResultWException());
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
createdDisputesService.callCreateDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.manual_created, disputeDao.get(disputeId).get().getStatus());
|
||||
@ -201,7 +201,7 @@ public class CreatedDisputesServiceTest {
|
||||
when(dominantService.getProxy(any())).thenReturn(createProxyNotFoundCase(serverPort).get());
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.createDispute(any())).thenThrow(getUnexpectedResultWException());
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
createdDisputesService.callCreateDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.manual_pending, disputeDao.get(disputeId).get().getStatus());
|
||||
@ -225,7 +225,7 @@ public class CreatedDisputesServiceTest {
|
||||
when(dominantService.getProxy(any())).thenReturn(createProxy().get());
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.createDispute(any())).thenReturn(createDisputeAlreadyExistResult());
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
createdDisputesService.callCreateDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.already_exist_created, disputeDao.get(disputeId).get().getStatus());
|
||||
|
@ -29,7 +29,7 @@ import static org.mockito.Mockito.when;
|
||||
public class PendingDisputesServiceTest {
|
||||
|
||||
@Autowired
|
||||
private ProviderIfaceBuilder providerIfaceBuilder;
|
||||
private ProviderDisputesIfaceBuilder providerDisputesIfaceBuilder;
|
||||
@Autowired
|
||||
private DominantService dominantService;
|
||||
@Autowired
|
||||
@ -74,7 +74,7 @@ public class PendingDisputesServiceTest {
|
||||
var disputeId = createdDisputesTestService.callCreateDisputeRemotely();
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.checkDisputeStatus(any())).thenReturn(createDisputeStatusFailResult());
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
pendingDisputesService.callPendingDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.failed, disputeDao.get(disputeId).get().getStatus());
|
||||
@ -88,7 +88,7 @@ public class PendingDisputesServiceTest {
|
||||
var disputeStatusFailResult = createDisputeStatusFailResult();
|
||||
disputeStatusFailResult.getStatusFail().getFailure().setCode(DISPUTES_UNKNOWN_MAPPING);
|
||||
when(providerMock.checkDisputeStatus(any())).thenReturn(disputeStatusFailResult);
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
pendingDisputesService.callPendingDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.manual_pending, disputeDao.get(disputeId).get().getStatus());
|
||||
@ -102,7 +102,7 @@ public class PendingDisputesServiceTest {
|
||||
var disputeId = createdDisputesTestService.callCreateDisputeRemotely();
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.checkDisputeStatus(any())).thenThrow(getUnexpectedResultWException());
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
pendingDisputesService.callPendingDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.manual_pending, disputeDao.get(disputeId).get().getStatus());
|
||||
@ -117,7 +117,7 @@ public class PendingDisputesServiceTest {
|
||||
var disputeId = createdDisputesTestService.callCreateDisputeRemotely();
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.checkDisputeStatus(any())).thenReturn(createDisputeStatusPendingResult());
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
pendingDisputesService.callPendingDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.pending, disputeDao.get(disputeId).get().getStatus());
|
||||
|
@ -7,7 +7,7 @@ import dev.vality.disputes.dao.DisputeDao;
|
||||
import dev.vality.disputes.domain.enums.DisputeStatus;
|
||||
import dev.vality.disputes.provider.ProviderDisputesServiceSrv;
|
||||
import dev.vality.disputes.schedule.core.CreatedDisputesService;
|
||||
import dev.vality.disputes.schedule.service.ProviderIfaceBuilder;
|
||||
import dev.vality.disputes.schedule.service.ProviderDisputesIfaceBuilder;
|
||||
import dev.vality.disputes.service.external.DominantService;
|
||||
import dev.vality.disputes.util.MockUtil;
|
||||
import dev.vality.disputes.util.TestUrlPaths;
|
||||
@ -32,7 +32,7 @@ import static org.mockito.Mockito.when;
|
||||
public class CreatedDisputesTestService {
|
||||
|
||||
@Autowired
|
||||
private ProviderIfaceBuilder providerIfaceBuilder;
|
||||
private ProviderDisputesIfaceBuilder providerDisputesIfaceBuilder;
|
||||
@Autowired
|
||||
private DominantService dominantService;
|
||||
@Autowired
|
||||
@ -65,7 +65,7 @@ public class CreatedDisputesTestService {
|
||||
when(dominantService.getProxy(any())).thenReturn(createProxy(String.format("http://127.0.0.1:%s%s", 8023, TestUrlPaths.ADAPTER)).get());
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.createDispute(any())).thenReturn(createDisputeCreatedSuccessResult(providerDisputeId));
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
createdDisputesService.callCreateDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.pending, disputeDao.get(disputeId).get().getStatus());
|
||||
|
@ -4,7 +4,7 @@ import dev.vality.disputes.dao.DisputeDao;
|
||||
import dev.vality.disputes.domain.enums.DisputeStatus;
|
||||
import dev.vality.disputes.provider.ProviderDisputesServiceSrv;
|
||||
import dev.vality.disputes.schedule.core.PendingDisputesService;
|
||||
import dev.vality.disputes.schedule.service.ProviderIfaceBuilder;
|
||||
import dev.vality.disputes.schedule.service.ProviderDisputesIfaceBuilder;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.TestComponent;
|
||||
@ -24,7 +24,7 @@ import static org.mockito.Mockito.when;
|
||||
public class PendingDisputesTestService {
|
||||
|
||||
@Autowired
|
||||
private ProviderIfaceBuilder providerIfaceBuilder;
|
||||
private ProviderDisputesIfaceBuilder providerDisputesIfaceBuilder;
|
||||
@Autowired
|
||||
private DisputeDao disputeDao;
|
||||
@Autowired
|
||||
@ -37,7 +37,7 @@ public class PendingDisputesTestService {
|
||||
var disputeId = createdDisputesTestService.callCreateDisputeRemotely();
|
||||
var providerMock = mock(ProviderDisputesServiceSrv.Client.class);
|
||||
when(providerMock.checkDisputeStatus(any())).thenReturn(createDisputeStatusSuccessResult());
|
||||
when(providerIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
when(providerDisputesIfaceBuilder.buildTHSpawnClient(any())).thenReturn(providerMock);
|
||||
var dispute = disputeDao.get(disputeId);
|
||||
pendingDisputesService.callPendingDisputeRemotely(dispute.get());
|
||||
assertEquals(DisputeStatus.create_adjustment, disputeDao.get(disputeId).get().getStatus());
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.vality.disputes.schedule.service.config;
|
||||
|
||||
import dev.vality.disputes.schedule.service.ProviderIfaceBuilder;
|
||||
import dev.vality.disputes.schedule.service.ProviderDisputesIfaceBuilder;
|
||||
import dev.vality.disputes.service.external.DominantService;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
@ -9,7 +9,7 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
public class RemoteClientTestConfig {
|
||||
|
||||
@MockBean
|
||||
private ProviderIfaceBuilder providerIfaceBuilder;
|
||||
private ProviderDisputesIfaceBuilder providerDisputesIfaceBuilder;
|
||||
@MockBean
|
||||
private DominantService dominantService;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user