add trxInfo for error flow (#67)

* add trxInfo for error flow

* add trxInfo for error flow
This commit is contained in:
Anatolii Karlov 2023-05-18 20:12:16 +06:00 committed by GitHub
parent 540e49b59e
commit 4c10c52e06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 21 deletions

View File

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

View File

@ -28,23 +28,26 @@ public class ExitModelToProxyResultConverter implements Converter<ExitStateModel
@Override
public PaymentProxyResult convert(ExitStateModel exitStateModel) {
if (StringUtils.hasText(exitStateModel.getErrorCode())) {
return new PaymentProxyResult(intentResultFactory.createFinishIntentFailed(exitStateModel));
return new PaymentProxyResult(intentResultFactory.createFinishIntentFailed(exitStateModel))
.setTrx(StringUtils.hasText(exitStateModel.getProviderTrxId())
? getTransactionInfo(exitStateModel)
: null);
}
Intent intent = resultIntentResolver.initIntentByStep(exitStateModel);
return new PaymentProxyResult(intent)
.setNextState(serializer.writeByte(contextConverter.convert(exitStateModel)))
.setTrx(
new TransactionInfo()
.setId(exitStateModel.getProviderTrxId())
.setExtra(exitStateModel.getTrxExtra() != null
? exitStateModel.getTrxExtra()
: new HashMap<>())
.setAdditionalInfo(AdditionalInfoUtils.initAdditionalTrxInfo(exitStateModel))
);
.setTrx(getTransactionInfo(exitStateModel));
}
private TransactionInfo getTransactionInfo(ExitStateModel exitStateModel) {
return new TransactionInfo()
.setId(exitStateModel.getProviderTrxId())
.setExtra(exitStateModel.getTrxExtra() != null
? exitStateModel.getTrxExtra()
: new HashMap<>())
.setAdditionalInfo(AdditionalInfoUtils.initAdditionalTrxInfo(exitStateModel));
}
}

View File

@ -11,6 +11,7 @@ import dev.vality.damsel.proxy_provider.RecurrentTokenIntent;
import dev.vality.damsel.proxy_provider.RecurrentTokenProxyResult;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;
import java.util.HashMap;
@ -28,23 +29,26 @@ public class ExitModelToRecTokenProxyResultConverter implements Converter<ExitSt
return new RecurrentTokenProxyResult(
recurrentIntentResultFactory.createFinishIntentFailed(
exitStateModel.getErrorCode(),
exitStateModel.getErrorMessage())
);
exitStateModel.getErrorMessage()))
.setTrx(StringUtils.hasText(exitStateModel.getProviderTrxId())
? getTransactionInfo(exitStateModel)
: null);
}
RecurrentTokenIntent intent = recurrentResultIntentResolver.initIntentByStep(exitStateModel);
return new RecurrentTokenProxyResult(intent)
.setNextState(serializer.writeByte(contextConverter.convert(exitStateModel)))
.setTrx(
new TransactionInfo()
.setId(exitStateModel.getProviderTrxId())
.setExtra(exitStateModel.getTrxExtra() != null
? exitStateModel.getTrxExtra()
: new HashMap<>())
.setAdditionalInfo(AdditionalInfoUtils.initAdditionalTrxInfo(exitStateModel))
);
.setTrx(getTransactionInfo(exitStateModel));
}
private TransactionInfo getTransactionInfo(ExitStateModel exitStateModel) {
return new TransactionInfo()
.setId(exitStateModel.getProviderTrxId())
.setExtra(exitStateModel.getTrxExtra() != null
? exitStateModel.getTrxExtra()
: new HashMap<>())
.setAdditionalInfo(AdditionalInfoUtils.initAdditionalTrxInfo(exitStateModel));
}
}

View File

@ -6,6 +6,7 @@ import dev.vality.adapter.flow.lib.model.ExitStateModel;
import dev.vality.adapter.flow.lib.utils.ErrorUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
@Slf4j
@RequiredArgsConstructor
@ -20,6 +21,10 @@ public class ErrorProcessor implements Processor<ExitStateModel, BaseResponseMod
exitStateModel.setErrorCode(String.valueOf(response.getErrorCode()));
exitStateModel.setErrorMessage(response.getErrorMessage());
exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo());
exitStateModel.setProviderTrxId(
StringUtils.hasText(response.getProviderTrxId())
? response.getProviderTrxId()
: entryStateModel.getBaseRequestModel().getProviderTrxId());
log.debug("Finish error process response: {} entryStateModel: {}", response, entryStateModel);
return exitStateModel;
}