Search in sources :

Example 1 with MiraklShopDocument

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");
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Converter(com.paypal.infrastructure.converter.Converter) java.util(java.util) LocalDateTime(java.time.LocalDateTime) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) KYCRejectionReasonService(com.paypal.kyc.service.KYCRejectionReasonService) StringUtils(org.apache.commons.lang3.StringUtils) MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Value(org.springframework.beans.factory.annotation.Value) HMCException(com.paypal.infrastructure.exceptions.HMCException) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop) Pair(org.apache.commons.lang3.tuple.Pair) MiraklException(com.mirakl.client.core.exception.MiraklException) MiraklUpdateShopWithErrors(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShopWithErrors) MiraklMarketplacePlatformOperatorApiClient(com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient) MiraklSellerDocumentsExtractService(com.paypal.kyc.service.documents.files.mirakl.MiraklSellerDocumentsExtractService) MapUtils(org.apache.commons.collections4.MapUtils) MiraklSimpleRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue) KYCDocumentNotificationModel(com.paypal.kyc.model.KYCDocumentNotificationModel) HyperwalletUser(com.hyperwallet.clientsdk.model.HyperwalletUser) Predicate(java.util.function.Predicate) MiraklLoggingErrorsUtil(com.paypal.infrastructure.util.MiraklLoggingErrorsUtil) Collectors(java.util.stream.Collectors) MailNotificationUtil(com.paypal.infrastructure.mail.MailNotificationUtil) Strategy(com.paypal.infrastructure.strategy.Strategy) ZoneId(java.time.ZoneId) MiraklShopKyc(com.mirakl.client.mmp.domain.shop.MiraklShopKyc) MiraklShopKycStatus(com.mirakl.client.mmp.domain.shop.MiraklShopKycStatus) MiraklUpdatedShopReturn(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn) MiraklRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue) Slf4j(lombok.extern.slf4j.Slf4j) HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD(com.paypal.kyc.model.KYCConstants.HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD) KYCDocumentStatusEnum(com.paypal.kyc.model.KYCDocumentStatusEnum) KYCUserStatusNotificationBodyModel(com.paypal.kyc.model.KYCUserStatusNotificationBodyModel) ErrorBean(com.mirakl.client.domain.common.error.ErrorBean) HYPERWALLET_KYC_REQUIRED_PROOF_AUTHORIZATION_BUSINESS_FIELD(com.paypal.kyc.model.KYCConstants.HYPERWALLET_KYC_REQUIRED_PROOF_AUTHORIZATION_BUSINESS_FIELD) MiraklShopDocument(com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument) KYCDocumentInfoModel(com.paypal.kyc.model.KYCDocumentInfoModel) KYCDocumentInfoModel(com.paypal.kyc.model.KYCDocumentInfoModel) MiraklShopDocument(com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument)

Example 2 with MiraklShopDocument

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);
}
Also used : MiraklShopDocument(com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument) MiraklGetShopDocumentsRequest(com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest) Test(org.junit.jupiter.api.Test)

Example 3 with MiraklShopDocument

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);
}
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 4 with MiraklShopDocument

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();
}
Also used : MiraklShopDocument(com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument) Test(org.junit.jupiter.api.Test)

Example 5 with MiraklShopDocument

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)));
}
Also used : MiraklException(com.mirakl.client.core.exception.MiraklException) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) MiraklShopDocument(com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument) MiraklGetShopDocumentsRequest(com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MiraklShopDocument (com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument)12 Test (org.junit.jupiter.api.Test)9 MiraklGetShopDocumentsRequest (com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest)7 MiraklException (com.mirakl.client.core.exception.MiraklException)4 KYCDocumentBusinessStakeHolderInfoModel (com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 KYCDocumentModel (com.paypal.kyc.model.KYCDocumentModel)2 HyperwalletUser (com.hyperwallet.clientsdk.model.HyperwalletUser)1 ErrorBean (com.mirakl.client.domain.common.error.ErrorBean)1 MiraklShopKyc (com.mirakl.client.mmp.domain.shop.MiraklShopKyc)1 MiraklShopKycStatus (com.mirakl.client.mmp.domain.shop.MiraklShopKycStatus)1 MiraklMarketplacePlatformOperatorApiClient (com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient)1 MiraklUpdateShop (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop)1 MiraklUpdateShopWithErrors (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShopWithErrors)1 MiraklUpdatedShopReturn (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn)1 MiraklUpdatedShops (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops)1 MiraklUpdateShopsRequest (com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest)1 MiraklRequestAdditionalFieldValue (com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue)1 MiraklSimpleRequestAdditionalFieldValue (com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue)1 MiraklDownloadShopsDocumentsRequest (com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest)1