Some refactoring

This commit is contained in:
Inal Arsanukaev 2019-07-19 17:17:19 +03:00
parent 27b95152e4
commit a8cf70300b
8 changed files with 62 additions and 112 deletions

View File

@ -103,7 +103,7 @@
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>adapter-common-lib</artifactId>
<version>0.0.7-SNAPSHOT</version>
<version>0.0.8</version>
</dependency>
<!-- test -->

View File

@ -3,10 +3,10 @@ package com.rbkmoney.adapter.bank.spring.boot.starter.flow;
import com.rbkmoney.adapter.bank.spring.boot.starter.model.*;
import com.rbkmoney.adapter.common.enums.Step;
public class DefaultStepResolverImpl implements StepResolver<StateModel> {
public class DefaultStepResolverImpl implements StepResolver<GeneralEntryStateModel, GeneralExitStateModel> {
@Override
public Step resolveEntry(StateModel stateModel) {
public Step resolveEntry(GeneralEntryStateModel stateModel) {
switch (stateModel.getTargetStatus()) {
case PROCESSED:
return resolveProcessedSteps(stateModel);
@ -21,7 +21,7 @@ public class DefaultStepResolverImpl implements StepResolver<StateModel> {
}
}
private Step resolveProcessedSteps(StateModel stateModel) {
private Step resolveProcessedSteps(GeneralEntryStateModel stateModel) {
if (isNextThreeDs(stateModel)) {
return Step.FINISH_THREE_DS;
} else if (stateModel.isMakeRecurrent()) {
@ -32,19 +32,19 @@ public class DefaultStepResolverImpl implements StepResolver<StateModel> {
return Step.AUTH;
}
private static boolean isNextThreeDs(StateModel stateModel) {
return stateModel.getAdapterContext() != null && stateModel.getAdapterContext().getNextStep() != null
&& (Step.FINISH_THREE_DS.equals(stateModel.getAdapterContext().getNextStep())
|| Step.GENERATE_TOKEN_FINISH_THREE_DS.equals(stateModel.getAdapterContext().getNextStep()));
private static boolean isNextThreeDs(GeneralEntryStateModel stateModel) {
return stateModel.getAdapterContext() != null && stateModel.getAdapterContext().getStep() != null
&& (Step.FINISH_THREE_DS.equals(stateModel.getAdapterContext().getStep())
|| Step.GENERATE_TOKEN_FINISH_THREE_DS.equals(stateModel.getAdapterContext().getStep()));
}
@Override
public Step resolveExit(StateModel stateModel) {
Step step = stateModel.getStep();
public Step resolveExit(GeneralExitStateModel stateModel) {
Step step = stateModel.getGeneralEntryStateModel().getAdapterContext().getStep();
Step nextStep = stateModel.getAdapterContext().getStep();
switch (step) {
case AUTH_RECURRENT:
if (Step.FINISH_THREE_DS.equals(stateModel.getNextStep())) {
if (Step.FINISH_THREE_DS.equals(nextStep)) {
return Step.GENERATE_TOKEN_FINISH_THREE_DS;
} else {
return Step.GENERATE_TOKEN_CAPTURE;
@ -56,7 +56,7 @@ public class DefaultStepResolverImpl implements StepResolver<StateModel> {
case GENERATE_TOKEN_REFUND:
return Step.GENERATE_TOKEN_FINISH;
default:
return stateModel.getNextStep();
return nextStep;
}
}
}

View File

@ -1,12 +1,13 @@
package com.rbkmoney.adapter.bank.spring.boot.starter.flow;
import com.rbkmoney.adapter.bank.spring.boot.starter.model.StateModel;
import com.rbkmoney.adapter.bank.spring.boot.starter.model.GeneralEntryStateModel;
import com.rbkmoney.adapter.bank.spring.boot.starter.model.GeneralExitStateModel;
import com.rbkmoney.adapter.common.enums.Step;
public interface StepResolver<T extends StateModel> {
public interface StepResolver<N extends GeneralEntryStateModel, X extends GeneralExitStateModel> {
Step resolveEntry(T stateModel);
Step resolveEntry(N entryStateModel);
Step resolveExit(T stateModel);
Step resolveExit(X exitStateModel);
}

View File

@ -1,9 +1,10 @@
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.rbkmoney.adapter.common.enums.TargetStatus;
import com.rbkmoney.adapter.common.model.AdapterContext;
import lombok.*;
import java.util.Map;
@Data
@Builder
@ -11,8 +12,44 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class GeneralEntryStateModel {
private OperationModel operationModel;
private StateModel stateModel;
private TransactionInfo transactionInfo;
@ToString.Exclude
private String pan;
@ToString.Exclude
private Byte expMonth;
@ToString.Exclude
private Short expYear;
@ToString.Exclude
private String cvv2;
@ToString.Exclude
private String cardHolder;
private String orderId;
private Long amount;
private Short currencyCode;
private String currencySymbolCode;
private String createdAt;
private String ip;
private String email;
private String phone;
private Long refundAmount;
private String refundId;
private String invoiceDetails;
private String callbackUrl;
private Map<String, String> options;
private AdapterContext adapterContext;
private TargetStatus targetStatus;
private String recToken;
private boolean makeRecurrent;
private String cryptogram;
private String eci;
private String trxId;
private Map<String, String> trxExtra;
}

View File

@ -1,6 +1,5 @@
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
import com.rbkmoney.adapter.common.enums.Step;
import com.rbkmoney.adapter.common.model.AdapterContext;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -15,7 +14,6 @@ import java.util.Map;
@AllArgsConstructor
public class GeneralExitStateModel {
private Step nextStep;
private String errorCode;
private String errorMessage;
private AdapterContext adapterContext;

View File

@ -1,41 +0,0 @@
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
import lombok.*;
import java.util.Map;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OperationModel {
@ToString.Exclude
private String pan;
@ToString.Exclude
private Byte expMonth;
@ToString.Exclude
private Short expYear;
@ToString.Exclude
private String cvv2;
@ToString.Exclude
private String cardHolder;
private String orderId;
private Long amount;
private Short currencyCode;
private String currencySymbolCode;
private String createdAt;
private String ip;
private String email;
private String phone;
private Long refundAmount;
private String refundId;
private String invoiceDetails;
private String callbackUrl;
private Map<String, String> options;
}

View File

@ -1,26 +0,0 @@
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
import com.rbkmoney.adapter.common.enums.Step;
import com.rbkmoney.adapter.common.enums.TargetStatus;
import com.rbkmoney.adapter.common.model.AdapterContext;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StateModel {
private AdapterContext adapterContext;
private TargetStatus targetStatus;
private String recToken;
private boolean makeRecurrent;
private String cryptogram;
private String eci;
}

View File

@ -1,19 +0,0 @@
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TransactionInfo {
private String trxId;
private Map<String, String> trxExtra;
}