Search in sources :

Example 1 with KYCDocumentModel

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

the class MiraklBusinessStakeholderDocumentDownloadExtractServiceImpl method getBusinessStakeholderDocumentsSelectedBySeller.

/**
 * {@inheritDoc}
 */
@Override
public KYCDocumentBusinessStakeHolderInfoModel getBusinessStakeholderDocumentsSelectedBySeller(final KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeHolderInfoModel) {
    final KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeholderInfoModelWithMiraklShops = populateMiraklShopBusinessStakeholderDocuments(kycBusinessStakeHolderInfoModel);
    if (isLoARequiredForKYCButNotUploaded(kycBusinessStakeholderInfoModelWithMiraklShops) || isLoARequiredButNotUploaded(kycBusinessStakeholderInfoModelWithMiraklShops) || isDocumentMissingForKYC(kycBusinessStakeholderInfoModelWithMiraklShops)) {
        log.warn("Some needed documents are missing for shop [{}], skipping pushing all documents to hyperwallet", kycBusinessStakeholderInfoModelWithMiraklShops.getClientUserId());
        return kycBusinessStakeholderInfoModelWithMiraklShops;
    }
    // @formatter:off
    final List<KYCDocumentModel> extractedBusinessStakeholderDocumentsSelectedBySeller = miraklKYCSelectionDocumentStrategyExecutor.execute(kycBusinessStakeholderInfoModelWithMiraklShops).stream().flatMap(List::stream).collect(Collectors.toList());
    return kycBusinessStakeholderInfoModelWithMiraklShops.toBuilder().documents(extractedBusinessStakeholderDocumentsSelectedBySeller).build();
}
Also used : KYCDocumentModel(com.paypal.kyc.model.KYCDocumentModel) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)

Example 2 with KYCDocumentModel

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

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

the class DocumentsExtractServiceImplTest method cleanUpFiles_shouldRemoveFilesReceivedAsParameter.

@Test
void cleanUpFiles_shouldRemoveFilesReceivedAsParameter() {
    final KYCDocumentModel kycDocumentModelOne = KYCDocumentModel.builder().file(fileOneMock).build();
    final KYCDocumentModel kycDocumentModelTwo = KYCDocumentModel.builder().file(fileTwoMock).build();
    final KYCDocumentSellerInfoModel kycDocumentOne = KYCDocumentSellerInfoModel.builder().clientUserId("2000").documents(List.of(kycDocumentModelOne, kycDocumentModelTwo)).build();
    final List<KYCDocumentSellerInfoModel> successfullyPushedDocumentsList = List.of(kycDocumentOne);
    testObj.cleanUpDocumentsFiles(successfullyPushedDocumentsList);
    verify(fileOneMock).delete();
    verify(fileTwoMock).delete();
    assertThat(logTrackerStub.contains("Cleaning up done successfully!")).isTrue();
}
Also used : KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel) KYCDocumentModel(com.paypal.kyc.model.KYCDocumentModel) Test(org.junit.jupiter.api.Test)

Example 4 with KYCDocumentModel

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

the class HyperwalletBusinessStakeholderExtractServiceImplTest method pushBusinessStakeholderDocuments_whenAllDocumentsAreFulfilledByBusinessStakeholder_shouldPushDocumentsForBusinessStakeholders.

@Test
void pushBusinessStakeholderDocuments_whenAllDocumentsAreFulfilledByBusinessStakeholder_shouldPushDocumentsForBusinessStakeholders() {
    // @formatter:off
    final KYCDocumentModel userOneBstkOneFrontDocument = KYCDocumentModel.builder().documentFieldName(PROOF_OF_IDENTITY_FRONT_BSH1).file(usrOneBstkOneFileFrontMock).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentModel userOneBstkOneBackDocument = KYCDocumentModel.builder().documentFieldName(PROOF_OF_IDENTITY_BACK_BSH1).file(usrOneBstkOneFileBackMock).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentModel userOneBstkThreeFrontDocument = KYCDocumentModel.builder().documentFieldName(PROOF_OF_IDENTITY_FRONT_BSH3).file(userOneBstkThreeFileFrontMock).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentModel userTwoBstkOneFrontDocument = KYCDocumentModel.builder().documentFieldName(PROOF_OF_IDENTITY_FRONT_BSH1).file(userTwoBstkThreeFileFrontMock).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel userOneBstkOne = Mockito.spy(KYCDocumentBusinessStakeHolderInfoModel.builder().hyperwalletProgram(HYPERWALLET_PROGRAM).businessStakeholderMiraklNumber(1).token("stk-1").requiresKYC(true).userToken("usr-1").clientUserId("2000").proofOfIdentity(KYCProofOfIdentityEnum.GOVERNMENT_ID).documents(List.of(userOneBstkOneFrontDocument, userOneBstkOneBackDocument)).build());
    // @formatter:on
    final KYCDocumentBusinessStakeHolderInfoModel userOneBstkOneSentToHW = userOneBstkOne.toBuilder().sentToHyperwallet(Boolean.TRUE).build();
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel userOneBstkThree = Mockito.spy(KYCDocumentBusinessStakeHolderInfoModel.builder().hyperwalletProgram(HYPERWALLET_PROGRAM).businessStakeholderMiraklNumber(3).token("stk-3").requiresKYC(true).userToken("usr-1").clientUserId("2000").proofOfIdentity(KYCProofOfIdentityEnum.PASSPORT).documents(List.of(userOneBstkThreeFrontDocument)).build());
    // @formatter:on
    final KYCDocumentBusinessStakeHolderInfoModel userOneBstkThreeSentToHW = userOneBstkThree.toBuilder().sentToHyperwallet(Boolean.TRUE).build();
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel userTwoBstkThree = Mockito.spy(KYCDocumentBusinessStakeHolderInfoModel.builder().hyperwalletProgram(HYPERWALLET_PROGRAM).businessStakeholderMiraklNumber(3).token("stk-3").requiresKYC(true).userToken("usr-2").clientUserId("2001").proofOfIdentity(KYCProofOfIdentityEnum.PASSPORT).documents(List.of(userTwoBstkOneFrontDocument)).build());
    // @formatter:on
    final KYCDocumentBusinessStakeHolderInfoModel userTwoBstkThreeSentToHW = userTwoBstkThree.toBuilder().sentToHyperwallet(Boolean.TRUE).build();
    when(userOneBstkOne.areDocumentsFilled()).thenReturn(true);
    when(userOneBstkThree.areDocumentsFilled()).thenReturn(true);
    when(userTwoBstkThree.areDocumentsFilled()).thenReturn(true);
    final List<HyperwalletVerificationDocument> usrOneBstOneFilesOneDataList = List.of(usrOneBstOneFilesOneDataMock);
    when(businessStakeholderDocumentInfoModelToHWVerificationDocumentMultipleStrategyExecutorMock.execute(userOneBstkOne)).thenReturn(usrOneBstOneFilesOneDataList);
    final List<HyperwalletVerificationDocument> usrOneBstThreeFilesDataList = List.of(usrOneBstThreeFilesDataMock);
    when(businessStakeholderDocumentInfoModelToHWVerificationDocumentMultipleStrategyExecutorMock.execute(userOneBstkThree)).thenReturn(usrOneBstThreeFilesDataList);
    final List<HyperwalletVerificationDocument> usrTwoBstOneFilesDataList = List.of(usrTwoBstThreeFilesDataMock);
    when(businessStakeholderDocumentInfoModelToHWVerificationDocumentMultipleStrategyExecutorMock.execute(userTwoBstkThree)).thenReturn(usrTwoBstOneFilesDataList);
    when(hyperwalletSDKServiceMock.getHyperwalletInstance(HYPERWALLET_PROGRAM)).thenReturn(hyperwalletApiClientMock);
    final List<KYCDocumentBusinessStakeHolderInfoModel> result = testObj.pushBusinessStakeholderDocuments(List.of(userOneBstkOne, userOneBstkThree, userTwoBstkThree));
    verify(hyperwalletApiClientMock).uploadStakeholderDocuments("usr-1", "stk-1", usrOneBstOneFilesOneDataList);
    verify(hyperwalletApiClientMock).uploadStakeholderDocuments("usr-1", "stk-3", usrOneBstThreeFilesDataList);
    verify(hyperwalletApiClientMock).uploadStakeholderDocuments("usr-2", "stk-3", usrTwoBstOneFilesDataList);
    assertThat(result).containsExactlyInAnyOrder(userOneBstkOneSentToHW, userOneBstkThreeSentToHW, userTwoBstkThreeSentToHW);
}
Also used : HyperwalletVerificationDocument(com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument) KYCDocumentModel(com.paypal.kyc.model.KYCDocumentModel) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Test(org.junit.jupiter.api.Test)

Example 5 with KYCDocumentModel

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

the class HyperwalletBusinessStakeholderExtractServiceImplTest method pushBusinessStakeholderDocuments_shouldSkipBusinessStakeholdersWithNotAllDocumentsFulfilled.

@Test
void pushBusinessStakeholderDocuments_shouldSkipBusinessStakeholdersWithNotAllDocumentsFulfilled() {
    // @formatter:off
    final KYCDocumentModel userOneBstkOneFrontDocument = KYCDocumentModel.builder().documentFieldName(PROOF_OF_IDENTITY_FRONT_BSH1).file(usrOneBstkOneFileFrontMock).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentModel userOneBstkOneBackDocument = KYCDocumentModel.builder().documentFieldName(PROOF_OF_IDENTITY_BACK_BSH1).file(usrOneBstkOneFileBackMock).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentModel userOneBstkThreeFrontDocument = KYCDocumentModel.builder().documentFieldName(PROOF_OF_IDENTITY_FRONT_BSH3).file(userOneBstkThreeFileFrontMock).build();
    // @formatter:on
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel userOneBstkOne = Mockito.spy(KYCDocumentBusinessStakeHolderInfoModel.builder().hyperwalletProgram(HYPERWALLET_PROGRAM).businessStakeholderMiraklNumber(1).token("stk-1").requiresKYC(true).userToken("usr-1").clientUserId("2000").proofOfIdentity(KYCProofOfIdentityEnum.GOVERNMENT_ID).documents(List.of(userOneBstkOneFrontDocument, userOneBstkOneBackDocument)).build());
    // @formatter:on
    final KYCDocumentBusinessStakeHolderInfoModel userOneBstkOneSentToHW = userOneBstkOne.toBuilder().sentToHyperwallet(Boolean.TRUE).build();
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel userOneBstkThree = Mockito.spy(KYCDocumentBusinessStakeHolderInfoModel.builder().hyperwalletProgram(HYPERWALLET_PROGRAM).businessStakeholderMiraklNumber(3).token("stk-3").requiresKYC(true).userToken("usr-1").clientUserId("2000").proofOfIdentity(KYCProofOfIdentityEnum.PASSPORT).documents(List.of(userOneBstkThreeFrontDocument)).build());
    // @formatter:on
    final KYCDocumentBusinessStakeHolderInfoModel userOneBstkThreeSentToHW = userOneBstkThree.toBuilder().sentToHyperwallet(Boolean.TRUE).build();
    // @formatter:off
    final KYCDocumentBusinessStakeHolderInfoModel userTwoBstkThree = Mockito.spy(KYCDocumentBusinessStakeHolderInfoModel.builder().hyperwalletProgram(HYPERWALLET_PROGRAM).businessStakeholderMiraklNumber(3).token("stk-3").requiresKYC(true).userToken("usr-2").clientUserId("2001").proofOfIdentity(KYCProofOfIdentityEnum.PASSPORT).build());
    // @formatter:on
    when(userOneBstkOne.areDocumentsFilled()).thenReturn(true);
    when(userOneBstkThree.areDocumentsFilled()).thenReturn(true);
    when(userTwoBstkThree.areDocumentsFilled()).thenReturn(false);
    final List<HyperwalletVerificationDocument> usrOneBstOneFilesOneDataList = List.of(usrOneBstOneFilesOneDataMock);
    when(businessStakeholderDocumentInfoModelToHWVerificationDocumentMultipleStrategyExecutorMock.execute(userOneBstkOne)).thenReturn(usrOneBstOneFilesOneDataList);
    final List<HyperwalletVerificationDocument> usrOneBstThreeFilesDataList = List.of(usrOneBstThreeFilesDataMock);
    when(businessStakeholderDocumentInfoModelToHWVerificationDocumentMultipleStrategyExecutorMock.execute(userOneBstkThree)).thenReturn(usrOneBstThreeFilesDataList);
    when(hyperwalletSDKServiceMock.getHyperwalletInstance(HYPERWALLET_PROGRAM)).thenReturn(hyperwalletApiClientMock);
    final List<KYCDocumentBusinessStakeHolderInfoModel> result = testObj.pushBusinessStakeholderDocuments(List.of(userOneBstkOne, userOneBstkThree, userTwoBstkThree));
    verify(hyperwalletApiClientMock).uploadStakeholderDocuments("usr-1", "stk-1", usrOneBstOneFilesOneDataList);
    verify(hyperwalletApiClientMock).uploadStakeholderDocuments("usr-1", "stk-3", usrOneBstThreeFilesDataList);
    assertThat(result).containsExactlyInAnyOrder(userOneBstkOneSentToHW, userOneBstkThreeSentToHW);
}
Also used : HyperwalletVerificationDocument(com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument) KYCDocumentModel(com.paypal.kyc.model.KYCDocumentModel) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Test(org.junit.jupiter.api.Test)

Aggregations

KYCDocumentModel (com.paypal.kyc.model.KYCDocumentModel)10 KYCDocumentBusinessStakeHolderInfoModel (com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)7 Test (org.junit.jupiter.api.Test)6 HyperwalletVerificationDocument (com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument)4 MiraklShopDocument (com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument)3 HyperwalletException (com.hyperwallet.clientsdk.HyperwalletException)2 MiraklGetShopDocumentsRequest (com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest)2 KYCDocumentSellerInfoModel (com.paypal.kyc.model.KYCDocumentSellerInfoModel)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Gson (com.google.gson.Gson)1 MiraklException (com.mirakl.client.core.exception.MiraklException)1 FileWrapper (com.mirakl.client.mmp.domain.common.FileWrapper)1 MiraklMarketplacePlatformOperatorApiClient (com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient)1 MiraklDownloadShopsDocumentsRequest (com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest)1 Strategy (com.paypal.infrastructure.strategy.Strategy)1 KYCDocumentInfoModel (com.paypal.kyc.model.KYCDocumentInfoModel)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1