Search in sources :

Example 1 with MiraklDownloadShopsDocumentsRequest

use of com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest in project mirakl-hyperwallet-connector by paypal.

the class AbstractMiraklSelectedDocumentsStrategyTest method execute_shouldReturnOnlyFilesDefinedOnGetMiraklFieldNames.

@Test
void execute_shouldReturnOnlyFilesDefinedOnGetMiraklFieldNames() {
    final MiraklShopDocument miraklShopDocumentIdentityCardFront = new MiraklShopDocument();
    miraklShopDocumentIdentityCardFront.setId("proofOfIdentityFront");
    miraklShopDocumentIdentityCardFront.setTypeCode("field1");
    final MiraklShopDocument miraklShopDocumentIdentityCardBack = new MiraklShopDocument();
    miraklShopDocumentIdentityCardBack.setId("proofOfIdentityBack");
    miraklShopDocumentIdentityCardBack.setTypeCode("field2");
    final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel = KYCDocumentSellerInfoModel.builder().clientUserId(MIRAKL_SHOP_ID).proofOfIdentity(List.of(new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(KYCConstants.HYPERWALLET_KYC_IND_PROOF_OF_IDENTITY_FIELD, KYCProofOfIdentityEnum.GOVERNMENT_ID.name()))).miraklShopDocuments(List.of(miraklShopDocumentIdentityCardFront, miraklShopDocumentIdentityCardBack)).build();
    final MiraklDownloadShopsDocumentsRequest downloadShopsDocumentFrontRequest = new MiraklDownloadShopsDocumentsRequest();
    downloadShopsDocumentFrontRequest.setDocumentIds(List.of("proofOfIdentityFront"));
    final MiraklDownloadShopsDocumentsRequest downloadShopsDocumentBackRequest = new MiraklDownloadShopsDocumentsRequest();
    downloadShopsDocumentBackRequest.setDocumentIds(List.of("proofOfIdentityBack"));
    when(miraklApiClientMock.downloadShopsDocuments(downloadShopsDocumentFrontRequest)).thenReturn(documentIdentityCardFrontFileWrapperMock);
    when(documentIdentityCardFrontFileWrapperMock.getFile()).thenReturn(fileFrontIdentityCardMock);
    when(miraklApiClientMock.downloadShopsDocuments(downloadShopsDocumentBackRequest)).thenReturn(documentIdentityCardBackFileWrapperMock);
    when(documentIdentityCardBackFileWrapperMock.getFile()).thenReturn(fileBackIdentityCardMock);
    final List<KYCDocumentModel> result = testObj.execute(kycDocumentSellerInfoModel);
    verify(miraklApiClientMock).downloadShopsDocuments(downloadShopsDocumentFrontRequest);
    verify(miraklApiClientMock).downloadShopsDocuments(downloadShopsDocumentBackRequest);
    final KYCDocumentModel kycFront = KYCDocumentModel.builder().documentFieldName("field1").file(fileFrontIdentityCardMock).build();
    final KYCDocumentModel kycBack = KYCDocumentModel.builder().documentFieldName("field2").file(fileBackIdentityCardMock).build();
    assertThat(result).containsExactlyInAnyOrder(kycFront, kycBack);
}
Also used : MiraklDownloadShopsDocumentsRequest(com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest) MiraklShopDocument(com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument) Test(org.junit.jupiter.api.Test)

Example 2 with MiraklDownloadShopsDocumentsRequest

use of com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest in project mirakl-hyperwallet-connector by paypal.

the class AbstractMiraklSelectedDocumentsStrategy method execute.

@Override
public List<KYCDocumentModel> execute(final KYCDocumentInfoModel source) {
    final List<String> miraklFields = getMiraklFieldNames(source);
    final Map<String, String> fieldNameAnDocumentIdList = getDocumentIds(source.getMiraklShopDocuments(), miraklFields);
    final List<Pair<String, MiraklDownloadShopsDocumentsRequest>> miraklDownloadShopRequests = fieldNameAnDocumentIdList.entrySet().stream().map(fieldNameAndDocumentIdPair -> {
        final MiraklDownloadShopsDocumentsRequest miraklDownloadDocumentRequest = new MiraklDownloadShopsDocumentsRequest();
        miraklDownloadDocumentRequest.setDocumentIds(List.of(fieldNameAndDocumentIdPair.getKey()));
        return Pair.of(fieldNameAndDocumentIdPair.getValue(), miraklDownloadDocumentRequest);
    }).collect(Collectors.toList());
    // @formatter:off
    return miraklDownloadShopRequests.stream().map(this::downloadDocument).filter(Objects::nonNull).collect(Collectors.toList());
// @formatter:on
}
Also used : MiraklDownloadShopsDocumentsRequest(com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Strategy(com.paypal.infrastructure.strategy.Strategy) Objects(java.util.Objects) KYCDocumentModel(com.paypal.kyc.model.KYCDocumentModel) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) MiraklException(com.mirakl.client.core.exception.MiraklException) Map(java.util.Map) FileWrapper(com.mirakl.client.mmp.domain.common.FileWrapper) MiraklShopDocument(com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument) MiraklMarketplacePlatformOperatorApiClient(com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient) KYCDocumentInfoModel(com.paypal.kyc.model.KYCDocumentInfoModel) MiraklDownloadShopsDocumentsRequest(com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with MiraklDownloadShopsDocumentsRequest

use of com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest in project mirakl-hyperwallet-connector by paypal.

the class AbstractMiraklSelectedDocumentsStrategy method downloadDocument.

private KYCDocumentModel downloadDocument(final Pair<String, MiraklDownloadShopsDocumentsRequest> fieldNameAndDocumentIdPair) {
    final MiraklDownloadShopsDocumentsRequest miraklDownloadShopsDocumentsRequest = fieldNameAndDocumentIdPair.getValue();
    final String fieldName = fieldNameAndDocumentIdPair.getKey();
    final String documentId = miraklDownloadShopsDocumentsRequest.getDocumentIds().stream().findAny().orElse(null);
    try {
        log.info("Trying to download file with id [{}]", documentId);
        final FileWrapper fileWrapper = miraklApiClient.downloadShopsDocuments(miraklDownloadShopsDocumentsRequest);
        log.info("Document with id [{}] downloaded", documentId);
        return KYCDocumentModel.builder().file(fileWrapper.getFile()).documentFieldName(fieldName).build();
    } catch (MiraklException e) {
        log.error("Something went wrong trying to download document with id [{}]", documentId);
        log.error(e.getMessage(), e);
    }
    return null;
}
Also used : MiraklException(com.mirakl.client.core.exception.MiraklException) MiraklDownloadShopsDocumentsRequest(com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest) FileWrapper(com.mirakl.client.mmp.domain.common.FileWrapper)

Aggregations

MiraklDownloadShopsDocumentsRequest (com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest)3 MiraklException (com.mirakl.client.core.exception.MiraklException)2 FileWrapper (com.mirakl.client.mmp.domain.common.FileWrapper)2 MiraklShopDocument (com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument)2 MiraklMarketplacePlatformOperatorApiClient (com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient)1 Strategy (com.paypal.infrastructure.strategy.Strategy)1 KYCDocumentInfoModel (com.paypal.kyc.model.KYCDocumentInfoModel)1 KYCDocumentModel (com.paypal.kyc.model.KYCDocumentModel)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Test (org.junit.jupiter.api.Test)1