Fix intent service (#8)

* fix state mapping

* exclude pan field
This commit is contained in:
vitaxa 2019-06-20 18:09:56 +03:00 committed by GitHub
parent a2e847a14e
commit 74a201ad6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 10 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.rbkmoney</groupId>
<artifactId>adapter-bank-payout-spring-boot-starter</artifactId>
<version>0.0.6-SNAPSHOT</version>
<version>0.0.7-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Adapter-bank-payout-spring-boot-starter</name>

View File

@ -1,4 +1,19 @@
package com.rbkmoney.adapter.bank.payout.spring.boot.starter.exception;
public class ValidationException extends RuntimeException {
public ValidationException() {
super();
}
public ValidationException(String message) {
super(message);
}
public ValidationException(String message, Throwable cause) {
super(message, cause);
}
public ValidationException(Throwable cause) {
super(cause);
}
}

View File

@ -13,6 +13,6 @@ import java.time.Instant;
@AllArgsConstructor
public class AdapterState {
private Step step;
private Instant maxDateTimePolling;
private Long maxTimePoolingMillis;
private TransactionInfo trxInfo;
}

View File

@ -1,6 +1,7 @@
package com.rbkmoney.adapter.bank.payout.spring.boot.starter.model;
import lombok.Data;
import lombok.ToString;
import java.util.Map;
@ -9,6 +10,7 @@ public class EntryStateModel {
private String withdrawalId;
private Long amount;
private String currencyCode;
@ToString.Exclude
private String pan;
private Map<String, String> options;

View File

@ -4,11 +4,9 @@ import com.rbkmoney.adapter.bank.payout.spring.boot.starter.model.EntryStateMode
import com.rbkmoney.adapter.bank.payout.spring.boot.starter.model.ExitStateModel;
import com.rbkmoney.damsel.withdrawals.provider_adapter.Intent;
import java.time.Instant;
public interface IntentService {
Intent getFailure(ExitStateModel exitStateModel);
Intent getSuccess(ExitStateModel exitStateModel);
Intent getSleep(ExitStateModel exitStateModel);
Instant getMaxDateTimeInstant(EntryStateModel entryStateModel);
Long getMaxDateTimeInstant(EntryStateModel entryStateModel);
}

View File

@ -31,15 +31,21 @@ public class IntentServiceImpl implements IntentService {
}
public Intent getSleep(ExitStateModel exitStateModel) {
if (exitStateModel.getNextState().getMaxDateTimePolling().getEpochSecond() < Instant.now().getEpochSecond()) {
if (exitStateModel.getNextState().getMaxTimePoolingMillis() == null) {
throw new IllegalArgumentException("Need to specify 'maxTimePoolingMillis' before sleep");
}
if (exitStateModel.getNextState().getMaxTimePoolingMillis() < Instant.now().toEpochMilli()) {
final Failure failure = new Failure("Sleep timeout");
failure.setReason("Max time pool limit reached");
return Intent.finish(new FinishIntent(FinishStatus.failure(new Failure())));
}
int timerPollingDelay = OptionsExtractors.extractPollingDelay(exitStateModel.getEntryStateModel().getOptions(), timerProperties.getPollingDelay());
return Intent.sleep(new SleepIntent(new Timer(Timer.timeout(timerPollingDelay))));
}
public Instant getMaxDateTimeInstant(EntryStateModel entryStateModel) {
public Long getMaxDateTimeInstant(EntryStateModel entryStateModel) {
int maxTimePolling = extractMaxTimePolling(entryStateModel.getOptions(), timerProperties.getMaxTimePolling());
return Instant.now().plus(maxTimePolling, ChronoUnit.MINUTES);
return Instant.now().plus(maxTimePolling, ChronoUnit.MINUTES).toEpochMilli();
}
}

View File

@ -27,7 +27,7 @@ public class PayoutAdapterService<T extends EntryStateModel, X extends ExitState
private final WithdrawalToEntryStateConverter<T> withdrawalToEntryStateConverter;
private final ExitStateToProcessResultConverter<X> exitStateToProcessResultConverter;
private final List<CommonHandler<T, X>> handlers;
private final StepResolver resolver;
private final StepResolver<T, X> resolver;
private final WithdrawalValidator validator;
@Override
@ -43,4 +43,4 @@ public class PayoutAdapterService<T extends EntryStateModel, X extends ExitState
exitStateModel.getNextState().setStep(resolver.resolveExit(exitStateModel));
return exitStateToProcessResultConverter.convert(exitStateModel);
}
}
}