Search in sources :

Example 1 with MiraklUpdatedShops

use of com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops 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 2 with MiraklUpdatedShops

use of com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops 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 3 with MiraklUpdatedShops

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

the class AbstractKYCUserStatusNotificationStrategy method updateShop.

protected void updateShop(final KYCUserStatusNotificationBodyModel kycUserStatusNotificationBodyModel) {
    final MiraklShopKycStatus status = expectedKycMiraklStatus(kycUserStatusNotificationBodyModel);
    if (Objects.nonNull(status)) {
        final String shopId = kycUserStatusNotificationBodyModel.getClientUserId();
        final MiraklUpdateShopsRequest request = createUpdateShopRequest(kycUserStatusNotificationBodyModel, status);
        log.info("Updating KYC status for shop [{}]", shopId);
        try {
            final MiraklUpdatedShops response = miraklOperatorClient.updateShops(request);
            if (response == null) {
                log.error("No response was received for update request for shop [{}]", shopId);
            } else {
                final List<MiraklUpdatedShopReturn> shopReturns = response.getShopReturns();
                shopReturns.forEach(this::logShopUpdates);
            }
            deleteInvalidDocuments(kycUserStatusNotificationBodyModel);
        } catch (final MiraklException ex) {
            final String errorMessage = String.format(MSG_ERROR_DETECTED, shopId, MiraklLoggingErrorsUtil.stringify(ex));
            log.error(errorMessage);
            mailNotificationUtil.sendPlainTextEmail(MAIL_SUBJECT, ERROR_MESSAGE_PREFIX + errorMessage);
            // Rethrow exception to handle it in AbstractNotificationListener
            throw ex;
        }
    }
}
Also used : MiraklException(com.mirakl.client.core.exception.MiraklException) MiraklUpdatedShopReturn(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn) MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklShopKycStatus(com.mirakl.client.mmp.domain.shop.MiraklShopKycStatus)

Example 4 with MiraklUpdatedShops

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

the class MiraklBusinessStakeholderDocumentsExtractServiceImplTest method setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse_whenNoShopsAreNeededForUpdate_shouldDoNothing.

@Test
void setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse_whenNoShopsAreNeededForUpdate_shouldDoNothing() {
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel kycUserOneBstOne = KYCDocumentBusinessStakeHolderInfoModel.builder().clientUserId("2000").businessStakeholderMiraklNumber(1).sentToHyperwallet(Boolean.FALSE).build();
    // @formatter:on
    final Optional<MiraklUpdatedShops> result = testObj.setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse(Collections.singletonList(kycUserOneBstOne));
    assertThat(result).isEmpty();
    verifyNoInteractions(miraklMarketplacePlatformOperatorApiClientMock);
}
Also used : MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Test(org.junit.jupiter.api.Test)

Example 5 with MiraklUpdatedShops

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

the class MiraklBusinessStakeholderDocumentsExtractServiceImplTest method setBusinessStakeholderFlagToPushBusinessStakeholderDocumentsToFalse_shouldCallMiraklWithTheClientUsersIdPassedAsParam.

@Test
void setBusinessStakeholderFlagToPushBusinessStakeholderDocumentsToFalse_shouldCallMiraklWithTheClientUsersIdPassedAsParam() {
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel kycUserOneBstOne = KYCDocumentBusinessStakeHolderInfoModel.builder().clientUserId("2000").businessStakeholderMiraklNumber(1).requiresKYC(Boolean.TRUE).sentToHyperwallet(Boolean.TRUE).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel kycUserTwoBstOne = KYCDocumentBusinessStakeHolderInfoModel.builder().clientUserId("2001").businessStakeholderMiraklNumber(1).requiresKYC(Boolean.TRUE).sentToHyperwallet(Boolean.TRUE).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel kycUserThreeBstOne = KYCDocumentBusinessStakeHolderInfoModel.builder().clientUserId("2002").businessStakeholderMiraklNumber(1).requiresKYC(Boolean.TRUE).sentToHyperwallet(Boolean.TRUE).requiresLetterOfAuthorization(Boolean.TRUE).build();
    // @formatter:on
    final List<KYCDocumentBusinessStakeHolderInfoModel> successfullyPushedDocumentsList = List.of(kycUserOneBstOne, kycUserThreeBstOne, kycUserTwoBstOne);
    when(miraklMarketplacePlatformOperatorApiClientMock.updateShops(any(MiraklUpdateShopsRequest.class))).thenReturn(miraklUpdateShopsMock);
    final Optional<MiraklUpdatedShops> result = testObj.setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse(successfullyPushedDocumentsList);
    verify(miraklMarketplacePlatformOperatorApiClientMock).updateShops(miraklUpdateShopArgumentCaptor.capture());
    final MiraklUpdateShopsRequest miraklUpdateShopRequest = miraklUpdateShopArgumentCaptor.getValue();
    final List<Long> updatedSellerIdList = miraklUpdateShopRequest.getShops().stream().map(MiraklUpdateShop::getShopId).collect(Collectors.toList());
    assertThat(updatedSellerIdList).containsExactlyInAnyOrder(2000L, 2001L, 2002L);
    assertThat(getUpdatedFlagValuesForShop(miraklUpdateShopRequest, 2000L)).containsExactlyEntriesOf(Map.of(BUSINESS_STAKEHOLDER_PROOF_IDENTITY_CODE, "false"));
    assertThat(getUpdatedFlagValuesForShop(miraklUpdateShopRequest, 2001L)).containsExactlyEntriesOf(Map.of(BUSINESS_STAKEHOLDER_PROOF_IDENTITY_CODE, "false"));
    assertThat(getUpdatedFlagValuesForShop(miraklUpdateShopRequest, 2002L)).containsAllEntriesOf(Map.of(BUSINESS_STAKEHOLDER_PROOF_IDENTITY_CODE, "false", BUSINESS_STAKEHOLDER_PROOF_AUTH_CODE, "false"));
    assertThat(result).hasValue(miraklUpdateShopsMock);
}
Also used : MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Test(org.junit.jupiter.api.Test)

Aggregations

MiraklUpdatedShops (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops)6 MiraklUpdateShopsRequest (com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest)5 MiraklException (com.mirakl.client.core.exception.MiraklException)3 Test (org.junit.jupiter.api.Test)3 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)2 MiraklUpdateShop (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop)2 MiraklUpdatedShopReturn (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn)2 MiraklRequestAdditionalFieldValue (com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue)2 KYCDocumentBusinessStakeHolderInfoModel (com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)2 KYCDocumentSellerInfoModel (com.paypal.kyc.model.KYCDocumentSellerInfoModel)2 AbstractMiraklShop (com.mirakl.client.mmp.domain.shop.AbstractMiraklShop)1 MiraklShopKycStatus (com.mirakl.client.mmp.domain.shop.MiraklShopKycStatus)1 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)1 MiraklMarketplacePlatformOperatorApiClient (com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient)1 MiraklGetShopsRequest (com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest)1 Converter (com.paypal.infrastructure.converter.Converter)1 MailNotificationUtil (com.paypal.infrastructure.mail.MailNotificationUtil)1 LoggingConstantsUtil (com.paypal.infrastructure.util.LoggingConstantsUtil)1 MiraklLoggingErrorsUtil (com.paypal.infrastructure.util.MiraklLoggingErrorsUtil)1 KYCConstants (com.paypal.kyc.model.KYCConstants)1