PROX-458: change requests, fix failure result, added failure test (#6)

This commit is contained in:
malkoas 2020-10-19 15:11:55 +03:00 committed by GitHub
parent 7d83eed632
commit a9fea613ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 108 additions and 42 deletions

@ -1 +1 @@
Subproject commit e89b885839df8013df804d48ff24dff10c9c451e
Subproject commit f42e059d9ec93826ba4ad23232eed8ce67bd5486

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.rbkmoney</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<version>2.3.4.RELEASE</version>
<relativePath/>
</parent>
@ -26,7 +26,7 @@
<exposed.ports>${server.port}</exposed.ports>
<project.maintainer>Anatoly Cherkasov &lt;a.cherkasov@rbkmoney.com&gt;</project.maintainer>
<dockerfile.Template>GENERATED DOCKER FILE</dockerfile.Template>
<dockerfile.base.service.tag>bc95d0d6dc13c693acd2b274531a7d604b877bf3</dockerfile.base.service.tag>
<dockerfile.base.service.tag>57e26d8ee999d7b0b50248c22afc63e6f926d276</dockerfile.base.service.tag>
<dockerfile.registry>dr2.rbkmoney.com</dockerfile.registry>
<shared.resources.version>0.3.8</shared.resources.version>
<logstash-logback-encoder.version>5.2</logstash-logback-encoder.version>
@ -102,6 +102,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>serializer</artifactId>
<version>${geck.version}</version>
</dependency>
<!--Third party libs-->
<dependency>
<groupId>org.projectlombok</groupId>

View File

@ -10,6 +10,7 @@ import com.rbkmoney.adapter.atol.service.atol.model.Receipt;
import com.rbkmoney.adapter.atol.service.atol.model.Service;
import com.rbkmoney.adapter.atol.service.atol.model.request.CommonRequest;
import com.rbkmoney.adapter.atol.service.atol.model.request.RequestWrapper;
import com.rbkmoney.adapter.atol.utils.DateFormate;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.config.properties.AdapterCashregProperties;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.constant.OptionalField;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.EntryStateModel;
@ -33,10 +34,9 @@ public class EntryStateToCommonRequestConverter implements Converter<EntryStateM
public RequestWrapper<CommonRequest> convert(EntryStateModel entryStateModel) {
CommonRequest commonRequest = new CommonRequest();
commonRequest.setLogin(entryStateModel.getAuth().getLogin());
commonRequest.setPass(entryStateModel.getAuth().getPass());
commonRequest.setExternalId(entryStateModel.getCashRegId());
commonRequest.setTimestamp(DateFormate.getCurrentDate());
commonRequest.setReceipt(
Receipt.builder()
@ -56,7 +56,6 @@ public class EntryStateToCommonRequestConverter implements Converter<EntryStateM
.payments(paymentsTransformer.transform(entryStateModel.getPayments())) //
.items(itemsTransformer.transform(entryStateModel.getItems()))
.total(entryStateModel.getTotal()) //
.vats(vatsTransformer.transform(entryStateModel.getVats())) //
.build());
Service service = Service.builder().callbackUrl(entryStateModel.getCallbackUrl()).build();
@ -68,7 +67,9 @@ public class EntryStateToCommonRequestConverter implements Converter<EntryStateM
entryStateModel.getOptions().get(OptionalField.GROUP.getField()),
entryStateModel.getOptions().get(OptionalField.COMPANY_NAME.getField()),
entryStateModel.getOptions().get(OptionalField.COMPANY_ADDRESS.getField()),
DEFAULT_EMPTY_VALUE_TOKEN_API
DEFAULT_EMPTY_VALUE_TOKEN_API,
entryStateModel.getOptions().get(OptionalField.LOGIN.getField()),
entryStateModel.getOptions().get(OptionalField.PASS.getField())
);
}

View File

@ -36,14 +36,9 @@ public class CtxToEntryModelConverter implements Converter<CashregContext, Entry
Map<String, String> options = context.getOptions();
EntryStateModel.EntryStateModelBuilder builder = EntryStateModel.builder();
builder.options(context.getOptions());
builder.options(options);
builder.cashRegId(context.getCashregId());
builder.auth(Auth.builder()
.login(options.get(OptionalField.LOGIN.getField()))
.pass(options.get(OptionalField.PASS.getField()))
.build());
PaymentInfo paymentInfo = context.getSourceCreation().getPayment();
builder.client(Client.builder()
.email(paymentInfo.getEmail())
@ -64,7 +59,6 @@ public class CtxToEntryModelConverter implements Converter<CashregContext, Entry
List<ItemsLine> itemsLines = paymentInfo.getCart().getLines();
builder.payments(itemsLines.stream().map(this::preparePayments).collect(Collectors.toList()));
builder.vats(itemsLines.stream().map(this::prepareVat).collect(Collectors.toList()));
TargetType targetType = TargetTypeResolver.resolve(context.getSession().getType());
StateModel.StateModelBuilder stateModelBuilder = StateModel.builder()
@ -78,12 +72,6 @@ public class CtxToEntryModelConverter implements Converter<CashregContext, Entry
return builder.build();
}
private Vat prepareVat(ItemsLine itemsLine) {
return Vat.builder()
.sum(prepareAmount(itemsLine.getPrice().getAmount()))
.type(itemsLine.getTax())
.build();
}
private Payments preparePayments(ItemsLine itemsLine) {
BigDecimal fullPriceAmount = prepareAmount(itemsLine.getPrice().getAmount() * itemsLine.getQuantity());
@ -103,7 +91,10 @@ public class CtxToEntryModelConverter implements Converter<CashregContext, Entry
.quantity(new BigDecimal(itemsLine.getQuantity()).setScale(1))
.price(prepareAmount(itemsLine.getPrice().getAmount()))
.sum(sum)
.vat(Vat.builder().type(itemsLine.getTax()).build())
.vat(Vat.builder().type(
com.rbkmoney.adapter.atol.service.atol.constant.Vat.codeTextOf(
itemsLine.getTax()).getCode())
.build())
.paymentMethod(options.get(OptionalField.PAYMENT_METHOD.getField()))
.paymentObject(options.get(OptionalField.PAYMENT_OBJECT.getField()))
.name(itemsLine.getProduct())

View File

@ -48,6 +48,7 @@ public class ExitModelToProxyResultConverter implements Converter<ExitStateModel
exitStateModel.getErrorMessage()
);
intent = CashregAdapterCreators.createFinishIntentFailure(failure);
return new CashregResult().setIntent(intent).setState(serializer.writeByte(adapterState));
}
if (exitStateModel.getInfo() == null) {

View File

@ -25,8 +25,12 @@ public class ErrorProcessor implements Processor<ExitStateModel, EntryStateModel
}
ExitStateModel exitStateModel = new ExitStateModel();
exitStateModel.setAdapterContext(adapterState);
exitStateModel.setEntryStateModel(entryStateModel);
if (ErrorUtils.hasError(response)) {
exitStateModel.setEntryStateModel(entryStateModel);
com.rbkmoney.adapter.atol.service.atol.model.Error error = response.getError();
exitStateModel.setErrorCode(error.getCode().toString());
exitStateModel.setErrorMessage(error.getText());
} else if (adapterState.getMaxDateTimePolling().getEpochSecond() < currentTime.getEpochSecond()) {
log.error("Sleep Timeout for response: {}!", response);
exitStateModel.setErrorCode(com.rbkmoney.adapter.cashreg.spring.boot.starter.constant.Error.SLEEP_TIMEOUT.getCode());

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rbkmoney.adapter.atol.service.atol.constant.Operations;
import com.rbkmoney.adapter.atol.service.atol.model.request.CommonRequest;
import com.rbkmoney.adapter.atol.service.atol.model.request.GetTokenRequest;
import com.rbkmoney.adapter.atol.service.atol.model.request.RequestWrapper;
import com.rbkmoney.adapter.atol.service.atol.model.response.CommonResponse;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.utils.converter.ip.ConverterIp;
@ -28,9 +29,9 @@ public class AtolApi {
String url = converterIp.replaceIpv4ToIpv6(requestWrapper.getUrl() + "getToken");
log.info("Atol getToken URL {}", url);
CommonRequest request = new CommonRequest();
request.setLogin(requestWrapper.getRequest().getLogin());
request.setPass(requestWrapper.getRequest().getPass());
GetTokenRequest request = new GetTokenRequest();
request.setLogin(requestWrapper.getLogin());
request.setPass(requestWrapper.getPassword());
try {
String body = objectMapper.writeValueAsString(request);
HttpEntity httpEntity = new HttpEntity(body, getHttpHeaders());

View File

@ -8,7 +8,7 @@ import lombok.Getter;
*/
@Getter
@AllArgsConstructor
public enum Operations {
public enum Operations {
// чек «Приход»
SELL("sell"),

View File

@ -16,20 +16,6 @@ import lombok.ToString;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CommonRequest {
/**
* логин пользователя для отправки данных.
* Логин для отправки данных можно получить из файла настроек для CMS в личном кабинете пользователя
*/
@JsonProperty("login")
private String login;
/**
* Пароль пользователя для отправки данных
* Пароль для отправки данных можно получить из файла настроек для CMS в личном кабинете пользователя.
*/
@JsonProperty("pass")
private String pass;
/**
* Идентификатор документа внешней системы, уникальный среди всех документов,
* отправляемых в данную группу ККТ. Тип данных строка.

View File

@ -0,0 +1,31 @@
package com.rbkmoney.adapter.atol.service.atol.model.request;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@ToString
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetTokenRequest {
/**
* логин пользователя для отправки данных.
* Логин для отправки данных можно получить из файла настроек для CMS в личном кабинете пользователя
*/
@JsonProperty("login")
private String login;
/**
* Пароль пользователя для отправки данных
* Пароль для отправки данных можно получить из файла настроек для CMS в личном кабинете пользователя.
*/
@JsonProperty("pass")
private String pass;
}

View File

@ -12,4 +12,6 @@ public class RequestWrapper<R> {
private String company;
private String companyAddress;
private String token;
private String login;
private String password;
}

View File

@ -0,0 +1,13 @@
package com.rbkmoney.adapter.atol.utils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class DateFormate {
public static String getCurrentDate() {
LocalDateTime now = LocalDateTime.now();
return now.format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss"));
}
}

View File

@ -4,5 +4,10 @@
"descriptionRegex": "Invalid cardholder",
"mapping": "authorization_failed:operation_blocked",
"state": "payment"
},
{
"codeRegex": "1",
"descriptionRegex": "test",
"mapping": "authorization_failed:operation_blocked"
}
]

View File

@ -25,7 +25,7 @@ public class MockUtils {
response.setPayload(Payload.builder()
.fnNumber("fnNumber")
.fiscalReceiptNumber(1L)
.build());
.build());
response.setUuid("uuid");
return response;
}).when(client).status(any());

View File

@ -3,15 +3,21 @@ package com.rbkmoney.adapter.atol.handler;
import com.rbkmoney.adapter.atol.IntegrationTest;
import com.rbkmoney.adapter.atol.MockUtils;
import com.rbkmoney.adapter.atol.service.atol.AtolClient;
import com.rbkmoney.adapter.atol.service.atol.constant.ErrorType;
import com.rbkmoney.adapter.atol.service.atol.constant.Status;
import com.rbkmoney.adapter.atol.service.atol.model.response.CommonResponse;
import com.rbkmoney.damsel.cashreg.adapter.CashregContext;
import com.rbkmoney.damsel.cashreg.adapter.CashregResult;
import org.apache.thrift.TException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import org.springframework.boot.test.mock.mockito.MockBean;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
public class AtolServerHandlerTest extends IntegrationTest {
@ -25,7 +31,7 @@ public class AtolServerHandlerTest extends IntegrationTest {
}
@Test
public void testMe() throws TException {
public void atolServerHandlerTest() throws TException {
CashregContext context = makeCashRegContext();
CashregResult result = handler.register(context);
assertTrue(result.getIntent().isSetSleep());
@ -36,4 +42,24 @@ public class AtolServerHandlerTest extends IntegrationTest {
assertTrue(result.getIntent().isSetFinish());
}
@Test
public void atolServerHandlerFailureTest() throws TException {
doAnswer((Answer<CommonResponse>) invocation -> {
CommonResponse response = new CommonResponse();
response.setStatus(Status.FAIL.getValue());
com.rbkmoney.adapter.atol.service.atol.model.Error error = new com.rbkmoney.adapter.atol.service.atol.model.Error();
error.setCode(1);
error.setText("test");
error.setErrorId("errorId");
error.setType(ErrorType.SYSTEM.getValue());
response.setError(error);
return response;
}).when(client).debit(any());
CashregContext context = makeCashRegContext();
CashregResult result = handler.register(context);
assertTrue(result.getIntent().getFinish().getStatus().isSetFailure());
}
}