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);
}
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
}
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;
}
Aggregations