Search in sources :

Example 11 with KYCDocumentSellerInfoModel

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

the class HyperwalletSellerExtractServiceMockImplTest method execute_shouldRunPushDocumentsToMockServer.

@Test
void execute_shouldRunPushDocumentsToMockServer() {
    final KYCDocumentSellerInfoModel kycDocumentOne = KYCDocumentSellerInfoModel.builder().userToken(List.of(new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(KYCConstants.HYPERWALLET_USER_TOKEN_FIELD, USER_TOKEN))).proofOfAddress(List.of(new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(KYCConstants.HYPERWALLET_KYC_IND_PROOF_OF_ADDRESS_FIELD, "BANK_STATEMENT"))).build();
    HyperwalletVerificationDocument hyperwalletVerificationDocument = new HyperwalletVerificationDocument();
    hyperwalletVerificationDocument.setCategory("category");
    hyperwalletVerificationDocument.setCountry("ES");
    hyperwalletVerificationDocument.setType("type");
    hyperwalletVerificationDocument.setUploadFiles(Map.of("key1", "value1"));
    when(testObj.getMockServerUrl()).thenReturn(MOCK_SERVER_URL);
    final Map<KYCDocumentSellerInfoModel, List<HyperwalletVerificationDocument>> kycDocumentOne1 = Map.of(kycDocumentOne, List.of(hyperwalletVerificationDocument));
    testObj.callHyperwalletAPI(kycDocumentOne1.entrySet().iterator().next());
    verify(restTemplateMock).postForObject(eq(MOCK_SERVER_URL + HYPERWALLET_PUSH_DOCUMENTS), Mockito.any(), eq(Object.class));
}
Also used : MiraklAdditionalFieldValue(com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue) HyperwalletVerificationDocument(com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument) KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 12 with KYCDocumentSellerInfoModel

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

the class HyperwalletSellerExtractServiceImplTest method pushDocuments_shouldSendEmailNotificationWhenHyperWalletExceptionIsThrown.

@Test
void pushDocuments_shouldSendEmailNotificationWhenHyperWalletExceptionIsThrown() {
    final KYCDocumentSellerInfoModel kycDocumentSellerInfoModelKOStub = Mockito.spy(KYCDocumentSellerInfoModel.builder().clientUserId(CLIENT_USER_ID_TWO).userToken(List.of(new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(KYCConstants.HYPERWALLET_USER_TOKEN_FIELD, USR_TOKEN_TWO))).hyperwalletProgram(List.of(new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(KYCConstants.HW_PROGRAM, EUROPE_HYPERWALLET_PROGRAM))).build());
    when(kycDocumentSellerInfoModelKOStub.areDocumentsFilled()).thenReturn(true);
    when(kycDocumentInfoToHWVerificationDocumentExecutorMock.execute(kycDocumentSellerInfoModelKOStub)).thenReturn(List.of(uploadDataTwoMock));
    when(hyperwalletSDKServiceMock.getHyperwalletInstance(Mockito.anyString())).thenReturn(hyperwalletClientMock);
    HyperwalletException hyperwalletException = new HyperwalletException("Something went wrong");
    doThrow(hyperwalletException).when(hyperwalletClientMock).uploadUserDocuments(USR_TOKEN_TWO, List.of(uploadDataTwoMock));
    testObj.pushProofOfIdentityAndBusinessSellerDocuments(List.of(kycDocumentSellerInfoModelKOStub));
    verify(mailNotificationUtilMock).sendPlainTextEmail("Issue detected pushing documents into Hyperwallet", String.format("Something went wrong pushing documents to Hyperwallet for shop Id [%s]%n%s", String.join(",", kycDocumentSellerInfoModelKOStub.getClientUserId()), HyperwalletLoggingErrorsUtil.stringify(hyperwalletException)));
}
Also used : MiraklAdditionalFieldValue(com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue) HyperwalletException(com.hyperwallet.clientsdk.HyperwalletException) KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel) Test(org.junit.jupiter.api.Test)

Example 13 with KYCDocumentSellerInfoModel

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

the class MiraklSellerDocumentsExtractServiceImplTest method setFlagToPushSellerDocumentsToFalse_shouldSendEmailNotificationWhenMiraklExceptionIsThrown.

@Test
void setFlagToPushSellerDocumentsToFalse_shouldSendEmailNotificationWhenMiraklExceptionIsThrown() {
    final KYCDocumentSellerInfoModel kycDocumentOne = KYCDocumentSellerInfoModel.builder().clientUserId("2000").build();
    final List<KYCDocumentSellerInfoModel> successfullyPushedDocumentsList = List.of(kycDocumentOne);
    final MiraklException miraklException = new MiraklException("Something went wrong");
    doThrow(miraklException).when(miraklMarketplacePlatformOperatorApiClientMock).updateShops(any(MiraklUpdateShopsRequest.class));
    testObj.setFlagToPushProofOfIdentityAndBusinessSellerDocumentsToFalse(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) KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) Test(org.junit.jupiter.api.Test)

Example 14 with KYCDocumentSellerInfoModel

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

the class MiraklSellerDocumentsExtractServiceImplTest method setFlagToPushSellerDocumentsToFalse_shouldCallMiraklWithTheClientUsersIdPassedAsParam.

@Test
void setFlagToPushSellerDocumentsToFalse_shouldCallMiraklWithTheClientUsersIdPassedAsParam() {
    final KYCDocumentSellerInfoModel kycDocumentOne = KYCDocumentSellerInfoModel.builder().clientUserId("2000").build();
    final KYCDocumentSellerInfoModel kycDocumentTwo = KYCDocumentSellerInfoModel.builder().clientUserId("2001").build();
    final List<KYCDocumentSellerInfoModel> successfullyPushedDocumentsList = List.of(kycDocumentOne, kycDocumentTwo);
    when(miraklMarketplacePlatformOperatorApiClientMock.updateShops(any(MiraklUpdateShopsRequest.class))).thenReturn(miraklUpdateShopsMock);
    final Optional<MiraklUpdatedShops> result = testObj.setFlagToPushProofOfIdentityAndBusinessSellerDocumentsToFalse(successfullyPushedDocumentsList);
    verify(miraklMarketplacePlatformOperatorApiClientMock).updateShops(miraklUpdateShopArgumentCaptor.capture());
    final MiraklUpdateShopsRequest miraklUpdateShopRequest = miraklUpdateShopArgumentCaptor.getValue();
    final List<Long> updatedSellerIdList = miraklUpdateShopRequest.getShops().stream().map(MiraklUpdateShop::getShopId).collect(Collectors.toList());
    final List<String> updatedFlagValueList = miraklUpdateShopRequest.getShops().stream().map(MiraklUpdateShop::getAdditionalFieldValues).flatMap(Collection::stream).filter(MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue.class::isInstance).map(MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue.class::cast).map(MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue::getValue).collect(Collectors.toList());
    final List<String> updatedFlagCodeList = miraklUpdateShopRequest.getShops().stream().map(MiraklUpdateShop::getAdditionalFieldValues).flatMap(Collection::stream).filter(MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue.class::isInstance).map(MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue.class::cast).map(MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue::getCode).collect(Collectors.toList());
    assertThat(updatedSellerIdList).containsExactlyInAnyOrder(2000L, 2001L);
    assertThat(updatedFlagValueList).containsExactlyInAnyOrder("false", "false");
    assertThat(updatedFlagCodeList).containsExactlyInAnyOrder(HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD, HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD);
    assertThat(result).hasValue(miraklUpdateShopsMock);
}
Also used : MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) Collection(java.util.Collection) MiraklRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue) Test(org.junit.jupiter.api.Test)

Example 15 with KYCDocumentSellerInfoModel

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

the class MiraklSellerDocumentDownloadExtractServiceImpl method getDocumentsSelectedBySeller.

/**
 * {@inheritDoc}
 */
@Override
public KYCDocumentSellerInfoModel getDocumentsSelectedBySeller(final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel) {
    final KYCDocumentSellerInfoModel kycDocumentSellerInfoModelWithMiraklShops = populateMiraklShopDocuments(kycDocumentSellerInfoModel);
    if (!kycDocumentSellerInfoModelWithMiraklShops.existsDocumentInMirakl()) {
        log.warn("Some needed documents are missing for shop [{}], skipping pushing all documents to hyperwallet", kycDocumentSellerInfoModelWithMiraklShops.getClientUserId());
        return kycDocumentSellerInfoModelWithMiraklShops;
    }
    final List<KYCDocumentModel> extractedDocumentsSelectedBySeller = miraklKYCSelectionDocumentStrategyExecutor.execute(kycDocumentSellerInfoModelWithMiraklShops).stream().flatMap(List::stream).collect(Collectors.toList());
    return kycDocumentSellerInfoModelWithMiraklShops.toBuilder().documents(extractedDocumentsSelectedBySeller).build();
}
Also used : KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel) KYCDocumentModel(com.paypal.kyc.model.KYCDocumentModel)

Aggregations

KYCDocumentSellerInfoModel (com.paypal.kyc.model.KYCDocumentSellerInfoModel)17 Test (org.junit.jupiter.api.Test)10 MiraklAdditionalFieldValue (com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue)7 HyperwalletVerificationDocument (com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument)6 HyperwalletException (com.hyperwallet.clientsdk.HyperwalletException)5 Map (java.util.Map)4 Strategy (com.paypal.infrastructure.strategy.Strategy)3 KYCDocumentCategoryEnum (com.paypal.kyc.model.KYCDocumentCategoryEnum)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Service (org.springframework.stereotype.Service)3 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)2 MiraklUpdateShopsRequest (com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest)2 KYCDocumentModel (com.paypal.kyc.model.KYCDocumentModel)2 List (java.util.List)2 ObjectUtils (org.springframework.util.ObjectUtils)2 Gson (com.google.gson.Gson)1 Hyperwallet (com.hyperwallet.clientsdk.Hyperwallet)1 HyperwalletUser (com.hyperwallet.clientsdk.model.HyperwalletUser)1 MiraklException (com.mirakl.client.core.exception.MiraklException)1