Add additional info + custom context (#68)

This commit is contained in:
Egor Cherniak 2023-06-05 11:19:46 +03:00 committed by GitHub
parent 4c10c52e06
commit 23c1665f0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 35 additions and 1 deletions

View File

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

View File

@ -12,6 +12,7 @@ public class ExitStateModelToTemporaryContextConverter implements Converter<Exit
.providerTrxId(source.getProviderTrxId()) .providerTrxId(source.getProviderTrxId())
.nextStep(source.getNextStep()) .nextStep(source.getNextStep())
.pollingInfo(source.getPollingInfo()) .pollingInfo(source.getPollingInfo())
.customContext(source.getCustomContext())
.build(); .build();
} }

View File

@ -17,6 +17,7 @@ import dev.vality.adapter.flow.lib.utils.TargetStatusResolver;
import dev.vality.cds.storage.Auth3DS; import dev.vality.cds.storage.Auth3DS;
import dev.vality.cds.storage.CardData; import dev.vality.cds.storage.CardData;
import dev.vality.cds.storage.SessionData; import dev.vality.cds.storage.SessionData;
import dev.vality.damsel.domain.AdditionalTransactionInfo;
import dev.vality.damsel.domain.BankCard; import dev.vality.damsel.domain.BankCard;
import dev.vality.damsel.domain.InvoiceDetails; import dev.vality.damsel.domain.InvoiceDetails;
import dev.vality.damsel.domain.TransactionInfo; import dev.vality.damsel.domain.TransactionInfo;
@ -88,6 +89,7 @@ public class CtxToEntryModelConverter implements Converter<PaymentContext, Entry
.adapterConfigurations(adapterConfigurations) .adapterConfigurations(adapterConfigurations)
.providerTrxId(trx != null ? trx.getId() : temporaryContext.getProviderTrxId()) .providerTrxId(trx != null ? trx.getId() : temporaryContext.getProviderTrxId())
.savedData(trx != null ? trx.getExtra() : new HashMap<>()) .savedData(trx != null ? trx.getExtra() : new HashMap<>())
.additionalTrxInfo(getAdditionalTrxInfo(context))
.successRedirectUrl(getSuccessRedirectUrl(payment, adapterConfigurations)) .successRedirectUrl(getSuccessRedirectUrl(payment, adapterConfigurations))
.failedRedirectUrl(getFailureRedirectUrl(payment, adapterConfigurations)) .failedRedirectUrl(getFailureRedirectUrl(payment, adapterConfigurations))
.threeDsDataFromMpiCallback(temporaryContext.getThreeDsData()) .threeDsDataFromMpiCallback(temporaryContext.getThreeDsData())
@ -186,5 +188,17 @@ public class CtxToEntryModelConverter implements Converter<PaymentContext, Entry
return cardDataService.getCardDataProxyModelFromCds(context); return cardDataService.getCardDataProxyModelFromCds(context);
} }
private AdditionalTrxInfo getAdditionalTrxInfo(PaymentContext context) {
TransactionInfo trx = context.getPaymentInfo().getPayment().getTrx();
if (trx == null || trx.getAdditionalInfo() == null) {
return null;
}
AdditionalTransactionInfo additionalTransactionInfo = trx.getAdditionalInfo();
return AdditionalTrxInfo.builder()
.approvalCode(additionalTransactionInfo.getApprovalCode())
.rrn(additionalTransactionInfo.getRrn())
.build();
}
} }

View File

@ -16,6 +16,7 @@ public class DoNothingHandler implements CommonHandler<ExitStateModel, EntryStat
exitStateModel.setProviderTrxId(entryStateModel.getBaseRequestModel().getProviderTrxId()); exitStateModel.setProviderTrxId(entryStateModel.getBaseRequestModel().getProviderTrxId());
exitStateModel.setNextStep(Step.DO_NOTHING); exitStateModel.setNextStep(Step.DO_NOTHING);
exitStateModel.setTrxExtra(entryStateModel.getBaseRequestModel().getSavedData()); exitStateModel.setTrxExtra(entryStateModel.getBaseRequestModel().getSavedData());
exitStateModel.setAdditionalTrxInfo(entryStateModel.getBaseRequestModel().getAdditionalTrxInfo());
if (entryStateModel.getBaseRequestModel().getRecurrentPaymentData().isMakeRecurrent()) { if (entryStateModel.getBaseRequestModel().getRecurrentPaymentData().isMakeRecurrent()) {
exitStateModel.setRecToken(entryStateModel.getBaseRequestModel().getRecurrentPaymentData().getRecToken()); exitStateModel.setRecToken(entryStateModel.getBaseRequestModel().getRecurrentPaymentData().getRecToken());
} }

View File

@ -86,10 +86,18 @@ public class BaseRequestModel {
* Data that you send to save on previous steps. * Data that you send to save on previous steps.
*/ */
private Map<String, String> savedData; private Map<String, String> savedData;
/**
* Additional trx info from previous steps.
*/
private AdditionalTrxInfo additionalTrxInfo;
/** /**
* Data that comes in a callback from mpi after the 3ds step. * Data that comes in a callback from mpi after the 3ds step.
* Parameter names can be unique to your implementation, only you can know. * Parameter names can be unique to your implementation, only you can know.
*/ */
private Map<String, String> threeDsDataFromMpiCallback; private Map<String, String> threeDsDataFromMpiCallback;
/**
* Custom data for more flexibility
*/
private byte[] customContext;
} }

View File

@ -42,5 +42,9 @@ public class BaseResponseModel {
* Data for support about transactions. * Data for support about transactions.
*/ */
private AdditionalTrxInfo additionalTrxInfo; private AdditionalTrxInfo additionalTrxInfo;
/**
* Custom data for more flexibility
*/
private byte[] customContext;
} }

View File

@ -29,6 +29,7 @@ public class ExitStateModel {
private AdditionalTrxInfo additionalTrxInfo; private AdditionalTrxInfo additionalTrxInfo;
private String recToken; private String recToken;
private byte[] customContext;
} }

View File

@ -18,5 +18,6 @@ public class TemporaryContext {
private String providerTrxId; private String providerTrxId;
private PollingInfo pollingInfo; private PollingInfo pollingInfo;
private Map<String, String> threeDsData; private Map<String, String> threeDsData;
private byte[] customContext;
} }

View File

@ -21,6 +21,7 @@ public class ErrorProcessor implements Processor<ExitStateModel, BaseResponseMod
exitStateModel.setErrorCode(String.valueOf(response.getErrorCode())); exitStateModel.setErrorCode(String.valueOf(response.getErrorCode()));
exitStateModel.setErrorMessage(response.getErrorMessage()); exitStateModel.setErrorMessage(response.getErrorMessage());
exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo()); exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo());
exitStateModel.setCustomContext(response.getCustomContext());
exitStateModel.setProviderTrxId( exitStateModel.setProviderTrxId(
StringUtils.hasText(response.getProviderTrxId()) StringUtils.hasText(response.getProviderTrxId())
? response.getProviderTrxId() ? response.getProviderTrxId()

View File

@ -27,6 +27,7 @@ public class RedirectProcessor implements Processor<ExitStateModel, BaseResponse
exitStateModel.setProviderTrxId(response.getProviderTrxId()); exitStateModel.setProviderTrxId(response.getProviderTrxId());
exitStateModel.setTrxExtra(response.getSaveData()); exitStateModel.setTrxExtra(response.getSaveData());
exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo()); exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo());
exitStateModel.setCustomContext(response.getCustomContext());
log.debug("Finish redirect process response: {} entryStateModel: {}", response, entryStateModel); log.debug("Finish redirect process response: {} entryStateModel: {}", response, entryStateModel);
return exitStateModel; return exitStateModel;
} }

View File

@ -28,6 +28,7 @@ public class RetryProcessor implements Processor<ExitStateModel, BaseResponseMod
: entryStateModel.getBaseRequestModel().getProviderTrxId()); : entryStateModel.getBaseRequestModel().getProviderTrxId());
exitStateModel.setTrxExtra(response.getSaveData()); exitStateModel.setTrxExtra(response.getSaveData());
exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo()); exitStateModel.setAdditionalTrxInfo(response.getAdditionalTrxInfo());
exitStateModel.setCustomContext(response.getCustomContext());
log.debug("Finish redirect process response: {} entryStateModel: {}", response, entryStateModel); log.debug("Finish redirect process response: {} entryStateModel: {}", response, entryStateModel);
return exitStateModel; return exitStateModel;
} }

View File

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