Search in sources :

Example 1 with MiraklShop

use of com.mirakl.client.mmp.domain.shop.MiraklShop in project mirakl-hyperwallet-connector by paypal.

the class MiraklBusinessStakeholderDocumentsExtractServiceImpl method extractBusinessStakeholderDocuments.

/**
 * {@inheritDoc}
 */
@Override
public List<KYCDocumentBusinessStakeHolderInfoModel> extractBusinessStakeholderDocuments(final Date delta) {
    final MiraklGetShopsRequest miraklGetShopsRequest = miraklGetShopsRequestConverter.convert(delta);
    log.info("Retrieving modified shops since [{}]", delta);
    final MiraklShops shops = miraklOperatorClient.getShops(miraklGetShopsRequest);
    // @formatter:off
    log.info("Retrieved modified shops since [{}]: [{}]", delta, Stream.ofNullable(shops.getShops()).flatMap(Collection::stream).map(MiraklShop::getId).collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
    // @formatter:on
    // @formatter:off
    final List<KYCDocumentBusinessStakeHolderInfoModel> kycBusinessStakeHolderInfoModelList = Stream.ofNullable(shops.getShops()).flatMap(Collection::stream).map(this::populateBusinessStakeholderForMiraklShop).flatMap(Collection::stream).collect(Collectors.toList());
    // @formatter:on
    // @formatter:off
    final Map<String, List<KYCDocumentBusinessStakeHolderInfoModel>> shopsWithBusinessStakeholderVerificationRequired = kycBusinessStakeHolderInfoModelList.stream().filter(kycDocStk -> kycDocStk.isRequiresKYC() || kycDocStk.isRequiresLetterOfAuthorization()).collect(Collectors.groupingBy(KYCDocumentInfoModel::getClientUserId));
    if (!CollectionUtils.isEmpty(shopsWithBusinessStakeholderVerificationRequired)) {
        // @formatter:off
        log.info("Shops with KYC business stakeholder verification required: [{}]", String.join(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR, shopsWithBusinessStakeholderVerificationRequired.keySet()));
    // @formatter:on
    }
    skipShopsWithNonBusinessStakeholderSelectedDocuments(shopsWithBusinessStakeholderVerificationRequired);
    final List<KYCDocumentBusinessStakeHolderInfoModel> shopsWithBusinessSelectedVerificationDocuments = shopsWithBusinessStakeholderVerificationRequired.values().stream().filter(bstkList -> bstkList.stream().allMatch(KYCDocumentBusinessStakeHolderInfoModel::hasSelectedDocumentsControlFieldsInBusinessStakeholder)).flatMap(Collection::stream).collect(Collectors.toList());
    // @formatter:off
    return shopsWithBusinessSelectedVerificationDocuments.stream().filter(kycBusinessStakeHolderInfoModel -> !ObjectUtils.isEmpty(kycBusinessStakeHolderInfoModel.getUserToken())).map(miraklBusinessStakeholderDocumentDownloadExtractService::getBusinessStakeholderDocumentsSelectedBySeller).collect(Collectors.toList());
// @formatter:on
}
Also used : IntStream(java.util.stream.IntStream) Converter(com.paypal.infrastructure.converter.Converter) java.util(java.util) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) KYCBusinessStakeHolderConverter(com.paypal.kyc.converter.KYCBusinessStakeHolderConverter) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop) MiraklException(com.mirakl.client.core.exception.MiraklException) Service(org.springframework.stereotype.Service) MiraklMarketplacePlatformOperatorApiClient(com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient) KYCConstants(com.paypal.kyc.model.KYCConstants) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Predicate(java.util.function.Predicate) ObjectUtils(org.springframework.util.ObjectUtils) MiraklShops(com.mirakl.client.mmp.domain.shop.MiraklShops) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) AbstractMiraklShop(com.mirakl.client.mmp.domain.shop.AbstractMiraklShop) MiraklLoggingErrorsUtil(com.paypal.infrastructure.util.MiraklLoggingErrorsUtil) Collectors(java.util.stream.Collectors) MailNotificationUtil(com.paypal.infrastructure.mail.MailNotificationUtil) MiraklAdditionalFieldValue(com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue) MiraklUpdatedShopReturn(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn) MiraklRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue) MiraklBusinessStakeholderDocumentsExtractService(com.paypal.kyc.service.documents.files.mirakl.MiraklBusinessStakeholderDocumentsExtractService) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) LoggingConstantsUtil(com.paypal.infrastructure.util.LoggingConstantsUtil) CollectionUtils(org.springframework.util.CollectionUtils) MiraklBusinessStakeholderDocumentDownloadExtractService(com.paypal.kyc.service.documents.files.mirakl.MiraklBusinessStakeholderDocumentDownloadExtractService) KYCDocumentInfoModel(com.paypal.kyc.model.KYCDocumentInfoModel) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) AbstractMiraklShop(com.mirakl.client.mmp.domain.shop.AbstractMiraklShop) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) MiraklShops(com.mirakl.client.mmp.domain.shop.MiraklShops) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)

Example 2 with MiraklShop

use of com.mirakl.client.mmp.domain.shop.MiraklShop in project mirakl-hyperwallet-connector by paypal.

the class MiraklBusinessStakeholderDocumentsExtractServiceImpl method miraklUpdateKYCShopCall.

private Optional<MiraklUpdatedShops> miraklUpdateKYCShopCall(final Map<String, List<KYCDocumentBusinessStakeHolderInfoModel>> shopsToUpdate) {
    if (CollectionUtils.isEmpty(shopsToUpdate)) {
        return Optional.empty();
    }
    final List<MiraklUpdateShop> miraklShopsToUpdate = shopsToUpdate.entrySet().stream().map(this::getMiraklUpdateShopWithProofOfDocumentFields).collect(Collectors.toList());
    final MiraklUpdateShopsRequest miraklUpdateShopRequest = new MiraklUpdateShopsRequest(miraklShopsToUpdate);
    try {
        final MiraklUpdatedShops miraklUpdatedShops = miraklOperatorClient.updateShops(miraklUpdateShopRequest);
        // @formatter:on
        log.info("Setting required KYC and letter of authorisation flag for shops with ids [{}] to false", miraklUpdatedShops.getShopReturns().stream().map(MiraklUpdatedShopReturn::getShopUpdated).map(MiraklShop::getId).collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
        return Optional.of(miraklUpdatedShops);
    // @formatter:off
    } catch (final MiraklException e) {
        log.error("Something went wrong when removing flag to retrieve documents for shops [{}]", String.join(",", shopsToUpdate.keySet()));
        kycMailNotificationUtil.sendPlainTextEmail("Issue setting push document flags to false in Mirakl", String.format("Something went wrong setting push document flag to false in Mirakl for shop Id [%s]%n%s", String.join(",", shopsToUpdate.keySet()), MiraklLoggingErrorsUtil.stringify(e)));
    }
    return Optional.empty();
}
Also used : MiraklException(com.mirakl.client.core.exception.MiraklException) MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) AbstractMiraklShop(com.mirakl.client.mmp.domain.shop.AbstractMiraklShop) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop)

Example 3 with MiraklShop

use of com.mirakl.client.mmp.domain.shop.MiraklShop in project mirakl-hyperwallet-connector by paypal.

the class MiraklSellerDocumentsExtractServiceImpl method miraklUpdateShopCall.

private Optional<MiraklUpdatedShops> miraklUpdateShopCall(final List<String> shopIdList) {
    if (CollectionUtils.isEmpty(shopIdList)) {
        return Optional.empty();
    }
    final List<MiraklUpdateShop> shopsToUpdate = shopIdList.stream().map(Long::valueOf).map(shopId -> {
        final MiraklUpdateShop miraklUpdateShop = new MiraklUpdateShop();
        miraklUpdateShop.setShopId(shopId);
        miraklUpdateShop.setAdditionalFieldValues(List.of(new MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue(KYCConstants.HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD, Boolean.FALSE.toString().toLowerCase())));
        return miraklUpdateShop;
    }).collect(Collectors.toList());
    final MiraklUpdateShopsRequest miraklUpdateShopRequest = new MiraklUpdateShopsRequest(shopsToUpdate);
    try {
        final MiraklUpdatedShops miraklUpdatedShops = miraklOperatorClient.updateShops(miraklUpdateShopRequest);
        // @formatter:on
        log.info("Setting required KYC flag for shops with ids [{}] to false", miraklUpdatedShops.getShopReturns().stream().map(MiraklUpdatedShopReturn::getShopUpdated).map(MiraklShop::getId).collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
        return Optional.of(miraklUpdatedShops);
    // @formatter:off
    } catch (final MiraklException e) {
        log.error("Something went wrong when removing flag to retrieve documents for shops [{}]", String.join(",", shopIdList));
        kycMailNotificationUtil.sendPlainTextEmail("Issue setting push document flags to false in Mirakl", String.format("Something went wrong setting push document flag to false in Mirakl for shop Id [%s]%n%s", String.join(",", shopIdList), MiraklLoggingErrorsUtil.stringify(e)));
    }
    return Optional.empty();
}
Also used : Converter(com.paypal.infrastructure.converter.Converter) java.util(java.util) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) CollectionUtils(org.apache.commons.collections4.CollectionUtils) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop) MiraklException(com.mirakl.client.core.exception.MiraklException) Service(org.springframework.stereotype.Service) KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel) MiraklMarketplacePlatformOperatorApiClient(com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient) MiraklSellerDocumentsExtractService(com.paypal.kyc.service.documents.files.mirakl.MiraklSellerDocumentsExtractService) KYCConstants(com.paypal.kyc.model.KYCConstants) Predicate(java.util.function.Predicate) ObjectUtils(org.springframework.util.ObjectUtils) MiraklShops(com.mirakl.client.mmp.domain.shop.MiraklShops) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) MiraklLoggingErrorsUtil(com.paypal.infrastructure.util.MiraklLoggingErrorsUtil) Collectors(java.util.stream.Collectors) MailNotificationUtil(com.paypal.infrastructure.mail.MailNotificationUtil) MiraklUpdatedShopReturn(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn) MiraklRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) LoggingConstantsUtil(com.paypal.infrastructure.util.LoggingConstantsUtil) MiraklSellerDocumentDownloadExtractService(com.paypal.kyc.service.documents.files.mirakl.MiraklSellerDocumentDownloadExtractService) KYCDocumentInfoModel(com.paypal.kyc.model.KYCDocumentInfoModel) MiraklException(com.mirakl.client.core.exception.MiraklException) MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop) MiraklRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue)

Example 4 with MiraklShop

use of com.mirakl.client.mmp.domain.shop.MiraklShop in project mirakl-hyperwallet-connector by paypal.

the class MiraklShopToKYCDocumentBusinessStakeholderInfoModelConverterTest method createMiraklShop.

private MiraklShop createMiraklShop() {
    final List<MiraklAdditionalFieldValue> additionalValues = List.of(new MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue(HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_STAKEHOLDER_FIELD, Boolean.TRUE.toString()), new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(HYPERWALLET_USER_TOKEN_FIELD, USER_TOKEN), new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(HYPERWALLET_BUSINESS_STAKEHOLDER_PROOF_OF_IDENTITY_COUNTRY_ISOCODE_FIELD, COUNTRY_ISO_CODE), new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(HYPERWALLET_BUSINESS_STAKEHOLDER_TOKEN_FIELD, BUSINESS_STAKEHOLDER_TOKEN), new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(HYPERWALLET_BUSINESS_STAKEHOLDER_PROOF_IDENTITY_TYPE_FIELD, GOVERNMENT_ID_DOC), new MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue(HW_STAKEHOLDER_BUSINESS_CONTACT_1, Boolean.TRUE.toString()), new MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue(HW_KYC_REQ_PROOF_AUTHORIZATION, Boolean.TRUE.toString()));
    MiraklShop miraklShop = new MiraklShop();
    miraklShop.setId(SHOP_ID);
    miraklShop.setAdditionalFieldValues(additionalValues);
    return miraklShop;
}
Also used : MiraklAdditionalFieldValue(com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop)

Example 5 with MiraklShop

use of com.mirakl.client.mmp.domain.shop.MiraklShop in project mirakl-hyperwallet-connector by paypal.

the class MiraklShopToKYCDocumentBusinessStakeholderInfoModelConverterTest method convert_shouldConvertFromMiraklShopToKYCDocumentBusinessStakeHolderInfoModel.

@Test
void convert_shouldConvertFromMiraklShopToKYCDocumentBusinessStakeHolderInfoModel() {
    final MiraklShop miraklShopStub = createMiraklShop();
    final KYCDocumentBusinessStakeHolderInfoModel result = testObj.convert(miraklShopStub, BUSINESS_STAKEHOLDER_NUMBER);
    assertThat(result.getClientUserId()).isEqualTo(SHOP_ID);
    assertThat(result.getUserToken()).isEqualTo(USER_TOKEN);
    assertThat(result.getCountryIsoCode()).isEqualTo(COUNTRY_ISO_CODE);
    assertThat(result.getToken()).isEqualTo(BUSINESS_STAKEHOLDER_TOKEN);
    assertThat(result.isRequiresKYC()).isTrue();
    assertThat(result.getBusinessStakeholderMiraklNumber()).isEqualTo(BUSINESS_STAKEHOLDER_NUMBER);
    assertThat(result.getProofOfIdentity()).isEqualTo(KYCProofOfIdentityEnum.GOVERNMENT_ID);
    assertThat(result.isContact()).isTrue();
    assertThat(result.isRequiresLetterOfAuthorization()).isTrue();
}
Also used : MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Test(org.junit.jupiter.api.Test)

Aggregations

MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)12 MiraklGetShopsRequest (com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest)7 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)6 MiraklException (com.mirakl.client.core.exception.MiraklException)5 MiraklUpdateShop (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop)5 MiraklUpdatedShops (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops)5 MiraklUpdateShopsRequest (com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest)5 MiraklAdditionalFieldValue (com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue)4 MiraklMarketplacePlatformOperatorApiClient (com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient)4 MiraklUpdatedShopReturn (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn)4 MiraklRequestAdditionalFieldValue (com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue)4 Converter (com.paypal.infrastructure.converter.Converter)4 MailNotificationUtil (com.paypal.infrastructure.mail.MailNotificationUtil)4 LoggingConstantsUtil (com.paypal.infrastructure.util.LoggingConstantsUtil)4 MiraklLoggingErrorsUtil (com.paypal.infrastructure.util.MiraklLoggingErrorsUtil)4 KYCConstants (com.paypal.kyc.model.KYCConstants)4 KYCDocumentInfoModel (com.paypal.kyc.model.KYCDocumentInfoModel)4 KYCDocumentSellerInfoModel (com.paypal.kyc.model.KYCDocumentSellerInfoModel)4 java.util (java.util)4 Predicate (java.util.function.Predicate)4