Search in sources :

Example 1 with MiraklException

use of com.mirakl.client.core.exception.MiraklException 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 MiraklException

use of com.mirakl.client.core.exception.MiraklException 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 MiraklException

use of com.mirakl.client.core.exception.MiraklException 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 MiraklException

use of com.mirakl.client.core.exception.MiraklException in project mirakl-hyperwallet-connector by paypal.

the class AbstractUserDocumentFlagsStrategy method fillMiraklProofIdentityOrBusinessFlagStatus.

protected void fillMiraklProofIdentityOrBusinessFlagStatus(final KYCUserDocumentFlagsNotificationBodyModel source) {
    final MiraklUpdateShop updateShop = new MiraklUpdateShop();
    final MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue additionalValue = new MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue(KYCConstants.HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD, Boolean.TRUE.toString());
    updateShop.setShopId(Long.valueOf(source.getClientUserId()));
    updateShop.setAdditionalFieldValues(List.of(additionalValue));
    try {
        log.info("Updating KYC proof of identity flag in Mirakl for shopId [{}]", source.getClientUserId());
        final MiraklUpdateShopsRequest miraklUpdateShopsRequest = new MiraklUpdateShopsRequest(List.of(updateShop));
        miraklMarketplacePlatformOperatorApiClient.updateShops(miraklUpdateShopsRequest);
        log.info("Proof of identity flag updated for shopId [{}]", source.getClientUserId());
    } catch (final MiraklException ex) {
        log.error("Something went wrong updating KYC information of shop [{}]. Details [{}]", source.getClientUserId(), ex.getMessage());
        mailNotificationUtil.sendPlainTextEmail("Issue detected updating KYC information in Mirakl", String.format(EMAIL_BODY_PREFIX + "Something went wrong updating KYC information of shop [%s]%n%s", source.getClientUserId(), MiraklLoggingErrorsUtil.stringify(ex)));
        // Rethrow exception to handle it in AbstractNotificationListener
        throw ex;
    }
}
Also used : MiraklException(com.mirakl.client.core.exception.MiraklException) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop) MiraklRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue)

Example 5 with MiraklException

use of com.mirakl.client.core.exception.MiraklException in project mirakl-hyperwallet-connector by paypal.

the class MiraklBusinessStakeholderDocumentsExtractServiceImplTest method setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse_whenMiraklExceptionIsThrown_shouldSendEmailNotification.

@Test
void setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse_whenMiraklExceptionIsThrown_shouldSendEmailNotification() {
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel kycDocumentOne = KYCDocumentBusinessStakeHolderInfoModel.builder().clientUserId("2000").businessStakeholderMiraklNumber(1).requiresKYC(Boolean.TRUE).sentToHyperwallet(Boolean.TRUE).build();
    final List<KYCDocumentBusinessStakeHolderInfoModel> successfullyPushedDocumentsList = List.of(kycDocumentOne);
    // @formatter:on
    final MiraklException miraklException = new MiraklException("Something went wrong");
    doThrow(miraklException).when(miraklMarketplacePlatformOperatorApiClientMock).updateShops(any(MiraklUpdateShopsRequest.class));
    testObj.setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse(successfullyPushedDocumentsList);
    verify(kycMailNotificationUtilMock).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 [2000]%n%s", String.join(",", MiraklLoggingErrorsUtil.stringify(miraklException))));
}
Also used : MiraklException(com.mirakl.client.core.exception.MiraklException) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Test(org.junit.jupiter.api.Test)

Aggregations

MiraklException (com.mirakl.client.core.exception.MiraklException)18 MiraklUpdateShopsRequest (com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest)9 Test (org.junit.jupiter.api.Test)8 MiraklUpdateShop (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop)4 MiraklRequestAdditionalFieldValue (com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue)4 MiraklGetShopDocumentsRequest (com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest)4 MiraklShopDocument (com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument)3 MiraklUpdatedShops (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops)3 KYCUserDocumentFlagsNotificationBodyModel (com.paypal.kyc.model.KYCUserDocumentFlagsNotificationBodyModel)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)2 MiraklMarketplacePlatformOperatorApiClient (com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient)2 MiraklUpdatedShopReturn (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn)2 MailNotificationUtil (com.paypal.infrastructure.mail.MailNotificationUtil)2 MiraklLoggingErrorsUtil (com.paypal.infrastructure.util.MiraklLoggingErrorsUtil)2 KYCDocumentBusinessStakeHolderInfoModel (com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)2 KYCDocumentSellerInfoModel (com.paypal.kyc.model.KYCDocumentSellerInfoModel)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 CollectionUtils (org.apache.commons.collections4.CollectionUtils)2