Add changedCost field mapping (#76)

This commit is contained in:
Egor Cherniak 2024-01-29 11:21:16 +03:00 committed by GitHub
parent 8beec311ad
commit f5a59d2032
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 34 additions and 12 deletions

View File

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

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -32,6 +32,7 @@ public class SuccessFinishProcessor
exitStateModel.setLastOperationStatus(response.getStatus());
exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo());
exitStateModel.setCustomContext(response.getCustomContext());
exitStateModel.setChangedCost(response.getChangedCost());
Map<String, String> saveData = response.getSaveData();
if (entryStateModel.getBaseRequestModel().getRecurrentPaymentData() != null
&& entryStateModel.getBaseRequestModel().getRecurrentPaymentData().isMakeRecurrent()) {

View File

@ -11,7 +11,7 @@ public interface IntentResultFactory {
Intent createSuspendIntentWithCallbackAfterTimeout(ExitStateModel exitStateModel);
Intent createFinishIntentSuccess();
Intent createFinishIntentSuccess(ExitStateModel exitStateModel);
Intent createSleepIntentWithExponentialPolling(ExitStateModel exitStateModel);

View File

@ -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())));
}

View File

@ -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())));
}

View File

@ -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())));
}