mirror of
https://github.com/valitydev/adapter-bank-spring-boot-starter.git
synced 2024-11-06 01:05:20 +00:00
Refactor
This commit is contained in:
parent
6d0a94d9cf
commit
f9b312f78e
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>adapter-bank-spring-boot-starter</artifactId>
|
||||
<version>0.0.2-SNAPSHOT</version>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
|
@ -1,16 +1,13 @@
|
||||
package com.rbkmoney.adapter.bank.spring.boot.starter.flow;
|
||||
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.AdapterContext;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.EntryStateModel;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.ExitStateModel;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.Step;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DefaultStepResolverImpl implements StepResolver<EntryStateModel, ExitStateModel> {
|
||||
public class DefaultStepResolverImpl implements StepResolver<StateModel, ExitStateModel> {
|
||||
|
||||
@Override
|
||||
public Step resolveEntry(EntryStateModel stateModel) {
|
||||
public Step resolveEntry(StateModel stateModel) {
|
||||
switch (stateModel.getTargetStatus()) {
|
||||
case PROCESSED:
|
||||
return resolveProcessedSteps(stateModel);
|
||||
@ -27,7 +24,7 @@ public class DefaultStepResolverImpl implements StepResolver<EntryStateModel, Ex
|
||||
}
|
||||
}
|
||||
|
||||
private Step resolveProcessedSteps(EntryStateModel stateModel) {
|
||||
private Step resolveProcessedSteps(StateModel stateModel) {
|
||||
if (isNextThreeDs(stateModel)) {
|
||||
return Step.FINISH_THREE_DS;
|
||||
} else if (stateModel.isMakeRecurrent()) {
|
||||
@ -38,7 +35,7 @@ public class DefaultStepResolverImpl implements StepResolver<EntryStateModel, Ex
|
||||
return Step.AUTH;
|
||||
}
|
||||
|
||||
private Step resolveAuthRecurrent(EntryStateModel stateModel) {
|
||||
private Step resolveAuthRecurrent(StateModel stateModel) {
|
||||
AdapterContext adapterContext = stateModel.getAdapterContext();
|
||||
if (adapterContext != null
|
||||
&& (Step.GENERATE_TOKEN_FINISH_THREE_DS.equals(adapterContext.getNextStep())
|
||||
@ -49,7 +46,7 @@ public class DefaultStepResolverImpl implements StepResolver<EntryStateModel, Ex
|
||||
return Step.AUTH_RECURRENT;
|
||||
}
|
||||
|
||||
private static boolean isNextThreeDs(EntryStateModel stateModel) {
|
||||
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()));
|
||||
@ -58,7 +55,7 @@ public class DefaultStepResolverImpl implements StepResolver<EntryStateModel, Ex
|
||||
@Override
|
||||
public Step resolveExit(ExitStateModel stateModel) {
|
||||
EntryStateModel entryStateModel = stateModel.getEntryStateModel();
|
||||
Step step = entryStateModel.getStep();
|
||||
Step step = entryStateModel.getStateModel().getStep();
|
||||
switch (step) {
|
||||
case AUTH_RECURRENT:
|
||||
if (Step.FINISH_THREE_DS.equals(stateModel.getNextStep())) {
|
||||
|
@ -2,9 +2,10 @@ package com.rbkmoney.adapter.bank.spring.boot.starter.flow;
|
||||
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.EntryStateModel;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.ExitStateModel;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.StateModel;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.Step;
|
||||
|
||||
public interface StepResolver<T extends EntryStateModel, R extends ExitStateModel> {
|
||||
public interface StepResolver<T extends StateModel, R extends ExitStateModel> {
|
||||
|
||||
Step resolveEntry(T stateModel);
|
||||
|
||||
|
@ -1,50 +1,14 @@
|
||||
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
|
||||
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.constants.TargetStatus;
|
||||
import com.rbkmoney.damsel.cds.ExpDate;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@ToString(exclude = {"pan", "cvv2", "expDate"})
|
||||
public class EntryStateModel {
|
||||
|
||||
private String pan;
|
||||
private ExpDate expDate;
|
||||
private String cvv2;
|
||||
private Long amount;
|
||||
private Short currency;
|
||||
private String currencyName;
|
||||
private String cardName;
|
||||
private OperationModel operationModel;
|
||||
private StateModel stateModel;
|
||||
private TransactionInfo transactionInfo;
|
||||
|
||||
private String modifiers;
|
||||
private String ip;
|
||||
private String email;
|
||||
private String country;
|
||||
private String city;
|
||||
private String region;
|
||||
private String address;
|
||||
private String phone;
|
||||
private String callbackUrl;
|
||||
|
||||
private String orderId;
|
||||
private String trxId;
|
||||
private String lastOpId;
|
||||
|
||||
private String key;
|
||||
private String refundId;
|
||||
private String descriptions;
|
||||
private String recToken;
|
||||
private TargetStatus targetStatus;
|
||||
private boolean makeRecurrent;
|
||||
private AdapterContext adapterContext;
|
||||
|
||||
private Map<String, String> parameters;
|
||||
|
||||
private Step step;
|
||||
}
|
||||
|
@ -1,4 +1,42 @@
|
||||
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
|
||||
|
||||
import com.rbkmoney.damsel.cds.ExpDate;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class OperationModel {
|
||||
|
||||
@ToString.Exclude
|
||||
private String pan;
|
||||
@ToString.Exclude
|
||||
private ExpDate expDate;
|
||||
@ToString.Exclude
|
||||
private String cvv2;
|
||||
private String cardName;
|
||||
|
||||
private Long amount;
|
||||
private Short currency;
|
||||
private String currencyName;
|
||||
|
||||
private String modifiers;
|
||||
private String ip;
|
||||
private String email;
|
||||
private String country;
|
||||
private String city;
|
||||
private String region;
|
||||
private String address;
|
||||
private String phone;
|
||||
|
||||
private String key;
|
||||
private String refundId;
|
||||
private String descriptions;
|
||||
private String callbackUrl;
|
||||
|
||||
private Map<String, String> parameters;
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,18 @@
|
||||
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
|
||||
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.constants.TargetStatus;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class StateModel {
|
||||
|
||||
private String recToken;
|
||||
private TargetStatus targetStatus;
|
||||
private boolean makeRecurrent;
|
||||
private AdapterContext adapterContext;
|
||||
|
||||
private Step step;
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,16 @@
|
||||
package com.rbkmoney.adapter.bank.spring.boot.starter.model;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class TransactionInfo {
|
||||
|
||||
private String orderId;
|
||||
private String trxId;
|
||||
private Map<String, String> operationHistory;
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.rbkmoney.adapter.bank.spring.boot.starter.flow;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.constants.TargetStatus;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.EntryStateModel;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.ExitStateModel;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.StateModel;
|
||||
import com.rbkmoney.adapter.bank.spring.boot.starter.model.Step;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -13,33 +14,35 @@ public class DefaultStepResolverImplTest {
|
||||
|
||||
@Test
|
||||
public void resolveEntry() {
|
||||
EntryStateModel entryStateModel = EntryStateModel.builder().
|
||||
targetStatus(TargetStatus.CANCELLED)
|
||||
StateModel stateModel = StateModel.builder()
|
||||
.targetStatus(TargetStatus.CANCELLED)
|
||||
.build();
|
||||
Step step = defaultStepResolver.resolveEntry(entryStateModel);
|
||||
Step step = defaultStepResolver.resolveEntry(stateModel);
|
||||
Assert.assertEquals(Step.CANCEL, step);
|
||||
|
||||
entryStateModel.setTargetStatus(TargetStatus.CAPTURED);
|
||||
step = defaultStepResolver.resolveEntry(entryStateModel);
|
||||
stateModel.setTargetStatus(TargetStatus.CAPTURED);
|
||||
step = defaultStepResolver.resolveEntry(stateModel);
|
||||
Assert.assertEquals(Step.CAPTURE, step);
|
||||
|
||||
entryStateModel.setTargetStatus(TargetStatus.PROCESSED);
|
||||
step = defaultStepResolver.resolveEntry(entryStateModel);
|
||||
stateModel.setTargetStatus(TargetStatus.PROCESSED);
|
||||
step = defaultStepResolver.resolveEntry(stateModel);
|
||||
Assert.assertEquals(Step.AUTH, step);
|
||||
|
||||
entryStateModel.setTargetStatus(TargetStatus.AUTH_RECURRENT);
|
||||
step = defaultStepResolver.resolveEntry(entryStateModel);
|
||||
stateModel.setTargetStatus(TargetStatus.AUTH_RECURRENT);
|
||||
step = defaultStepResolver.resolveEntry(stateModel);
|
||||
Assert.assertEquals(Step.AUTH_RECURRENT, step);
|
||||
|
||||
entryStateModel.setTargetStatus(TargetStatus.REFUNDED);
|
||||
step = defaultStepResolver.resolveEntry(entryStateModel);
|
||||
stateModel.setTargetStatus(TargetStatus.REFUNDED);
|
||||
step = defaultStepResolver.resolveEntry(stateModel);
|
||||
Assert.assertEquals(Step.REFUND, step);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveExit() {
|
||||
EntryStateModel entryStateModel = EntryStateModel.builder()
|
||||
.step(Step.AUTH)
|
||||
.stateModel(StateModel.builder()
|
||||
.step(Step.AUTH)
|
||||
.build())
|
||||
.build();
|
||||
ExitStateModel exitStateModel = ExitStateModel.builder()
|
||||
.entryStateModel(entryStateModel)
|
||||
@ -48,7 +51,8 @@ public class DefaultStepResolverImplTest {
|
||||
Step step = defaultStepResolver.resolveExit(exitStateModel);
|
||||
Assert.assertEquals(Step.FINISH_THREE_DS, step);
|
||||
|
||||
entryStateModel.setStep(Step.AUTH_RECURRENT);
|
||||
entryStateModel.setStateModel(StateModel.builder()
|
||||
.step(Step.AUTH_RECURRENT).build());
|
||||
step = defaultStepResolver.resolveExit(exitStateModel);
|
||||
Assert.assertEquals(Step.GENERATE_TOKEN_FINISH_THREE_DS, step);
|
||||
|
||||
@ -56,15 +60,18 @@ public class DefaultStepResolverImplTest {
|
||||
step = defaultStepResolver.resolveExit(exitStateModel);
|
||||
Assert.assertEquals(Step.GENERATE_TOKEN_CAPTURE, step);
|
||||
|
||||
entryStateModel.setStep(Step.GENERATE_TOKEN_FINISH_THREE_DS);
|
||||
entryStateModel.setStateModel(StateModel.builder()
|
||||
.step(Step.GENERATE_TOKEN_FINISH_THREE_DS).build());
|
||||
step = defaultStepResolver.resolveExit(exitStateModel);
|
||||
Assert.assertEquals(Step.GENERATE_TOKEN_CAPTURE, step);
|
||||
|
||||
entryStateModel.setStep(Step.GENERATE_TOKEN_CAPTURE);
|
||||
entryStateModel.setStateModel(StateModel.builder()
|
||||
.step(Step.GENERATE_TOKEN_CAPTURE).build());
|
||||
step = defaultStepResolver.resolveExit(exitStateModel);
|
||||
Assert.assertEquals(Step.GENERATE_TOKEN_REFUND, step);
|
||||
|
||||
entryStateModel.setStep(Step.GENERATE_TOKEN_REFUND);
|
||||
entryStateModel.setStateModel(StateModel.builder()
|
||||
.step(Step.GENERATE_TOKEN_REFUND).build());
|
||||
step = defaultStepResolver.resolveExit(exitStateModel);
|
||||
Assert.assertEquals(Step.GENERATE_TOKEN_FINISH, step);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user