mirror of
https://github.com/valitydev/adapter-bank-payout-spring-boot-starter.git
synced 2024-11-06 00:45:21 +00:00
parent
a2e847a14e
commit
74a201ad6d
2
pom.xml
2
pom.xml
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ import java.time.Instant;
|
||||
@AllArgsConstructor
|
||||
public class AdapterState {
|
||||
private Step step;
|
||||
private Instant maxDateTimePolling;
|
||||
private Long maxTimePoolingMillis;
|
||||
private TransactionInfo trxInfo;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user