Add new implementation for Intent result factory without change termU… (#63)

This commit is contained in:
struga 2023-03-10 14:18:51 +07:00 committed by GitHub
parent 577d4b465d
commit abb37c3447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 226 additions and 13 deletions

View File

@ -12,7 +12,7 @@
</parent>
<artifactId>adapter-flow-lib</artifactId>
<version>0.1.21</version>
<version>0.1.22</version>
<packaging>jar</packaging>
<name>adapter-flow-lib</name>

View File

@ -4,7 +4,7 @@ import dev.vality.adapter.flow.lib.converter.ExitStateModelToTemporaryContextCon
import dev.vality.adapter.flow.lib.flow.ResultIntentResolver;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.serde.TemporaryContextSerializer;
import dev.vality.adapter.flow.lib.service.IntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.IntentResultFactory;
import dev.vality.adapter.flow.lib.utils.AdditionalInfoUtils;
import dev.vality.damsel.domain.TransactionInfo;
import dev.vality.damsel.proxy_provider.Intent;

View File

@ -4,7 +4,7 @@ import dev.vality.adapter.flow.lib.converter.ExitStateModelToTemporaryContextCon
import dev.vality.adapter.flow.lib.flow.RecurrentResultIntentResolver;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.serde.TemporaryContextSerializer;
import dev.vality.adapter.flow.lib.service.RecurrentIntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.RecurrentIntentResultFactory;
import dev.vality.adapter.flow.lib.utils.AdditionalInfoUtils;
import dev.vality.damsel.domain.TransactionInfo;
import dev.vality.damsel.proxy_provider.RecurrentTokenIntent;

View File

@ -3,7 +3,7 @@ package dev.vality.adapter.flow.lib.flow.full;
import dev.vality.adapter.flow.lib.constant.Step;
import dev.vality.adapter.flow.lib.flow.RecurrentResultIntentResolver;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.service.RecurrentIntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.RecurrentIntentResultFactory;
import dev.vality.damsel.proxy_provider.RecurrentTokenIntent;
import lombok.RequiredArgsConstructor;

View File

@ -4,7 +4,7 @@ import dev.vality.adapter.flow.lib.constant.Step;
import dev.vality.adapter.flow.lib.flow.ResultIntentResolver;
import dev.vality.adapter.flow.lib.model.EntryStateModel;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.service.IntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.IntentResultFactory;
import dev.vality.damsel.proxy_provider.Intent;
import lombok.RequiredArgsConstructor;

View File

@ -3,7 +3,7 @@ package dev.vality.adapter.flow.lib.flow.simple;
import dev.vality.adapter.flow.lib.constant.Step;
import dev.vality.adapter.flow.lib.flow.RecurrentResultIntentResolver;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.service.RecurrentIntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.RecurrentIntentResultFactory;
import dev.vality.damsel.proxy_provider.RecurrentTokenIntent;
import lombok.RequiredArgsConstructor;

View File

@ -5,7 +5,7 @@ import dev.vality.adapter.flow.lib.constant.Step;
import dev.vality.adapter.flow.lib.constant.TargetStatus;
import dev.vality.adapter.flow.lib.flow.ResultIntentResolver;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.service.IntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.IntentResultFactory;
import dev.vality.damsel.proxy_provider.Intent;
import lombok.RequiredArgsConstructor;

View File

@ -1,4 +1,4 @@
package dev.vality.adapter.flow.lib.service;
package dev.vality.adapter.flow.lib.service.factory;
import dev.vality.adapter.common.mapper.ErrorMapping;
import dev.vality.adapter.flow.lib.constant.HttpMethod;
@ -8,6 +8,10 @@ import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.model.PollingInfo;
import dev.vality.adapter.flow.lib.model.ThreeDsData;
import dev.vality.adapter.flow.lib.serde.ParametersSerializer;
import dev.vality.adapter.flow.lib.service.CallbackUrlExtractor;
import dev.vality.adapter.flow.lib.service.ExponentialBackOffPollingService;
import dev.vality.adapter.flow.lib.service.PollingInfoService;
import dev.vality.adapter.flow.lib.service.TagManagementService;
import dev.vality.adapter.flow.lib.utils.ThreeDsDataInitializer;
import dev.vality.adapter.flow.lib.utils.TimeoutUtils;
import dev.vality.adapter.flow.lib.utils.TimerProperties;

View File

@ -0,0 +1,123 @@
package dev.vality.adapter.flow.lib.service.factory;
import dev.vality.adapter.common.mapper.ErrorMapping;
import dev.vality.adapter.flow.lib.constant.HttpMethod;
import dev.vality.adapter.flow.lib.model.EntryStateModel;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.model.PollingInfo;
import dev.vality.adapter.flow.lib.model.ThreeDsData;
import dev.vality.adapter.flow.lib.serde.ParametersSerializer;
import dev.vality.adapter.flow.lib.service.ExponentialBackOffPollingService;
import dev.vality.adapter.flow.lib.service.PollingInfoService;
import dev.vality.adapter.flow.lib.service.TagManagementService;
import dev.vality.adapter.flow.lib.utils.ThreeDsDataInitializer;
import dev.vality.adapter.flow.lib.utils.TimeoutUtils;
import dev.vality.adapter.flow.lib.utils.TimerProperties;
import dev.vality.damsel.base.Timer;
import dev.vality.damsel.proxy_provider.*;
import dev.vality.damsel.timeout_behaviour.TimeoutBehaviour;
import dev.vality.damsel.user_interaction.UserInteraction;
import lombok.RequiredArgsConstructor;
import java.nio.ByteBuffer;
import java.util.Map;
import static dev.vality.adapter.common.damsel.OptionsExtractors.extractRedirectTimeout;
import static dev.vality.adapter.common.damsel.ProxyProviderPackageCreators.*;
@RequiredArgsConstructor
public class IntentResultForwardThreeDsParamsFactory {
private final TimerProperties timerProperties;
private final TagManagementService tagManagementService;
private final ParametersSerializer parametersSerializer;
private final PollingInfoService pollingInfoService;
private final ErrorMapping errorMapping;
private final ExponentialBackOffPollingService exponentialBackOffPollingService;
public Intent createFinishIntentSuccessWithCheckToken(ExitStateModel exitStateModel) {
EntryStateModel entryStateModel = exitStateModel.getEntryStateModel();
if (entryStateModel.getBaseRequestModel().getRecurrentPaymentData() != null
&& entryStateModel.getBaseRequestModel().getRecurrentPaymentData().isMakeRecurrent()) {
return createFinishIntentSuccessWithToken(exitStateModel.getRecToken());
}
return createFinishIntentSuccess();
}
public Intent createSuspendIntentWithFailedAfterTimeout(ExitStateModel exitStateModel) {
EntryStateModel entryStateModel = exitStateModel.getEntryStateModel();
ThreeDsData threeDsData = exitStateModel.getThreeDsData();
Map<String, String> params = ThreeDsDataInitializer.initThreeDsParameters(exitStateModel);
Map<String, String> adapterConfigurations = entryStateModel.getBaseRequestModel().getAdapterConfigurations();
int timerRedirectTimeoutMin = extractRedirectTimeout(
adapterConfigurations,
timerProperties.getRedirectTimeoutMin());
return Intent.suspend(
new SuspendIntent(
tagManagementService.findTag(params),
Timer.timeout(TimeoutUtils.toSeconds(timerRedirectTimeoutMin))
).setUserInteraction(createUserInteraction(threeDsData, params))
);
}
public Intent createSuspendIntentWithCallbackAfterTimeout(ExitStateModel exitStateModel) {
Map<String, String> params = ThreeDsDataInitializer.initThreeDsParameters(exitStateModel);
EntryStateModel entryStateModel = exitStateModel.getEntryStateModel();
PollingInfo pollingInfo = pollingInfoService.initPollingInfo(entryStateModel);
if (pollingInfoService.isDeadline(pollingInfo)) {
return createFinishIntentFailed("Sleep timeout", "Max time pool limit reached");
}
exitStateModel.setPollingInfo(pollingInfo);
Map<String, String> adapterConfigurations = entryStateModel.getBaseRequestModel().getAdapterConfigurations();
int timerRedirectTimeoutMin = extractRedirectTimeout(
adapterConfigurations,
timerProperties.getRedirectTimeoutMin());
return Intent.suspend(
new SuspendIntent(
tagManagementService.findTag(params),
Timer.timeout(TimeoutUtils.toSeconds(timerRedirectTimeoutMin)))
.setTimeoutBehaviour(TimeoutBehaviour.callback(
ByteBuffer.wrap(parametersSerializer.writeByte(params)))
).setUserInteraction(createUserInteraction(exitStateModel.getThreeDsData(), params))
);
}
private UserInteraction createUserInteraction(ThreeDsData threeDsData, Map<String, String> parameters) {
if (threeDsData.getHttpMethod() == HttpMethod.GET) {
return createGetUserInteraction(threeDsData.getAcsUrl());
} else {
return createPostUserInteraction(threeDsData.getAcsUrl(), parameters);
}
}
public Intent createFinishIntentSuccess() {
return Intent.finish(new FinishIntent(FinishStatus.success(new Success())));
}
public Intent createSleepIntentWithExponentialPolling(ExitStateModel exitStateModel) {
EntryStateModel entryStateModel = exitStateModel.getEntryStateModel();
PollingInfo pollingInfo = pollingInfoService.initPollingInfo(entryStateModel);
if (pollingInfoService.isDeadline(pollingInfo)) {
return createFinishIntentFailed("Sleep timeout", "Max time pool limit reached");
}
exitStateModel.setPollingInfo(pollingInfo);
Map<String, String> adapterConfigurations = entryStateModel.getBaseRequestModel().getAdapterConfigurations();
int nextTimeoutSec =
exponentialBackOffPollingService.prepareNextPollingInterval(pollingInfo, adapterConfigurations);
return Intent.sleep(new SleepIntent(Timer.timeout(nextTimeoutSec)));
}
public Intent createFinishIntentFailed(ExitStateModel exitStateModel) {
return Intent.finish(new FinishIntent(FinishStatus.failure(
errorMapping.mapFailure(exitStateModel.getErrorCode(),
exitStateModel.getErrorMessage()))));
}
public Intent createFinishIntentFailed(String errorCode, String errorMessage) {
return Intent.finish(new FinishIntent(FinishStatus.failure(
errorMapping.mapFailure(errorCode, errorMessage))));
}
}

View File

@ -1,4 +1,4 @@
package dev.vality.adapter.flow.lib.service;
package dev.vality.adapter.flow.lib.service.factory;
import dev.vality.adapter.common.mapper.ErrorMapping;
import dev.vality.adapter.flow.lib.constant.RedirectFields;
@ -6,6 +6,10 @@ import dev.vality.adapter.flow.lib.model.EntryStateModel;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.model.PollingInfo;
import dev.vality.adapter.flow.lib.model.ThreeDsData;
import dev.vality.adapter.flow.lib.service.CallbackUrlExtractor;
import dev.vality.adapter.flow.lib.service.ExponentialBackOffPollingService;
import dev.vality.adapter.flow.lib.service.PollingInfoService;
import dev.vality.adapter.flow.lib.service.TagManagementService;
import dev.vality.adapter.flow.lib.utils.ThreeDsDataInitializer;
import dev.vality.adapter.flow.lib.utils.TimeoutUtils;
import dev.vality.adapter.flow.lib.utils.TimerProperties;

View File

@ -0,0 +1,80 @@
package dev.vality.adapter.flow.lib.service.factory;
import dev.vality.adapter.common.mapper.ErrorMapping;
import dev.vality.adapter.flow.lib.model.EntryStateModel;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.model.PollingInfo;
import dev.vality.adapter.flow.lib.model.ThreeDsData;
import dev.vality.adapter.flow.lib.service.ExponentialBackOffPollingService;
import dev.vality.adapter.flow.lib.service.PollingInfoService;
import dev.vality.adapter.flow.lib.service.TagManagementService;
import dev.vality.adapter.flow.lib.utils.ThreeDsDataInitializer;
import dev.vality.adapter.flow.lib.utils.TimeoutUtils;
import dev.vality.adapter.flow.lib.utils.TimerProperties;
import dev.vality.damsel.base.Timer;
import dev.vality.damsel.proxy_provider.*;
import lombok.RequiredArgsConstructor;
import java.util.Map;
import static dev.vality.adapter.common.damsel.OptionsExtractors.extractRedirectTimeout;
import static dev.vality.adapter.common.damsel.ProxyProviderPackageCreators.createPostUserInteraction;
import static dev.vality.adapter.common.damsel.ProxyProviderPackageCreators.createRecurrentTokenStatusSuccess;
@RequiredArgsConstructor
public class RecurrentIntentResultForwardThreeDsParamsFactory {
private final TimerProperties timerProperties;
private final TagManagementService tagManagementService;
private final PollingInfoService pollingInfoService;
private final ErrorMapping errorMapping;
private final ExponentialBackOffPollingService exponentialBackOffPollingService;
public RecurrentTokenIntent createIntentWithSuspension(ExitStateModel exitStateModel) {
EntryStateModel entryStateModel = exitStateModel.getEntryStateModel();
ThreeDsData threeDsData = exitStateModel.getThreeDsData();
Map<String, String> params = ThreeDsDataInitializer.initThreeDsParameters(exitStateModel);
Map<String, String> adapterConfigurations = entryStateModel.getBaseRequestModel().getAdapterConfigurations();
int timerRedirectTimeoutMin = extractRedirectTimeout(
adapterConfigurations,
timerProperties.getRedirectTimeoutMin());
return RecurrentTokenIntent.suspend(
new SuspendIntent(
tagManagementService.findTag(params),
Timer.timeout(TimeoutUtils.toSeconds(timerRedirectTimeoutMin))
).setUserInteraction(createPostUserInteraction(threeDsData.getAcsUrl(), params))
);
}
public RecurrentTokenIntent createSleepIntentForReinvocation() {
return RecurrentTokenIntent.sleep(new SleepIntent(Timer.timeout(0)));
}
public RecurrentTokenIntent createSleepIntentWithExponentialPolling(ExitStateModel exitStateModel) {
EntryStateModel entryStateModel = exitStateModel.getEntryStateModel();
PollingInfo pollingInfo = pollingInfoService.initPollingInfo(entryStateModel);
if (pollingInfoService.isDeadline(pollingInfo)) {
return createFinishIntentFailed("Sleep timeout", "Max time pool limit reached");
}
exitStateModel.setPollingInfo(pollingInfo);
Map<String, String> adapterConfigurations = entryStateModel.getBaseRequestModel().getAdapterConfigurations();
int nextTimeoutSec =
exponentialBackOffPollingService.prepareNextPollingInterval(pollingInfo, adapterConfigurations);
return RecurrentTokenIntent.sleep(
new SleepIntent(Timer.timeout(nextTimeoutSec))
);
}
public RecurrentTokenIntent createFinishIntent(String recToken) {
return RecurrentTokenIntent.finish(
createRecurrentTokenStatusSuccess(recToken)
);
}
public RecurrentTokenIntent createFinishIntentFailed(String errorCode, String errorMessage) {
return RecurrentTokenIntent.finish(new RecurrentTokenFinishIntent(RecurrentTokenFinishStatus.failure(
errorMapping.mapFailure(errorCode, errorMessage)))
);
}
}

View File

@ -22,6 +22,8 @@ import dev.vality.adapter.flow.lib.serde.ParametersSerializer;
import dev.vality.adapter.flow.lib.serde.TemporaryContextDeserializer;
import dev.vality.adapter.flow.lib.serde.TemporaryContextSerializer;
import dev.vality.adapter.flow.lib.service.*;
import dev.vality.adapter.flow.lib.service.factory.IntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.RecurrentIntentResultFactory;
import dev.vality.adapter.flow.lib.utils.AdapterProperties;
import dev.vality.adapter.flow.lib.service.CallbackUrlExtractor;
import dev.vality.adapter.flow.lib.utils.TimerProperties;

View File

@ -20,8 +20,8 @@ import dev.vality.adapter.flow.lib.model.BaseResponseModel;
import dev.vality.adapter.flow.lib.model.EntryStateModel;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.processor.Processor;
import dev.vality.adapter.flow.lib.service.IntentResultFactory;
import dev.vality.adapter.flow.lib.service.RecurrentIntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.IntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.RecurrentIntentResultFactory;
import dev.vality.damsel.proxy_provider.PaymentContext;
import dev.vality.damsel.proxy_provider.PaymentProxyResult;
import dev.vality.damsel.proxy_provider.RecurrentTokenContext;

View File

@ -20,8 +20,8 @@ import dev.vality.adapter.flow.lib.model.BaseResponseModel;
import dev.vality.adapter.flow.lib.model.EntryStateModel;
import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.processor.Processor;
import dev.vality.adapter.flow.lib.service.IntentResultFactory;
import dev.vality.adapter.flow.lib.service.RecurrentIntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.IntentResultFactory;
import dev.vality.adapter.flow.lib.service.factory.RecurrentIntentResultFactory;
import dev.vality.damsel.proxy_provider.PaymentContext;
import dev.vality.damsel.proxy_provider.PaymentProxyResult;
import dev.vality.damsel.proxy_provider.RecurrentTokenContext;