From f5a59d2032c7c50d2351bc91d5051ee3bc8439da Mon Sep 17 00:00:00 2001 From: Egor Cherniak Date: Mon, 29 Jan 2024 11:21:16 +0300 Subject: [PATCH] Add changedCost field mapping (#76) --- pom.xml | 2 +- .../SimpleRedirectWithPollingResultIntentResolver.java | 4 ++-- .../adapter/flow/lib/model/BaseResponseModel.java | 6 ++++++ .../vality/adapter/flow/lib/model/ExitStateModel.java | 3 ++- .../flow/lib/processor/SuccessFinishProcessor.java | 1 + .../flow/lib/service/factory/IntentResultFactory.java | 2 +- .../IntentResultForwardThreeDsParamsFactory.java | 9 +++++++-- .../service/factory/IntentResultQrPaymentFactory.java | 10 +++++++--- .../lib/service/factory/SimpleIntentResultFactory.java | 9 +++++++-- 9 files changed, 34 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 0d936b5..6926357 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ adapter-flow-lib - 0.2.3 + 0.2.4 jar adapter-flow-lib diff --git a/src/main/java/dev/vality/adapter/flow/lib/flow/simple/SimpleRedirectWithPollingResultIntentResolver.java b/src/main/java/dev/vality/adapter/flow/lib/flow/simple/SimpleRedirectWithPollingResultIntentResolver.java index add8256..cc8b7a6 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/flow/simple/SimpleRedirectWithPollingResultIntentResolver.java +++ b/src/main/java/dev/vality/adapter/flow/lib/flow/simple/SimpleRedirectWithPollingResultIntentResolver.java @@ -22,7 +22,7 @@ public class SimpleRedirectWithPollingResultIntentResolver implements ResultInte ? intentResultFactory.createSuspendIntentWithCallbackAfterTimeout(exitStateModel) : intentResultFactory.createSleepIntentWithExponentialPolling(exitStateModel); case DO_NOTHING -> createIntentByTargetStatus(exitStateModel); - case REFUND, CANCEL -> intentResultFactory.createFinishIntentSuccess(); + case REFUND, CANCEL -> intentResultFactory.createFinishIntentSuccess(exitStateModel); default -> throw new IllegalStateException("Wrong nextStep: " + nextStep); }; } @@ -30,7 +30,7 @@ public class SimpleRedirectWithPollingResultIntentResolver implements ResultInte private Intent createIntentByTargetStatus(ExitStateModel exitStateModel) { if (exitStateModel.getEntryStateModel().getTargetStatus() == TargetStatus.CANCELLED || exitStateModel.getEntryStateModel().getTargetStatus() == TargetStatus.REFUNDED) { - return intentResultFactory.createFinishIntentSuccess(); + return intentResultFactory.createFinishIntentSuccess(exitStateModel); } return intentResultFactory.createFinishIntentSuccessWithCheckToken(exitStateModel); } diff --git a/src/main/java/dev/vality/adapter/flow/lib/model/BaseResponseModel.java b/src/main/java/dev/vality/adapter/flow/lib/model/BaseResponseModel.java index bcfa48c..bb19615 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/model/BaseResponseModel.java +++ b/src/main/java/dev/vality/adapter/flow/lib/model/BaseResponseModel.java @@ -1,6 +1,7 @@ package dev.vality.adapter.flow.lib.model; import dev.vality.adapter.flow.lib.constant.Status; +import dev.vality.damsel.proxy_provider.Cash; import lombok.Data; import lombok.experimental.SuperBuilder; @@ -50,5 +51,10 @@ public class BaseResponseModel { * Custom data for more flexibility */ private byte[] customContext; + /** + * Cash that was actually received by provider. + * Is used when payer transferred wrong amount of money. + */ + private Cash changedCost; } \ No newline at end of file diff --git a/src/main/java/dev/vality/adapter/flow/lib/model/ExitStateModel.java b/src/main/java/dev/vality/adapter/flow/lib/model/ExitStateModel.java index c277c11..d93d9e5 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/model/ExitStateModel.java +++ b/src/main/java/dev/vality/adapter/flow/lib/model/ExitStateModel.java @@ -2,6 +2,7 @@ package dev.vality.adapter.flow.lib.model; import dev.vality.adapter.flow.lib.constant.Status; import dev.vality.adapter.flow.lib.constant.Step; +import dev.vality.damsel.proxy_provider.Cash; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -31,6 +32,6 @@ public class ExitStateModel { private String recToken; private byte[] customContext; - + private Cash changedCost; } \ No newline at end of file diff --git a/src/main/java/dev/vality/adapter/flow/lib/processor/SuccessFinishProcessor.java b/src/main/java/dev/vality/adapter/flow/lib/processor/SuccessFinishProcessor.java index 8fd3603..d855480 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/processor/SuccessFinishProcessor.java +++ b/src/main/java/dev/vality/adapter/flow/lib/processor/SuccessFinishProcessor.java @@ -32,6 +32,7 @@ public class SuccessFinishProcessor exitStateModel.setLastOperationStatus(response.getStatus()); exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo()); exitStateModel.setCustomContext(response.getCustomContext()); + exitStateModel.setChangedCost(response.getChangedCost()); Map saveData = response.getSaveData(); if (entryStateModel.getBaseRequestModel().getRecurrentPaymentData() != null && entryStateModel.getBaseRequestModel().getRecurrentPaymentData().isMakeRecurrent()) { diff --git a/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultFactory.java b/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultFactory.java index cf1fa3b..3698fc4 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultFactory.java +++ b/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultFactory.java @@ -11,7 +11,7 @@ public interface IntentResultFactory { Intent createSuspendIntentWithCallbackAfterTimeout(ExitStateModel exitStateModel); - Intent createFinishIntentSuccess(); + Intent createFinishIntentSuccess(ExitStateModel exitStateModel); Intent createSleepIntentWithExponentialPolling(ExitStateModel exitStateModel); diff --git a/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultForwardThreeDsParamsFactory.java b/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultForwardThreeDsParamsFactory.java index 5015d05..010204d 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultForwardThreeDsParamsFactory.java +++ b/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultForwardThreeDsParamsFactory.java @@ -18,6 +18,7 @@ import dev.vality.damsel.proxy_provider.*; import dev.vality.damsel.timeout_behaviour.TimeoutBehaviour; import dev.vality.damsel.user_interaction.UserInteraction; import lombok.RequiredArgsConstructor; +import org.springframework.util.ObjectUtils; import java.nio.ByteBuffer; import java.util.Map; @@ -42,7 +43,7 @@ public class IntentResultForwardThreeDsParamsFactory implements IntentResultFact && entryStateModel.getBaseRequestModel().getRecurrentPaymentData().isMakeRecurrent()) { return createFinishIntentSuccessWithToken(exitStateModel.getRecToken()); } - return createFinishIntentSuccess(); + return createFinishIntentSuccess(exitStateModel); } @Override @@ -95,7 +96,11 @@ public class IntentResultForwardThreeDsParamsFactory implements IntentResultFact } @Override - public Intent createFinishIntentSuccess() { + public Intent createFinishIntentSuccess(ExitStateModel exitStateModel) { + var success = new Success(); + if (!ObjectUtils.isEmpty(exitStateModel.getChangedCost())) { + success.setChangedCost(exitStateModel.getChangedCost()); + } return Intent.finish(new FinishIntent(FinishStatus.success(new Success()))); } diff --git a/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultQrPaymentFactory.java b/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultQrPaymentFactory.java index 8972634..3422e40 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultQrPaymentFactory.java +++ b/src/main/java/dev/vality/adapter/flow/lib/service/factory/IntentResultQrPaymentFactory.java @@ -1,7 +1,6 @@ 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.*; import dev.vality.adapter.flow.lib.serde.ParametersSerializer; import dev.vality.adapter.flow.lib.service.ExponentialBackOffPollingService; @@ -16,6 +15,7 @@ import dev.vality.damsel.user_interaction.QrCode; import dev.vality.damsel.user_interaction.QrCodeDisplayRequest; import dev.vality.damsel.user_interaction.UserInteraction; import lombok.RequiredArgsConstructor; +import org.springframework.util.ObjectUtils; import java.nio.ByteBuffer; import java.util.Map; @@ -41,7 +41,7 @@ public class IntentResultQrPaymentFactory implements IntentResultFactory { && entryStateModel.getBaseRequestModel().getRecurrentPaymentData().isMakeRecurrent()) { return createFinishIntentSuccessWithToken(exitStateModel.getRecToken()); } - return createFinishIntentSuccess(); + return createFinishIntentSuccess(exitStateModel); } @Override @@ -96,7 +96,11 @@ public class IntentResultQrPaymentFactory implements IntentResultFactory { } @Override - public Intent createFinishIntentSuccess() { + public Intent createFinishIntentSuccess(ExitStateModel exitStateModel) { + var success = new Success(); + if (!ObjectUtils.isEmpty(exitStateModel.getChangedCost())) { + success.setChangedCost(exitStateModel.getChangedCost()); + } return Intent.finish(new FinishIntent(FinishStatus.success(new Success()))); } diff --git a/src/main/java/dev/vality/adapter/flow/lib/service/factory/SimpleIntentResultFactory.java b/src/main/java/dev/vality/adapter/flow/lib/service/factory/SimpleIntentResultFactory.java index 17c65f4..f6a7b32 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/service/factory/SimpleIntentResultFactory.java +++ b/src/main/java/dev/vality/adapter/flow/lib/service/factory/SimpleIntentResultFactory.java @@ -20,6 +20,7 @@ import dev.vality.damsel.proxy_provider.*; import dev.vality.damsel.timeout_behaviour.TimeoutBehaviour; import dev.vality.damsel.user_interaction.UserInteraction; import lombok.RequiredArgsConstructor; +import org.springframework.util.ObjectUtils; import java.nio.ByteBuffer; import java.util.Map; @@ -45,7 +46,7 @@ public class SimpleIntentResultFactory implements IntentResultFactory { && entryStateModel.getBaseRequestModel().getRecurrentPaymentData().isMakeRecurrent()) { return createFinishIntentSuccessWithToken(exitStateModel.getRecToken()); } - return createFinishIntentSuccess(); + return createFinishIntentSuccess(exitStateModel); } @Override @@ -106,7 +107,11 @@ public class SimpleIntentResultFactory implements IntentResultFactory { } @Override - public Intent createFinishIntentSuccess() { + public Intent createFinishIntentSuccess(ExitStateModel exitStateModel) { + var success = new Success(); + if (!ObjectUtils.isEmpty(exitStateModel.getChangedCost())) { + success.setChangedCost(exitStateModel.getChangedCost()); + } return Intent.finish(new FinishIntent(FinishStatus.success(new Success()))); }