Search in sources :

Example 6 with KYCDocumentBusinessStakeHolderInfoModel

use of com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel in project mirakl-hyperwallet-connector by paypal.

the class HyperwalletBusinessStakeholderExtractServiceMockImpl method callHyperwalletAPI.

/**
 * {@inheritDoc}
 */
@Override
protected KYCDocumentBusinessStakeHolderInfoModel callHyperwalletAPI(final Map.Entry<KYCDocumentBusinessStakeHolderInfoModel, List<HyperwalletVerificationDocument>> entry) {
    final KYCDocumentBusinessStakeHolderInfoModel kycDocumentBusinessStakeHolderInfoModel = entry.getKey();
    final List<HyperwalletVerificationDocument> hyperwalletVerificationDocuments = entry.getValue();
    final String postURL = HYPERWALLET_PUSH_DOCUMENTS.replace("{userToken}", kycDocumentBusinessStakeHolderInfoModel.getUserToken()).replace("{bstToken}", kycDocumentBusinessStakeHolderInfoModel.getToken());
    try {
        if (checkFailingFiles(hyperwalletVerificationDocuments)) {
            throw new HyperwalletException("Something bad happened");
        }
        Gson gsonConverter = new Gson();
        restTemplate.postForObject(getMockServerUrl() + postURL, gsonConverter.toJson(entry.getValue()), Object.class);
        log.info("Pushed successfully to mockserver documents [{}] for shopId  [{}]", kycDocumentBusinessStakeHolderInfoModel.getIdentityDocuments().stream().map(KYCDocumentModel::getDocumentFieldName).collect(Collectors.joining(",")), kycDocumentBusinessStakeHolderInfoModel.getClientUserId());
        return kycDocumentBusinessStakeHolderInfoModel.toBuilder().sentToHyperwallet(true).build();
    } catch (HyperwalletException ex) {
        log.error("Error uploading document to hyperwallet: [{}]", HyperwalletLoggingErrorsUtil.stringify(ex));
        getKycMailNotificationUtil().sendPlainTextEmail("Issue detected pushing documents into Hyperwallet", String.format("Something went wrong pushing documents to Hyperwallet for shop Id [%s] and business stakeholder number [%s]%n%s", kycDocumentBusinessStakeHolderInfoModel.getClientUserId(), kycDocumentBusinessStakeHolderInfoModel.getBusinessStakeholderMiraklNumber(), HyperwalletLoggingErrorsUtil.stringify(ex)));
        return kycDocumentBusinessStakeHolderInfoModel;
    }
}
Also used : HyperwalletVerificationDocument(com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument) HyperwalletException(com.hyperwallet.clientsdk.HyperwalletException) Gson(com.google.gson.Gson) KYCDocumentModel(com.paypal.kyc.model.KYCDocumentModel) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)

Example 7 with KYCDocumentBusinessStakeHolderInfoModel

use of com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel 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)

Example 8 with KYCDocumentBusinessStakeHolderInfoModel

use of com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel 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 9 with KYCDocumentBusinessStakeHolderInfoModel

use of com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel 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)

Example 10 with KYCDocumentBusinessStakeHolderInfoModel

use of com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel in project mirakl-hyperwallet-connector by paypal.

the class KYCReadyForReviewServiceImplTest method notifyBstkReadyForReview_shouldSendAnEmailWhenThereIsAnErrorNotifyingToHW.

@Test
void notifyBstkReadyForReview_shouldSendAnEmailWhenThereIsAnErrorNotifyingToHW() {
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel kycDocumentSent = KYCDocumentBusinessStakeHolderInfoModel.builder().clientUserId(SHOP_ID).hyperwalletProgram(HYPERWALLET_PROGRAM).userToken(List.of(new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(KYCConstants.HYPERWALLET_USER_TOKEN_FIELD, USER_TOKEN_1))).build();
    // @formatter:on
    when(hyperwalletSDKServiceMock.getHyperwalletInstance(HYPERWALLET_PROGRAM)).thenReturn(hyperwalletApiClientMock);
    HyperwalletException hwException = new HyperwalletException("Something bad happened");
    doThrow(hwException).when(hyperwalletApiClientMock).updateUser(Mockito.any(HyperwalletUser.class));
    testObj.notifyBstkReadyForReview(Map.entry(USER_TOKEN_1, List.of(kycDocumentSent)));
    verify(hyperwalletSDKServiceMock).getHyperwalletInstance(HYPERWALLET_PROGRAM);
    verify(hyperwalletApiClientMock).updateUser(hyperwalletUserCaptor.capture());
    verify(testObj).notifyBstkReadyForReview(Map.entry(USER_TOKEN_1, List.of(kycDocumentSent)));
    verify(kycMailNotificationUtilMock).sendPlainTextEmail("Issue in Hyperwallet status notification", String.format("There was an error notifying Hyperwallet all documents were sent for shop Id [2000], so Hyperwallet will not be notified about this new situation%n%s", HyperwalletLoggingErrorsUtil.stringify(hwException)));
    assertThat(logTrackerStub.contains("Error notifying to Hyperwallet that all documents were sent")).isTrue();
}
Also used : MiraklAdditionalFieldValue(com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue) HyperwalletUser(com.hyperwallet.clientsdk.model.HyperwalletUser) HyperwalletException(com.hyperwallet.clientsdk.HyperwalletException) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Test(org.junit.jupiter.api.Test)

Aggregations

KYCDocumentBusinessStakeHolderInfoModel (com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)36 Test (org.junit.jupiter.api.Test)27 MiraklAdditionalFieldValue (com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 HyperwalletVerificationDocument (com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument)8 KYCDocumentModel (com.paypal.kyc.model.KYCDocumentModel)7 HyperwalletException (com.hyperwallet.clientsdk.HyperwalletException)6 MiraklException (com.mirakl.client.core.exception.MiraklException)4 MiraklShopDocument (com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument)4 MiraklUpdatedShops (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops)4 MiraklUpdateShopsRequest (com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest)4 MiraklGetShopDocumentsRequest (com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest)4 Collectors (java.util.stream.Collectors)4 Service (org.springframework.stereotype.Service)4 ObjectUtils (org.springframework.util.ObjectUtils)4 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)3 Map (java.util.Map)3 HyperwalletUser (com.hyperwallet.clientsdk.model.HyperwalletUser)2 AbstractMiraklShop (com.mirakl.client.mmp.domain.shop.AbstractMiraklShop)2 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)2