use of com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument in project mirakl-hyperwallet-connector by paypal.
the class AbstractKYCUserStatusNotificationStrategy method deleteInvalidDocuments.
protected void deleteInvalidDocuments(final KYCUserStatusNotificationBodyModel kycUserNotification) {
final String clientUserId = kycUserNotification.getClientUserId();
final KYCDocumentInfoModel kycDocumentInfoModel = miraklSellerDocumentsExtractService.extractKYCSellerDocuments(clientUserId);
final Map<String, LocalDateTime> documentsToBeDeleted = kycUserNotification.getDocuments().stream().filter(kycDocumentNotificationModel -> KYCDocumentStatusEnum.INVALID.equals(kycDocumentNotificationModel.getDocumentStatus())).map(kycDocumentNotificationModel -> Pair.of(kycDocumentNotificationModelListConverter.convert(kycDocumentNotificationModel), kycDocumentNotificationModel.getCreatedOn())).map(this::getMapDocumentUploadTime).flatMap(map -> map.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (MapUtils.isNotEmpty(documentsToBeDeleted)) {
final List<MiraklShopDocument> miraklDocumentsToBeDeleted = kycDocumentInfoModel.getMiraklShopDocuments().stream().filter(miraklShopDocument -> documentsToBeDeleted.containsKey(miraklShopDocument.getTypeCode())).filter(Predicate.not(miraklShopDocument -> isANewMiraklDocument(documentsToBeDeleted, miraklShopDocument))).collect(Collectors.toList());
final String documentTypeCodesToBeDeleted = miraklDocumentsToBeDeleted.stream().map(MiraklShopDocument::getTypeCode).collect(Collectors.joining(COMMA));
if (!StringUtils.isEmpty(documentTypeCodesToBeDeleted)) {
log.info("Deleting documents [{}] for shop [{}]", documentTypeCodesToBeDeleted, clientUserId);
miraklSellerDocumentsExtractService.deleteDocuments(miraklDocumentsToBeDeleted);
log.info("Documents deleted");
}
}
}
use of com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument in project mirakl-hyperwallet-connector by paypal.
the class MiraklSellerDocumentDownloadExtractServiceImplTest method getDocumentsSelectedBySeller_shouldPopulateKYCInfoModelWithDocumentInformationAndReturnDocumentsReturnedByStrategies.
@Test
void getDocumentsSelectedBySeller_shouldPopulateKYCInfoModelWithDocumentInformationAndReturnDocumentsReturnedByStrategies() {
final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel = KYCDocumentSellerInfoModel.builder().clientUserId(MIRAKL_SHOP_ID).proofOfIdentity(KYCProofOfIdentityEnum.GOVERNMENT_ID).proofOfAddress(KYCProofOfAddressEnum.BANK_STATEMENT).build();
final KYCDocumentModel kycDocumentModelFront = KYCDocumentModel.builder().documentFieldName(KYCConstants.HwDocuments.PROOF_OF_IDENTITY_FRONT).build();
final KYCDocumentModel kycDocumentModelBack = KYCDocumentModel.builder().documentFieldName(KYCConstants.HwDocuments.PROOF_OF_IDENTITY_BACK).build();
final MiraklShopDocument miraklShopProofOfIdentityDocumentFront = new MiraklShopDocument();
miraklShopProofOfIdentityDocumentFront.setTypeCode("hw-ind-proof-identity-front");
final MiraklShopDocument miraklShopProofOfIdentityDocumentBack = new MiraklShopDocument();
miraklShopProofOfIdentityDocumentBack.setTypeCode("hw-ind-proof-identity-back");
final MiraklShopDocument miraklShopProofOfAddressFront = new MiraklShopDocument();
miraklShopProofOfAddressFront.setTypeCode("hw-ind-proof-address");
final List<MiraklShopDocument> miraklShopDocumentsList = List.of(miraklShopProofOfIdentityDocumentFront, miraklShopProofOfIdentityDocumentBack, miraklShopProofOfAddressFront);
when(miraklMarketplacePlatformOperatorApiClientMock.getShopDocuments(new MiraklGetShopDocumentsRequest(List.of(MIRAKL_SHOP_ID)))).thenReturn(miraklShopDocumentsList);
final KYCDocumentSellerInfoModel kycDocumentSellerInfoModelWithMiraklDocumentsShopInformation = kycDocumentSellerInfoModel.toBuilder().miraklShopDocuments(miraklShopDocumentsList).build();
when(proofOfIdentityStrategyExecutorMock.execute(kycDocumentSellerInfoModelWithMiraklDocumentsShopInformation)).thenReturn(List.of(List.of(kycDocumentModelFront, kycDocumentModelBack)));
final KYCDocumentSellerInfoModel result = testObj.getDocumentsSelectedBySeller(kycDocumentSellerInfoModel);
verify(miraklMarketplacePlatformOperatorApiClientMock).getShopDocuments(new MiraklGetShopDocumentsRequest(List.of(MIRAKL_SHOP_ID)));
verifyNoMoreInteractions(miraklMarketplacePlatformOperatorApiClientMock);
assertThat(result.getDocuments()).containsExactlyInAnyOrder(kycDocumentModelFront, kycDocumentModelBack);
}
use of com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument 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.domain.shop.document.MiraklShopDocument in project mirakl-hyperwallet-connector by paypal.
the class KYCDocumentBusinessStakeHolderInfoModelTest method existsLetterOfAuthorizationDocumentInMirakl_shouldReturnTrueWhenMiraklContainsProofOfAuthorizationAndRequiresLetterOfAuthorizationIsFalse.
@Test
void existsLetterOfAuthorizationDocumentInMirakl_shouldReturnTrueWhenMiraklContainsProofOfAuthorizationAndRequiresLetterOfAuthorizationIsFalse() {
final MiraklShopDocument documentForLetterOfAuthorization = new MiraklShopDocument();
documentForLetterOfAuthorization.setTypeCode(PROOF_OF_AUTHORIZATION);
// @formatter:off
final KYCDocumentBusinessStakeHolderInfoModel kycDocumentBusinessStakeholderInfoModel = KYCDocumentBusinessStakeHolderInfoModel.builder().contact(Boolean.TRUE).miraklShopDocuments(List.of(documentForLetterOfAuthorization)).requiresLetterOfAuthorization(Boolean.FALSE).build();
// @formatter:on
final boolean result = kycDocumentBusinessStakeholderInfoModel.existsLetterOfAuthorizationDocumentInMirakl();
assertThat(result).isFalse();
}
use of com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument in project mirakl-hyperwallet-connector by paypal.
the class MiraklBusinessStakeholderDocumentDownloadExtractServiceImplTest method getBusinessStakeholderDocumentsSelectedBySeller_shouldSendMailNotificationWhenMiraklExceptionIsThrown.
@Test
void getBusinessStakeholderDocumentsSelectedBySeller_shouldSendMailNotificationWhenMiraklExceptionIsThrown() {
// @formatter:off
final KYCDocumentBusinessStakeHolderInfoModel kycDocumentBusinessStakeHolderInfoModel = KYCDocumentBusinessStakeHolderInfoModel.builder().businessStakeholderMiraklNumber(1).clientUserId(MIRAKL_SHOP_ID).proofOfIdentity(KYCProofOfIdentityEnum.GOVERNMENT_ID).build();
// @formatter:on
final MiraklShopDocument miraklShopProofOfIdentityDocumentFront = new MiraklShopDocument();
miraklShopProofOfIdentityDocumentFront.setTypeCode("hw-bsh1-proof-identity-front");
final MiraklShopDocument miraklShopProofOfIdentityDocumentBack = new MiraklShopDocument();
miraklShopProofOfIdentityDocumentBack.setTypeCode("hw-bsh1-proof-identity-back");
final MiraklException miraklException = new MiraklException("Something wrong happened");
doThrow(miraklException).when(miraklMarketplacePlatformOperatorApiClientMock).getShopDocuments(new MiraklGetShopDocumentsRequest(List.of(MIRAKL_SHOP_ID)));
testObj.getBusinessStakeholderDocumentsSelectedBySeller(kycDocumentBusinessStakeHolderInfoModel);
verify(kycMailNotificationUtilMock).sendPlainTextEmail("Issue detected getting business stakeholder documents from Mirakl", String.format("Something went wrong getting documents from Mirakl for shop Id [%s]%n%s", String.join(",", kycDocumentBusinessStakeHolderInfoModel.getClientUserId()), MiraklLoggingErrorsUtil.stringify(miraklException)));
}
Aggregations