From 6ffe114df5b3ab44ed8260d700bd27ab98a12710 Mon Sep 17 00:00:00 2001 From: struga Date: Tue, 15 Mar 2022 17:26:44 +0300 Subject: [PATCH] Refactor lib (#16) --- README.md | 5 +++- docs/flow_using_lib.md | 8 ++++--- ...Simple Redirect With Polling Flow Steps.md | 1 - ...s.md => full_three_ds_v1_v2_flow_steps.md} | 0 ...svg => full_three_ds_v1_v2_flow steps.svg} | 0 ...direct_with_polling_flow_steps.drawio.svg} | 0 ...simple_redirect_with_polling_flow_steps.md | 8 +++++++ docs/spring-boot-configuration.md | 1 + pom.xml | 2 +- .../adapter/flow/lib/constant/HttpMethod.java | 7 ++++++ .../entry/CtxToEntryModelConverter.java | 7 ++++-- .../entry/RecCtxToEntryModelConverter.java | 8 ++++++- ...directWithPollingResultIntentResolver.java | 2 -- .../flow/lib/model/BaseRequestModel.java | 8 +++---- .../adapter/flow/lib/model/Currency.java | 23 +++++++++++++++++++ .../adapter/flow/lib/model/ThreeDsData.java | 5 ++++ .../flow/lib/service/IntentResultFactory.java | 16 +++++++++---- 17 files changed, 81 insertions(+), 20 deletions(-) delete mode 100644 docs/flows/Simple Redirect With Polling Flow Steps.md rename docs/flows/{Full Three Ds V1 V2 Flow Steps.md => full_three_ds_v1_v2_flow_steps.md} (100%) rename docs/flows/imgs/{Full Three Ds V1 V2 Flow Steps.svg => full_three_ds_v1_v2_flow steps.svg} (100%) rename docs/flows/imgs/{Simple Redirect With Polling Flow Steps.drawio.svg => simple_redirect_with_polling_flow_steps.drawio.svg} (100%) create mode 100644 docs/flows/simple_redirect_with_polling_flow_steps.md create mode 100644 src/main/java/dev/vality/adapter/flow/lib/constant/HttpMethod.java create mode 100644 src/main/java/dev/vality/adapter/flow/lib/model/Currency.java diff --git a/README.md b/README.md index de7e847..ea4f0c2 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -# adapter-flow-lib \ No newline at end of file +# adapter-flow-lib + +### License +[Apache 2.0 License.](/LICENSE) \ No newline at end of file diff --git a/docs/flow_using_lib.md b/docs/flow_using_lib.md index a582872..0728a08 100644 --- a/docs/flow_using_lib.md +++ b/docs/flow_using_lib.md @@ -1,12 +1,14 @@ ### Как использовать бибилиотеку? 1. Необходимо провести аналитику и определить какой процесс вам подходит. Список процессов: - * [Процесс с полным прохождением 3дс версии 1.0 и 2.0](./flows/Full Three Ds V1 V2 Flow Steps.md) - * [Простой процесс с редиректом и поллингом статусов после всех операций](./flows/Full Three Ds V1 V2 Flow Steps.md) + * [Процесс с полным прохождением 3дс версии 1.0 и 2.0](./flows/full_three_ds_v1_v2_flow_steps.md) + * [Простой процесс с редиректом и поллингом статусов после всех операций](./flows/simple_redirect_with_polling_flow_steps.md) + 2. Если подходящий вам процесс найден, процесс продолжается по следующему пути: 1. Подготавливается конфигурация под spring-boot [настройка конфигурации](./spring-boot-configuration.md). 2. Релизовать, соответствующие выбранному флоу, методы из [RemoteClient](../src/main/java/dev/vality/adapter/flow/lib/client/RemoteClient.java) [инструкция](./client_implementations_manual.md) 3. Реализовать валидаторы для ваших входных параметров, уникальных для вашего адаптера и настраевымых командой - поддержки поддержкой(options - на уровне протокола damsel) [интерфейс](../src/main/java/dev/vality/adapter/flow/lib/validator/Validator.java) + поддержки поддержкой(options - на уровне протокола + damsel) [интерфейс](../src/main/java/dev/vality/adapter/flow/lib/validator/Validator.java) 4. Реализация тестов \ No newline at end of file diff --git a/docs/flows/Simple Redirect With Polling Flow Steps.md b/docs/flows/Simple Redirect With Polling Flow Steps.md deleted file mode 100644 index e1cc912..0000000 --- a/docs/flows/Simple Redirect With Polling Flow Steps.md +++ /dev/null @@ -1 +0,0 @@ -### Простой процесс с редиректом и поллингом статусов после всех операций \ No newline at end of file diff --git a/docs/flows/Full Three Ds V1 V2 Flow Steps.md b/docs/flows/full_three_ds_v1_v2_flow_steps.md similarity index 100% rename from docs/flows/Full Three Ds V1 V2 Flow Steps.md rename to docs/flows/full_three_ds_v1_v2_flow_steps.md diff --git a/docs/flows/imgs/Full Three Ds V1 V2 Flow Steps.svg b/docs/flows/imgs/full_three_ds_v1_v2_flow steps.svg similarity index 100% rename from docs/flows/imgs/Full Three Ds V1 V2 Flow Steps.svg rename to docs/flows/imgs/full_three_ds_v1_v2_flow steps.svg diff --git a/docs/flows/imgs/Simple Redirect With Polling Flow Steps.drawio.svg b/docs/flows/imgs/simple_redirect_with_polling_flow_steps.drawio.svg similarity index 100% rename from docs/flows/imgs/Simple Redirect With Polling Flow Steps.drawio.svg rename to docs/flows/imgs/simple_redirect_with_polling_flow_steps.drawio.svg diff --git a/docs/flows/simple_redirect_with_polling_flow_steps.md b/docs/flows/simple_redirect_with_polling_flow_steps.md new file mode 100644 index 0000000..2d085ad --- /dev/null +++ b/docs/flows/simple_redirect_with_polling_flow_steps.md @@ -0,0 +1,8 @@ +### Простой процесс с редиректом и поллингом статусов после всех операций + +![alt text](imgs/simple_redirect_with_polling_flow_steps.drawio.svg) + +1. Запрос на авторизацию +2. Получение ссылки для перенаправления клиента +3. Перенаправление клиента +4. Опрос статуса после прохождения таймаута \ No newline at end of file diff --git a/docs/spring-boot-configuration.md b/docs/spring-boot-configuration.md index 95d87e6..239e402 100644 --- a/docs/spring-boot-configuration.md +++ b/docs/spring-boot-configuration.md @@ -1 +1,2 @@ ### Конфигурация Spring Boot? + diff --git a/pom.xml b/pom.xml index 986cbdc..16e4231 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ adapter-flow-lib - 0.0.11 + 0.1.0 jar adapter-flow-lib diff --git a/src/main/java/dev/vality/adapter/flow/lib/constant/HttpMethod.java b/src/main/java/dev/vality/adapter/flow/lib/constant/HttpMethod.java new file mode 100644 index 0000000..1631cb0 --- /dev/null +++ b/src/main/java/dev/vality/adapter/flow/lib/constant/HttpMethod.java @@ -0,0 +1,7 @@ +package dev.vality.adapter.flow.lib.constant; + +public enum HttpMethod { + + GET, POST; + +} diff --git a/src/main/java/dev/vality/adapter/flow/lib/converter/entry/CtxToEntryModelConverter.java b/src/main/java/dev/vality/adapter/flow/lib/converter/entry/CtxToEntryModelConverter.java index 6e4a2b1..149a7d6 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/converter/entry/CtxToEntryModelConverter.java +++ b/src/main/java/dev/vality/adapter/flow/lib/converter/entry/CtxToEntryModelConverter.java @@ -66,8 +66,11 @@ public class CtxToEntryModelConverter implements Converter exitStateModel.getLastOperationStatus() == Status.NEED_REDIRECT ? intentResultFactory.createSuspendIntentWithCallbackAfterTimeout(exitStateModel) diff --git a/src/main/java/dev/vality/adapter/flow/lib/model/BaseRequestModel.java b/src/main/java/dev/vality/adapter/flow/lib/model/BaseRequestModel.java index 1384857..50c559f 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/model/BaseRequestModel.java +++ b/src/main/java/dev/vality/adapter/flow/lib/model/BaseRequestModel.java @@ -17,7 +17,7 @@ import java.util.Map; public class BaseRequestModel { /** - * Uniq Long identifier for payment. + * Uniq Long identifier for payment. */ private Long paymentId; /** @@ -29,12 +29,12 @@ public class BaseRequestModel { */ private Long amount; /** - * Currency in symbolic formats (example: "USD"). + * Code and symbolic code of currency. */ - private String currency; + private Currency currency; /** * Timestamp RFC 3339. - * + *

* The string must contain the date and time in UTC in the following format: * `2016-03-22T06:12:27Z` */ diff --git a/src/main/java/dev/vality/adapter/flow/lib/model/Currency.java b/src/main/java/dev/vality/adapter/flow/lib/model/Currency.java new file mode 100644 index 0000000..e52511e --- /dev/null +++ b/src/main/java/dev/vality/adapter/flow/lib/model/Currency.java @@ -0,0 +1,23 @@ +package dev.vality.adapter.flow.lib.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class Currency { + + /** + * Currency in symbolic formats (example: "USD"). + */ + private String symbolicCode; + /** + * Currency in symbolic formats (example: "USD"). + */ + private Short numericCode; + +} diff --git a/src/main/java/dev/vality/adapter/flow/lib/model/ThreeDsData.java b/src/main/java/dev/vality/adapter/flow/lib/model/ThreeDsData.java index 17817fb..3a273dc 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/model/ThreeDsData.java +++ b/src/main/java/dev/vality/adapter/flow/lib/model/ThreeDsData.java @@ -1,5 +1,6 @@ package dev.vality.adapter.flow.lib.model; +import dev.vality.adapter.flow.lib.constant.HttpMethod; import dev.vality.adapter.flow.lib.constant.ThreeDsType; import lombok.AllArgsConstructor; import lombok.Data; @@ -14,6 +15,10 @@ import java.util.Map; @AllArgsConstructor public class ThreeDsData { + /** + * Http method type. + */ + private HttpMethod httpMethod = HttpMethod.GET; /** * Use type to select desired 3ds flow. */ diff --git a/src/main/java/dev/vality/adapter/flow/lib/service/IntentResultFactory.java b/src/main/java/dev/vality/adapter/flow/lib/service/IntentResultFactory.java index 8dcd9d3..1655bef 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/service/IntentResultFactory.java +++ b/src/main/java/dev/vality/adapter/flow/lib/service/IntentResultFactory.java @@ -1,5 +1,6 @@ package dev.vality.adapter.flow.lib.service; +import dev.vality.adapter.flow.lib.constant.HttpMethod; import dev.vality.adapter.flow.lib.constant.RedirectFields; import dev.vality.adapter.flow.lib.model.EntryStateModel; import dev.vality.adapter.flow.lib.model.ExitStateModel; @@ -13,6 +14,7 @@ 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 dev.vality.error.mapping.ErrorMapping; import lombok.RequiredArgsConstructor; @@ -81,18 +83,22 @@ public class IntentResultFactory { Timer.timeout(TimeoutUtils.toSeconds(timerRedirectTimeoutMin))) .setTimeoutBehaviour(TimeoutBehaviour.callback( ByteBuffer.wrap(parametersSerializer.writeByte(params))) - ).setUserInteraction(createGetUserInteraction(threeDsData.getAcsUrl())) + ).setUserInteraction(createUserInteraction(threeDsData)) ); } + private UserInteraction createUserInteraction(ThreeDsData threeDsData) { + if (threeDsData.getHttpMethod() == HttpMethod.GET) { + return createGetUserInteraction(threeDsData.getAcsUrl()); + } else { + return createPostUserInteraction(threeDsData.getAcsUrl(), threeDsData.getParameters()); + } + } + public Intent createFinishIntentSuccess() { return Intent.finish(new FinishIntent(FinishStatus.success(new Success()))); } - public Intent createSleepIntentForReinvocation() { - return Intent.sleep(new SleepIntent(Timer.timeout(0))); - } - public Intent createSleepIntentWithExponentialPolling(ExitStateModel exitStateModel) { EntryStateModel entryStateModel = exitStateModel.getEntryStateModel(); PollingInfo pollingInfo = pollingInfoService.initPollingInfo(entryStateModel);