index int64 0 0 | repo_id stringlengths 9 205 | file_path stringlengths 31 246 | content stringlengths 1 12.2M | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/test/java/com/paypal/kyc/statussynchronization | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/test/java/com/paypal/kyc/statussynchronization/controllers/KYCStatusResyncJobControllerTest.java | package com.paypal.kyc.statussynchronization.controllers;
import com.paypal.infrastructure.support.date.DateUtil;
import com.paypal.infrastructure.support.date.TimeMachine;
import com.paypal.jobsystem.quartzintegration.services.JobService;
import com.paypal.jobsystem.quartzintegration.support.AbstractDeltaInfoJob;
import com.paypal.kyc.statussynchronization.jobs.KYCUserStatusResyncJob;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.quartz.SchedulerException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
class KYCStatusResyncJobControllerTest {
@InjectMocks
private KYCStatusResyncJobController testObj;
private static final String JOB_NAME = "jobName";
@Mock
private JobService jobService;
@Test
void runJob_shouldCallJobServiceWithValuesPassedAsParam() throws SchedulerException {
TimeMachine.useFixedClockAt(LocalDateTime.of(2020, 11, 10, 20, 45));
final LocalDateTime now = TimeMachine.now();
final Date delta = DateUtil.convertToDate(now, ZoneId.systemDefault());
testObj.runJob(delta, "jobName");
verify(jobService).createAndRunSingleExecutionJob(JOB_NAME, KYCUserStatusResyncJob.class,
AbstractDeltaInfoJob.createJobDataMap(delta), null);
}
}
| 5,300 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/test/java/com/paypal/kyc/statussynchronization | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/test/java/com/paypal/kyc/statussynchronization/services/HyperwalletKycUserStatusExtractServiceImplTest.java | package com.paypal.kyc.statussynchronization.services;
import com.hyperwallet.clientsdk.Hyperwallet;
import com.hyperwallet.clientsdk.model.HyperwalletList;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.statussynchronization.model.KYCUserStatusInfoModel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Date;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class HyperwalletKycUserStatusExtractServiceImplTest {
private HyperwalletKycUserStatusExtractServiceImpl testObj;
@Mock
private Converter<HyperwalletUser, KYCUserStatusInfoModel> kycUserStatusInfoModelConverterMock;
@Mock
private UserHyperwalletSDKService userHyperwalletSDKServiceMock;
@Mock
private Hyperwallet hyperwalletMock;
@Mock
private HyperwalletUser hyperwalletUserMock;
@Mock
private KYCUserStatusInfoModel kycUserStatusInfoModelMock;
@BeforeEach
void setUp() {
when(userHyperwalletSDKServiceMock.getHyperwalletInstance()).thenReturn(hyperwalletMock);
testObj = new HyperwalletKycUserStatusExtractServiceImpl(userHyperwalletSDKServiceMock,
kycUserStatusInfoModelConverterMock);
}
@Test
void extractKycUserStatuses_shouldReturnAConvertedListOfKYCUserStatusInfoModel_whenDatesAreCorrect() {
final List<HyperwalletUser> listOfUsers = List.of(hyperwalletUserMock);
final HyperwalletList<HyperwalletUser> hyperwalletListOfUsers = new HyperwalletList<>();
hyperwalletListOfUsers.setData(listOfUsers);
when(hyperwalletMock.listUsers(any())).thenReturn(hyperwalletListOfUsers);
when(kycUserStatusInfoModelConverterMock.convert(hyperwalletUserMock)).thenReturn(kycUserStatusInfoModelMock);
final Date startDate = new Date();
final Date endDate = new Date();
final List<KYCUserStatusInfoModel> extractedData = testObj.extractKycUserStatuses(startDate, endDate);
assertThat(extractedData.get(0)).isEqualTo(kycUserStatusInfoModelMock);
verify(hyperwalletMock, times(1))
.listUsers(argThat(x -> x.getCreatedAfter().equals(startDate) && x.getCreatedBefore().equals(endDate)));
};
}
| 5,301 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/test/java/com/paypal/kyc/statussynchronization/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/test/java/com/paypal/kyc/statussynchronization/services/converters/HyperwalletUserToKycUserStatusNotificationBodyModelConverterTest.java | package com.paypal.kyc.statussynchronization.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.kyc.documentextractioncommons.model.KYCConstants;
import com.paypal.kyc.incomingnotifications.model.KYCRejectionReasonTypeEnum;
import com.paypal.kyc.incomingnotifications.model.KYCUserStatusNotificationBodyModel;
import com.paypal.kyc.incomingnotifications.services.converters.HyperWalletObjectToKYCUserStatusNotificationBodyModelConverter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class HyperwalletUserToKycUserStatusNotificationBodyModelConverterTest {
public static final List<KYCRejectionReasonTypeEnum> LIST_OF_REASONS = List.of(KYCRejectionReasonTypeEnum.UNKWOWN,
KYCRejectionReasonTypeEnum.VERIFICATIONSTATUS_IND_REQUIRED,
KYCRejectionReasonTypeEnum.LETTER_OF_AUTHORIZATION_REQUIRED);
public static final String CLIENT_1_ID = "client_1";
@InjectMocks
private HyperwalletUserToKycUserStatusNotificationBodyModelConverter testObj;
@Mock
private HyperWalletObjectToKYCUserStatusNotificationBodyModelConverter hyperWalletObjectToKYCUserStatusNotificationBodyModelConverterMock;
@Captor
ArgumentCaptor<Map<String, Object>> hyperwalletUserMapCaptor;
@Mock
private KYCUserStatusNotificationBodyModel kycUserStatusNotificationBodyModelMock;
@Test
void hyperwalletUser_shouldCreateKycUserStatusNotificationBodyModel() {
final HyperwalletUser hyperwalletUser = new HyperwalletUser();
hyperwalletUser.setVerificationStatus(HyperwalletUser.VerificationStatus.VERIFIED);
hyperwalletUser.setBusinessStakeholderVerificationStatus(
HyperwalletUser.BusinessStakeholderVerificationStatus.VERIFIED);
hyperwalletUser.setClientUserId(CLIENT_1_ID);
hyperwalletUser.setProfileType(HyperwalletUser.ProfileType.INDIVIDUAL);
hyperwalletUser.setLetterOfAuthorizationStatus(HyperwalletUser.LetterOfAuthorizationStatus.VERIFIED);
final HyperwalletVerificationDocument hyperwalletVerificationDocument = new HyperwalletVerificationDocument();
hyperwalletVerificationDocument.setCategory(KYCConstants.HwDocuments.PROOF_OF_ADDRESS);
hyperwalletUser.setDocuments(List.of(hyperwalletVerificationDocument));
when(hyperWalletObjectToKYCUserStatusNotificationBodyModelConverterMock.convert(any()))
.thenReturn(kycUserStatusNotificationBodyModelMock);
final KYCUserStatusNotificationBodyModel result = testObj.convert(hyperwalletUser);
assertThat(result).isEqualTo(kycUserStatusNotificationBodyModelMock);
verify(hyperWalletObjectToKYCUserStatusNotificationBodyModelConverterMock)
.convert(hyperwalletUserMapCaptor.capture());
final Map<String, Object> hyperwalletUserMapCaptorValue = hyperwalletUserMapCaptor.getValue();
assertThat(hyperwalletUserMapCaptorValue).containsEntry("verificationStatus", "VERIFIED")
.containsEntry("businessStakeholderVerificationStatus", "VERIFIED")
.containsEntry("clientUserId", CLIENT_1_ID).containsEntry("profileType", "INDIVIDUAL")
.containsEntry("letterOfAuthorizationStatus", "VERIFIED");
final List<Map<String, Object>> documents = (List<Map<String, Object>>) hyperwalletUserMapCaptorValue
.get("documents");
assertThat(documents.get(0)).containsEntry("category", KYCConstants.HwDocuments.PROOF_OF_ADDRESS);
}
}
| 5,302 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal/kyc/BusinessStakeholdersDocumentsExtractBatchJobItemProcessorITTest.java | package com.paypal.kyc;
import com.callibrity.logging.test.LogTracker;
import com.callibrity.logging.test.LogTrackerStub;
import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException;
import com.paypal.kyc.documentextractioncommons.support.AbstractDocumentsBatchJobItemProcessor;
import com.paypal.kyc.documentextractioncommons.model.KYCConstants;
import com.paypal.kyc.stakeholdersdocumentextraction.batchjobs.BusinessStakeholdersDocumentsExtractBatchJobItem;
import com.paypal.kyc.stakeholdersdocumentextraction.batchjobs.BusinessStakeholdersDocumentsExtractBatchJobItemProcessor;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentModel;
import com.paypal.testsupport.AbstractMockEnabledIntegrationTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class BusinessStakeholdersDocumentsExtractBatchJobItemProcessorITTest extends AbstractMockEnabledIntegrationTest {
@Autowired
private BusinessStakeholdersDocumentsExtractBatchJobItemProcessor testObj;
@RegisterExtension
private final LogTrackerStub logTrackerStub = LogTrackerStub.create().recordForLevel(LogTracker.LogLevel.INFO)
.recordForType(AbstractDocumentsBatchJobItemProcessor.class);
@Test
void processItem_shouldPushFlagNotifyAndCleanDocuments_whenDocumentsCanBePushed() throws IOException {
final File hello = Files.createTempFile("hello", ".file").toFile();
final String shopId = "1234";
final String userToken = "userToken";
final String kycToken = "token";
final boolean requiresKYC = false;
final BusinessStakeholdersDocumentsExtractBatchJobItem item = createValidItem(hello, requiresKYC, shopId,
kycToken, userToken);
businessStakeHoldersEndpointMock.uploadDocument(userToken, kycToken);
miraklShopsEndpointMock.updateDocument(shopId);
usersEndpointMock.updatedUser(userToken);
testObj.processItem(null, item);
businessStakeHoldersEndpointMock.verifyUploadDocument(userToken, kycToken);
miraklShopsEndpointMock.verifyUpdateDocument(Long.parseLong(shopId));
usersEndpointMock.verifyUpdatedUser(userToken);
Assertions.assertFalse(hello.exists());
assertThat(logTrackerStub.contains("File selected to be deleted [%s]".formatted(hello.getAbsolutePath())))
.isTrue();
}
@Test
void processItem_shouldNotNotifyAndCleanDocuments_whenDocumentsCanNotBePushed() throws IOException {
final File hello = Files.createTempFile("hello", ".file").toFile();
final boolean requiresKYC = true;
final BusinessStakeholdersDocumentsExtractBatchJobItem item = createValidItem(hello, requiresKYC, "1234",
"token", "userToken");
testObj.processItem(null, item);
Assertions.assertFalse(hello.exists());
assertThat(logTrackerStub.contains("File selected to be deleted [%s]".formatted(hello.getAbsolutePath())))
.isTrue();
}
@Test
void processItem_cleanUpFile_whenSomeErrorHappens() throws IOException {
final File hello = Files.createTempFile("hello", ".file").toFile();
final boolean requiresKYC = false;
final String withouUserToken = null;
final BusinessStakeholdersDocumentsExtractBatchJobItem item = createValidItem(hello, requiresKYC, "1234",
"token", withouUserToken);
assertThatThrownBy(() -> testObj.processItem(null, item)).isInstanceOf(HMCHyperwalletAPIException.class);
Assertions.assertFalse(hello.exists());
assertThat(logTrackerStub.contains("File selected to be deleted [%s]".formatted(hello.getAbsolutePath())))
.isTrue();
}
private static BusinessStakeholdersDocumentsExtractBatchJobItem createValidItem(final File file,
final boolean requiresKYC, final String shopId, final String kycToken, final String userToken) {
final KYCDocumentModel document = KYCDocumentModel.builder().file(file)
.documentFieldName(KYCConstants.HwDocuments.PROOF_OF_AUTHORIZATION).build();
final KYCDocumentBusinessStakeHolderInfoModel kycDocument = KYCDocumentBusinessStakeHolderInfoModel.builder()
.hyperwalletProgram("DEFAULT").requiresKYC(requiresKYC).requiresLetterOfAuthorization(true)
.contact(true).documents(List.of(document)).clientUserId(shopId).token(kycToken).userToken(userToken)
.build();
return new BusinessStakeholdersDocumentsExtractBatchJobItem(kycDocument);
}
}
| 5,303 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal/kyc/KYCUserStatusResyncBatchJobITTest.java | package com.paypal.kyc;
import com.paypal.infrastructure.changestaging.service.StagedChangesPoller;
import com.paypal.infrastructure.changestaging.service.StagedChangesProcessor;
import com.paypal.infrastructure.support.date.DateUtil;
import com.paypal.infrastructure.support.date.TimeMachine;
import com.paypal.jobsystem.batchjobfailures.services.BatchJobFailedItemService;
import com.paypal.kyc.statussynchronization.batchjobs.KYCUserStatusResyncBatchJobItemProcessor;
import com.paypal.kyc.statussynchronization.jobs.KYCUserStatusResyncJob;
import com.paypal.testsupport.AbstractMockEnabledIntegrationTest;
import com.paypal.testsupport.TestJobExecutor;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockserver.model.JsonPathBody;
import org.mockserver.verify.VerificationTimes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockserver.model.HttpRequest.request;
@Transactional
class KYCUserStatusResyncBatchJobITTest extends AbstractMockEnabledIntegrationTest {
public static final int NUM_MOCKED_HYPERWALLETUSERS = 5;
@Value("${server.url}")
private String mockServerUrl;
@Autowired
private KYCUserStatusResyncBatchJobItemProcessor kycUserStatusResyncBatchJobItemProcessor;
@Autowired
private BatchJobFailedItemService batchJobFailedItemService;
@Autowired
private TestJobExecutor testJobExecutor;
@Autowired
private StagedChangesPoller stagedChangesPoller;
@Autowired
private StagedChangesProcessor stagedChangesProcessor;
@Value("${hmc.jobs.settings.resync-maxdays}")
private Integer resyncMaxDays;
@BeforeEach
void setUpFixtures() {
TimeMachine.useFixedClockAt(LocalDateTime.now());
}
@AfterEach
void tearDown() {
TimeMachine.useSystemDefaultZoneClock();
}
@Test
void shouldSynchronizeTheKYCStatus_WhenTheJobIsExecutedWithStagedChanges() {
// given
final Date to = DateUtil.convertToDate(TimeMachine.now(), UTC);
final Date from = DateUtil.convertToDate(TimeMachine.now().minusDays(resyncMaxDays), UTC);
mockServerExpectationsLoader.loadExpectationsFromFolder("mocks/testsets/kycuserstatusresyncbatchjob",
"hyperwallet", Map.of("https://uat-api.paylution.com", mockServerUrl));
mockServerExpectationsLoader.loadExpectationsFromFolder("mocks/testsets/kycuserstatusresyncbatchjob", "mirakl",
Map.of());
final int operationBatchSize = 3;
setOperationBatchSize(operationBatchSize);
// when
testJobExecutor.executeJobAndWaitForCompletion(KYCUserStatusResyncJob.class, Map.of("delta", from));
for (int i = 0; i < NUM_MOCKED_HYPERWALLETUSERS; i += operationBatchSize) {
stagedChangesPoller.performStagedChange();
}
// then
mockServerClient.verify(request().withPath("/api/shops").withMethod("PUT"), VerificationTimes.exactly(2));
verifyMiraklKYCStatusRequest("2001", "APPROVED");
verifyMiraklKYCStatusRequest("2002", "REFUSED");
verifyMiraklKYCStatusRequest("2003", "PENDING_APPROVAL");
verifyMiraklKYCStatusRequest("2005", "APPROVED");
assertThat(batchJobFailedItemService.getFailedItems("KYCUserStatusInfo")).isEmpty();
}
private void verifyMiraklKYCStatusRequest(final String shopId, final String status) {
mockServerClient.verify(
request().withPath("/api/shops").withMethod("PUT")
.withBody(JsonPathBody.jsonPath(
"$.shops[?(@.shop_id==\"%s\" && @.kyc.status == \"%s\")]".formatted(shopId, status))),
VerificationTimes.exactly(1));
}
private void setChangeStaging(final boolean useStaging) {
ReflectionTestUtils.setField(kycUserStatusResyncBatchJobItemProcessor, "useStaging", useStaging);
}
private void setOperationBatchSize(final int operationBatchSize) {
ReflectionTestUtils.setField(stagedChangesProcessor, "operationBatchSize", operationBatchSize);
}
}
| 5,304 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal/kyc/BusinessStakeholdersDocumentsExtractBatchJobItemExtractorITTest.java | package com.paypal.kyc;
import com.paypal.jobsystem.batchjob.model.BatchJobContext;
import com.paypal.kyc.stakeholdersdocumentextraction.batchjobs.BusinessStakeholdersDocumentsExtractBatchJobItem;
import com.paypal.kyc.stakeholdersdocumentextraction.batchjobs.BusinessStakeholdersDocumentsExtractBatchJobItemExtractor;
import com.paypal.testsupport.AbstractMockEnabledIntegrationTest;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Collection;
import java.util.Date;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
class BusinessStakeholdersDocumentsExtractBatchJobItemExtractorITTest extends AbstractMockEnabledIntegrationTest {
@Autowired
private BusinessStakeholdersDocumentsExtractBatchJobItemExtractor testObj;
@Mock
private BatchJobContext batchJobContextMock;
@Test
void getItems_ShouldReturnAllBusinessStakeholderDocumentsForAGivenDelta_WhenNoPartialErrorsHappened() {
final Date delta = new Date();
miraklShopsEndpointMock.getShops(delta, false, "get-shops-bstk.json");
miraklShopsDocumentsEndpointMock.getShopDocuments("1", "get-shops-documents-1.json");
miraklShopsDocumentsEndpointMock.getShopDocuments("2", "get-shops-documents-2.json");
miraklShopsDocumentsEndpointMock.getShopDocument("1001", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("1002", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("1003", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("1004", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("2001", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("2002", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("2003", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("2004", "get-shops-document.png");
final Collection<BusinessStakeholdersDocumentsExtractBatchJobItem> result = invokeGetItems(delta);
assertThat(result.stream().map(BusinessStakeholdersDocumentsExtractBatchJobItem::getItem)
.collect(Collectors.toList())).hasSize(4);
verify(batchJobContextMock, times(1)).setPartialItemExtraction(false);
verify(batchJobContextMock, times(1)).setNumberOfItemsNotSuccessfullyExtracted(0);
}
@Test
void getItems_ShouldReturnNotFailedBusinessStakeholderDocumentsForAGivenDeltaAndSetAPartialExtraction_WhenPartialErrorsHappened() {
final Date delta = new Date();
miraklShopsEndpointMock.getShops(delta, false, "get-shops-bstk.json");
miraklShopsDocumentsEndpointMock.getShopDocuments("1", "get-shops-documents-1.json");
miraklShopsDocumentsEndpointMock.getShopDocuments("2", "get-shops-documents-2.json");
miraklShopsDocumentsEndpointMock.getShopDocument("1001", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("1002", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("1003", "get-shops-document.png");
final Collection<BusinessStakeholdersDocumentsExtractBatchJobItem> result = invokeGetItems(delta);
assertThat(result.stream().map(BusinessStakeholdersDocumentsExtractBatchJobItem::getItem)
.collect(Collectors.toList())).hasSize(1);
verify(batchJobContextMock, times(1)).setPartialItemExtraction(true);
verify(batchJobContextMock, times(1)).setNumberOfItemsNotSuccessfullyExtracted(3);
}
private Collection<BusinessStakeholdersDocumentsExtractBatchJobItem> invokeGetItems(final Date delta) {
return ReflectionTestUtils.invokeMethod(testObj, "getItems", batchJobContextMock, delta);
}
}
| 5,305 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal/kyc/SellersDocumentsExtractBatchJobItemExtractorITTest.java | package com.paypal.kyc;
import com.paypal.jobsystem.batchjob.model.BatchJobContext;
import com.paypal.kyc.sellersdocumentextraction.batchjobs.SellersDocumentsExtractBatchJobItem;
import com.paypal.kyc.sellersdocumentextraction.batchjobs.SellersDocumentsExtractBatchJobItemExtractor;
import com.paypal.testsupport.AbstractMockEnabledIntegrationTest;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Collection;
import java.util.Date;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
class SellersDocumentsExtractBatchJobItemExtractorITTest extends AbstractMockEnabledIntegrationTest {
@Autowired
private SellersDocumentsExtractBatchJobItemExtractor testObj;
@Mock
private BatchJobContext batchJobContextMock;
@Test
void getItems_ShouldReturnAllSellerDocumentsForAGivenDelta_WhenNoPartialErrorsHappened() {
final Date delta = new Date();
miraklShopsEndpointMock.getShops(delta, false, "get-shops-sellers.json");
miraklShopsDocumentsEndpointMock.getShopDocuments("1", "get-shops-documents-1.json");
miraklShopsDocumentsEndpointMock.getShopDocuments("2", "get-shops-documents-2.json");
miraklShopsDocumentsEndpointMock.getShopDocument("1005", "get-shops-document.png");
miraklShopsDocumentsEndpointMock.getShopDocument("2005", "get-shops-document.png");
final Collection<SellersDocumentsExtractBatchJobItem> result = invokeGetItems(delta);
assertThat(result.stream().map(SellersDocumentsExtractBatchJobItem::getItem).collect(Collectors.toList()))
.hasSize(2);
verify(batchJobContextMock, times(1)).setPartialItemExtraction(false);
verify(batchJobContextMock, times(1)).setNumberOfItemsNotSuccessfullyExtracted(0);
}
@Test
void getItems_ShouldReturnNotFailedSellerDocumentsForAGivenDeltaAndSetAPartialExtraction_WhenPartialErrorsHappened() {
final Date delta = new Date();
miraklShopsEndpointMock.getShops(delta, false, "get-shops-sellers.json");
miraklShopsDocumentsEndpointMock.getShopDocuments("1", "get-shops-documents-1.json");
miraklShopsDocumentsEndpointMock.getShopDocuments("2", "get-shops-documents-2.json");
miraklShopsDocumentsEndpointMock.getShopDocument("1005", "get-shops-document.png");
final Collection<SellersDocumentsExtractBatchJobItem> result = invokeGetItems(delta);
assertThat(result.stream().map(SellersDocumentsExtractBatchJobItem::getItem).collect(Collectors.toList()))
.hasSize(1);
verify(batchJobContextMock, times(1)).setPartialItemExtraction(true);
verify(batchJobContextMock, times(1)).setNumberOfItemsNotSuccessfullyExtracted(1);
}
private Collection<SellersDocumentsExtractBatchJobItem> invokeGetItems(final Date delta) {
return ReflectionTestUtils.invokeMethod(testObj, "getItems", batchJobContextMock, delta);
}
}
| 5,306 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal/kyc | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/integrationTest/java/com/paypal/kyc/testsupport/HyperwalletUsersMockServerFixtures.java | package com.paypal.kyc.testsupport;
import com.paypal.testsupport.mocks.AbstractMockServerFixtures;
import org.mockserver.client.MockServerClient;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class HyperwalletUsersMockServerFixtures extends AbstractMockServerFixtures {
private static final String ISO_8601_DATE_FORMAT_REGEX = "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z";
private final String mockServerUrl;
public HyperwalletUsersMockServerFixtures(final MockServerClient mockServerClient, final String mockServerUrl) {
super(mockServerClient);
this.mockServerUrl = mockServerUrl;
}
@Override
protected String getFolder() {
return "mocks/hyperwallet/users";
}
public void mockGetHyperwalletUsers(final Date from, final Date to) {
//@formatter:off
final Map<String, List<String>> queryParameters = Map.of("createdAfter", List.of(ISO_8601_DATE_FORMAT_REGEX),
"createdBefore", List.of(ISO_8601_DATE_FORMAT_REGEX));
mockGet("/api/rest/v4/users",
Map.of("createdAfter", List.of(ISO_8601_DATE_FORMAT_REGEX),
"createdBefore", List.of(ISO_8601_DATE_FORMAT_REGEX),
"after", List.of("usr-73080ef1-79b1-4faf-8794-88d485170cdf")),
"hyperwallet-users-01.json", 200);
mockGet("/api/rest/v4/users",
Map.of("createdAfter", List.of(ISO_8601_DATE_FORMAT_REGEX),
"createdBefore", List.of(ISO_8601_DATE_FORMAT_REGEX),
"after", List.of("usr-d2c0d3f3-ba8b-4f34-b544-8206267db547")),
"hyperwallet-users-02.json", 200);
mockGet("/api/rest/v4/users", queryParameters, "hyperwallet-users-00.json", 200);
//@formatter:on
}
@Override
protected String loadResource(final String responseFile) {
return super.loadResource(responseFile, Map.of("https://uat-api.paylution.com", mockServerUrl));
}
}
| 5,307 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/batchjobs/BusinessStakeholdersDocumentsExtractBatchJobItemProcessor.java | package com.paypal.kyc.stakeholdersdocumentextraction.batchjobs;
import com.paypal.kyc.documentextractioncommons.services.KYCReadyForReviewService;
import com.paypal.kyc.documentextractioncommons.support.AbstractDocumentsBatchJobItemProcessor;
import com.paypal.kyc.stakeholdersdocumentextraction.services.HyperwalletBusinessStakeholderExtractService;
import com.paypal.kyc.stakeholdersdocumentextraction.services.MiraklBusinessStakeholderDocumentsExtractService;
import org.springframework.stereotype.Component;
/**
* Handles processing of business stakeholder documents by pushing them to Hyperwallet.
*/
@Component
public class BusinessStakeholdersDocumentsExtractBatchJobItemProcessor
extends AbstractDocumentsBatchJobItemProcessor<BusinessStakeholdersDocumentsExtractBatchJobItem> {
private final MiraklBusinessStakeholderDocumentsExtractService miraklBusinessStakeholderDocumentsExtractService;
private final HyperwalletBusinessStakeholderExtractService hyperwalletBusinessStakeholderExtractService;
public BusinessStakeholdersDocumentsExtractBatchJobItemProcessor(
final MiraklBusinessStakeholderDocumentsExtractService miraklBusinessStakeholderDocumentsExtractService,
final HyperwalletBusinessStakeholderExtractService hyperwalletBusinessStakeholderExtractService,
final KYCReadyForReviewService kycReadyForReviewService) {
super(kycReadyForReviewService);
this.miraklBusinessStakeholderDocumentsExtractService = miraklBusinessStakeholderDocumentsExtractService;
this.hyperwalletBusinessStakeholderExtractService = hyperwalletBusinessStakeholderExtractService;
}
/**
* Push and flag the {@link BusinessStakeholdersDocumentsExtractBatchJobItem} with the
* {@link HyperwalletBusinessStakeholderExtractService} and
* {@link MiraklBusinessStakeholderDocumentsExtractService}
* @param jobItem The {@link BusinessStakeholdersDocumentsExtractBatchJobItem}
* @return If document was pushed to Hyperwallet
*/
@Override
protected boolean pushAndFlagDocuments(final BusinessStakeholdersDocumentsExtractBatchJobItem jobItem) {
final boolean areDocumentsPushedToHW = hyperwalletBusinessStakeholderExtractService
.pushDocuments(jobItem.getItem());
if (areDocumentsPushedToHW) {
miraklBusinessStakeholderDocumentsExtractService
.setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse(jobItem.getItem());
}
return areDocumentsPushedToHW;
}
}
| 5,308 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/batchjobs/BusinessStakeholdersDocumentsExtractBatchJobItemExtractor.java | package com.paypal.kyc.stakeholdersdocumentextraction.batchjobs;
import com.paypal.jobsystem.batchjob.model.BatchJobContext;
import com.paypal.jobsystem.batchjobaudit.services.BatchJobTrackingService;
import com.paypal.jobsystem.batchjobsupport.support.AbstractDynamicWindowDeltaBatchJobItemsExtractor;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentsExtractionResult;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.stakeholdersdocumentextraction.services.MiraklBusinessStakeholderDocumentsExtractService;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.Date;
import java.util.stream.Collectors;
/**
* Handles the extraction of business stakeholders documents. It retrieves all documents
* from shops that have been modified in Mirakl.
*/
@Component
public class BusinessStakeholdersDocumentsExtractBatchJobItemExtractor extends
AbstractDynamicWindowDeltaBatchJobItemsExtractor<BatchJobContext, BusinessStakeholdersDocumentsExtractBatchJobItem> {
private final MiraklBusinessStakeholderDocumentsExtractService miraklBusinessStakeholderDocumentsExtractService;
public BusinessStakeholdersDocumentsExtractBatchJobItemExtractor(
final MiraklBusinessStakeholderDocumentsExtractService miraklBusinessStakeholderDocumentsExtractService,
final BatchJobTrackingService batchJobTrackingService) {
super(batchJobTrackingService);
this.miraklBusinessStakeholderDocumentsExtractService = miraklBusinessStakeholderDocumentsExtractService;
}
/**
* Retrieves all the business stakeholder documents modified since the {@code delta}
* time and returns them as a {@link Collection} of
* {@link BusinessStakeholdersDocumentsExtractBatchJobItem}
* @param delta the cut-out {@link Date}
* @return a {@link Collection} of
* {@link BusinessStakeholdersDocumentsExtractBatchJobItem}
*/
@Override
protected Collection<BusinessStakeholdersDocumentsExtractBatchJobItem> getItems(final BatchJobContext ctx,
final Date delta) {
//@formatter:off
final KYCDocumentsExtractionResult<KYCDocumentBusinessStakeHolderInfoModel> kycDocumentsExtractionResult =
miraklBusinessStakeholderDocumentsExtractService.extractBusinessStakeholderDocuments(delta);
ctx.setPartialItemExtraction(kycDocumentsExtractionResult.hasFailed());
ctx.setNumberOfItemsNotSuccessfullyExtracted(kycDocumentsExtractionResult.getNumberOfFailures());
return kycDocumentsExtractionResult.getExtractedDocuments().stream()
.map(BusinessStakeholdersDocumentsExtractBatchJobItem::new)
.collect(Collectors.toList());
//@formatter:on
}
}
| 5,309 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/batchjobs/BusinessStakeholdersDocumentsExtractBatchJob.java | package com.paypal.kyc.stakeholdersdocumentextraction.batchjobs;
import com.paypal.jobsystem.batchjob.model.BatchJobContext;
import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemProcessor;
import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemsExtractor;
import com.paypal.jobsystem.batchjobsupport.support.AbstractExtractBatchJob;
import org.springframework.stereotype.Component;
/**
* This job extracts the business stakeholders documents for all the modified shops in
* Mirakl and uploads the documents to Hyperwallet
*/
@Component
public class BusinessStakeholdersDocumentsExtractBatchJob
extends AbstractExtractBatchJob<BatchJobContext, BusinessStakeholdersDocumentsExtractBatchJobItem> {
private final BusinessStakeholdersDocumentsExtractBatchJobItemProcessor businessStakeholdersDocumentsExtractBatchJobItemProcessor;
private final BusinessStakeholdersDocumentsExtractBatchJobItemExtractor businessStakeholdersDocumentsExtractBatchJobItemExtractor;
public BusinessStakeholdersDocumentsExtractBatchJob(
final BusinessStakeholdersDocumentsExtractBatchJobItemProcessor businessStakeholdersDocumentsExtractBatchJobItemProcessor,
final BusinessStakeholdersDocumentsExtractBatchJobItemExtractor businessStakeholdersDocumentsExtractBatchJobItemExtractor) {
this.businessStakeholdersDocumentsExtractBatchJobItemProcessor = businessStakeholdersDocumentsExtractBatchJobItemProcessor;
this.businessStakeholdersDocumentsExtractBatchJobItemExtractor = businessStakeholdersDocumentsExtractBatchJobItemExtractor;
}
@Override
protected BatchJobItemProcessor<BatchJobContext, BusinessStakeholdersDocumentsExtractBatchJobItem> getBatchJobItemProcessor() {
return businessStakeholdersDocumentsExtractBatchJobItemProcessor;
}
@Override
protected BatchJobItemsExtractor<BatchJobContext, BusinessStakeholdersDocumentsExtractBatchJobItem> getBatchJobItemsExtractor() {
return businessStakeholdersDocumentsExtractBatchJobItemExtractor;
}
}
| 5,310 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/batchjobs/BusinessStakeholdersDocumentsExtractBatchJobItem.java | package com.paypal.kyc.stakeholdersdocumentextraction.batchjobs;
import com.paypal.jobsystem.batchjob.model.BatchJobItem;
import com.paypal.jobsystem.batchjobsupport.support.AbstractBatchJobItem;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
/**
* Class that holds the needed information for batch processing
* {@link KYCDocumentBusinessStakeHolderInfoModel}
*/
public class BusinessStakeholdersDocumentsExtractBatchJobItem
extends AbstractBatchJobItem<KYCDocumentBusinessStakeHolderInfoModel> {
public BusinessStakeholdersDocumentsExtractBatchJobItem(final KYCDocumentBusinessStakeHolderInfoModel item) {
super(item);
}
/**
* Returns the {@code clientUserId}, {@code BusinessStakeholderMiraklNumber} and
* {@code token} of a {@link KYCDocumentBusinessStakeHolderInfoModel}
* @return the {@link String} as the item identifier.
*/
@Override
public String getItemId() {
return getItem().getClientUserId() + "-" + getItem().getBusinessStakeholderMiraklNumber() + "-"
+ getItem().getToken();
}
/**
* Returns the type as {@link String} of the {@link BatchJobItem}
* @return {@code BusinessStakeholderDocument}
*/
@Override
public String getItemType() {
return "BusinessStakeholderDocument";
}
}
| 5,311 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/model/KYCDocumentBusinessStakeHolderInfoModel.java | package com.paypal.kyc.stakeholdersdocumentextraction.model;
import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentSideEnum;
import com.paypal.kyc.documentextractioncommons.model.KYCProofOfIdentityEnum;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.paypal.kyc.documentextractioncommons.model.KYCConstants.*;
import static com.paypal.kyc.documentextractioncommons.model.KYCConstants.HwDocuments.PROOF_OF_AUTHORIZATION;
/**
* Defines model for business stakeholder kyc verification
*/
@Slf4j
@Getter
public class KYCDocumentBusinessStakeHolderInfoModel extends KYCDocumentInfoModel {
private final String token;
private final int businessStakeholderMiraklNumber;
private final boolean requiresLetterOfAuthorization;
private final boolean contact;
private final boolean notifiedDocumentsReadyForReview;
public KYCDocumentBusinessStakeHolderInfoModel(final Builder builder) {
super(builder);
token = builder.token;
businessStakeholderMiraklNumber = builder.businessStakeholderMiraklNumber;
requiresLetterOfAuthorization = builder.requiresLetterOfAuthorization;
contact = builder.contact;
notifiedDocumentsReadyForReview = builder.notifiedDocumentsReadyForReview;
}
public static Builder builder() {
return new Builder();
}
public List<KYCDocumentModel> getIdentityDocuments() {
if (KYCProofOfIdentityEnum.PASSPORT.equals(proofOfIdentity)) {
//@formatter:off
return Stream.ofNullable(getDocuments())
.flatMap(Collection::stream)
.filter(document -> KYCDocumentCategoryEnum.IDENTIFICATION.equals(document.getDocumentCategory()))
.filter(document -> document.getDocumentSide().equals(KYCDocumentSideEnum.FRONT))
.collect(Collectors.toList());
//@formatter:on
}
//@formatter:off
return Stream.ofNullable(getDocuments())
.flatMap(Collection::stream)
.filter(document -> document.getDocumentCategory().equals(KYCDocumentCategoryEnum.IDENTIFICATION))
.collect(Collectors.toList());
//@formatter:on
}
public List<KYCDocumentModel> getLetterOfAuthorizationDocument() {
if (isContact() && isRequiresLetterOfAuthorization()) {
return Stream
.ofNullable(getDocuments()).flatMap(Collection::stream).filter(kycDocumentModel -> kycDocumentModel
.getDocumentCategory().equals(KYCDocumentCategoryEnum.AUTHORIZATION))
.collect(Collectors.toList());
}
return List.of();
}
public boolean isIdentityDocumentsFilled() {
if (Objects.nonNull(this.getProofOfIdentity()) && Objects.nonNull(this.getDocuments())) {
return this.getIdentityDocuments().size() == KYCProofOfIdentityEnum.getMiraklFields(this.proofOfIdentity)
.size();
}
return false;
}
public boolean existsLetterOfAuthorizationDocumentInMirakl() {
final List<String> documentsExistingInMirakl = Stream.ofNullable(miraklShopDocuments)
.flatMap(Collection::stream).map(MiraklShopDocument::getTypeCode).collect(Collectors.toList());
if (isRequiresLetterOfAuthorization()) {
return documentsExistingInMirakl.contains(PROOF_OF_AUTHORIZATION);
}
return false;
}
@Override
public boolean existsDocumentInMirakl() {
final List<String> documentsExistingInMirakl = Stream.ofNullable(miraklShopDocuments)
.flatMap(Collection::stream).map(MiraklShopDocument::getTypeCode).collect(Collectors.toList());
final KYCProofOfIdentityEnum proofOfIdentity = this.getProofOfIdentity();
final List<String> proofOfIdentityMiraklFields = KYCProofOfIdentityEnum.getMiraklFields(proofOfIdentity,
this.businessStakeholderMiraklNumber);
return documentsExistingInMirakl.containsAll(proofOfIdentityMiraklFields);
}
public boolean isEmpty() {
return Objects.isNull(token) && Objects.isNull(proofOfIdentity) && Objects.isNull(getDocuments());
}
public boolean hasSelectedDocumentsControlFieldsInBusinessStakeholder() {
if (requiresKYC) {
return Objects.nonNull(getProofOfIdentity());
}
return true;
}
@Override
public String getDocumentTracingIdentifier() {
return "Shop Id [%s] and Business Stakeholder number [%s]".formatted(getClientUserId(),
getBusinessStakeholderMiraklNumber());
}
public Builder toBuilder() {
//@formatter:off
return KYCDocumentBusinessStakeHolderInfoModel.builder()
.token(token)
.requiresKYC(requiresKYC)
.requiresLetterOfAuthorization(requiresLetterOfAuthorization)
.countryIsoCode(countryIsoCode)
.businessStakeholderMiraklNumber(businessStakeholderMiraklNumber)
.userToken(userToken)
.clientUserId(clientUserId)
.proofOfIdentity(proofOfIdentity)
.miraklShopDocuments(miraklShopDocuments)
.contact(contact)
.notifiedDocumentsReadyForReview(notifiedDocumentsReadyForReview)
.hyperwalletProgram(hyperwalletProgram)
.documents(getDocuments());
//@formatter:on
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof KYCDocumentBusinessStakeHolderInfoModel)) {
return false;
}
final KYCDocumentBusinessStakeHolderInfoModel that = (KYCDocumentBusinessStakeHolderInfoModel) o;
return EqualsBuilder.reflectionEquals(this, that, "miraklShopDocuments", "documents")
&& CollectionUtils.isEqualCollection(Optional.ofNullable(getMiraklShopDocuments()).orElse(List.of()),
Optional.ofNullable(that.getMiraklShopDocuments()).orElse(List.of()))
&& CollectionUtils.isEqualCollection(Optional.ofNullable(getDocuments()).orElse(List.of()),
Optional.ofNullable(that.getDocuments()).orElse(List.of()));
}
@Override
public boolean areDocumentsFilled() {
boolean proofOfIdentityFilled = true;
if (requiresKYC) {
proofOfIdentityFilled = isIdentityDocumentsFilled();
}
boolean letterOfAuthorizationRequired = true;
if (isRequiresLetterOfAuthorization()) {
letterOfAuthorizationRequired = CollectionUtils.isNotEmpty(getLetterOfAuthorizationDocument());
}
return proofOfIdentityFilled && letterOfAuthorizationRequired;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public static class Builder extends KYCDocumentInfoModel.Builder<Builder> {
private static final String BUSINESS_STAKE_HOLDER_OUT_OF_INBOUND_MESSAGE = "Business Stake Holder number {} incorrect. System only allows Business stake holder attributes from 1 to 5";
private boolean notifiedDocumentsReadyForReview;
private String token;
private int businessStakeholderMiraklNumber;
private boolean requiresLetterOfAuthorization;
private boolean contact;
@Override
public Builder getThis() {
return this;
}
public Builder businessStakeholderMiraklNumber(final Integer businessStakeHolderNumber) {
this.businessStakeholderMiraklNumber = businessStakeHolderNumber;
return this;
}
public Builder userToken(final List<MiraklAdditionalFieldValue> fields) {
getMiraklStringCustomFieldValue(fields, HYPERWALLET_USER_TOKEN_FIELD)
.ifPresent(retrievedToken -> userToken = retrievedToken);
return this;
}
public Builder token(final List<MiraklAdditionalFieldValue> fieldValues,
final Integer businessStakeHolderNumber) {
if (validateBusinessStakeHolderNumber(businessStakeHolderNumber)) {
token = getMiraklStringCustomFieldValue(fieldValues, getCustomFieldCode(
HYPERWALLET_PREFIX + STAKEHOLDER_PREFIX + STAKEHOLDER_TOKEN_PREFIX, businessStakeHolderNumber))
.orElse(null);
}
else {
log.warn(BUSINESS_STAKE_HOLDER_OUT_OF_INBOUND_MESSAGE, businessStakeHolderNumber);
}
return this;
}
public Builder requiresKYC(final List<MiraklAdditionalFieldValue> fields,
final Integer businessStakeHolderNumber) {
if (validateBusinessStakeHolderNumber(businessStakeHolderNumber)) {
getMiraklBooleanCustomFieldValue(fields,
getCustomFieldCode(HYPERWALLET_PREFIX + STAKEHOLDER_PREFIX + REQUIRED_PROOF_IDENTITY,
businessStakeHolderNumber))
.ifPresent(termsConsent -> requiresKYC = Boolean.parseBoolean(termsConsent));
}
else {
log.warn(BUSINESS_STAKE_HOLDER_OUT_OF_INBOUND_MESSAGE, businessStakeHolderNumber);
}
return this;
}
public Builder proofOfIdentity(final List<MiraklAdditionalFieldValue> fields,
final Integer businessStakeHolderNumber) {
if (validateBusinessStakeHolderNumber(businessStakeHolderNumber)) {
getMiraklSingleValueListCustomFieldValue(fields,
getCustomFieldCode(HYPERWALLET_PREFIX + STAKEHOLDER_PREFIX + STAKEHOLDER_PROOF_IDENTITY,
businessStakeHolderNumber))
.ifPresent(retrievedProofOfIdentity -> proofOfIdentity = EnumUtils
.getEnum(KYCProofOfIdentityEnum.class, retrievedProofOfIdentity));
}
else {
log.warn(BUSINESS_STAKE_HOLDER_OUT_OF_INBOUND_MESSAGE, businessStakeHolderNumber);
}
return this;
}
public Builder countryIsoCode(final List<MiraklAdditionalFieldValue> fields,
final Integer businessStakeHolderNumber) {
if (validateBusinessStakeHolderNumber(businessStakeHolderNumber)) {
getMiraklStringCustomFieldValue(fields,
getCustomFieldCode(HYPERWALLET_PREFIX + STAKEHOLDER_PREFIX + PROOF_IDENTITY_PREFIX
+ STAKEHOLDER_COUNTRY_PREFIX, businessStakeHolderNumber))
.ifPresent(retrievedCountryIsoCode -> countryIsoCode = retrievedCountryIsoCode);
}
else {
log.warn(BUSINESS_STAKE_HOLDER_OUT_OF_INBOUND_MESSAGE, businessStakeHolderNumber);
}
return this;
}
public Builder requiresLetterOfAuthorization(final List<MiraklAdditionalFieldValue> fields) {
getMiraklBooleanCustomFieldValue(fields, HYPERWALLET_KYC_REQUIRED_PROOF_AUTHORIZATION_BUSINESS_FIELD)
.ifPresent(requiresLetterOfAuthorizationValue -> requiresLetterOfAuthorization = Boolean
.parseBoolean(requiresLetterOfAuthorizationValue));
return this;
}
public Builder contact(final List<MiraklAdditionalFieldValue> fields, final int businessStakeholderNumber) {
if (validateBusinessStakeHolderNumber(businessStakeholderNumber)) {
getMiraklBooleanCustomFieldValue(fields,
getCustomFieldCode(HYPERWALLET_PREFIX + STAKEHOLDER_PREFIX + CONTACT,
businessStakeholderNumber))
.ifPresent(isContact -> contact = Boolean.parseBoolean(isContact));
}
else {
log.warn(BUSINESS_STAKE_HOLDER_OUT_OF_INBOUND_MESSAGE, businessStakeholderNumber);
}
return this;
}
@Override
public Builder documents(final List<KYCDocumentModel> documents) {
this.documents = Stream.ofNullable(documents).flatMap(Collection::stream).filter(Objects::nonNull)
.map(document -> document.toBuilder().build()).collect(Collectors.toList());
return this;
}
public Builder token(final String token) {
this.token = token;
return getThis();
}
public Builder notifiedDocumentsReadyForReview(final boolean notifiedDocumentsReadyForReview) {
this.notifiedDocumentsReadyForReview = notifiedDocumentsReadyForReview;
return this;
}
@Override
public KYCDocumentBusinessStakeHolderInfoModel build() {
return new KYCDocumentBusinessStakeHolderInfoModel(this);
}
private boolean validateBusinessStakeHolderNumber(final Integer businessStakeHolderNumber) {
return Objects.nonNull(businessStakeHolderNumber) && businessStakeHolderNumber > 0
&& businessStakeHolderNumber < 6;
}
private String getCustomFieldCode(final String customField, final Integer businessStakeHolderNumber) {
return customField.concat(String.valueOf(businessStakeHolderNumber));
}
private Optional<String> getMiraklStringCustomFieldValue(final List<MiraklAdditionalFieldValue> fields,
final String customFieldCode) {
return fields.stream().filter(field -> field.getCode().equals(customFieldCode))
.filter(MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue.class::isInstance)
.map(MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue.class::cast).findAny()
.map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue);
}
private Optional<String> getMiraklBooleanCustomFieldValue(final List<MiraklAdditionalFieldValue> fields,
final String customFieldCode) {
return fields.stream().filter(field -> field.getCode().equals(customFieldCode))
.filter(MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue.class::isInstance)
.map(MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue.class::cast).findAny()
.map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue);
}
public Builder requiresLetterOfAuthorization(final boolean requiresLetterOfAuthorization) {
this.requiresLetterOfAuthorization = requiresLetterOfAuthorization;
return this;
}
public Builder contact(final boolean contact) {
this.contact = contact;
return this;
}
}
}
| 5,312 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/model/KYCBusinessStakeholderProofOfIdentityEnum.java | package com.paypal.kyc.stakeholdersdocumentextraction.model;
import com.paypal.kyc.documentextractioncommons.model.KYCConstants;
import com.paypal.kyc.documentextractioncommons.model.KYCMiraklFields;
import java.util.List;
/**
* Enum that defines each proof of identity type for business stakeholders
*/
public enum KYCBusinessStakeholderProofOfIdentityEnum {
DRIVERS_LICENSE, GOVERNMENT_ID, PASSPORT;
/**
* Obtains a {@link List<String>} of custom parameters defined ini Mirakl for document
* based on the proof of identity received
* @param kycBusinessStakeholderProofOfIdentityEnum proof of identity
* @param businessStakeholderNumber business stakeholder position in Mirakl seller
* @return {@link List<String>} containing all required document custom parameters
*/
public static List<String> getMiraklFields(
final KYCBusinessStakeholderProofOfIdentityEnum kycBusinessStakeholderProofOfIdentityEnum,
final int businessStakeholderNumber) {
final String prefixFieldName = KYCConstants.HYPERWALLET_PREFIX + KYCConstants.STAKEHOLDER_PREFIX
+ KYCConstants.REQUIRED_PROOF_IDENTITY + businessStakeholderNumber;
return KYCMiraklFields.populateMiraklFields(prefixFieldName, kycBusinessStakeholderProofOfIdentityEnum.name());
}
}
| 5,313 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/MiraklBusinessStakeholderDocumentDownloadExtractService.java | package com.paypal.kyc.stakeholdersdocumentextraction.services;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
/**
* Interface that manages logic of downloading business stakeholder KYC files from Mirakl
*/
public interface MiraklBusinessStakeholderDocumentDownloadExtractService {
/**
* Populates all KYC documents at business stakeholder lever attached in Mirakl to
* object received as parameter
* @param kycBusinessStakeHolderInfoModel
* @return {@link KYCDocumentBusinessStakeHolderInfoModel} that contains all documents
* attached in Mirakl for an specific business stakeholder
*/
KYCDocumentBusinessStakeHolderInfoModel getBusinessStakeholderDocumentsSelectedBySeller(
KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeHolderInfoModel);
}
| 5,314 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/HyperwalletBusinessStakeholderExtractServiceImpl.java | package com.paypal.kyc.stakeholdersdocumentextraction.services;
import com.hyperwallet.clientsdk.Hyperwallet;
import com.hyperwallet.clientsdk.model.HyperwalletBusinessStakeholder;
import com.hyperwallet.clientsdk.model.HyperwalletList;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService;
import com.paypal.kyc.documentextractioncommons.services.HyperwalletDocumentUploadService;
import com.paypal.kyc.documentextractioncommons.support.AbstractHyperwalletDocumentExtractService;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.stakeholdersdocumentextraction.services.converters.KYCBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.hyperwallet.clientsdk.model.HyperwalletBusinessStakeholder.VerificationStatus.REQUIRED;
/**
* Implementation of {@link HyperwalletBusinessStakeholderExtractService}
*/
@Slf4j
@Service
@Getter
public class HyperwalletBusinessStakeholderExtractServiceImpl
extends AbstractHyperwalletDocumentExtractService<KYCDocumentBusinessStakeHolderInfoModel>
implements HyperwalletBusinessStakeholderExtractService {
private final KYCBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor kycBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor;
public HyperwalletBusinessStakeholderExtractServiceImpl(final UserHyperwalletSDKService userHyperwalletSDKService,
final HyperwalletDocumentUploadService hyperwalletDocumentUploadService,
final KYCBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor kycBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor) {
super(userHyperwalletSDKService, hyperwalletDocumentUploadService);
this.kycBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor = kycBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor;
}
/**
* {@inheritDoc}
*/
@Override
public List<String> getKYCRequiredVerificationBusinessStakeHolders(final String hyperwalletProgram,
final String userToken) {
final Hyperwallet hyperwallet = getHyperwalletSDKService()
.getHyperwalletInstanceByHyperwalletProgram(hyperwalletProgram);
final List<HyperwalletBusinessStakeholder> businessStakeholders = getBusinessStakeholders(userToken,
hyperwallet);
return businessStakeholders.stream()
.filter(hyperwalletBusinessStakeholder -> REQUIRED
.equals(hyperwalletBusinessStakeholder.getVerificationStatus()))
.map(HyperwalletBusinessStakeholder::getToken).collect(Collectors.toList());
}
private List<HyperwalletBusinessStakeholder> getBusinessStakeholders(final String userToken,
final Hyperwallet hyperwallet) {
final HyperwalletList<HyperwalletBusinessStakeholder> businessStakeHolders = hyperwallet
.listBusinessStakeholders(userToken);
return Optional.ofNullable(businessStakeHolders).map(HyperwalletList::getData)
.filter(CollectionUtils::isNotEmpty).orElse(Collections.emptyList());
}
@Override
protected List<HyperwalletVerificationDocument> getHyperwalletVerificationDocuments(
final KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeHolderInfoModel) {
return kycBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor
.execute(kycBusinessStakeHolderInfoModel);
}
}
| 5,315 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/MiraklBusinessStakeholderDocumentsExtractServiceImpl.java | package com.paypal.kyc.stakeholdersdocumentextraction.services;
import com.mirakl.client.core.exception.MiraklException;
import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue;
import com.mirakl.client.mmp.domain.shop.AbstractMiraklShop;
import com.mirakl.client.mmp.domain.shop.MiraklShop;
import com.mirakl.client.mmp.domain.shop.MiraklShops;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops;
import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest;
import com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue;
import com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.infrastructure.support.logging.LoggingConstantsUtil;
import com.paypal.kyc.stakeholdersdocumentextraction.services.converters.KYCBusinessStakeHolderConverter;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentsExtractionResult;
import com.paypal.kyc.documentextractioncommons.support.AbstractMiraklDocumentExtractServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static com.paypal.kyc.documentextractioncommons.model.KYCConstants.*;
/**
* Implementation of {@link MiraklBusinessStakeholderDocumentsExtractService}
*/
@Slf4j
@Service
public class MiraklBusinessStakeholderDocumentsExtractServiceImpl extends AbstractMiraklDocumentExtractServiceImpl
implements MiraklBusinessStakeholderDocumentsExtractService {
private final MiraklBusinessStakeholderDocumentDownloadExtractService miraklBusinessStakeholderDocumentDownloadExtractService;
private final Converter<Date, MiraklGetShopsRequest> miraklGetShopsRequestConverter;
private final KYCBusinessStakeHolderConverter kycBusinessStakeHolderConverter;
private final MiraklClient miraklOperatorClient;
public MiraklBusinessStakeholderDocumentsExtractServiceImpl(
final MiraklBusinessStakeholderDocumentDownloadExtractService miraklBusinessStakeholderDocumentDownloadExtractService,
final Converter<Date, MiraklGetShopsRequest> miraklGetShopsRequestConverter,
final KYCBusinessStakeHolderConverter kycBusinessStakeHolderConverter,
final MiraklClient miraklOperatorClient, final MailNotificationUtil kycMailNotificationUtil) {
super(miraklOperatorClient, kycMailNotificationUtil);
this.miraklBusinessStakeholderDocumentDownloadExtractService = miraklBusinessStakeholderDocumentDownloadExtractService;
this.miraklGetShopsRequestConverter = miraklGetShopsRequestConverter;
this.kycBusinessStakeHolderConverter = kycBusinessStakeHolderConverter;
this.miraklOperatorClient = miraklOperatorClient;
}
/**
* {@inheritDoc}
*/
@Override
public KYCDocumentsExtractionResult<KYCDocumentBusinessStakeHolderInfoModel> extractBusinessStakeholderDocuments(
final Date delta) {
final MiraklGetShopsRequest miraklGetShopsRequest = miraklGetShopsRequestConverter.convert(delta);
log.info("Retrieving modified shops since [{}]", delta);
final MiraklShops shops = miraklOperatorClient.getShops(miraklGetShopsRequest);
//@formatter:off
log.info("Retrieved modified shops since [{}]: [{}]", delta,
Stream.ofNullable(shops.getShops())
.flatMap(Collection::stream)
.map(MiraklShop::getId)
.collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
//@formatter:on
//@formatter:off
final List<KYCDocumentBusinessStakeHolderInfoModel> kycBusinessStakeHolderInfoModelList = Stream.ofNullable(shops.getShops())
.flatMap(Collection::stream)
.map(this::populateBusinessStakeholderForMiraklShop)
.flatMap(Collection::stream)
.collect(Collectors.toList());
//@formatter:on
//@formatter:off
final Map<String, List<KYCDocumentBusinessStakeHolderInfoModel>> shopsWithBusinessStakeholderVerificationRequired = kycBusinessStakeHolderInfoModelList.stream()
.filter(kycDocStk -> kycDocStk.isRequiresKYC() || kycDocStk.isRequiresLetterOfAuthorization())
.collect(Collectors.groupingBy(KYCDocumentInfoModel::getClientUserId));
//@formatter:on
if (!CollectionUtils.isEmpty(shopsWithBusinessStakeholderVerificationRequired)) {
//@formatter:off
log.info("Shops with KYC business stakeholder verification required: [{}]",
String.join(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR, shopsWithBusinessStakeholderVerificationRequired.keySet()));
//@formatter:on
}
skipShopsWithNonBusinessStakeholderSelectedDocuments(shopsWithBusinessStakeholderVerificationRequired);
final List<KYCDocumentBusinessStakeHolderInfoModel> shopsWithBusinessSelectedVerificationDocuments = shopsWithBusinessStakeholderVerificationRequired
.values().stream()
.filter(bstkList -> bstkList.stream().allMatch(
KYCDocumentBusinessStakeHolderInfoModel::hasSelectedDocumentsControlFieldsInBusinessStakeholder))
.flatMap(Collection::stream).collect(Collectors.toList());
final KYCDocumentsExtractionResult<KYCDocumentBusinessStakeHolderInfoModel> kycDocumentsExtractionResult = new KYCDocumentsExtractionResult<>();
//@formatter:off
shopsWithBusinessSelectedVerificationDocuments.stream()
.filter(kycBusinessStakeHolderInfoModel -> !ObjectUtils.isEmpty(kycBusinessStakeHolderInfoModel.getUserToken()))
.forEach(kycBusinessStakeHolderInfoModel -> kycDocumentsExtractionResult.addDocument(
() -> miraklBusinessStakeholderDocumentDownloadExtractService.getBusinessStakeholderDocumentsSelectedBySeller(kycBusinessStakeHolderInfoModel)));
return kycDocumentsExtractionResult;
//@formatter:on
}
/**
* {@inheritDoc}
*/
@Override
public void setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse(
final KYCDocumentBusinessStakeHolderInfoModel successfullyPushedListOfDocument) {
miraklUpdateKYCShopCall(successfullyPushedListOfDocument);
}
private List<KYCDocumentBusinessStakeHolderInfoModel> populateBusinessStakeholderForMiraklShop(
final MiraklShop miraklShop) {
//@formatter:off
return IntStream.range(1, 6)
.mapToObj(i -> kycBusinessStakeHolderConverter.convert(miraklShop, i))
.filter(Objects::nonNull)
.filter(Predicate.not(KYCDocumentBusinessStakeHolderInfoModel::isEmpty))
.collect(Collectors.toCollection(ArrayList::new));
//@formatter:on
}
private Optional<MiraklShop> extractMiraklShop(final String shopId) {
final MiraklGetShopsRequest miraklGetShopsRequest = new MiraklGetShopsRequest();
miraklGetShopsRequest.setShopIds(List.of(shopId));
log.info("Retrieving shopId [{}]", shopId);
final MiraklShops shops = miraklOperatorClient.getShops(miraklGetShopsRequest);
return Optional.ofNullable(shops).orElse(new MiraklShops()).getShops().stream()
.filter(shop -> shopId.equals(shop.getId())).findAny();
}
/**
* {@inheritDoc}
*/
@Override
public List<String> getKYCCustomValuesRequiredVerificationBusinessStakeholders(final String shopId,
final List<String> requiredVerificationBusinessStakeholderTokens) {
if (Objects.nonNull(shopId) && !CollectionUtils.isEmpty(requiredVerificationBusinessStakeholderTokens)) {
final Optional<MiraklShop> miraklShop = extractMiraklShop(shopId);
//@formatter:off
final List<String> requiredVerificationBusinessStakeHolderCodes = miraklShop
.map(AbstractMiraklShop::getAdditionalFieldValues).stream()
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(element -> element.getCode().contains(HYPERWALLET_PREFIX + STAKEHOLDER_PREFIX + STAKEHOLDER_TOKEN_PREFIX))
.filter(MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue.class::isInstance)
.map(MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue.class::cast)
.filter(element -> requiredVerificationBusinessStakeholderTokens.contains(element.getValue()))
.map(MiraklAdditionalFieldValue::getCode)
.collect(Collectors.toList());
//@formatter:on
return Optional.of(requiredVerificationBusinessStakeHolderCodes).orElse(List.of()).stream()
.map(requiredVerificationBusinessStakeHolderCode -> HYPERWALLET_PREFIX + STAKEHOLDER_PREFIX
+ REQUIRED_PROOF_IDENTITY.concat(requiredVerificationBusinessStakeHolderCode
.substring(requiredVerificationBusinessStakeHolderCode.length() - 1)))
.collect(Collectors.toList());
}
return List.of();
}
private void skipShopsWithNonBusinessStakeholderSelectedDocuments(
final Map<String, List<KYCDocumentBusinessStakeHolderInfoModel>> shopsWithBusinessStakeholderVerificationRequired) {
final Map<String, String> shopsWithNotAllBstkDocumentsSelected = shopsWithBusinessStakeholderVerificationRequired
.entrySet().stream()
.filter(entry -> entry.getValue().stream().anyMatch(Predicate.not(
KYCDocumentBusinessStakeHolderInfoModel::hasSelectedDocumentsControlFieldsInBusinessStakeholder)))
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().filter(Predicate.not(
KYCDocumentBusinessStakeHolderInfoModel::hasSelectedDocumentsControlFieldsInBusinessStakeholder))
.map(KYCDocumentBusinessStakeHolderInfoModel::getBusinessStakeholderMiraklNumber)
.map(String::valueOf).collect(Collectors.joining(","))));
if (!CollectionUtils.isEmpty(shopsWithNotAllBstkDocumentsSelected)) {
//@formatter:off
shopsWithNotAllBstkDocumentsSelected.forEach((key, value) ->
log.warn("Skipping shop with id [{}] because business stakeholders with following numbers has not selected a document for uploading [{}]", key, value));
//@formatter:on
}
}
private void miraklUpdateKYCShopCall(final KYCDocumentBusinessStakeHolderInfoModel shopToUpdate) {
final MiraklUpdateShop miraklShopToUpdate = getMiraklUpdateShopWithProofOfDocumentFields(shopToUpdate);
final MiraklUpdateShopsRequest miraklUpdateShopRequest = new MiraklUpdateShopsRequest(
List.of(miraklShopToUpdate));
try {
final MiraklUpdatedShops miraklUpdatedShops = miraklOperatorClient.updateShops(miraklUpdateShopRequest);
logUpdatedShops(miraklUpdatedShops);
}
catch (final MiraklException e) {
log.error(String.format("Something went wrong when removing flag to retrieve documents for shop [%s]",
shopToUpdate.getClientUserId()), e);
reportError(shopToUpdate.getDocumentTracingIdentifier(), e);
throw new HMCMiraklAPIException(e);
}
}
private void logUpdatedShops(final MiraklUpdatedShops miraklUpdatedShops) {
//@formatter:on
log.info("Setting required KYC and letter of authorisation flag for shop with id [{}] to false",
miraklUpdatedShops.getShopReturns().stream().map(MiraklUpdatedShopReturn::getShopUpdated)
.map(MiraklShop::getId)
.collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
//@formatter:off
}
private MiraklUpdateShop getMiraklUpdateShopWithProofOfDocumentFields(final KYCDocumentBusinessStakeHolderInfoModel shopToUpdate) {
final MiraklUpdateShop miraklUpdateShop = new MiraklUpdateShop();
miraklUpdateShop.setShopId(Long.valueOf(shopToUpdate.getClientUserId()));
final List<MiraklRequestAdditionalFieldValue> additionalValues = new ArrayList<>();
if (shopToUpdate.isRequiresKYC()) {
final MiraklRequestAdditionalFieldValue miraklRequestProofIdentity = new MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue(
HYPERWALLET_PREFIX + STAKEHOLDER_PREFIX + REQUIRED_PROOF_IDENTITY
+ shopToUpdate.getBusinessStakeholderMiraklNumber(),
Boolean.FALSE.toString().toLowerCase());
additionalValues.add(miraklRequestProofIdentity);
}
if (shopToUpdate.isRequiresLetterOfAuthorization()) {
final MiraklRequestAdditionalFieldValue miraklRequestProofOfAuthorization = new MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue(
HYPERWALLET_KYC_REQUIRED_PROOF_AUTHORIZATION_BUSINESS_FIELD,
Boolean.FALSE.toString().toLowerCase());
additionalValues.add(miraklRequestProofOfAuthorization);
}
miraklUpdateShop.setAdditionalFieldValues(additionalValues);
return miraklUpdateShop;
}
}
| 5,316 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/HyperwalletBusinessStakeholderExtractService.java | package com.paypal.kyc.stakeholdersdocumentextraction.services;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import java.util.List;
/**
* Interface that manages logic of pushing documents to Hyperwallet at business
* stakeholder level
*/
public interface HyperwalletBusinessStakeholderExtractService {
/**
* Obtains List of required verification business stakeholders based on a user token
* and an hyperwalletProgram
* @param hyperwalletProgram Program for which the verification will be obtained
* @param userToken Token of the user
* @return List of {@link String} with required verification business stakeholders
* tokens
*/
List<String> getKYCRequiredVerificationBusinessStakeHolders(String hyperwalletProgram, String userToken);
/**
* Pushes the documents into HW
* @param kycBusinessStakeHolderInfoModel Business stakeholders documents to push
* @return If the document was pushed to HW
*/
boolean pushDocuments(final KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeHolderInfoModel);
}
| 5,317 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/MiraklBusinessStakeholderDocumentsExtractService.java | package com.paypal.kyc.stakeholdersdocumentextraction.services;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentsExtractionResult;
import com.paypal.kyc.documentextractioncommons.services.MiraklDocumentsExtractService;
import java.util.Date;
import java.util.List;
/**
* Interface that manages logic of getting business stakeholder information related to KYC
* in Mirakl
*/
public interface MiraklBusinessStakeholderDocumentsExtractService extends MiraklDocumentsExtractService {
/**
* Obtains valids and requiresKYC flagged business stakeholders since a delta time
* @param delta
* @return {@link KYCDocumentsExtractionResult<KYCDocumentBusinessStakeHolderInfoModel>}
* with documents valids to be sent to other system for KYC verification, including
* information about failures during the extraction process
*/
KYCDocumentsExtractionResult<KYCDocumentBusinessStakeHolderInfoModel> extractBusinessStakeholderDocuments(
Date delta);
/**
* Obtains a list of business stakeholders defined in Mirakl based on a specific
* seller id and its business stakeholder HW tokens
* @param shopId seller Id
* @param businessStakeholderTokens business stakeholder HW tokens
* @return {@link List<KYCDocumentBusinessStakeHolderInfoModel>} list of different
* business stakeholder custom parameters identified by its number in Mirakl
*/
List<String> getKYCCustomValuesRequiredVerificationBusinessStakeholders(String shopId,
List<String> businessStakeholderTokens);
/**
* Sets KYC required verification flag for business stakeholder to false in Mirakl
* @param correctlySentBusinessStakeholderDocument
* {@link KYCDocumentBusinessStakeHolderInfoModel} a business stakeholder to be
* unchecked from KYC verification.
*/
void setBusinessStakeholderFlagKYCToPushBusinessStakeholderDocumentsToFalse(
KYCDocumentBusinessStakeHolderInfoModel correctlySentBusinessStakeholderDocument);
}
| 5,318 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/MiraklBusinessStakeholderDocumentDownloadExtractServiceImpl.java | package com.paypal.kyc.stakeholdersdocumentextraction.services;
import com.mirakl.client.core.exception.MiraklException;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentModel;
import com.paypal.kyc.documentextractioncommons.services.MiraklDocumentsSelector;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* Implementation of {@link MiraklBusinessStakeholderDocumentDownloadExtractService}
*/
@Slf4j
@Service
public class MiraklBusinessStakeholderDocumentDownloadExtractServiceImpl
implements MiraklBusinessStakeholderDocumentDownloadExtractService {
private final MiraklClient miraklMarketplacePlatformOperatorApiClient;
private final MiraklDocumentsSelector miraklKYCSelectionDocumentStrategyExecutor;
private final MailNotificationUtil kycMailNotificationUtil;
public MiraklBusinessStakeholderDocumentDownloadExtractServiceImpl(
final MiraklClient miraklMarketplacePlatformOperatorApiClient,
final MiraklDocumentsSelector miraklKYCSelectionDocumentStrategyExecutor,
final MailNotificationUtil kycMailNotificationUtil) {
this.miraklMarketplacePlatformOperatorApiClient = miraklMarketplacePlatformOperatorApiClient;
this.miraklKYCSelectionDocumentStrategyExecutor = miraklKYCSelectionDocumentStrategyExecutor;
this.kycMailNotificationUtil = kycMailNotificationUtil;
}
/**
* {@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());
//@formatter:on
return kycBusinessStakeholderInfoModelWithMiraklShops.toBuilder()
.documents(extractedBusinessStakeholderDocumentsSelectedBySeller).build();
}
private boolean isDocumentMissingForKYC(
final KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeholderInfoModelWithMiraklShops) {
//@formatter:off
return kycBusinessStakeholderInfoModelWithMiraklShops.isRequiresKYC()
&& !kycBusinessStakeholderInfoModelWithMiraklShops.existsDocumentInMirakl();
//@formatter:on
}
private boolean isLoARequiredButNotUploaded(
final KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeholderInfoModelWithMiraklShops) {
//@formatter:off
return kycBusinessStakeholderInfoModelWithMiraklShops.isRequiresLetterOfAuthorization()
&& !kycBusinessStakeholderInfoModelWithMiraklShops.existsLetterOfAuthorizationDocumentInMirakl();
//@formatter:on
}
private boolean isLoARequiredForKYCButNotUploaded(
final KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeholderInfoModelWithMiraklShops) {
//@formatter:off
// Requires KYC and LoA
return kycBusinessStakeholderInfoModelWithMiraklShops.isRequiresLetterOfAuthorization() && kycBusinessStakeholderInfoModelWithMiraklShops.isRequiresKYC()
// And LoA document is not uploaded to Mirakl
&& (!kycBusinessStakeholderInfoModelWithMiraklShops.existsDocumentInMirakl() || !kycBusinessStakeholderInfoModelWithMiraklShops.existsLetterOfAuthorizationDocumentInMirakl());
//@formatter:on
}
protected KYCDocumentBusinessStakeHolderInfoModel populateMiraklShopBusinessStakeholderDocuments(
final KYCDocumentBusinessStakeHolderInfoModel kycBusinessStakeHolderInfoModel) {
final MiraklGetShopDocumentsRequest getShopBusinessStakeholderDocumentsRequest = new MiraklGetShopDocumentsRequest(
List.of(kycBusinessStakeHolderInfoModel.getClientUserId()));
try {
log.info("Retrieving business stakeholder documents for seller with id [{}]",
kycBusinessStakeHolderInfoModel.getClientUserId());
final List<MiraklShopDocument> shopDocuments = miraklMarketplacePlatformOperatorApiClient
.getShopDocuments(getShopBusinessStakeholderDocumentsRequest);
//@formatter:off
log.info("Business stakeholder documents available for seller with id [{}]: [{}]", kycBusinessStakeHolderInfoModel.getClientUserId(),
shopDocuments.stream()
.map(miraklDocument -> "Id:" + miraklDocument.getId() + " ,fileName:" + miraklDocument.getFileName() + " ,typeCode:" + miraklDocument.getTypeCode())
.collect(Collectors.joining(" | ")));
//@formatter:on
return kycBusinessStakeHolderInfoModel.toBuilder().miraklShopDocuments(shopDocuments).build();
}
catch (final MiraklException e) {
log.error(String.format(
"Something went wrong trying to receive business stakeholder documents from Mirakl for seller with id [%s]",
kycBusinessStakeHolderInfoModel.getClientUserId()), e);
kycMailNotificationUtil.sendPlainTextEmail(
"Issue detected getting business stakeholder documents from Mirakl",
String.format("Something went wrong getting documents from Mirakl for shop Id [%s]%n%s",
String.join(",", kycBusinessStakeHolderInfoModel.getClientUserId()),
MiraklLoggingErrorsUtil.stringify(e)));
}
return kycBusinessStakeHolderInfoModel.toBuilder().build();
}
}
| 5,319 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/documentselectors/MiraklLetterOfAuthorizationBusinessStakeholderSelectorStrategy.java | package com.paypal.kyc.stakeholdersdocumentextraction.services.documentselectors;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.kyc.documentextractioncommons.support.AbstractMiraklDocumentsSelectorStrategy;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import org.springframework.stereotype.Service;
import java.util.List;
import static com.paypal.kyc.documentextractioncommons.model.KYCConstants.HwDocuments.PROOF_OF_AUTHORIZATION;
@Service
public class MiraklLetterOfAuthorizationBusinessStakeholderSelectorStrategy
extends AbstractMiraklDocumentsSelectorStrategy {
protected MiraklLetterOfAuthorizationBusinessStakeholderSelectorStrategy(final MiraklClient miraklApiClient) {
super(miraklApiClient);
}
@Override
protected List<String> getMiraklFieldNames(final KYCDocumentInfoModel source) {
return List.of(PROOF_OF_AUTHORIZATION);
}
/**
* Checks whether the strategy must be executed based on the {@code source}
* @param source the source object
* @return returns whether the strategy is applicable or not
*/
@Override
public boolean isApplicable(final KYCDocumentInfoModel source) {
if (!(source instanceof KYCDocumentBusinessStakeHolderInfoModel)) {
return false;
}
final KYCDocumentBusinessStakeHolderInfoModel kycDocumentBusinessStakeHolderInfoModel = (KYCDocumentBusinessStakeHolderInfoModel) source;
return kycDocumentBusinessStakeHolderInfoModel.isContact()
&& kycDocumentBusinessStakeHolderInfoModel.isRequiresLetterOfAuthorization();
}
}
| 5,320 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/documentselectors/MiraklProofOfIdentityBusinessStakeholderSelectorStrategy.java | package com.paypal.kyc.stakeholdersdocumentextraction.services.documentselectors;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.kyc.documentextractioncommons.support.AbstractMiraklDocumentsSelectorStrategy;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCProofOfIdentityEnum;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
@Service
public class MiraklProofOfIdentityBusinessStakeholderSelectorStrategy extends AbstractMiraklDocumentsSelectorStrategy {
protected MiraklProofOfIdentityBusinessStakeholderSelectorStrategy(final MiraklClient miraklApiClient) {
super(miraklApiClient);
}
@Override
protected List<String> getMiraklFieldNames(final KYCDocumentInfoModel source) {
final KYCDocumentBusinessStakeHolderInfoModel kycDocumentBusinessStakeHolderInfoModel = (KYCDocumentBusinessStakeHolderInfoModel) source;
return KYCProofOfIdentityEnum.getMiraklFields(source.getProofOfIdentity(),
kycDocumentBusinessStakeHolderInfoModel.getBusinessStakeholderMiraklNumber());
}
/**
* Checks whether the strategy must be executed based on the {@code source}
* @param source the source object
* @return returns whether the strategy is applicable or not
*/
@Override
public boolean isApplicable(final KYCDocumentInfoModel source) {
if (!(source instanceof KYCDocumentBusinessStakeHolderInfoModel)) {
return false;
}
final KYCDocumentBusinessStakeHolderInfoModel kycDocumentBusinessStakeHolderInfoModel = (KYCDocumentBusinessStakeHolderInfoModel) source;
return source.isRequiresKYC() && Objects.nonNull(kycDocumentBusinessStakeHolderInfoModel.getProofOfIdentity());
}
}
| 5,321 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/converters/KYCBusinessStakeholderDocumentInfoModelToLetterOfAuthorizationHyperwalletVerificationDocumentStrategy.java | package com.paypal.kyc.stakeholdersdocumentextraction.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class KYCBusinessStakeholderDocumentInfoModelToLetterOfAuthorizationHyperwalletVerificationDocumentStrategy
implements Strategy<KYCDocumentBusinessStakeHolderInfoModel, HyperwalletVerificationDocument> {
private static final String LETTER_OF_AUTHORIZATION_NAME = "letter_of_authorization_front";
private static final String LETTER_OF_AUTHORIZATION_TYPE = "LETTER_OF_AUTHORIZATION";
/**
* {@inheritDoc}
*/
@Override
public HyperwalletVerificationDocument execute(final KYCDocumentBusinessStakeHolderInfoModel source) {
//@formatter:off
final Map<String, String> uploadFiles = source.getLetterOfAuthorizationDocument()
.stream()
.collect(Collectors.toMap(kycDocumentModel -> LETTER_OF_AUTHORIZATION_NAME, kycDocumentModel -> kycDocumentModel.getFile()
.getAbsolutePath()));
//@formatter:on
final HyperwalletVerificationDocument hyperwalletVerificationDocument = new HyperwalletVerificationDocument();
hyperwalletVerificationDocument.setType(LETTER_OF_AUTHORIZATION_TYPE);
hyperwalletVerificationDocument.setCategory(KYCDocumentCategoryEnum.AUTHORIZATION.name());
hyperwalletVerificationDocument.setUploadFiles(uploadFiles);
return hyperwalletVerificationDocument;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(final KYCDocumentBusinessStakeHolderInfoModel source) {
return source.isRequiresLetterOfAuthorization() && source.isContact()
&& !ObjectUtils.isEmpty(source.getLetterOfAuthorizationDocument());
}
}
| 5,322 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/converters/DateToMiraklGetShopsRequestConverter.java | package com.paypal.kyc.stakeholdersdocumentextraction.services.converters;
import com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest;
import com.paypal.infrastructure.support.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import java.util.Date;
/***
* Converts from Date to MiraklGetShopsRequest
*/
@Service
public class DateToMiraklGetShopsRequestConverter implements Converter<Date, MiraklGetShopsRequest> {
@Override
public MiraklGetShopsRequest convert(@NonNull final Date source) {
final MiraklGetShopsRequest miraklGetShopsRequest = new MiraklGetShopsRequest();
miraklGetShopsRequest.setUpdatedSince(source);
miraklGetShopsRequest.setPaginate(false);
return miraklGetShopsRequest;
}
}
| 5,323 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/converters/MiraklShopToKYCDocumentBusinessStakeholderInfoModelConverter.java | package com.paypal.kyc.stakeholdersdocumentextraction.services.converters;
import com.mirakl.client.mmp.domain.shop.MiraklShop;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import org.springframework.stereotype.Service;
/**
* Implementation of {@link KYCBusinessStakeHolderConverter} interface
*/
@Service
public class MiraklShopToKYCDocumentBusinessStakeholderInfoModelConverter implements KYCBusinessStakeHolderConverter {
/**
* {@inheritDoc}
*/
@Override
public KYCDocumentBusinessStakeHolderInfoModel convert(final MiraklShop source,
final int businessStakeholderNumber) {
//@formatter:off
final KYCDocumentBusinessStakeHolderInfoModel kycDocStk = KYCDocumentBusinessStakeHolderInfoModel.builder()
.clientUserId(source.getId())
.businessStakeholderMiraklNumber(businessStakeholderNumber)
.countryIsoCode(source.getAdditionalFieldValues(), businessStakeholderNumber)
.userToken(source.getAdditionalFieldValues())
.token(source.getAdditionalFieldValues(), businessStakeholderNumber)
.requiresKYC(source.getAdditionalFieldValues(), businessStakeholderNumber)
.proofOfIdentity(source.getAdditionalFieldValues(), businessStakeholderNumber)
.contact(source.getAdditionalFieldValues(), businessStakeholderNumber)
.hyperwalletProgram(source.getAdditionalFieldValues())
.build();
//@formatter:on
if (kycDocStk.isContact()) {
return kycDocStk.toBuilder().requiresLetterOfAuthorization(source.getAdditionalFieldValues()).build();
}
return kycDocStk;
}
}
| 5,324 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/converters/KYCBusinessStakeHolderConverter.java | package com.paypal.kyc.stakeholdersdocumentextraction.services.converters;
import com.mirakl.client.mmp.domain.shop.MiraklShop;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import org.springframework.lang.NonNull;
/**
* Interface to convert business stakeholder objects from source class {@link MiraklShop}
* into target class {@link KYCDocumentBusinessStakeHolderInfoModel}
*/
public interface KYCBusinessStakeHolderConverter {
/**
* Method that retrieves a {@link MiraklShop} and returns a
* {@link KYCDocumentBusinessStakeHolderInfoModel}
* @param source the source object {@link MiraklShop}
* @param businessStakeholderNumber business stakeholder position in the source
* @return the returned object {@link KYCDocumentBusinessStakeHolderInfoModel}
*/
KYCDocumentBusinessStakeHolderInfoModel convert(@NonNull final MiraklShop source, int businessStakeholderNumber);
}
| 5,325 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/converters/KYCBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor.java | package com.paypal.kyc.stakeholdersdocumentextraction.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.support.strategy.MultipleAbstractStrategyExecutor;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import org.springframework.stereotype.Service;
import java.util.Set;
@Service
public class KYCBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor extends
MultipleAbstractStrategyExecutor<KYCDocumentBusinessStakeHolderInfoModel, HyperwalletVerificationDocument> {
private final Set<Strategy<KYCDocumentBusinessStakeHolderInfoModel, HyperwalletVerificationDocument>> strategies;
public KYCBusinessStakeholderDocumentInfoModelToHWVerificationDocumentExecutor(
final Set<Strategy<KYCDocumentBusinessStakeHolderInfoModel, HyperwalletVerificationDocument>> strategies) {
this.strategies = strategies;
}
@Override
protected Set<Strategy<KYCDocumentBusinessStakeHolderInfoModel, HyperwalletVerificationDocument>> getStrategies() {
return this.strategies;
}
}
| 5,326 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/stakeholdersdocumentextraction/services/converters/KYCBusinessStakeholderDocumentInfoModelToProofOfIdentityHyperwalletVerificationDocumentStrategy.java | package com.paypal.kyc.stakeholdersdocumentextraction.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class KYCBusinessStakeholderDocumentInfoModelToProofOfIdentityHyperwalletVerificationDocumentStrategy
implements Strategy<KYCDocumentBusinessStakeHolderInfoModel, HyperwalletVerificationDocument> {
/**
* {@inheritDoc}
*/
@Override
public HyperwalletVerificationDocument execute(final KYCDocumentBusinessStakeHolderInfoModel source) {
final String countryIsoCode = source.getCountryIsoCode();
//@formatter:off
final Map<String, String> uploadFiles = source.getIdentityDocuments()
.stream()
.collect(Collectors.toMap(kycDocumentModel -> source.getProofOfIdentity()
.name()
.toLowerCase() + '_' + kycDocumentModel
.getDocumentSide()
.name()
.toLowerCase(), kycDocumentModel -> kycDocumentModel.getFile()
.getAbsolutePath()));
//@formatter:on
final HyperwalletVerificationDocument hyperwalletVerificationDocument = new HyperwalletVerificationDocument();
hyperwalletVerificationDocument.setType(source.getProofOfIdentity().name());
hyperwalletVerificationDocument.setCountry(countryIsoCode);
hyperwalletVerificationDocument.setCategory(KYCDocumentCategoryEnum.IDENTIFICATION.name());
hyperwalletVerificationDocument.setUploadFiles(uploadFiles);
return hyperwalletVerificationDocument;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(final KYCDocumentBusinessStakeHolderInfoModel source) {
return Objects.nonNull(source.getProofOfIdentity()) && !ObjectUtils.isEmpty(source.getIdentityDocuments());
}
}
| 5,327 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/batchjobs/SellersDocumentsExtractBatchJobItem.java | package com.paypal.kyc.sellersdocumentextraction.batchjobs;
import com.paypal.jobsystem.batchjob.model.BatchJobItem;
import com.paypal.jobsystem.batchjobsupport.support.AbstractBatchJobItem;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
/**
* Class that holds the needed information for batch processing
* {@link KYCDocumentSellerInfoModel}
*/
public class SellersDocumentsExtractBatchJobItem extends AbstractBatchJobItem<KYCDocumentSellerInfoModel> {
protected SellersDocumentsExtractBatchJobItem(final KYCDocumentSellerInfoModel item) {
super(item);
}
/**
* Returns the {@code clientUserId} of a {@link KYCDocumentSellerInfoModel}
* @return the {@link String} as the item identifier.
*/
@Override
public String getItemId() {
return getItem().getClientUserId();
}
/**
* Returns the type as {@link String} of the {@link BatchJobItem}
* @return {@code SellerDocument}
*/
@Override
public String getItemType() {
return "SellerDocument";
}
}
| 5,328 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/batchjobs/SellersDocumentsExtractBatchJobItemExtractor.java | package com.paypal.kyc.sellersdocumentextraction.batchjobs;
import com.paypal.jobsystem.batchjob.model.BatchJobContext;
import com.paypal.jobsystem.batchjobaudit.services.BatchJobTrackingService;
import com.paypal.jobsystem.batchjobsupport.support.AbstractDynamicWindowDeltaBatchJobItemsExtractor;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentsExtractionResult;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.sellersdocumentextraction.services.MiraklSellerDocumentsExtractService;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.Date;
import java.util.stream.Collectors;
/**
* Handles the extraction of seller documents. It retrieves all documents from shops that
* have been modified in Mirakl.
*/
@Component
public class SellersDocumentsExtractBatchJobItemExtractor
extends AbstractDynamicWindowDeltaBatchJobItemsExtractor<BatchJobContext, SellersDocumentsExtractBatchJobItem> {
private final MiraklSellerDocumentsExtractService miraklSellerDocumentsExtractService;
public SellersDocumentsExtractBatchJobItemExtractor(
final MiraklSellerDocumentsExtractService miraklSellerDocumentsExtractService,
final BatchJobTrackingService batchJobTrackingService) {
super(batchJobTrackingService);
this.miraklSellerDocumentsExtractService = miraklSellerDocumentsExtractService;
}
/**
* Retrieves all the seller documents modified since the {@code delta} time and
* returns them as a {@link Collection} of {@link SellersDocumentsExtractBatchJobItem}
* @param delta the cut-out {@link Date}
* @return a {@link Collection} of {@link SellersDocumentsExtractBatchJobItem}
*/
@Override
protected Collection<SellersDocumentsExtractBatchJobItem> getItems(final BatchJobContext ctx, final Date delta) {
//@formatter:off
final KYCDocumentsExtractionResult<KYCDocumentSellerInfoModel> kycDocumentsExtractionResult =
miraklSellerDocumentsExtractService.extractProofOfIdentityAndBusinessSellerDocuments(delta);
ctx.setPartialItemExtraction(kycDocumentsExtractionResult.hasFailed());
ctx.setNumberOfItemsNotSuccessfullyExtracted(kycDocumentsExtractionResult.getNumberOfFailures());
return kycDocumentsExtractionResult.getExtractedDocuments().stream()
.map(SellersDocumentsExtractBatchJobItem::new)
.collect(Collectors.toList());
//@formatter:on
}
}
| 5,329 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/batchjobs/SellersDocumentsExtractBatchJobItemProcessor.java | package com.paypal.kyc.sellersdocumentextraction.batchjobs;
import com.paypal.kyc.documentextractioncommons.services.KYCReadyForReviewService;
import com.paypal.kyc.documentextractioncommons.support.AbstractDocumentsBatchJobItemProcessor;
import com.paypal.kyc.sellersdocumentextraction.services.HyperwalletSellerExtractService;
import com.paypal.kyc.sellersdocumentextraction.services.MiraklSellerDocumentsExtractService;
import org.springframework.stereotype.Component;
/**
* Handles processing of seller documents by pushing them to Hyperwallet.
*/
@Component
public class SellersDocumentsExtractBatchJobItemProcessor
extends AbstractDocumentsBatchJobItemProcessor<SellersDocumentsExtractBatchJobItem> {
private final MiraklSellerDocumentsExtractService miraklSellerDocumentsExtractService;
private final HyperwalletSellerExtractService hyperwalletSellerExtractService;
public SellersDocumentsExtractBatchJobItemProcessor(
final MiraklSellerDocumentsExtractService miraklSellerDocumentsExtractService,
final HyperwalletSellerExtractService hyperwalletSellerExtractService,
final KYCReadyForReviewService kycReadyForReviewService) {
super(kycReadyForReviewService);
this.miraklSellerDocumentsExtractService = miraklSellerDocumentsExtractService;
this.hyperwalletSellerExtractService = hyperwalletSellerExtractService;
}
/**
* Push and flag the {@link SellersDocumentsExtractBatchJobItem} with the
* {@link HyperwalletSellerExtractService} and
* {@link MiraklSellerDocumentsExtractService}
* @param jobItem The {@link SellersDocumentsExtractBatchJobItem}
* @return If document was pushed to Hyperwallet
*/
@Override
protected boolean pushAndFlagDocuments(final SellersDocumentsExtractBatchJobItem jobItem) {
final boolean areDocumentsPushedToHW = hyperwalletSellerExtractService.pushDocuments(jobItem.getItem());
if (areDocumentsPushedToHW) {
miraklSellerDocumentsExtractService
.setFlagToPushProofOfIdentityAndBusinessSellerDocumentsToFalse(jobItem.getItem());
}
return areDocumentsPushedToHW;
}
}
| 5,330 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/batchjobs/SellersDocumentsExtractBatchJob.java | package com.paypal.kyc.sellersdocumentextraction.batchjobs;
import com.paypal.jobsystem.batchjob.model.BatchJobContext;
import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemProcessor;
import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemsExtractor;
import com.paypal.jobsystem.batchjobsupport.support.AbstractExtractBatchJob;
import org.springframework.stereotype.Component;
/**
* This job extracts the seller documents for all the modified shops in Mirakl and uploads
* the documents to Hyperwallet
*/
@Component
public class SellersDocumentsExtractBatchJob
extends AbstractExtractBatchJob<BatchJobContext, SellersDocumentsExtractBatchJobItem> {
private final SellersDocumentsExtractBatchJobItemProcessor sellersDocumentsExtractBatchJobItemProcessor;
private final SellersDocumentsExtractBatchJobItemExtractor sellersDocumentsExtractBatchJobItemExtractor;
public SellersDocumentsExtractBatchJob(
final SellersDocumentsExtractBatchJobItemProcessor sellersDocumentsExtractBatchJobItemProcessor,
final SellersDocumentsExtractBatchJobItemExtractor sellersDocumentsExtractBatchJobItemExtractor) {
this.sellersDocumentsExtractBatchJobItemProcessor = sellersDocumentsExtractBatchJobItemProcessor;
this.sellersDocumentsExtractBatchJobItemExtractor = sellersDocumentsExtractBatchJobItemExtractor;
}
@Override
protected BatchJobItemProcessor<BatchJobContext, SellersDocumentsExtractBatchJobItem> getBatchJobItemProcessor() {
return sellersDocumentsExtractBatchJobItemProcessor;
}
@Override
protected BatchJobItemsExtractor<BatchJobContext, SellersDocumentsExtractBatchJobItem> getBatchJobItemsExtractor() {
return sellersDocumentsExtractBatchJobItemExtractor;
}
}
| 5,331 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/model/KYCProofOfAddressEnum.java | package com.paypal.kyc.sellersdocumentextraction.model;
import com.paypal.kyc.documentextractioncommons.model.KYCConstants;
import java.util.List;
import java.util.Objects;
/**
* Enum that defines proof of identity types for seller
*/
public enum KYCProofOfAddressEnum {
PASSPORT, BANK_STATEMENT, CREDIT_CARD_STATEMENT, OFFICIAL_GOVERNMENT_LETTER, PROPERTY_TAX_ASSESSMENT, TAX_RETURN, UTILITY_BILL;
public static List<String> getMiraklFields() {
return List.of(KYCConstants.HwDocuments.PROOF_OF_ADDRESS);
}
public static List<String> getMiraklFields(final KYCProofOfAddressEnum kycProofOfAddressEnum,
final int businessStakeholderMiraklNumber) {
if (Objects.isNull(kycProofOfAddressEnum)) {
return List.of();
}
return List.of(KYCConstants.HYPERWALLET_PREFIX + KYCConstants.BUSINESS_STAKEHOLDER_PREFIX
+ businessStakeholderMiraklNumber + "-" + KYCConstants.PROOF_ADDRESS_SUFFIX);
}
}
| 5,332 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/model/KYCProofOfBusinessEnum.java | package com.paypal.kyc.sellersdocumentextraction.model;
import com.paypal.kyc.documentextractioncommons.model.KYCConstants;
import java.util.List;
/**
* Enum that defines proof of business types
*/
public enum KYCProofOfBusinessEnum {
INCORPORATION, BUSINESS_REGISTRATION, OPERATING_AGREEMENT;
public static List<String> getMiraklFields() {
return List.of(KYCConstants.HwDocuments.PROOF_OF_BUSINESS);
}
}
| 5,333 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/model/KYCDocumentSellerInfoModel.java | package com.paypal.kyc.sellersdocumentextraction.model;
import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentSideEnum;
import com.paypal.kyc.documentextractioncommons.model.KYCProofOfIdentityEnum;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.paypal.kyc.documentextractioncommons.model.KYCConstants.*;
/**
* Creates an object that holds all required KYC data verification for Seller(Shop)
*/
@Slf4j
@Getter
public class KYCDocumentSellerInfoModel extends KYCDocumentInfoModel {
private final boolean professional;
private final KYCProofOfBusinessEnum proofOfBusiness;
private final KYCProofOfAddressEnum proofOfAddress;
public List<KYCDocumentModel> getIdentityDocuments() {
if (KYCProofOfIdentityEnum.PASSPORT.equals(proofOfIdentity)) {
//@formatter:off
return Stream.ofNullable(getDocuments())
.flatMap(Collection::stream)
.filter(document -> document.getDocumentCategory().equals(KYCDocumentCategoryEnum.IDENTIFICATION))
.filter(document -> document.getDocumentSide().equals(KYCDocumentSideEnum.FRONT))
.collect(Collectors.toList());
//@formatter:on
}
//@formatter:off
return Stream.ofNullable(getDocuments())
.flatMap(Collection::stream)
.filter(document -> document.getDocumentCategory().equals(KYCDocumentCategoryEnum.IDENTIFICATION))
.collect(Collectors.toList());
//@formatter:on
}
public List<KYCDocumentModel> getAddressDocuments() {
//@formatter:off
return Stream.ofNullable(getDocuments())
.flatMap(Collection::stream)
.filter(document -> document.getDocumentCategory().equals(KYCDocumentCategoryEnum.ADDRESS))
.collect(Collectors.toList());
//@formatter:on
}
public List<KYCDocumentModel> getProofOfBusinessDocuments() {
return Stream.ofNullable(getDocuments()).flatMap(Collection::stream)
.filter(document -> document.getDocumentCategory().equals(KYCDocumentCategoryEnum.BUSINESS))
.collect(Collectors.toList());
}
public boolean isIdentityDocumentsFilled() {
if (Objects.nonNull(this.getProofOfIdentity()) && Objects.nonNull(this.getDocuments())) {
return this.getIdentityDocuments().size() == KYCProofOfIdentityEnum.getMiraklFields(this.proofOfIdentity)
.size();
}
return false;
}
@Override
public boolean existsDocumentInMirakl() {
final List<String> documentsExistingInMirakl = miraklShopDocuments.stream().map(MiraklShopDocument::getTypeCode)
.collect(Collectors.toList());
final KYCProofOfIdentityEnum proofOfIdentity = this.getProofOfIdentity();
if (!isProfessional()) {
final List<String> proofOfIdentityMiraklFields = KYCProofOfIdentityEnum.getMiraklFields(proofOfIdentity);
final List<String> proofOfAddressMiraklFields = KYCProofOfAddressEnum.getMiraklFields();
return documentsExistingInMirakl.containsAll(proofOfIdentityMiraklFields)
&& documentsExistingInMirakl.containsAll(proofOfAddressMiraklFields);
}
else {
final List<String> proofOfBusinessMiraklFields = KYCProofOfBusinessEnum.getMiraklFields();
return documentsExistingInMirakl.containsAll(proofOfBusinessMiraklFields);
}
}
public boolean isAddressDocumentsFilled() {
if (Objects.nonNull(this.proofOfAddress) && Objects.nonNull(this.getDocuments())) {
return this.getAddressDocuments().size() == KYCProofOfAddressEnum.getMiraklFields().size();
}
return false;
}
public boolean isProofOfBusinessFilled() {
if (Objects.nonNull(this.proofOfBusiness) && Objects.nonNull(this.getDocuments())) {
return this.getProofOfBusinessDocuments().size() == KYCProofOfBusinessEnum.getMiraklFields().size();
}
return false;
}
public boolean hasSelectedDocumentControlFields() {
if (isProfessional()) {
return Objects.nonNull(getProofOfBusiness());
}
return Objects.nonNull(getProofOfAddress()) && Objects.nonNull(getProofOfIdentity());
}
@Override
public boolean areDocumentsFilled() {
if (isProfessional()) {
return isProofOfBusinessFilled();
}
return isAddressDocumentsFilled() && isIdentityDocumentsFilled();
}
@Override
public String getDocumentTracingIdentifier() {
return "shop Id [%s]".formatted(getClientUserId());
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final KYCDocumentSellerInfoModel that = (KYCDocumentSellerInfoModel) o;
return EqualsBuilder.reflectionEquals(this, that, "documents", "miraklShopDocuments")
&& CollectionUtils.isEqualCollection(Optional.ofNullable(getDocuments()).orElse(List.of()),
Optional.ofNullable(that.getDocuments()).orElse(List.of()))
&& CollectionUtils.isEqualCollection(Optional.ofNullable(miraklShopDocuments).orElse(List.of()),
Optional.ofNullable(that.miraklShopDocuments).orElse(List.of()));
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public KYCDocumentSellerInfoModel(final Builder builder) {
super(builder);
professional = builder.professional;
proofOfBusiness = builder.proofOfBusiness;
proofOfAddress = builder.proofOfAddress;
}
public Builder toBuilder() {
//@formatter:off
return KYCDocumentSellerInfoModel.builder()
.userToken(userToken)
.clientUserId(clientUserId)
.professional(professional)
.requiresKYC(requiresKYC)
.countryIsoCode(countryIsoCode)
.proofOfIdentity(proofOfIdentity)
.proofOfAddress(proofOfAddress)
.proofOfBusiness(proofOfBusiness)
.miraklShopDocuments(miraklShopDocuments)
.hyperwalletProgram(hyperwalletProgram)
.documents(getDocuments());
//@formatter:on
}
public static Builder builder() {
return new Builder();
}
public static class Builder extends KYCDocumentInfoModel.Builder<Builder> {
private boolean professional;
private KYCProofOfBusinessEnum proofOfBusiness;
private KYCProofOfAddressEnum proofOfAddress;
@Override
public Builder getThis() {
return this;
}
public Builder professional(final boolean professional) {
this.professional = professional;
return getThis();
}
@Override
public Builder countryIsoCode(final String countryIsoCode) {
this.countryIsoCode = countryIsoCode;
return getThis();
}
public Builder proofOfAddress(final KYCProofOfAddressEnum proofOfAddress) {
this.proofOfAddress = proofOfAddress;
return getThis();
}
public Builder proofOfBusiness(final KYCProofOfBusinessEnum proofOfBusiness) {
this.proofOfBusiness = proofOfBusiness;
return getThis();
}
public Builder userToken(final List<MiraklAdditionalFieldValue> fields) {
getMiraklStringCustomFieldValue(fields, HYPERWALLET_USER_TOKEN_FIELD)
.ifPresent(retrievedToken -> userToken = retrievedToken);
return this;
}
public Builder requiresKYC(final List<MiraklAdditionalFieldValue> fields) {
getMiraklBooleanCustomFieldValue(fields, HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD)
.ifPresent(requiresKYCValue -> requiresKYC = Boolean.parseBoolean(requiresKYCValue));
return this;
}
@Override
public Builder documents(final List<KYCDocumentModel> documents) {
this.documents = Stream.ofNullable(documents).flatMap(Collection::stream).filter(Objects::nonNull)
.map(document -> document.toBuilder().build()).collect(Collectors.toList());
return this;
}
public Builder proofOfIdentity(final List<MiraklAdditionalFieldValue> fields) {
getMiraklSingleValueListCustomFieldValue(fields, HYPERWALLET_KYC_IND_PROOF_OF_IDENTITY_FIELD)
.ifPresent(retrievedProofOfIdentity -> proofOfIdentity = EnumUtils
.getEnum(KYCProofOfIdentityEnum.class, retrievedProofOfIdentity));
return this;
}
public Builder proofOfAddress(final List<MiraklAdditionalFieldValue> fields) {
getMiraklSingleValueListCustomFieldValue(fields, HYPERWALLET_KYC_IND_PROOF_OF_ADDRESS_FIELD)
.ifPresent(retrievedProofOfAddress -> proofOfAddress = EnumUtils
.getEnum(KYCProofOfAddressEnum.class, retrievedProofOfAddress));
return this;
}
public Builder countryIsoCode(final List<MiraklAdditionalFieldValue> fields) {
getMiraklStringCustomFieldValue(fields, HYPERWALLET_KYC_IND_PROOF_OF_IDENTITY_COUNTRY_ISOCODE)
.ifPresent(retrievedCountryIsocode -> countryIsoCode = retrievedCountryIsocode);
return this;
}
public Builder proofOfBusiness(final List<MiraklAdditionalFieldValue> fields) {
getMiraklSingleValueListCustomFieldValue(fields, HYPERWALLET_KYC_PROF_PROOF_OF_BUSINESS_FIELD)
.ifPresent(retrievedProofOfBusiness -> proofOfBusiness = EnumUtils
.getEnum(KYCProofOfBusinessEnum.class, retrievedProofOfBusiness));
return this;
}
@Override
public Builder miraklShopDocuments(final List<MiraklShopDocument> miraklShopDocuments) {
this.miraklShopDocuments = Stream.ofNullable(miraklShopDocuments).flatMap(Collection::stream)
.map(miraklShopDocument -> {
final MiraklShopDocument miraklShopDocumentCopy = new MiraklShopDocument();
miraklShopDocumentCopy.setId(miraklShopDocument.getId());
miraklShopDocumentCopy.setTypeCode(miraklShopDocument.getTypeCode());
miraklShopDocumentCopy.setDateDeleted(miraklShopDocument.getDateDeleted());
miraklShopDocumentCopy.setDateUploaded(miraklShopDocument.getDateUploaded());
miraklShopDocumentCopy.setFileName(miraklShopDocument.getFileName());
miraklShopDocumentCopy.setShopId(miraklShopDocument.getShopId());
return miraklShopDocumentCopy;
}).collect(Collectors.toList());
return this;
}
@Override
public KYCDocumentSellerInfoModel build() {
return new KYCDocumentSellerInfoModel(this);
}
private Optional<String> getMiraklStringCustomFieldValue(final List<MiraklAdditionalFieldValue> fields,
final String customFieldCode) {
return fields.stream().filter(field -> field.getCode().equals(customFieldCode))
.filter(MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue.class::isInstance)
.map(MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue.class::cast).findAny()
.map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue);
}
private Optional<String> getMiraklBooleanCustomFieldValue(final List<MiraklAdditionalFieldValue> fields,
final String customFieldCode) {
return fields.stream().filter(field -> field.getCode().equals(customFieldCode))
.filter(MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue.class::isInstance)
.map(MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue.class::cast).findAny()
.map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue);
}
}
}
| 5,334 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/MiraklSellerDocumentDownloadExtractServiceImpl.java | package com.paypal.kyc.sellersdocumentextraction.services;
import com.mirakl.client.core.exception.MiraklException;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.documentextractioncommons.services.MiraklDocumentsSelector;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* Implementation of {@link MiraklSellerDocumentDownloadExtractService}
*/
@Slf4j
@Service
public class MiraklSellerDocumentDownloadExtractServiceImpl implements MiraklSellerDocumentDownloadExtractService {
private final MiraklClient miraklMarketplacePlatformOperatorApiClient;
private final MiraklDocumentsSelector miraklKYCSelectionDocumentStrategyExecutor;
private final MailNotificationUtil kycMailNotificationUtil;
public MiraklSellerDocumentDownloadExtractServiceImpl(final MiraklClient miraklMarketplacePlatformOperatorApiClient,
final MiraklDocumentsSelector miraklKYCSelectionDocumentStrategyExecutor,
final MailNotificationUtil kycMailNotificationUtil) {
this.miraklMarketplacePlatformOperatorApiClient = miraklMarketplacePlatformOperatorApiClient;
this.miraklKYCSelectionDocumentStrategyExecutor = miraklKYCSelectionDocumentStrategyExecutor;
this.kycMailNotificationUtil = kycMailNotificationUtil;
}
/**
* {@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());
//@formatter:on
return kycDocumentSellerInfoModelWithMiraklShops.toBuilder().documents(extractedDocumentsSelectedBySeller)
.build();
}
/**
* {@inheritDoc}
*/
@Override
public KYCDocumentSellerInfoModel populateMiraklShopDocuments(
final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel) {
final MiraklGetShopDocumentsRequest getShopDocumentsRequest = new MiraklGetShopDocumentsRequest(
List.of(kycDocumentSellerInfoModel.getClientUserId()));
try {
log.info("Retrieving documents for seller with id [{}]", kycDocumentSellerInfoModel.getClientUserId());
final List<MiraklShopDocument> shopDocuments = miraklMarketplacePlatformOperatorApiClient
.getShopDocuments(getShopDocumentsRequest);
log.info("Documents retrieved for seller with id [{}]: [{}]", kycDocumentSellerInfoModel.getClientUserId(),
shopDocuments.stream().map(MiraklShopDocument::getId).collect(Collectors.joining(",")));
return kycDocumentSellerInfoModel.toBuilder().miraklShopDocuments(shopDocuments).build();
}
catch (final MiraklException e) {
log.error(String.format(
"Something went wrong trying to receive documents from Mirakl for seller with id [%s]",
kycDocumentSellerInfoModel.getClientUserId()), e);
kycMailNotificationUtil.sendPlainTextEmail("Issue detected getting documents from Mirakl",
String.format("Something went wrong getting documents from Mirakl for shop Id [%s]%n%s",
String.join(",", kycDocumentSellerInfoModel.getClientUserId()),
MiraklLoggingErrorsUtil.stringify(e)));
}
return kycDocumentSellerInfoModel.toBuilder().build();
}
}
| 5,335 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/HyperwalletSellerExtractService.java | package com.paypal.kyc.sellersdocumentextraction.services;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
/**
* Interface that manages logic of pushing documents to Hyperwallet at seller level
*/
public interface HyperwalletSellerExtractService {
/**
* Pushes proof of identity/business documents into HW
* @param kycDocumentSellerInfoModel
* @return If the document was pushed to HW
*/
boolean pushDocuments(KYCDocumentSellerInfoModel kycDocumentSellerInfoModel);
}
| 5,336 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/HyperwalletSellerExtractServiceImpl.java | package com.paypal.kyc.sellersdocumentextraction.services;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService;
import com.paypal.kyc.documentextractioncommons.services.HyperwalletDocumentUploadService;
import com.paypal.kyc.documentextractioncommons.support.AbstractHyperwalletDocumentExtractService;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.sellersdocumentextraction.services.converters.KYCDocumentInfoToHWVerificationDocumentExecutor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Implementation of {@link HyperwalletSellerExtractService}
*/
@Slf4j
@Getter
@Service
public class HyperwalletSellerExtractServiceImpl
extends AbstractHyperwalletDocumentExtractService<KYCDocumentSellerInfoModel>
implements HyperwalletSellerExtractService {
private final KYCDocumentInfoToHWVerificationDocumentExecutor kycDocumentInfoToHWVerificationDocumentExecutor;
public HyperwalletSellerExtractServiceImpl(final UserHyperwalletSDKService userHyperwalletSDKService,
final HyperwalletDocumentUploadService hyperwalletDocumentUploadService,
final KYCDocumentInfoToHWVerificationDocumentExecutor kycDocumentInfoToHWVerificationDocumentExecutor) {
super(userHyperwalletSDKService, hyperwalletDocumentUploadService);
this.kycDocumentInfoToHWVerificationDocumentExecutor = kycDocumentInfoToHWVerificationDocumentExecutor;
}
@Override
protected List<HyperwalletVerificationDocument> getHyperwalletVerificationDocuments(
final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel) {
return kycDocumentInfoToHWVerificationDocumentExecutor.execute(kycDocumentSellerInfoModel);
}
}
| 5,337 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/MiraklSellerDocumentsExtractService.java | package com.paypal.kyc.sellersdocumentextraction.services;
import com.paypal.kyc.documentextractioncommons.services.MiraklDocumentsExtractService;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentsExtractionResult;
import java.util.Date;
/**
* Interface that manages logic of getting seller information related to KYC in Mirakl
*/
public interface MiraklSellerDocumentsExtractService extends MiraklDocumentsExtractService {
/**
* Obtains valid and requiresKYC flagged proof of identity/business sellers since a
* delta time
* @param delta
* @return {@link KYCDocumentsExtractionResult< KYCDocumentSellerInfoModel >} valids
* to be sent to other system for KYC verification, including information about
* failures during the extraction process
*/
KYCDocumentsExtractionResult<KYCDocumentSellerInfoModel> extractProofOfIdentityAndBusinessSellerDocuments(
Date delta);
/**
* Retrieves a KYCDocumentInfoModel filled with all the information from a MiraklShop
* id
* @param shopId Mirakl shop id
* @return {@link KYCDocumentInfoModel} Model containing Seller information
*/
KYCDocumentInfoModel extractKYCSellerDocuments(final String shopId);
/**
* Sets KYC required verification proof of identity/business flag for seller to false
* in Mirakl
* @param successFullPushedListOfDocument {@link KYCDocumentSellerInfoModel} seller to
* be unchecked from KYC verification
*/
void setFlagToPushProofOfIdentityAndBusinessSellerDocumentsToFalse(
KYCDocumentSellerInfoModel successFullPushedListOfDocument);
}
| 5,338 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/MiraklSellerDocumentDownloadExtractService.java | package com.paypal.kyc.sellersdocumentextraction.services;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
public interface MiraklSellerDocumentDownloadExtractService {
/**
* Populates all KYC documents at seller level attached in Mirakl to object received
* as parameter if all documents required are present
* @param kycDocumentSellerInfoModel
* @return {@link KYCDocumentSellerInfoModel} that contains all documents attached in
* Mirakl for an specific seller
*/
KYCDocumentSellerInfoModel getDocumentsSelectedBySeller(KYCDocumentSellerInfoModel kycDocumentSellerInfoModel);
/**
* Populates all KYC documents at seller level attached in Mirakl to object received
* as parameter
* @param kycDocumentSellerInfoModel
* @return {@link KYCDocumentSellerInfoModel} that contains all documents attached in
* Mirakl for an specific seller
*/
KYCDocumentSellerInfoModel populateMiraklShopDocuments(KYCDocumentSellerInfoModel kycDocumentSellerInfoModel);
}
| 5,339 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/MiraklSellerDocumentsExtractServiceImpl.java | package com.paypal.kyc.sellersdocumentextraction.services;
import com.mirakl.client.core.exception.MiraklException;
import com.mirakl.client.mmp.domain.shop.MiraklShop;
import com.mirakl.client.mmp.domain.shop.MiraklShops;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops;
import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest;
import com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue;
import com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.infrastructure.support.logging.LoggingConstantsUtil;
import com.paypal.kyc.documentextractioncommons.support.AbstractMiraklDocumentExtractServiceImpl;
import com.paypal.kyc.documentextractioncommons.model.KYCConstants;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentsExtractionResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Implementation of {@link MiraklSellerDocumentsExtractService}
*/
@Slf4j
@Service
public class MiraklSellerDocumentsExtractServiceImpl extends AbstractMiraklDocumentExtractServiceImpl
implements MiraklSellerDocumentsExtractService {
private final MiraklSellerDocumentDownloadExtractService miraklSellerDocumentDownloadExtractService;
private final Converter<Date, MiraklGetShopsRequest> miraklGetShopsRequestConverter;
private final Converter<MiraklShop, KYCDocumentSellerInfoModel> miraklShopKYCDocumentInfoModelConverter;
private final MiraklClient miraklOperatorClient;
public MiraklSellerDocumentsExtractServiceImpl(
final MiraklSellerDocumentDownloadExtractService miraklSellerDocumentDownloadExtractService,
final Converter<Date, MiraklGetShopsRequest> miraklGetShopsRequestConverter,
final Converter<MiraklShop, KYCDocumentSellerInfoModel> miraklShopKYCDocumentInfoModelConverter,
final MiraklClient miraklOperatorClient, final MailNotificationUtil kycMailNotificationUtil) {
super(miraklOperatorClient, kycMailNotificationUtil);
this.miraklSellerDocumentDownloadExtractService = miraklSellerDocumentDownloadExtractService;
this.miraklGetShopsRequestConverter = miraklGetShopsRequestConverter;
this.miraklShopKYCDocumentInfoModelConverter = miraklShopKYCDocumentInfoModelConverter;
this.miraklOperatorClient = miraklOperatorClient;
}
/**
* {@inheritDoc}
*/
@Override
public KYCDocumentsExtractionResult<KYCDocumentSellerInfoModel> extractProofOfIdentityAndBusinessSellerDocuments(
final Date delta) {
final MiraklGetShopsRequest miraklGetShopsRequest = miraklGetShopsRequestConverter.convert(delta);
log.info("Retrieving modified shops for proof of identity/business sellers documents since [{}]", delta);
final MiraklShops shops = miraklOperatorClient.getShops(miraklGetShopsRequest);
//@formatter:off
log.info("Retrieved modified shops since [{}]: [{}]", delta,
Stream.ofNullable(shops.getShops())
.flatMap(Collection::stream)
.map(MiraklShop::getId)
.collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
//@formatter:on
//@formatter:off
final List<KYCDocumentSellerInfoModel> kycDocumentInfoList = Stream.ofNullable(shops.getShops())
.flatMap(Collection::stream)
.map(miraklShopKYCDocumentInfoModelConverter::convert)
.collect(Collectors.toList());
//@formatter:on
//@formatter:off
final Map<Boolean, List<KYCDocumentSellerInfoModel>> documentGroups = kycDocumentInfoList.stream()
.collect(Collectors.groupingBy(KYCDocumentSellerInfoModel::isRequiresKYC));
//@formatter:on
final Collection<KYCDocumentSellerInfoModel> docsFromShopsWithVerificationRequired = CollectionUtils
.emptyIfNull(documentGroups.get(true));
final Collection<KYCDocumentSellerInfoModel> docsFromShopsWithoutVerificationRequired = CollectionUtils
.emptyIfNull(documentGroups.get(false));
if (!CollectionUtils.isEmpty(docsFromShopsWithVerificationRequired)) {
//@formatter:off
log.info("Shops with KYC seller verification required: [{}]",
docsFromShopsWithVerificationRequired.stream()
.map(KYCDocumentSellerInfoModel::getClientUserId)
.collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
//@formatter:on
}
if (!CollectionUtils.isEmpty(docsFromShopsWithoutVerificationRequired)) {
//@formatter:off
log.info("Shops without KYC seller verification required: [{}]",
docsFromShopsWithoutVerificationRequired.stream()
.map(KYCDocumentSellerInfoModel::getClientUserId)
.collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
//@formatter:on
}
skipShopsWithNonSelectedDocuments(docsFromShopsWithVerificationRequired);
//@formatter:off
final List<KYCDocumentSellerInfoModel> shopsWithSelectedVerificationDocuments = docsFromShopsWithVerificationRequired.stream()
.filter(KYCDocumentSellerInfoModel::hasSelectedDocumentControlFields)
.collect(Collectors.toList());
//@formatter:on
final KYCDocumentsExtractionResult<KYCDocumentSellerInfoModel> kycDocumentsExtractionResult = new KYCDocumentsExtractionResult<>();
//@formatter:off
shopsWithSelectedVerificationDocuments.stream()
.filter(kycDocumentInfoModel -> !ObjectUtils.isEmpty(kycDocumentInfoModel.getUserToken()))
.forEach(kycDocumentSellerInfoModel -> kycDocumentsExtractionResult.addDocument(
() -> miraklSellerDocumentDownloadExtractService.getDocumentsSelectedBySeller(kycDocumentSellerInfoModel)));
return kycDocumentsExtractionResult;
//@formatter:on
}
protected Optional<MiraklShop> extractMiraklShop(final String shopId) {
final MiraklGetShopsRequest miraklGetShopsRequest = new MiraklGetShopsRequest();
miraklGetShopsRequest.setShopIds(List.of(shopId));
log.info("Retrieving shopId [{}]", shopId);
final MiraklShops shops = miraklOperatorClient.getShops(miraklGetShopsRequest);
return Optional.ofNullable(shops).orElse(new MiraklShops()).getShops().stream()
.filter(shop -> shopId.equals(shop.getId())).findAny();
}
/**
* {@inheritDoc}
*/
@Override
public void setFlagToPushProofOfIdentityAndBusinessSellerDocumentsToFalse(
final KYCDocumentSellerInfoModel successfullyPushedListOfDocument) {
miraklUpdateShopCall(successfullyPushedListOfDocument.getClientUserId());
}
/**
* {@inheritDoc}
*/
@Override
public KYCDocumentInfoModel extractKYCSellerDocuments(final String shopId) {
return extractMiraklShop(shopId)
.map(miraklShop -> miraklSellerDocumentDownloadExtractService
.populateMiraklShopDocuments(miraklShopKYCDocumentInfoModelConverter.convert(miraklShop)))
.orElse(null);
}
private void skipShopsWithNonSelectedDocuments(
final Collection<KYCDocumentSellerInfoModel> shopsWithVerificationRequired) {
//@formatter:off
final List<KYCDocumentSellerInfoModel> shopsWithNonSelectedVerificationDocuments = shopsWithVerificationRequired.stream()
.filter(Predicate.not(KYCDocumentSellerInfoModel::hasSelectedDocumentControlFields))
.collect(Collectors.toList());
//@formatter:on
if (!CollectionUtils.isEmpty(shopsWithNonSelectedVerificationDocuments)) {
log.warn("Skipping shops for seller with non selected documents to push to hyperwallet: [{}]",
shopsWithNonSelectedVerificationDocuments.stream().map(KYCDocumentSellerInfoModel::getClientUserId)
.collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
}
}
private void miraklUpdateShopCall(final String shopId) {
final MiraklUpdateShop miraklUpdateShop = new MiraklUpdateShop();
miraklUpdateShop.setShopId(Long.valueOf(shopId));
miraklUpdateShop.setAdditionalFieldValues(
List.of(new MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue(
KYCConstants.HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD,
Boolean.FALSE.toString().toLowerCase())));
final MiraklUpdateShopsRequest miraklUpdateShopRequest = new MiraklUpdateShopsRequest(
List.of(miraklUpdateShop));
try {
final MiraklUpdatedShops miraklUpdatedShops = miraklOperatorClient.updateShops(miraklUpdateShopRequest);
logUpdatedShops(miraklUpdatedShops);
}
catch (final MiraklException e) {
log.error("Something went wrong when removing flag to retrieve documents for shop [%s]".formatted(shopId),
e);
reportError("Shop Id " + shopId, e);
throw new HMCMiraklAPIException(e);
}
}
private void logUpdatedShops(final MiraklUpdatedShops miraklUpdatedShops) {
//@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)));
//@formatter:off
}
}
| 5,340 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/documentselectors/MiraklProofOfAddressSelectorStrategy.java | package com.paypal.kyc.sellersdocumentextraction.services.documentselectors;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.kyc.documentextractioncommons.support.AbstractMiraklDocumentsSelectorStrategy;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCProofOfAddressEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
@Slf4j
@Service
public class MiraklProofOfAddressSelectorStrategy extends AbstractMiraklDocumentsSelectorStrategy {
protected MiraklProofOfAddressSelectorStrategy(final MiraklClient miraklApiClient) {
super(miraklApiClient);
}
@Override
public boolean isApplicable(final KYCDocumentInfoModel source) {
if (!(source instanceof KYCDocumentSellerInfoModel)) {
return false;
}
final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel = (KYCDocumentSellerInfoModel) source;
return Objects.nonNull(kycDocumentSellerInfoModel.getProofOfAddress());
}
@Override
protected List<String> getMiraklFieldNames(final KYCDocumentInfoModel source) {
return KYCProofOfAddressEnum.getMiraklFields();
}
}
| 5,341 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/documentselectors/MiraklProofOfBusinessSelectorStrategy.java | package com.paypal.kyc.sellersdocumentextraction.services.documentselectors;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.kyc.documentextractioncommons.support.AbstractMiraklDocumentsSelectorStrategy;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCProofOfBusinessEnum;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
@Service
public class MiraklProofOfBusinessSelectorStrategy extends AbstractMiraklDocumentsSelectorStrategy {
protected MiraklProofOfBusinessSelectorStrategy(final MiraklClient miraklApiClient) {
super(miraklApiClient);
}
@Override
protected List<String> getMiraklFieldNames(final KYCDocumentInfoModel source) {
return KYCProofOfBusinessEnum.getMiraklFields();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(final KYCDocumentInfoModel source) {
if (!(source instanceof KYCDocumentSellerInfoModel)) {
return false;
}
final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel = (KYCDocumentSellerInfoModel) source;
return Objects.nonNull(kycDocumentSellerInfoModel.getProofOfBusiness());
}
}
| 5,342 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/documentselectors/MiraklProofOfIdentitySelectorStrategy.java | package com.paypal.kyc.sellersdocumentextraction.services.documentselectors;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.kyc.documentextractioncommons.support.AbstractMiraklDocumentsSelectorStrategy;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCProofOfIdentityEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
@Slf4j
@Service
public class MiraklProofOfIdentitySelectorStrategy extends AbstractMiraklDocumentsSelectorStrategy {
protected MiraklProofOfIdentitySelectorStrategy(final MiraklClient miraklApiClient) {
super(miraklApiClient);
}
@Override
protected List<String> getMiraklFieldNames(final KYCDocumentInfoModel source) {
return KYCProofOfIdentityEnum.getMiraklFields(source.getProofOfIdentity());
}
/**
* Executes the strategy if the {@code source} is of type
* {@link KYCDocumentSellerInfoModel} and it's not a professional
* @param source the source object
* @return
*/
@Override
public boolean isApplicable(final KYCDocumentInfoModel source) {
if (!(source instanceof KYCDocumentSellerInfoModel)) {
return false;
}
final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel = (KYCDocumentSellerInfoModel) source;
return Objects.nonNull(kycDocumentSellerInfoModel.getProofOfIdentity())
&& !kycDocumentSellerInfoModel.isProfessional();
}
}
| 5,343 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/converters/KYCDocumentInfoToHWVerificationDocumentExecutor.java | package com.paypal.kyc.sellersdocumentextraction.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.support.strategy.MultipleAbstractStrategyExecutor;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import org.springframework.stereotype.Service;
import java.util.Set;
@Service
public class KYCDocumentInfoToHWVerificationDocumentExecutor
extends MultipleAbstractStrategyExecutor<KYCDocumentSellerInfoModel, HyperwalletVerificationDocument> {
private final Set<Strategy<KYCDocumentSellerInfoModel, HyperwalletVerificationDocument>> strategies;
public KYCDocumentInfoToHWVerificationDocumentExecutor(
final Set<Strategy<KYCDocumentSellerInfoModel, HyperwalletVerificationDocument>> strategies) {
this.strategies = strategies;
}
@Override
protected Set<Strategy<KYCDocumentSellerInfoModel, HyperwalletVerificationDocument>> getStrategies() {
return this.strategies;
}
}
| 5,344 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/converters/KYCDocumentInfoModelToProofOfIdentityHyperwalletVerificationDocumentStrategy.java | package com.paypal.kyc.sellersdocumentextraction.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class KYCDocumentInfoModelToProofOfIdentityHyperwalletVerificationDocumentStrategy
implements Strategy<KYCDocumentSellerInfoModel, HyperwalletVerificationDocument> {
@Override
public HyperwalletVerificationDocument execute(final KYCDocumentSellerInfoModel source) {
final String countryIsoCode = source.getCountryIsoCode();
//@formatter:off
final Map<String, String> uploadFiles = source.getIdentityDocuments()
.stream()
.collect(Collectors.toMap(kycDocumentModel -> source.getProofOfIdentity()
.name()
.toLowerCase() + '_' + kycDocumentModel
.getDocumentSide()
.name()
.toLowerCase(), kycDocumentModel -> kycDocumentModel.getFile()
.getAbsolutePath()));
//@formatter:on
final HyperwalletVerificationDocument hyperwalletVerificationDocument = new HyperwalletVerificationDocument();
hyperwalletVerificationDocument.setType(source.getProofOfIdentity().name());
hyperwalletVerificationDocument.setCountry(countryIsoCode);
hyperwalletVerificationDocument.setCategory(KYCDocumentCategoryEnum.IDENTIFICATION.name());
hyperwalletVerificationDocument.setUploadFiles(uploadFiles);
return hyperwalletVerificationDocument;
}
@Override
public boolean isApplicable(final KYCDocumentSellerInfoModel source) {
return !source.isProfessional() && Objects.nonNull(source.getProofOfIdentity())
&& !ObjectUtils.isEmpty(source.getIdentityDocuments());
}
}
| 5,345 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/converters/MiraklShopToKYCDocumentSellerInfoModelConverter.java | package com.paypal.kyc.sellersdocumentextraction.services.converters;
import com.mirakl.client.mmp.domain.shop.MiraklShop;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
/**
* Converts {@link MiraklShop} object into {@link KYCDocumentSellerInfoModel}
*/
@Service
public class MiraklShopToKYCDocumentSellerInfoModelConverter
implements Converter<MiraklShop, KYCDocumentSellerInfoModel> {
@Override
public KYCDocumentSellerInfoModel convert(@NonNull final MiraklShop source) {
//@formatter:off
return KYCDocumentSellerInfoModel.builder()
.clientUserId(source.getId())
.professional(source.isProfessional())
.userToken(source.getAdditionalFieldValues())
.requiresKYC(source.getAdditionalFieldValues())
.proofOfAddress(source.getAdditionalFieldValues())
.proofOfIdentity(source.getAdditionalFieldValues())
.proofOfBusiness(source.getAdditionalFieldValues())
.countryIsoCode(source.getAdditionalFieldValues())
.hyperwalletProgram(source.getAdditionalFieldValues())
.build();
//@formatter:on
}
}
| 5,346 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/converters/KYCDocumentInfoModelToProofOAddressHyperwalletVerificationDocumentStrategy.java | package com.paypal.kyc.sellersdocumentextraction.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class KYCDocumentInfoModelToProofOAddressHyperwalletVerificationDocumentStrategy
implements Strategy<KYCDocumentSellerInfoModel, HyperwalletVerificationDocument> {
@Override
public HyperwalletVerificationDocument execute(final KYCDocumentSellerInfoModel source) {
//@formatter:off
final Map<String, String> uploadFiles = source.getAddressDocuments()
.stream()
.collect(Collectors.toMap(kycDocumentModel -> source.getProofOfAddress()
.name()
.toLowerCase()
+ '_' + kycDocumentModel.getDocumentSide()
.name()
.toLowerCase(),
kycDocumentModel -> kycDocumentModel.getFile()
.getAbsolutePath()));
//@formatter:on
final HyperwalletVerificationDocument hyperwalletVerificationDocument = new HyperwalletVerificationDocument();
hyperwalletVerificationDocument.setType(source.getProofOfAddress().name());
hyperwalletVerificationDocument.setCategory(KYCDocumentCategoryEnum.ADDRESS.name());
hyperwalletVerificationDocument.setUploadFiles(uploadFiles);
return hyperwalletVerificationDocument;
}
@Override
public boolean isApplicable(final KYCDocumentSellerInfoModel source) {
return !source.isProfessional() && Objects.nonNull(source.getProofOfAddress())
&& !ObjectUtils.isEmpty(source.getAddressDocuments());
}
}
| 5,347 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/sellersdocumentextraction/services/converters/KYCDocumentInfoModelToProofOfBusinessHyperwalletVerificationDocumentStrategy.java | package com.paypal.kyc.sellersdocumentextraction.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class KYCDocumentInfoModelToProofOfBusinessHyperwalletVerificationDocumentStrategy
implements Strategy<KYCDocumentSellerInfoModel, HyperwalletVerificationDocument> {
/**
* {@inheritDoc}
*/
@Override
public HyperwalletVerificationDocument execute(final KYCDocumentSellerInfoModel source) {
//@formatter:off
final Map<String, String> uploadFiles = source.getProofOfBusinessDocuments()
.stream()
.collect(Collectors.toMap(kycDocumentModel -> source.getProofOfBusiness()
.name()
.toLowerCase() + '_' + kycDocumentModel
.getDocumentSide()
.name()
.toLowerCase(), kycDocumentModel -> kycDocumentModel.getFile()
.getAbsolutePath()));
//@formatter:on
final HyperwalletVerificationDocument hyperwalletVerificationDocument = new HyperwalletVerificationDocument();
hyperwalletVerificationDocument.setType(source.getProofOfBusiness().name());
hyperwalletVerificationDocument.setCategory(KYCDocumentCategoryEnum.BUSINESS.name());
hyperwalletVerificationDocument.setUploadFiles(uploadFiles);
return hyperwalletVerificationDocument;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(final KYCDocumentSellerInfoModel source) {
return source.isProfessional() && Objects.nonNull(source.getProofOfBusiness())
&& Objects.nonNull(source.getProofOfBusinessDocuments());
}
}
| 5,348 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/DocumentsExtractionJobsConfig.java | package com.paypal.kyc.documentextractioncommons;
import com.paypal.kyc.documentextractioncommons.jobs.DocumentsExtractJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Configuration class for scheduling jobs at startup
*/
@Configuration
public class DocumentsExtractionJobsConfig {
private static final String TRIGGER_SUFFIX = "Trigger";
private static final String JOB_NAME = "DocumentsExtractJob";
/**
* Creates a recurring job {@link DocumentsExtractJob}
* @return the {@link JobDetail}
*/
@Bean
public JobDetail documentsExtractJob() {
//@formatter:off
return JobBuilder.newJob(DocumentsExtractJob.class)
.withIdentity(JOB_NAME)
.storeDurably()
.build();
//@formatter:on
}
/**
* Schedules the recurring job {@link DocumentsExtractJob} with the {@code jobDetails}
* set on {@link DocumentsExtractionJobsConfig#documentsExtractJob()}
* @param jobDetails the {@link JobDetail}
* @return the {@link Trigger}
*/
@Bean
public Trigger documentsExtractJobTrigger(@Qualifier("documentsExtractJob") final JobDetail jobDetails,
@Value("${hmc.jobs.scheduling.extract-jobs.kycdocuments}") final String cronExpression) {
//@formatter:off
return TriggerBuilder.newTrigger()
.forJob(jobDetails)
.withIdentity(TRIGGER_SUFFIX + JOB_NAME)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
.build();
//@formatter:on
}
}
| 5,349 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/support/AbstractMiraklDocumentsSelectorStrategy.java | package com.paypal.kyc.documentextractioncommons.support;
import com.mirakl.client.core.exception.MiraklException;
import com.mirakl.client.mmp.domain.common.FileWrapper;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest;
import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
public abstract class AbstractMiraklDocumentsSelectorStrategy
implements Strategy<KYCDocumentInfoModel, List<KYCDocumentModel>> {
private final MiraklClient miraklApiClient;
protected AbstractMiraklDocumentsSelectorStrategy(final MiraklClient miraklApiClient) {
this.miraklApiClient = miraklApiClient;
}
@Override
public List<KYCDocumentModel> execute(final KYCDocumentInfoModel source) {
final List<String> miraklFields = getMiraklFieldNames(source);
final Map<String, String> fieldNameAnDocumentIdList = getDocumentIds(source.getMiraklShopDocuments(),
miraklFields);
final List<Pair<String, MiraklDownloadShopsDocumentsRequest>> miraklDownloadShopRequests = fieldNameAnDocumentIdList
.entrySet().stream().map(fieldNameAndDocumentIdPair -> {
final MiraklDownloadShopsDocumentsRequest miraklDownloadDocumentRequest = new MiraklDownloadShopsDocumentsRequest();
miraklDownloadDocumentRequest.setDocumentIds(List.of(fieldNameAndDocumentIdPair.getKey()));
return Pair.of(fieldNameAndDocumentIdPair.getValue(), miraklDownloadDocumentRequest);
}).collect(Collectors.toList());
// @formatter:off
return miraklDownloadShopRequests.stream()
.map(this::downloadDocument)
.collect(Collectors.toList());
// @formatter:on
}
protected abstract List<String> getMiraklFieldNames(KYCDocumentInfoModel source);
private Map<String, String> getDocumentIds(final List<MiraklShopDocument> miraklShopDocuments,
final List<String> miraklFields) {
final Map<String, String> existingDocuments = miraklShopDocuments.stream()
.collect(Collectors.toMap(MiraklShopDocument::getTypeCode, MiraklShopDocument::getId));
//@formatter:off
return miraklFields.stream()
.collect(Collectors.toMap(existingDocuments::get, Function.identity()))
.entrySet()
.stream()
.filter(miraklField -> Objects.nonNull(miraklField.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
//@formatter:on
}
private KYCDocumentModel downloadDocument(
final Pair<String, MiraklDownloadShopsDocumentsRequest> fieldNameAndDocumentIdPair) {
final MiraklDownloadShopsDocumentsRequest miraklDownloadShopsDocumentsRequest = fieldNameAndDocumentIdPair
.getValue();
final String fieldName = fieldNameAndDocumentIdPair.getKey();
final String documentId = miraklDownloadShopsDocumentsRequest.getDocumentIds().stream().findAny().orElse(null);
try {
log.info("Trying to download file with id [{}]", documentId);
final FileWrapper fileWrapper = miraklApiClient.downloadShopsDocuments(miraklDownloadShopsDocumentsRequest);
log.info("Document with id [{}] downloaded", documentId);
return KYCDocumentModel.builder().file(fileWrapper.getFile()).documentFieldName(fieldName).build();
}
catch (final MiraklException e) {
log.error("Something went wrong trying to download document with id [%s]".formatted(documentId), e);
log.error(MiraklLoggingErrorsUtil.stringify(e), e);
throw new HMCMiraklAPIException(e);
}
}
}
| 5,350 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/support/AbstractMiraklDocumentExtractServiceImpl.java | package com.paypal.kyc.documentextractioncommons.support;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.mirakl.client.core.exception.MiraklException;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import com.mirakl.client.mmp.request.shop.document.MiraklDeleteShopDocumentRequest;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.services.MiraklDocumentsExtractService;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class AbstractMiraklDocumentExtractServiceImpl implements MiraklDocumentsExtractService {
private final MiraklClient miraklOperatorClient;
private final MailNotificationUtil kycMailNotificationUtil;
protected AbstractMiraklDocumentExtractServiceImpl(final MiraklClient miraklOperatorClient,
final MailNotificationUtil kycMailNotificationUtil) {
this.miraklOperatorClient = miraklOperatorClient;
this.kycMailNotificationUtil = kycMailNotificationUtil;
}
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("java:S3864")
public void deleteAllDocumentsFromSeller(final List<KYCDocumentInfoModel> successFullPushedListOfDocuments) {
final List<MiraklShopDocument> miraklShopDocuments = Stream.ofNullable(successFullPushedListOfDocuments)
.flatMap(Collection::stream).filter(Objects::nonNull).map(KYCDocumentInfoModel::getMiraklShopDocuments)
.flatMap(Collection::stream).collect(Collectors.toList());
final List<MiraklDeleteShopDocumentRequest> miraklDeleteShopDocumentRequests = Stream
.ofNullable(miraklShopDocuments).flatMap(Collection::stream).map(MiraklShopDocument::getId)
.map(MiraklDeleteShopDocumentRequest::new).collect(Collectors.toList());
miraklDeleteShopDocumentRequests.stream()
.peek(deleteUpdatedDocumentRequest -> log.info("Deleting document from Mirakl with id [{}]",
deleteUpdatedDocumentRequest.getDocumentId()))
.forEach(miraklOperatorClient::deleteShopDocument);
}
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("java:S3864")
public void deleteDocuments(final List<MiraklShopDocument> documentsToBeDeleted) {
final List<MiraklDeleteShopDocumentRequest> miraklDeleteShopDocumentRequests = Stream
.ofNullable(documentsToBeDeleted).flatMap(Collection::stream).map(MiraklShopDocument::getId)
.map(MiraklDeleteShopDocumentRequest::new).collect(Collectors.toList());
miraklDeleteShopDocumentRequests.stream()
.peek(deleteUpdatedDocumentRequest -> log.info("Deleting document from Mirakl with id [{}]",
deleteUpdatedDocumentRequest.getDocumentId()))
.forEach(miraklOperatorClient::deleteShopDocument);
}
protected void reportError(final String shopIdentifier, final MiraklException e) {
kycMailNotificationUtil.sendPlainTextEmail("Issue setting push document flags to false in Mirakl",
"Something went wrong setting push document flag to false in Mirakl for %s%n%s"
.formatted(shopIdentifier, MiraklLoggingErrorsUtil.stringify(e)));
}
}
| 5,351 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/support/AbstractHyperwalletDocumentExtractService.java | package com.paypal.kyc.documentextractioncommons.support;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.services.HyperwalletDocumentUploadService;
import com.paypal.kyc.sellersdocumentextraction.services.HyperwalletSellerExtractServiceImpl;
import com.paypal.kyc.stakeholdersdocumentextraction.services.HyperwalletBusinessStakeholderExtractServiceImpl;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* Class that holds common functionality for both
* {@link HyperwalletBusinessStakeholderExtractServiceImpl} and
* {@link HyperwalletSellerExtractServiceImpl}
*
* @param <T> the job item type.
*/
@Slf4j
public abstract class AbstractHyperwalletDocumentExtractService<T extends KYCDocumentInfoModel> {
private final UserHyperwalletSDKService userHyperwalletSDKService;
private final HyperwalletDocumentUploadService hyperwalletDocumentUploadService;
protected AbstractHyperwalletDocumentExtractService(final UserHyperwalletSDKService userHyperwalletSDKService,
final HyperwalletDocumentUploadService hyperwalletDocumentUploadService) {
this.userHyperwalletSDKService = userHyperwalletSDKService;
this.hyperwalletDocumentUploadService = hyperwalletDocumentUploadService;
}
public boolean pushDocuments(final T kycDocumentInfoModel) {
if (!kycDocumentInfoModel.areDocumentsFilled()) {
log.warn("Mandatory documents missing for shop with id [{}] ", kycDocumentInfoModel.getClientUserId());
return false;
}
final List<HyperwalletVerificationDocument> hyperwalletVerificationDocuments = getHyperwalletVerificationDocuments(
kycDocumentInfoModel);
hyperwalletDocumentUploadService.uploadDocument(kycDocumentInfoModel, hyperwalletVerificationDocuments);
return true;
}
protected abstract List<HyperwalletVerificationDocument> getHyperwalletVerificationDocuments(
T kycDocumentInfoModel);
protected UserHyperwalletSDKService getHyperwalletSDKService() {
return userHyperwalletSDKService;
}
}
| 5,352 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/support/AbstractDocumentsBatchJobItemProcessor.java | package com.paypal.kyc.documentextractioncommons.support;
import com.paypal.jobsystem.batchjob.model.BatchJobContext;
import com.paypal.jobsystem.batchjob.model.BatchJobItem;
import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemProcessor;
import com.paypal.kyc.stakeholdersdocumentextraction.batchjobs.BusinessStakeholdersDocumentsExtractBatchJobItemProcessor;
import com.paypal.kyc.sellersdocumentextraction.batchjobs.SellersDocumentsExtractBatchJobItemProcessor;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentModel;
import com.paypal.kyc.documentextractioncommons.services.KYCReadyForReviewService;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.util.Objects;
/**
* Class that holds common functionality for both
* {@link BusinessStakeholdersDocumentsExtractBatchJobItemProcessor} and
* {@link SellersDocumentsExtractBatchJobItemProcessor}
*
* @param <T> the job item type.
*/
@Slf4j
public abstract class AbstractDocumentsBatchJobItemProcessor<T extends BatchJobItem<? extends KYCDocumentInfoModel>>
implements BatchJobItemProcessor<BatchJobContext, T> {
private final KYCReadyForReviewService kycReadyForReviewService;
protected AbstractDocumentsBatchJobItemProcessor(final KYCReadyForReviewService kycReadyForReviewService) {
this.kycReadyForReviewService = kycReadyForReviewService;
}
/**
* {@inheritDoc}
*/
@Override
public void processItem(final BatchJobContext ctx, final T jobItem) {
try {
final boolean areDocumentsPushedToHW = pushAndFlagDocuments(jobItem);
if (areDocumentsPushedToHW) {
notifyReadyToReviewDocuments(jobItem.getItem());
}
}
finally {
cleanUpDocumentsFiles(jobItem.getItem());
}
}
protected abstract boolean pushAndFlagDocuments(T jobItem);
private void notifyReadyToReviewDocuments(final KYCDocumentInfoModel kycDocumentInfoModel) {
getKycReadyForReviewService().notifyReadyForReview(kycDocumentInfoModel);
}
@SuppressWarnings("java:S3864")
protected <R extends KYCDocumentInfoModel> void cleanUpDocumentsFiles(final R successFullPushedDocument) {
log.info("Cleaning up files from disk...");
//@formatter:off
successFullPushedDocument.getDocuments().stream()
.map(KYCDocumentModel::getFile)
.filter(Objects::nonNull)
.peek(file -> log.info("File selected to be deleted [{}]", file.getAbsolutePath()))
.forEach(File::delete);
//@formatter:on
log.info("Cleaning up done successfully!");
}
protected KYCReadyForReviewService getKycReadyForReviewService() {
return kycReadyForReviewService;
}
}
| 5,353 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/model/KYCMiraklFields.java | package com.paypal.kyc.documentextractioncommons.model;
import java.util.List;
/**
* Contains logic that returns how many documents are needed when proof of identity type
* is received
*/
public interface KYCMiraklFields {
/**
* Obtains a {@link List<String>} of custom parameters defined ini Mirakl for document
* based on the proof of identity received
* @param prefixFieldName prefix field defined as custom parameter in Mirakl
* @param proofIdentityType proof of identity type received
* @return {@link List<String>} custom parameters defined in Mirakl for documents
*/
static List<String> populateMiraklFields(final String prefixFieldName, final String proofIdentityType) {
return switch (proofIdentityType) {
case "GOVERNMENT_ID", "DRIVERS_LICENSE" -> List.of(prefixFieldName + KYCConstants.PROOF_IDENTITY_SIDE_FRONT,
prefixFieldName + KYCConstants.PROOF_IDENTITY_SIDE_BACK);
case "PASSPORT" -> List.of(prefixFieldName + KYCConstants.PROOF_IDENTITY_SIDE_FRONT);
default -> List.of();
};
}
}
| 5,354 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/model/KYCDocumentsExtractionResult.java | package com.paypal.kyc.documentextractioncommons.model;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
/**
* This class holds the results of a document extraction, storing the extracted documents
* along some error information related to the extraction process.
*
* @param <T> The type of {@link KYCDocumentInfoModel}, so this class can be used both for
* Seller and BusinessStakeholder documents.
*/
public class KYCDocumentsExtractionResult<T extends KYCDocumentInfoModel> {
private int numberOfFailures = 0;
private final List<T> kycDocumentInfoModels = new ArrayList<>();
/**
* Adds a new document to the extraction process result. It receives a method that
* should return the document to be added. If an exception is thrown by the method it
* will increase the internal count of failures in the extraction process.
* @param documentSupplier a method returning the extracted document to be added to
* the result.
*/
public void addDocument(final Supplier<T> documentSupplier) {
try {
kycDocumentInfoModels.add(documentSupplier.get());
}
catch (final Exception e) {
numberOfFailures++;
}
}
/**
* Returns the list of extracted documents.
* @return a list of extracted documents.
*/
public List<T> getExtractedDocuments() {
return kycDocumentInfoModels;
}
/**
* Checks if there has been errors during the extraction process.
* @return a boolean indicating if any error was captured.
*/
public boolean hasFailed() {
return numberOfFailures != 0;
}
/**
* Return the number of errors captured during the extraction process.
* @return the number of errors captured during the extraction process.
*/
public int getNumberOfFailures() {
return numberOfFailures;
}
}
| 5,355 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/model/KYCDocumentSideEnum.java | package com.paypal.kyc.documentextractioncommons.model;
/**
* Enum that defines possible side for documents
*/
public enum KYCDocumentSideEnum {
FRONT, BACK;
public static KYCDocumentSideEnum getDocumentSideByFieldName(final String fieldName) {
if (fieldName.toLowerCase().endsWith("back")) {
return BACK;
}
else {
return FRONT;
}
}
}
| 5,356 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/model/KYCDocumentInfoModel.java | package com.paypal.kyc.documentextractioncommons.model;
import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import lombok.Getter;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.io.Serializable;
import java.util.List;
import java.util.Optional;
import static com.paypal.kyc.documentextractioncommons.model.KYCConstants.HW_PROGRAM;
/**
* Model where all KYC Models must extend (except KYCDocumentModel)
*/
@Getter
public class KYCDocumentInfoModel implements Serializable {
protected final String userToken;
protected final String clientUserId;
protected final boolean requiresKYC;
protected final String countryIsoCode;
protected final KYCProofOfIdentityEnum proofOfIdentity;
protected final transient List<MiraklShopDocument> miraklShopDocuments;
protected final String hyperwalletProgram;
private final List<KYCDocumentModel> documents;
protected KYCDocumentInfoModel(final Builder<?> builder) {
userToken = builder.userToken;
clientUserId = builder.clientUserId;
countryIsoCode = builder.countryIsoCode;
requiresKYC = builder.requiresKYC;
proofOfIdentity = builder.proofOfIdentity;
miraklShopDocuments = builder.miraklShopDocuments;
documents = builder.documents;
hyperwalletProgram = builder.hyperwalletProgram;
}
@SuppressWarnings("java:S3740")
public static Builder builder() {
return new Builder() {
@Override
public Builder getThis() {
return this;
}
};
}
public boolean existsDocumentInMirakl() {
return false;
}
public boolean areDocumentsFilled() {
return false;
}
public String getDocumentTracingIdentifier() {
return StringUtils.EMPTY;
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof KYCDocumentInfoModel)) {
return false;
}
final KYCDocumentInfoModel that = (KYCDocumentInfoModel) o;
return EqualsBuilder.reflectionEquals(this, that, "miraklShopDocuments", "documents")
&& CollectionUtils.isEqualCollection(Optional.ofNullable(getMiraklShopDocuments()).orElse(List.of()),
Optional.ofNullable(that.getMiraklShopDocuments()).orElse(List.of()))
&& CollectionUtils.isEqualCollection(Optional.ofNullable(getDocuments()).orElse(List.of()),
Optional.ofNullable(that.getDocuments()).orElse(List.of()));
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public abstract static class Builder<T extends Builder<T>> {
protected String userToken;
protected String clientUserId;
protected boolean requiresKYC;
protected String countryIsoCode;
protected KYCProofOfIdentityEnum proofOfIdentity;
protected List<MiraklShopDocument> miraklShopDocuments;
protected List<KYCDocumentModel> documents;
protected String hyperwalletProgram;
public abstract T getThis();
public T userToken(final String userToken) {
this.userToken = userToken;
return getThis();
}
public T clientUserId(final String clientUserId) {
this.clientUserId = clientUserId;
return getThis();
}
public T requiresKYC(final boolean requiresKYC) {
this.requiresKYC = requiresKYC;
return getThis();
}
public T proofOfIdentity(final KYCProofOfIdentityEnum proofOfIdentity) {
this.proofOfIdentity = proofOfIdentity;
return getThis();
}
public T miraklShopDocuments(final List<MiraklShopDocument> miraklShopDocuments) {
this.miraklShopDocuments = miraklShopDocuments;
return getThis();
}
public T documents(final List<KYCDocumentModel> documents) {
this.documents = documents;
return getThis();
}
public T countryIsoCode(final String countryIsoCode) {
this.countryIsoCode = countryIsoCode;
return getThis();
}
public T hyperwalletProgram(final String hyperwalletProgram) {
this.hyperwalletProgram = hyperwalletProgram;
return getThis();
}
public T hyperwalletProgram(final List<MiraklAdditionalFieldValue> fields) {
getMiraklSingleValueListCustomFieldValue(fields, HW_PROGRAM)
.ifPresent(retrievedHyperwalletProgram -> this.hyperwalletProgram = retrievedHyperwalletProgram);
return getThis();
}
public KYCDocumentInfoModel build() {
return new KYCDocumentInfoModel(this);
}
protected Optional<String> getMiraklSingleValueListCustomFieldValue(
final List<MiraklAdditionalFieldValue> fields, final String customFieldCode) {
//@formatter:off
return fields.stream()
.filter(field -> field.getCode().equals(customFieldCode))
.filter(MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue.class::isInstance)
.map(MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue.class::cast).findAny()
.map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue);
//@formatter:on
}
}
}
| 5,357 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/model/KYCProofOfIdentityEnum.java | package com.paypal.kyc.documentextractioncommons.model;
import java.util.List;
import java.util.Objects;
/**
* Enum that defines proof of identity types
*/
public enum KYCProofOfIdentityEnum implements KYCMiraklFields {
DRIVERS_LICENSE, GOVERNMENT_ID, PASSPORT;
public static List<String> getMiraklFields(final KYCProofOfIdentityEnum kycProofOfIdentityEnum) {
if (Objects.isNull(kycProofOfIdentityEnum)) {
return List.of();
}
final String prefixFieldName = KYCConstants.HYPERWALLET_PREFIX + KYCConstants.INDIVIDUAL_PREFIX
+ KYCConstants.PROOF_IDENTITY_PREFIX;
return KYCMiraklFields.populateMiraklFields(prefixFieldName, kycProofOfIdentityEnum.name());
}
public static List<String> getMiraklFields(final KYCProofOfIdentityEnum kycProofOfIdentityEnum,
final int businessStakeholderMiraklNumber) {
if (Objects.isNull(kycProofOfIdentityEnum)) {
return List.of();
}
final String prefixFieldName = KYCConstants.HYPERWALLET_PREFIX + KYCConstants.BUSINESS_STAKEHOLDER_PREFIX
+ businessStakeholderMiraklNumber + "-" + KYCConstants.PROOF_IDENTITY_PREFIX;
return KYCMiraklFields.populateMiraklFields(prefixFieldName, kycProofOfIdentityEnum.name());
}
}
| 5,358 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/model/KYCConstants.java | package com.paypal.kyc.documentextractioncommons.model;
import java.util.List;
/**
* Defines constants needed and defined base on custom parameters in Mirakl
*/
public final class KYCConstants {
private KYCConstants() {
}
public static final String HYPERWALLET_PREFIX = "hw-";
public static final String INDIVIDUAL_PREFIX = "ind-";
public static final String BUSINESS_STAKEHOLDER_PREFIX = "bsh";
public static final String STAKEHOLDER_PREFIX = "stakeholder-";
public static final String STAKEHOLDER_COUNTRY_PREFIX = "ctry-";
public static final String STAKEHOLDER_TOKEN_PREFIX = "token-";
public static final String REQUIRED_PROOF_IDENTITY = "req-proof-identity-";
public static final String PROOF_IDENTITY_PREFIX = "proof-identity-";
public static final String PROOF_ADDRESS_SUFFIX = "proof-address";
public static final String PROOF_AUTHORIZATION_PREFIX = "proof-authorization-";
public static final String CONTACT = "business-contact-";
public static final String STAKEHOLDER_PROOF_IDENTITY = "proof-identity-type-";
public static final String PROOF_IDENTITY_SIDE_FRONT = "front";
public static final String PROOF_IDENTITY_SIDE_BACK = "back";
public static final String HW_PROGRAM = "hw-program";
public static final String HYPERWALLET_KYC_REQUIRED_PROOF_IDENTITY_BUSINESS_FIELD = "hw-kyc-req-proof-identity-business";
public static final String HYPERWALLET_KYC_REQUIRED_PROOF_AUTHORIZATION_BUSINESS_FIELD = "hw-kyc-req-proof-authorization";
public static final String HYPERWALLET_KYC_IND_PROOF_OF_IDENTITY_FIELD = "hw-ind-proof-identity-type";
public static final String HYPERWALLET_KYC_PROF_PROOF_OF_BUSINESS_FIELD = "hw-prof-proof-business-type";
public static final String HYPERWALLET_KYC_IND_PROOF_OF_IDENTITY_COUNTRY_ISOCODE = "hw-ind-proof-identity-country";
public static final String HYPERWALLET_KYC_IND_PROOF_OF_ADDRESS_FIELD = "hw-ind-proof-address-type";
public static final String HYPERWALLET_USER_TOKEN_FIELD = "hw-user-token";
public static final class HwDocuments {
private HwDocuments() {
}
public static final String PROOF_OF_IDENTITY_FRONT = "hw-ind-proof-identity-front";
public static final String PROOF_OF_IDENTITY_BACK = "hw-ind-proof-identity-back";
public static final String PROOF_OF_BUSINESS = "hw-prof-proof-business-front";
public static final String PROOF_OF_ADDRESS = "hw-ind-proof-address";
public static final String PROOF_OF_IDENTITY_FRONT_BSH1 = "hw-bsh1-proof-identity-front";
public static final String PROOF_OF_IDENTITY_FRONT_BSH2 = "hw-bsh2-proof-identity-front";
public static final String PROOF_OF_IDENTITY_FRONT_BSH3 = "hw-bsh3-proof-identity-front";
public static final String PROOF_OF_IDENTITY_FRONT_BSH4 = "hw-bsh4-proof-identity-front";
public static final String PROOF_OF_IDENTITY_FRONT_BSH5 = "hw-bsh5-proof-identity-front";
public static final String PROOF_OF_IDENTITY_BACK_BSH1 = "hw-bsh1-proof-identity-back";
public static final String PROOF_OF_IDENTITY_BACK_BSH2 = "hw-bsh2-proof-identity-back";
public static final String PROOF_OF_IDENTITY_BACK_BSH3 = "hw-bsh3-proof-identity-back";
public static final String PROOF_OF_IDENTITY_BACK_BSH4 = "hw-bsh4-proof-identity-back";
public static final String PROOF_OF_IDENTITY_BACK_BSH5 = "hw-bsh5-proof-identity-back";
public static final String PROOF_OF_AUTHORIZATION = "hw-bsh-letter-authorization";
public static List<String> getAllDocumentsTypes() {
return List.of(PROOF_OF_IDENTITY_FRONT, PROOF_OF_IDENTITY_BACK, PROOF_OF_ADDRESS);
}
}
public static final class HwWebhookNotificationType {
private HwWebhookNotificationType() {
}
public static final String USERS_BUSINESS_STAKEHOLDERS_CREATED = "USERS.BUSINESS_STAKEHOLDERS.CREATED";
public static final String USERS_BUSINESS_STAKEHOLDERS_VERIFICATION_STATUS = "USERS.BUSINESS_STAKEHOLDERS.UPDATED.VERIFICATION_STATUS";
}
}
| 5,359 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/model/KYCDocumentCategoryEnum.java | package com.paypal.kyc.documentextractioncommons.model;
/**
* Enum that defines each document category
*/
public enum KYCDocumentCategoryEnum {
IDENTIFICATION, BUSINESS, ADDRESS, AUTHORIZATION, UNKNOWN;
public static KYCDocumentCategoryEnum getDocumentCategoryForField(final String fieldName) {
return switch (fieldName) {
case KYCConstants.HwDocuments.PROOF_OF_ADDRESS -> ADDRESS;
case KYCConstants.HwDocuments.PROOF_OF_BUSINESS -> BUSINESS;
case KYCConstants.HwDocuments.PROOF_OF_AUTHORIZATION -> AUTHORIZATION;
case KYCConstants.HwDocuments.PROOF_OF_IDENTITY_BACK, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_FRONT, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_FRONT_BSH1, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_FRONT_BSH2, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_FRONT_BSH3, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_FRONT_BSH4, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_FRONT_BSH5, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_BACK_BSH1, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_BACK_BSH2, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_BACK_BSH3, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_BACK_BSH4, KYCConstants.HwDocuments.PROOF_OF_IDENTITY_BACK_BSH5 -> IDENTIFICATION;
default -> UNKNOWN;
};
}
}
| 5,360 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/model/KYCDocumentModel.java | package com.paypal.kyc.documentextractioncommons.model;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.io.File;
import java.io.Serializable;
import java.util.List;
/**
* Creates an object of KYCDocumentModel
*/
@Slf4j
@Getter
@Builder
public class KYCDocumentModel implements Serializable {
private final String documentFieldName;
private final File file;
public KYCDocumentModelBuilder toBuilder() {
//@formatter:off
return KYCDocumentModel.builder()
.documentFieldName(documentFieldName)
.file(file);
//@formatter:on
}
public KYCDocumentSideEnum getDocumentSide() {
return KYCDocumentSideEnum.getDocumentSideByFieldName(documentFieldName);
}
public KYCDocumentCategoryEnum getDocumentCategory() {
return KYCDocumentCategoryEnum.getDocumentCategoryForField(documentFieldName);
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final KYCDocumentModel that = (KYCDocumentModel) o;
return EqualsBuilder.reflectionEquals(this, that, List.of());
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
| 5,361 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/jobs/DocumentsExtractJob.java | package com.paypal.kyc.documentextractioncommons.jobs;
import com.paypal.jobsystem.quartzadapter.support.AbstractBatchJobSupportQuartzJob;
import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobAdapterFactory;
import com.paypal.kyc.stakeholdersdocumentextraction.batchjobs.BusinessStakeholdersDocumentsExtractBatchJob;
import com.paypal.kyc.sellersdocumentextraction.batchjobs.SellersDocumentsExtractBatchJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
/**
* Extract documents job for extracting Mirakl sellers documents data and populate them on
* HyperWallet for KYC validation
*/
@Slf4j
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class DocumentsExtractJob extends AbstractBatchJobSupportQuartzJob implements Job {
private final SellersDocumentsExtractBatchJob sellersDocumentsExtractBatchJob;
private final BusinessStakeholdersDocumentsExtractBatchJob businessStakeholdersDocumentsExtractBatchJob;
public DocumentsExtractJob(final QuartzBatchJobAdapterFactory quartzBatchJobAdapterFactory,
final SellersDocumentsExtractBatchJob sellersDocumentsExtractBatchJob,
final BusinessStakeholdersDocumentsExtractBatchJob businessStakeholdersDocumentsExtractBatchJob) {
super(quartzBatchJobAdapterFactory);
this.sellersDocumentsExtractBatchJob = sellersDocumentsExtractBatchJob;
this.businessStakeholdersDocumentsExtractBatchJob = businessStakeholdersDocumentsExtractBatchJob;
}
/**
* {@inheritDoc}
*/
@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
executeBatchJob(sellersDocumentsExtractBatchJob, context);
executeBatchJob(businessStakeholdersDocumentsExtractBatchJob, context);
}
}
| 5,362 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/controllers/DocumentsExtractJobController.java | package com.paypal.kyc.documentextractioncommons.controllers;
import com.paypal.jobsystem.quartzintegration.controllers.AbstractJobController;
import com.paypal.kyc.documentextractioncommons.jobs.DocumentsExtractJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
/**
* Controller that calls manually to all logic responsible of extracting documents from
* Mirakl and sending them to hyperwallet
*/
@Slf4j
@RestController
@RequestMapping("/job")
public class DocumentsExtractJobController extends AbstractJobController {
private static final String DEFAULT_DOCUMENTS_EXTRACT_JOB_NAME = "DocumentsExtractJobSingleExecution";
/**
* Triggers the {@link DocumentsExtractJob} with the {@code delta} time to retrieve
* shops created or updated since that {@code delta} and schedules the job with the
* {@code name} provided
* @param delta the {@link Date} in {@link DateTimeFormat.ISO}
* @param name the job name in {@link String}
* @return a {@link ResponseEntity <String>} with the name of the job scheduled
* @throws SchedulerException if quartz {@link org.quartz.Scheduler} fails
*/
@PostMapping("/documents-extract")
public ResponseEntity<String> runJob(
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) final Date delta,
@RequestParam(required = false, defaultValue = DEFAULT_DOCUMENTS_EXTRACT_JOB_NAME) final String name)
throws SchedulerException {
runSingleJob(name, DocumentsExtractJob.class, delta);
return ResponseEntity.accepted().body(name);
}
}
| 5,363 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/services/KYCReadyForReviewServiceImpl.java | package com.paypal.kyc.documentextractioncommons.services;
import com.hyperwallet.clientsdk.Hyperwallet;
import com.hyperwallet.clientsdk.HyperwalletException;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException;
import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
/**
* Implementation of {@link KYCReadyForReviewService}
*/
@Slf4j
@Getter
@Service
public class KYCReadyForReviewServiceImpl implements KYCReadyForReviewService {
private final UserHyperwalletSDKService userHyperwalletSDKService;
private final MailNotificationUtil kycMailNotificationUtil;
public KYCReadyForReviewServiceImpl(final UserHyperwalletSDKService userHyperwalletSDKService,
final MailNotificationUtil kycMailNotificationUtil) {
this.userHyperwalletSDKService = userHyperwalletSDKService;
this.kycMailNotificationUtil = kycMailNotificationUtil;
}
@Override
public void notifyReadyForReview(final KYCDocumentInfoModel kycDocumentInfoModel) {
final String token = kycDocumentInfoModel.getUserToken();
final HyperwalletUser user = new HyperwalletUser();
user.setToken(token);
user.setBusinessStakeholderVerificationStatus(
HyperwalletUser.BusinessStakeholderVerificationStatus.READY_FOR_REVIEW);
try {
final String hyperwalletProgram = kycDocumentInfoModel.getHyperwalletProgram();
if (StringUtils.isNotEmpty(hyperwalletProgram)) {
final Hyperwallet hyperwallet = userHyperwalletSDKService
.getHyperwalletInstanceByHyperwalletProgram(hyperwalletProgram);
final HyperwalletUser hyperwalletUser = hyperwallet.updateUser(user);
log.info("Seller with id [{}] has been set as Ready for review", hyperwalletUser.getClientUserId());
}
else {
log.error("Seller with shop Id [{}] has no Hyperwallet Program",
kycDocumentInfoModel.getClientUserId());
}
}
catch (final HyperwalletException e) {
reportHyperwalletAPIError(kycDocumentInfoModel, e);
throw new HMCHyperwalletAPIException(e);
}
}
private void reportHyperwalletAPIError(final KYCDocumentInfoModel kycDocumentInfoModel,
final HyperwalletException e) {
log.error("Error notifying to Hyperwallet that all documents were sent.%n%s"
.formatted(HyperwalletLoggingErrorsUtil.stringify(e)), e);
kycMailNotificationUtil.sendPlainTextEmail("Issue in Hyperwallet status notification", String.format(
"There was an error notifying Hyperwallet all documents were sent for shop Id [%s], so Hyperwallet will not be notified about this new situation%n%s",
kycDocumentInfoModel.getClientUserId(), HyperwalletLoggingErrorsUtil.stringify(e)));
}
}
| 5,364 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/services/HyperwalletDocumentUploadServiceImpl.java | package com.paypal.kyc.documentextractioncommons.services;
import com.hyperwallet.clientsdk.Hyperwallet;
import com.hyperwallet.clientsdk.HyperwalletException;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException;
import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil;
import com.paypal.infrastructure.support.logging.LoggingConstantsUtil;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCDocumentSellerInfoModel;
import com.paypal.kyc.stakeholdersdocumentextraction.model.KYCDocumentBusinessStakeHolderInfoModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
* {@inheritDoc}
*/
@Slf4j
@Service
public class HyperwalletDocumentUploadServiceImpl implements HyperwalletDocumentUploadService {
private final UserHyperwalletSDKService userHyperwalletSDKService;
private final MailNotificationUtil kycMailNotificationUtil;
public HyperwalletDocumentUploadServiceImpl(final UserHyperwalletSDKService userHyperwalletSDKService,
final MailNotificationUtil kycMailNotificationUtil) {
this.userHyperwalletSDKService = userHyperwalletSDKService;
this.kycMailNotificationUtil = kycMailNotificationUtil;
}
/**
* {@inheritDoc}
*/
@Override
public void uploadDocument(final KYCDocumentInfoModel kycDocumentInfoModel,
final List<HyperwalletVerificationDocument> hyperwalletVerificationDocuments) {
try {
final Hyperwallet hyperwallet = userHyperwalletSDKService
.getHyperwalletInstanceByHyperwalletProgram(kycDocumentInfoModel.getHyperwalletProgram());
invokeHyperwalletAPI(kycDocumentInfoModel, hyperwalletVerificationDocuments, hyperwallet);
logUploadedDocuments(kycDocumentInfoModel, hyperwalletVerificationDocuments);
}
catch (final HyperwalletException e) {
log.error(
"Error uploading document to Hyperwallet.%n%s".formatted(HyperwalletLoggingErrorsUtil.stringify(e)),
e);
reportError(kycDocumentInfoModel, e);
throw new HMCHyperwalletAPIException(e);
}
}
protected void invokeHyperwalletAPI(final KYCDocumentInfoModel kycDocumentInfoModel,
final List<HyperwalletVerificationDocument> hyperwalletVerificationDocuments,
final Hyperwallet hyperwallet) {
if (kycDocumentInfoModel instanceof KYCDocumentBusinessStakeHolderInfoModel) {
final KYCDocumentBusinessStakeHolderInfoModel kycDocumentBusinessStakeHolderInfoModel = (KYCDocumentBusinessStakeHolderInfoModel) kycDocumentInfoModel;
hyperwallet.uploadStakeholderDocuments(kycDocumentBusinessStakeHolderInfoModel.getUserToken(),
kycDocumentBusinessStakeHolderInfoModel.getToken(), hyperwalletVerificationDocuments);
}
else {
final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel = (KYCDocumentSellerInfoModel) kycDocumentInfoModel;
hyperwallet.uploadUserDocuments(kycDocumentSellerInfoModel.getUserToken(),
hyperwalletVerificationDocuments);
}
}
private void reportError(final KYCDocumentInfoModel kycDocumentInfoModel, final HyperwalletException e) {
kycMailNotificationUtil.sendPlainTextEmail("Issue detected pushing documents into Hyperwallet",
"Something went wrong pushing documents to Hyperwallet for %s%n%s".formatted(
kycDocumentInfoModel.getDocumentTracingIdentifier(),
HyperwalletLoggingErrorsUtil.stringify(e)));
}
protected void logUploadedDocuments(final KYCDocumentInfoModel kycDocumentInfoModel,
final List<HyperwalletVerificationDocument> hyperwalletVerificationDocuments) {
final String documentsToUpload = hyperwalletVerificationDocuments.stream()
.map(hyperwalletVerificationDocument -> hyperwalletVerificationDocument.getUploadFiles().keySet())
.flatMap(Collection::stream).collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR));
log.info("Documents [{}] uploaded for {}", documentsToUpload,
kycDocumentInfoModel.getDocumentTracingIdentifier());
}
}
| 5,365 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/services/KYCReadyForReviewService.java | package com.paypal.kyc.documentextractioncommons.services;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
/**
* Service in charge of sending a notification when business-related, proof of identity or
* proof of business documents are updated and imported to Hyperwallet
* <p>
* This notification allows the user process validation to continue after all the
* documents are sent
*/
public interface KYCReadyForReviewService {
void notifyReadyForReview(KYCDocumentInfoModel kycDocumentInfoModel);
}
| 5,366 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/services/MiraklDocumentsExtractService.java | package com.paypal.kyc.documentextractioncommons.services;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import java.util.List;
/**
* Interface that manages documents attached to sellers in Mirakl
*/
public interface MiraklDocumentsExtractService {
/**
* Deletes all Mirakl documents from the seller
* @param successFullPushedListOfDocuments {@link List<KYCDocumentInfoModel>}
*/
void deleteAllDocumentsFromSeller(List<KYCDocumentInfoModel> successFullPushedListOfDocuments);
/**
* Deletes Mirakl documents from the seller
* @param documentsToBeDeleted
*/
void deleteDocuments(final List<MiraklShopDocument> documentsToBeDeleted);
}
| 5,367 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/services/MiraklDocumentsSelector.java | package com.paypal.kyc.documentextractioncommons.services;
import com.paypal.infrastructure.support.strategy.MultipleAbstractStrategyExecutor;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentModel;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;
@Service
public class MiraklDocumentsSelector
extends MultipleAbstractStrategyExecutor<KYCDocumentInfoModel, List<KYCDocumentModel>> {
private final Set<Strategy<KYCDocumentInfoModel, List<KYCDocumentModel>>> strategies;
public MiraklDocumentsSelector(final Set<Strategy<KYCDocumentInfoModel, List<KYCDocumentModel>>> strategies) {
this.strategies = strategies;
}
@Override
protected Set<Strategy<KYCDocumentInfoModel, List<KYCDocumentModel>>> getStrategies() {
return this.strategies;
}
}
| 5,368 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/documentextractioncommons/services/HyperwalletDocumentUploadService.java | package com.paypal.kyc.documentextractioncommons.services;
import com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentInfoModel;
import java.util.List;
/**
* Interface to upload documents to Hyperwallet. It can upload both sellers and business
* stakeholders documents.
*/
public interface HyperwalletDocumentUploadService {
/**
* Upload a document to Hyperwallet
* @param kycDocumentInfoModel Documents to push
* @param hyperwalletVerificationDocuments List of documents in Hyperwallet format
*/
void uploadDocument(KYCDocumentInfoModel kycDocumentInfoModel,
List<HyperwalletVerificationDocument> hyperwalletVerificationDocuments);
}
| 5,369 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCBusinessStakeholderStatusNotificationBodyModel.java | package com.paypal.kyc.incomingnotifications.model;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
@Getter
@SuperBuilder
public class KYCBusinessStakeholderStatusNotificationBodyModel extends KYCNotificationBodyModel {
protected final String token;
protected final String userToken;
protected final Boolean isBusinessContact;
protected final Boolean isDirector;
}
| 5,370 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCUserDocumentFlagsNotificationBodyModel.java | package com.paypal.kyc.incomingnotifications.model;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
/**
* Model that manages notifications used to flag a seller as KYC-verification needed
*/
@Getter
@SuperBuilder
public class KYCUserDocumentFlagsNotificationBodyModel extends KYCNotificationBodyModel {
private final String userToken;
private final String hyperwalletProgram;
}
| 5,371 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCRejectionReasonTypeEnum.java | package com.paypal.kyc.incomingnotifications.model;
import lombok.Getter;
@Getter
/**
* Controls different KYC rejection reasons types and their messages to send to Mirakl
*/
public enum KYCRejectionReasonTypeEnum {
//@formatter:off
VERIFICATIONSTATUS_IND_REQUIRED("<li>Filled all your account details correctly.</li><li>Submitted your Proof of Identity and Proof of Address documents.</li>"),
VERIFICATIONSTATUS_PROF_REQUIRED("<li>Filled all your account details correctly.</li><li>Submitted Certificate of incorporation.</li>"),
BUSINESS_STAKEHOLDER_REQUIRED("<li>Filled Business Stakeholder details.</li><li>Submitted their Proof of Identity documents.</li>"),
LETTER_OF_AUTHORIZATION_REQUIRED("<li>Provided a Letter of Authorization document for the nominated Business Contact who is not a Director.</li>"),
UNKWOWN("<li>Unknown issue.</li>");
//@formatter:on
private final String reason;
private static final String HEADER = "There is an issue with verifying your details in Hyperwallet. Please ensure that you: <br /><ul>";
private static final String FOOTER = "</ul><br />For more information on document requirements please refer to the <a href=\"https://docs.hyperwallet.com/content/payee-requirements/v1/payee-verification/required-data\">Hyperwallet guidelines</a>.";
KYCRejectionReasonTypeEnum(final String reason) {
this.reason = reason;
}
/**
* Gets the common error header for each message
* @return {@link String} with the error header
*/
public static String getReasonHeader() {
return HEADER;
}
/**
* Gets the common error footer for each message
* @return {@link String} with the error footer
*/
public static String getReasonFooter() {
return FOOTER;
}
}
| 5,372 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCNotificationBodyModel.java | package com.paypal.kyc.incomingnotifications.model;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.paypal.notifications.storage.model.NotificationBodyModel;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
/**
* Model for KYC Notification objects received
*/
@Getter
@SuperBuilder
public class KYCNotificationBodyModel implements NotificationBodyModel {
protected final HyperwalletUser.VerificationStatus verificationStatus;
protected final HyperwalletUser.BusinessStakeholderVerificationStatus businessStakeholderVerificationStatus;
protected final String clientUserId;
protected final HyperwalletUser.ProfileType profileType;
protected final String hyperwalletWebhookNotificationType;
}
| 5,373 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCDocumentTypeEnum.java | package com.paypal.kyc.incomingnotifications.model;
public enum KYCDocumentTypeEnum {
//@formatter:off
DRIVERS_LICENSE, GOVERNMENT_ID, PASSPORT, BANK_STATEMENT, CREDIT_CARD_STATEMENT, OFFICIAL_GOVERNMENT_LETTER, PROPERTY_TAX_ASSESSMENT, TAX_RETURN, UTILITY_BILL, INCORPORATION, BUSINESS_REGISTRATION, OPERATING_AGREEMENT
//@formatter:on
}
| 5,374 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCUserStatusNotificationBodyModel.java | package com.paypal.kyc.incomingnotifications.model;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import java.util.List;
@Getter
@SuperBuilder
public class KYCUserStatusNotificationBodyModel extends KYCNotificationBodyModel {
protected final HyperwalletUser.LetterOfAuthorizationStatus letterOfAuthorizationStatus;
protected final transient List<KYCRejectionReasonTypeEnum> reasonsType;
protected final transient List<KYCDocumentNotificationModel> documents;
}
| 5,375 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCUserDocumentsNotificationBodyModel.java | package com.paypal.kyc.incomingnotifications.model;
import com.mirakl.client.mmp.domain.shop.document.MiraklShopDocument;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* Model that manages notifications used to remove documents when KYC-verification is
* needed
*/
@Getter
@SuperBuilder
public class KYCUserDocumentsNotificationBodyModel extends KYCNotificationBodyModel {
protected final transient List<MiraklShopDocument> miraklShopDocuments;
}
| 5,376 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCDocumentStatusEnum.java | package com.paypal.kyc.incomingnotifications.model;
public enum KYCDocumentStatusEnum {
VALID, INVALID
}
| 5,377 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCDocumentNotificationModel.java | package com.paypal.kyc.incomingnotifications.model;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import java.time.LocalDateTime;
import java.util.List;
@Getter
@SuperBuilder
public class KYCDocumentNotificationModel {
private KYCDocumentCategoryEnum documentCategory;
private KYCDocumentTypeEnum documentType;
private KYCDocumentStatusEnum documentStatus;
private List<KYCDocumentRejectedReasonEnum> documentRejectedReasons;
private LocalDateTime createdOn;
}
| 5,378 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/model/KYCDocumentRejectedReasonEnum.java | package com.paypal.kyc.incomingnotifications.model;
public enum KYCDocumentRejectedReasonEnum {
DOCUMENT_EXPIRED("Document is expired or not issued within specified timeframe."), DOCUMENT_NOT_RELATED_TO_PROFILE(
"Document does not match account information."), DOCUMENT_NOT_READABLE(
"Document is not readable."), DOCUMENT_NOT_DECISIVE(
"Decision cannot be made based on document. Alternative document required."), DOCUMENT_NOT_COMPLETE(
"Document is incomplete."), DOCUMENT_CORRECTION_REQUIRED(
"Document requires correction."), DOCUMENT_NOT_VALID_WITH_NOTES(
"Document is invalid and rejection details are noted on the account."), DOCUMENT_TYPE_NOT_VALID(
"Document type does not apply.");
private final String reason;
KYCDocumentRejectedReasonEnum(final String reason) {
this.reason = reason;
}
}
| 5,379 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/listeners/KYCBusinessStakeHolderListener.java | package com.paypal.kyc.incomingnotifications.listeners;
import com.hyperwallet.clientsdk.model.HyperwalletWebhookNotification;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.incomingnotifications.services.KYCBusinessStakeholderNotificationService;
import com.paypal.notifications.events.model.KycBusinessStakeholderEvent;
import com.paypal.notifications.events.support.AbstractNotificationListener;
import com.paypal.notifications.failures.repositories.FailedNotificationInformationRepository;
import com.paypal.notifications.storage.repositories.entities.NotificationInfoEntity;
import org.springframework.stereotype.Component;
/**
* Listener for business stakeholder Kyc events
*/
@Component
public class KYCBusinessStakeHolderListener extends AbstractNotificationListener<KycBusinessStakeholderEvent> {
private static final String NOTIFICATION_TYPE = "Business stakeholder KYC";
private final KYCBusinessStakeholderNotificationService kycBusinessStakeholderNotificationService;
public KYCBusinessStakeHolderListener(final MailNotificationUtil mailNotificationUtil,
final FailedNotificationInformationRepository failedNotificationInformationRepository,
final KYCBusinessStakeholderNotificationService kycBusinessStakeholderNotificationService,
final Converter<HyperwalletWebhookNotification, NotificationInfoEntity> notificationInfoEntityToNotificationConverter) {
super(mailNotificationUtil, failedNotificationInformationRepository,
notificationInfoEntityToNotificationConverter);
this.kycBusinessStakeholderNotificationService = kycBusinessStakeholderNotificationService;
}
@Override
protected void processNotification(final HyperwalletWebhookNotification notification) {
kycBusinessStakeholderNotificationService.updateBusinessStakeholderKYCStatus(notification);
}
@Override
protected String getNotificationType() {
return NOTIFICATION_TYPE;
}
}
| 5,380 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/listeners/KYCUserEventListener.java | package com.paypal.kyc.incomingnotifications.listeners;
import com.hyperwallet.clientsdk.model.HyperwalletWebhookNotification;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.incomingnotifications.services.KYCUserNotificationService;
import com.paypal.notifications.events.model.KycUserEvent;
import com.paypal.notifications.events.support.AbstractNotificationListener;
import com.paypal.notifications.failures.repositories.FailedNotificationInformationRepository;
import com.paypal.notifications.storage.repositories.entities.NotificationInfoEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* Listener for user Kyc events
*/
@Component
@Slf4j
public class KYCUserEventListener extends AbstractNotificationListener<KycUserEvent> {
private static final String NOTIFICATION_TYPE = "KYC";
private final KYCUserNotificationService kycNotificationService;
public KYCUserEventListener(final MailNotificationUtil mailNotificationUtil,
final KYCUserNotificationService kycNotificationService,
final FailedNotificationInformationRepository failedNotificationInformationRepository,
final Converter<HyperwalletWebhookNotification, NotificationInfoEntity> notificationInfoEntityToNotificationConverter) {
super(mailNotificationUtil, failedNotificationInformationRepository,
notificationInfoEntityToNotificationConverter);
this.kycNotificationService = kycNotificationService;
}
@Override
protected void processNotification(final HyperwalletWebhookNotification notification) {
kycNotificationService.updateUserKYCStatus(notification);
kycNotificationService.updateUserDocumentsFlags(notification);
}
@Override
protected String getNotificationType() {
return NOTIFICATION_TYPE;
}
}
| 5,381 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCUserNotificationService.java | package com.paypal.kyc.incomingnotifications.services;
import com.hyperwallet.clientsdk.model.HyperwalletWebhookNotification;
/**
* Service to process incoming user kyc notifications
*/
public interface KYCUserNotificationService {
/**
* Based on a {@link HyperwalletWebhookNotification} notification, updates KYC Proof
* of Identity/Business status in Mirakl
* @param incomingNotificationDTO {@link HyperwalletWebhookNotification} KYC Proof of
* Identity/Business status in user notification
*/
void updateUserKYCStatus(HyperwalletWebhookNotification incomingNotificationDTO);
/**
* Based on a {@link HyperwalletWebhookNotification} notification, updates document
* flags in Mirakl
* @param incomingNotificationDTO {@link HyperwalletWebhookNotification} KYC user
* notification
*/
void updateUserDocumentsFlags(HyperwalletWebhookNotification incomingNotificationDTO);
}
| 5,382 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCRejectionReasonServiceImpl.java | package com.paypal.kyc.incomingnotifications.services;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.paypal.kyc.incomingnotifications.model.KYCRejectionReasonTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* Implementation of {@link KYCRejectionReasonService}
*/
@Slf4j
@Service
public class KYCRejectionReasonServiceImpl implements KYCRejectionReasonService {
private static final String BUSINESS = "BUSINESS";
private static final String VERIFICATION_STATUS = "verificationStatus";
private static final String BUSINESS_STAKEHOLDER_VERIFICATION_STATUS = "businessStakeholderVerificationStatus";
private static final String LETTER_OF_AUTHORIZATION_STATUS = "letterOfAuthorizationStatus";
private static final String PROFILE_TYPE = "profileType";
@Override
@SuppressWarnings("unchecked")
public List<KYCRejectionReasonTypeEnum> getReasonTypes(final Object notificationObject) {
final List<KYCRejectionReasonTypeEnum> reasons = new ArrayList<>();
if (notificationObject instanceof Map) {
final Map<String, String> notificationDetails = (Map<String, String>) notificationObject;
final HyperwalletUser.VerificationStatus verificationStatus = EnumUtils.getEnum(
HyperwalletUser.VerificationStatus.class,
Optional.ofNullable(notificationDetails.get(VERIFICATION_STATUS)).orElse(null));
final HyperwalletUser.BusinessStakeholderVerificationStatus businessStakeholderVerificationStatus = EnumUtils
.getEnum(HyperwalletUser.BusinessStakeholderVerificationStatus.class,
Optional.ofNullable(notificationDetails.get(BUSINESS_STAKEHOLDER_VERIFICATION_STATUS))
.orElse(null));
final HyperwalletUser.LetterOfAuthorizationStatus letterOfAuthorizationStatus = EnumUtils.getEnum(
HyperwalletUser.LetterOfAuthorizationStatus.class,
Optional.ofNullable(notificationDetails.get(LETTER_OF_AUTHORIZATION_STATUS)).orElse(null));
//@formatter:off
final boolean isProfessional = Optional.ofNullable(notificationDetails.get(PROFILE_TYPE))
.orElse(StringUtils.EMPTY)
.equals(BUSINESS);
//@formatter:on
if (HyperwalletUser.BusinessStakeholderVerificationStatus.REQUIRED
.equals(businessStakeholderVerificationStatus)) {
reasons.add(KYCRejectionReasonTypeEnum.BUSINESS_STAKEHOLDER_REQUIRED);
}
if (HyperwalletUser.LetterOfAuthorizationStatus.REQUIRED.equals(letterOfAuthorizationStatus)) {
reasons.add(KYCRejectionReasonTypeEnum.LETTER_OF_AUTHORIZATION_REQUIRED);
}
if (HyperwalletUser.VerificationStatus.REQUIRED.equals(verificationStatus)) {
if (isProfessional) {
reasons.add(KYCRejectionReasonTypeEnum.VERIFICATIONSTATUS_PROF_REQUIRED);
}
else {
reasons.add(KYCRejectionReasonTypeEnum.VERIFICATIONSTATUS_IND_REQUIRED);
}
}
}
else {
log.warn("The notification object received is not a Map instance.");
}
return reasons;
}
@Override
public String getRejectionReasonDescriptions(final List<KYCRejectionReasonTypeEnum> reasonsType) {
if (Objects.isNull(reasonsType) || CollectionUtils.isEmpty(reasonsType)) {
return "";
}
final String reasonsDescription = reasonsType.stream().map(KYCRejectionReasonTypeEnum::getReason)
.collect(Collectors.joining(""));
return KYCRejectionReasonTypeEnum.getReasonHeader() + reasonsDescription
+ KYCRejectionReasonTypeEnum.getReasonFooter();
}
}
| 5,383 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCUserStatusExecutor.java | package com.paypal.kyc.incomingnotifications.services;
import com.paypal.infrastructure.support.strategy.SingleAbstractStrategyExecutor;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.incomingnotifications.model.KYCUserStatusNotificationBodyModel;
import org.springframework.stereotype.Service;
import java.util.Set;
@Service
public class KYCUserStatusExecutor extends SingleAbstractStrategyExecutor<KYCUserStatusNotificationBodyModel, Void> {
private final Set<Strategy<KYCUserStatusNotificationBodyModel, Void>> strategies;
public KYCUserStatusExecutor(final Set<Strategy<KYCUserStatusNotificationBodyModel, Void>> strategies) {
this.strategies = strategies;
}
@Override
protected Set<Strategy<KYCUserStatusNotificationBodyModel, Void>> getStrategies() {
return strategies;
}
}
| 5,384 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCUserNotificationServiceImpl.java | package com.paypal.kyc.incomingnotifications.services;
import com.hyperwallet.clientsdk.model.HyperwalletWebhookNotification;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.incomingnotifications.model.KYCUserDocumentFlagsNotificationBodyModel;
import com.paypal.kyc.incomingnotifications.model.KYCUserStatusNotificationBodyModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* Implementation of interface {@link KYCUserNotificationService}
*/
@Slf4j
@Service
public class KYCUserNotificationServiceImpl implements KYCUserNotificationService {
private final KYCUserStatusExecutor kyCUserStatusExecutor;
private final KYCUserDocumentFlagsExecutor kycUserDocumentFlagsExecutor;
private final Converter<Object, KYCUserStatusNotificationBodyModel> hyperWalletObjectToKycUserNotificationBodyModelConverter;
private final Converter<Object, KYCUserDocumentFlagsNotificationBodyModel> hyperWalletObjectToKycUserDocumentFlagsNotificationBodyModelConverter;
public KYCUserNotificationServiceImpl(final KYCUserStatusExecutor kyCUserStatusExecutor,
final KYCUserDocumentFlagsExecutor kycUserDocumentFlagsExecutor,
final Converter<Object, KYCUserStatusNotificationBodyModel> hyperWalletObjectToKycUserNotificationBodyModelConverter,
final Converter<Object, KYCUserDocumentFlagsNotificationBodyModel> hyperWalletObjectToKycUserDocumentFlagsNotificationBodyModelConverter) {
this.kyCUserStatusExecutor = kyCUserStatusExecutor;
this.kycUserDocumentFlagsExecutor = kycUserDocumentFlagsExecutor;
this.hyperWalletObjectToKycUserNotificationBodyModelConverter = hyperWalletObjectToKycUserNotificationBodyModelConverter;
this.hyperWalletObjectToKycUserDocumentFlagsNotificationBodyModelConverter = hyperWalletObjectToKycUserDocumentFlagsNotificationBodyModelConverter;
}
/**
* {@inheritDoc}
*/
@Override
public void updateUserKYCStatus(final HyperwalletWebhookNotification incomingNotification) {
final KYCUserStatusNotificationBodyModel kycUserNotification = hyperWalletObjectToKycUserNotificationBodyModelConverter
.convert(incomingNotification.getObject());
kyCUserStatusExecutor.execute(kycUserNotification);
}
/**
* {@inheritDoc}
*/
@Override
public void updateUserDocumentsFlags(final HyperwalletWebhookNotification incomingNotification) {
final KYCUserDocumentFlagsNotificationBodyModel kycUserDocumentFlagsNotificationBodyModel = hyperWalletObjectToKycUserDocumentFlagsNotificationBodyModelConverter
.convert(incomingNotification.getObject());
kycUserDocumentFlagsExecutor.execute(kycUserDocumentFlagsNotificationBodyModel);
}
}
| 5,385 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCRejectionReasonService.java | package com.paypal.kyc.incomingnotifications.services;
import com.paypal.kyc.incomingnotifications.model.KYCRejectionReasonTypeEnum;
import java.util.List;
import java.util.Map;
/**
* Service that manages KYC Reasons
*/
public interface KYCRejectionReasonService {
/**
* Receives a notification object based on a {@link Map <String,String>} and returns
* verificationStatus, businessStakeholderVerificationStatus,
* letterOfAuthorizationStatus {@link KYCRejectionReasonTypeEnum} types
* @param notificationObject
* @return {@link List< KYCRejectionReasonTypeEnum >}
*/
List<KYCRejectionReasonTypeEnum> getReasonTypes(final Object notificationObject);
/**
* Generates a {@link String} with the error message to send to other systems.
* @param reasonsType {@link List<KYCRejectionReasonTypeEnum>} with all rejection
* reasons.
* @return {@link String} Error descriptions with all rejection reasons received
*/
String getRejectionReasonDescriptions(List<KYCRejectionReasonTypeEnum> reasonsType);
}
| 5,386 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCBusinessStakeholderNotificationService.java | package com.paypal.kyc.incomingnotifications.services;
import com.hyperwallet.clientsdk.model.HyperwalletWebhookNotification;
/**
* Service to process incoming user kyc notifications
*/
public interface KYCBusinessStakeholderNotificationService {
/**
* Based on a {@link HyperwalletWebhookNotification} notification, updates KYC Proof
* of Identity status in Mirakl
* @param incomingNotificationDTO {@link HyperwalletWebhookNotification} KYC Proof of
* Identity status in user notification
*/
void updateBusinessStakeholderKYCStatus(HyperwalletWebhookNotification incomingNotificationDTO);
}
| 5,387 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCBusinessStakeholderNotificationServiceImpl.java | package com.paypal.kyc.incomingnotifications.services;
import com.hyperwallet.clientsdk.HyperwalletException;
import com.hyperwallet.clientsdk.model.HyperwalletWebhookNotification;
import com.mirakl.client.core.exception.MiraklException;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil;
import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil;
import com.paypal.kyc.incomingnotifications.model.KYCBusinessStakeholderStatusNotificationBodyModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* Implementation of interface {@link KYCUserNotificationService}
*/
@Slf4j
@Service
public class KYCBusinessStakeholderNotificationServiceImpl implements KYCBusinessStakeholderNotificationService {
private final KYCBusinessStakeholderStatusExecutor kycBusinessStakeholderStatusExecutor;
private final Converter<HyperwalletWebhookNotification, KYCBusinessStakeholderStatusNotificationBodyModel> hyperWalletObjectToKycBusinessStakeholderStatusNotificationBodyModelConverter;
public KYCBusinessStakeholderNotificationServiceImpl(
final KYCBusinessStakeholderStatusExecutor kycBusinessStakeholderStatusExecutor,
final Converter<HyperwalletWebhookNotification, KYCBusinessStakeholderStatusNotificationBodyModel> hyperWalletObjectToKycBusinessStakeholderStatusNotificationBodyModelConverter) {
this.kycBusinessStakeholderStatusExecutor = kycBusinessStakeholderStatusExecutor;
this.hyperWalletObjectToKycBusinessStakeholderStatusNotificationBodyModelConverter = hyperWalletObjectToKycBusinessStakeholderStatusNotificationBodyModelConverter;
}
/**
* {@inheritDoc}
*/
@Override
public void updateBusinessStakeholderKYCStatus(final HyperwalletWebhookNotification incomingNotification) {
final KYCBusinessStakeholderStatusNotificationBodyModel kycBusinessStakeholderNotification = hyperWalletObjectToKycBusinessStakeholderStatusNotificationBodyModelConverter
.convert(incomingNotification);
try {
kycBusinessStakeholderStatusExecutor.execute(kycBusinessStakeholderNotification);
}
// Rethrow exception to handle it in AbstractNotificationListener
catch (final HyperwalletException ex) {
logException(incomingNotification, HyperwalletLoggingErrorsUtil.stringify(ex), ex);
throw ex;
}
catch (final MiraklException ex) {
logException(incomingNotification, MiraklLoggingErrorsUtil.stringify(ex), ex);
throw ex;
}
catch (final RuntimeException ex) {
logException(incomingNotification, ex.getMessage(), ex);
throw ex;
}
}
private void logException(final HyperwalletWebhookNotification incomingNotification, final String exceptionMessage,
final Exception e) {
log.error(
"Notification [%s] could not be processed - the KYC Letter of authorization for a business stakeholder could not be updated.%n%s"
.formatted(incomingNotification.getToken(), exceptionMessage),
e);
}
}
| 5,388 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCBusinessStakeholderStatusExecutor.java | package com.paypal.kyc.incomingnotifications.services;
import com.paypal.infrastructure.support.strategy.SingleAbstractStrategyExecutor;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.incomingnotifications.model.KYCBusinessStakeholderStatusNotificationBodyModel;
import org.springframework.stereotype.Service;
import java.util.Set;
@Service
public class KYCBusinessStakeholderStatusExecutor
extends SingleAbstractStrategyExecutor<KYCBusinessStakeholderStatusNotificationBodyModel, Void> {
private final Set<Strategy<KYCBusinessStakeholderStatusNotificationBodyModel, Void>> strategies;
public KYCBusinessStakeholderStatusExecutor(
final Set<Strategy<KYCBusinessStakeholderStatusNotificationBodyModel, Void>> strategies) {
this.strategies = strategies;
}
@Override
protected Set<Strategy<KYCBusinessStakeholderStatusNotificationBodyModel, Void>> getStrategies() {
return strategies;
}
}
| 5,389 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/KYCUserDocumentFlagsExecutor.java | package com.paypal.kyc.incomingnotifications.services;
import com.paypal.infrastructure.support.strategy.SingleAbstractStrategyExecutor;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.kyc.incomingnotifications.model.KYCUserDocumentFlagsNotificationBodyModel;
import org.springframework.stereotype.Service;
import java.util.Set;
@Service
public class KYCUserDocumentFlagsExecutor
extends SingleAbstractStrategyExecutor<KYCUserDocumentFlagsNotificationBodyModel, Void> {
private final Set<Strategy<KYCUserDocumentFlagsNotificationBodyModel, Void>> strategies;
public KYCUserDocumentFlagsExecutor(
final Set<Strategy<KYCUserDocumentFlagsNotificationBodyModel, Void>> strategies) {
this.strategies = strategies;
}
@Override
protected Set<Strategy<KYCUserDocumentFlagsNotificationBodyModel, Void>> getStrategies() {
return strategies;
}
}
| 5,390 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/flags/AbstractUserDocumentFlagsStrategy.java | package com.paypal.kyc.incomingnotifications.services.flags;
import com.mirakl.client.core.exception.MiraklException;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop;
import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest;
import com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.infrastructure.support.strategy.Strategy;
import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil;
import com.paypal.kyc.documentextractioncommons.model.KYCConstants;
import com.paypal.kyc.incomingnotifications.model.KYCUserDocumentFlagsNotificationBodyModel;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j
public abstract class AbstractUserDocumentFlagsStrategy
implements Strategy<KYCUserDocumentFlagsNotificationBodyModel, Void> {
protected final MailNotificationUtil mailNotificationUtil;
protected final MiraklClient miraklMarketplacePlatformOperatorApiClient;
protected static final String EMAIL_BODY_PREFIX = "There was an error, please check the logs for further information:\n";
protected AbstractUserDocumentFlagsStrategy(final MailNotificationUtil mailNotificationUtil,
final MiraklClient miraklMarketplacePlatformOperatorApiClient) {
this.mailNotificationUtil = mailNotificationUtil;
this.miraklMarketplacePlatformOperatorApiClient = miraklMarketplacePlatformOperatorApiClient;
}
/**
* {@inheritDoc}
*/
@Override
public Void execute(final KYCUserDocumentFlagsNotificationBodyModel source) {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(final KYCUserDocumentFlagsNotificationBodyModel source) {
return false;
}
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(String.format("Something went wrong updating KYC information of shop [%s]. Details [%s]",
source.getClientUserId(), ex.getMessage()), ex);
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;
}
}
}
| 5,391 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/flags/KYCUserDocumentFlagProofIdentityBusinessStakeHolderStrategy.java | package com.paypal.kyc.incomingnotifications.services.flags;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.mirakl.client.core.exception.MiraklException;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop;
import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest;
import com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil;
import com.paypal.kyc.incomingnotifications.model.KYCUserDocumentFlagsNotificationBodyModel;
import com.paypal.kyc.stakeholdersdocumentextraction.services.HyperwalletBusinessStakeholderExtractService;
import com.paypal.kyc.stakeholdersdocumentextraction.services.MiraklBusinessStakeholderDocumentsExtractService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service
public class KYCUserDocumentFlagProofIdentityBusinessStakeHolderStrategy extends AbstractUserDocumentFlagsStrategy {
protected final HyperwalletBusinessStakeholderExtractService hyperwalletBusinessStakeholderExtractService;
protected final MiraklBusinessStakeholderDocumentsExtractService miraklBusinessStakeholderDocumentsExtractService;
protected KYCUserDocumentFlagProofIdentityBusinessStakeHolderStrategy(
final MailNotificationUtil mailNotificationUtil,
final MiraklClient miraklMarketplacePlatformOperatorApiClient,
final HyperwalletBusinessStakeholderExtractService hyperwalletBusinessStakeholderExtractService,
final MiraklBusinessStakeholderDocumentsExtractService miraklBusinessStakeholderDocumentsExtractService) {
super(mailNotificationUtil, miraklMarketplacePlatformOperatorApiClient);
this.hyperwalletBusinessStakeholderExtractService = hyperwalletBusinessStakeholderExtractService;
this.miraklBusinessStakeholderDocumentsExtractService = miraklBusinessStakeholderDocumentsExtractService;
}
/**
* {@inheritDoc}
*/
@Override
public Void execute(final KYCUserDocumentFlagsNotificationBodyModel source) {
final List<String> businessStakeholdersPendingToBeVerified = hyperwalletBusinessStakeholderExtractService
.getKYCRequiredVerificationBusinessStakeHolders(source.getHyperwalletProgram(), source.getUserToken());
final List<String> kycCustomValuesRequiredVerificationBusinessStakeholders = miraklBusinessStakeholderDocumentsExtractService
.getKYCCustomValuesRequiredVerificationBusinessStakeholders(source.getClientUserId(),
businessStakeholdersPendingToBeVerified);
fillMiraklProofIdentityOrBusinessFlagStatus(source, kycCustomValuesRequiredVerificationBusinessStakeholders);
return null;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(final KYCUserDocumentFlagsNotificationBodyModel source) {
return HyperwalletUser.ProfileType.BUSINESS.equals(source.getProfileType())
&& HyperwalletUser.BusinessStakeholderVerificationStatus.REQUIRED
.equals(source.getBusinessStakeholderVerificationStatus());
}
protected void fillMiraklProofIdentityOrBusinessFlagStatus(final KYCUserDocumentFlagsNotificationBodyModel source,
final List<String> kycCustomValuesRequiredVerificationBusinessStakeholders) {
if (CollectionUtils.isNotEmpty(kycCustomValuesRequiredVerificationBusinessStakeholders)) {
final MiraklUpdateShop updateShop = new MiraklUpdateShop();
final List<MiraklRequestAdditionalFieldValue> additionalFieldValues = kycCustomValuesRequiredVerificationBusinessStakeholders
.stream()
.map(kycCustomValueRequiredVerification -> new MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue(
kycCustomValueRequiredVerification, Boolean.TRUE.toString()))
.collect(Collectors.toList());
updateShop.setShopId(Long.valueOf(source.getClientUserId()));
updateShop.setAdditionalFieldValues(additionalFieldValues);
try {
log.info("Updating KYC proof of identity flag in Mirakl for business Stakeholder for shopId [{}]",
source.getClientUserId());
final MiraklUpdateShopsRequest miraklUpdateShopsRequest = new MiraklUpdateShopsRequest(
List.of(updateShop));
miraklMarketplacePlatformOperatorApiClient.updateShops(miraklUpdateShopsRequest);
log.info("Proof of identity flag updated for business Stakeholder for shopId [{}]",
source.getClientUserId());
}
catch (final MiraklException ex) {
log.error(String.format(
"Something went wrong updating KYC business stakeholder information of shop [%s]. Details [%s]",
source.getClientUserId(), ex.getMessage()), ex);
mailNotificationUtil.sendPlainTextEmail(
"Issue detected updating KYC business stakeholder information in Mirakl",
String.format(EMAIL_BODY_PREFIX
+ "Something went wrong updating KYC business stakeholder information for shop [%s]%n%s",
source.getClientUserId(), MiraklLoggingErrorsUtil.stringify(ex)));
// Rethrow exception to handle it in AbstractNotificationListener
throw ex;
}
}
}
}
| 5,392 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/flags/KYCUserDocumentFlagIndividualStrategy.java | package com.paypal.kyc.incomingnotifications.services.flags;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.kyc.incomingnotifications.model.KYCUserDocumentFlagsNotificationBodyModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class KYCUserDocumentFlagIndividualStrategy extends AbstractUserDocumentFlagsStrategy {
public KYCUserDocumentFlagIndividualStrategy(final MiraklClient miraklMarketplacePlatformOperatorApiClient,
final MailNotificationUtil mailNotificationUtil) {
super(mailNotificationUtil, miraklMarketplacePlatformOperatorApiClient);
}
/**
* {@inheritDoc}
*/
@Override
public Void execute(final KYCUserDocumentFlagsNotificationBodyModel source) {
superFillMiraklProofIdentityOrBusinessFlagStatus(source);
return null;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(final KYCUserDocumentFlagsNotificationBodyModel source) {
return HyperwalletUser.ProfileType.INDIVIDUAL.equals(source.getProfileType())
&& HyperwalletUser.VerificationStatus.REQUIRED.equals(source.getVerificationStatus());
}
protected void superFillMiraklProofIdentityOrBusinessFlagStatus(
final KYCUserDocumentFlagsNotificationBodyModel notification) {
super.fillMiraklProofIdentityOrBusinessFlagStatus(notification);
}
}
| 5,393 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/flags/KYCUserDocumentFlagProofOfBusinessStrategy.java | package com.paypal.kyc.incomingnotifications.services.flags;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.paypal.infrastructure.mail.services.MailNotificationUtil;
import com.paypal.infrastructure.mirakl.client.MiraklClient;
import com.paypal.kyc.incomingnotifications.model.KYCUserDocumentFlagsNotificationBodyModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class KYCUserDocumentFlagProofOfBusinessStrategy extends AbstractUserDocumentFlagsStrategy {
public KYCUserDocumentFlagProofOfBusinessStrategy(final MiraklClient miraklMarketplacePlatformOperatorApiClient,
final MailNotificationUtil mailNotificationUtil) {
super(mailNotificationUtil, miraklMarketplacePlatformOperatorApiClient);
}
/**
* {@inheritDoc}
*/
@Override
public Void execute(final KYCUserDocumentFlagsNotificationBodyModel source) {
superFillMiraklProofIdentityOrBusinessFlagStatus(source);
return null;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(final KYCUserDocumentFlagsNotificationBodyModel source) {
return HyperwalletUser.ProfileType.BUSINESS.equals(source.getProfileType())
&& HyperwalletUser.VerificationStatus.REQUIRED.equals(source.getVerificationStatus());
}
protected void superFillMiraklProofIdentityOrBusinessFlagStatus(
final KYCUserDocumentFlagsNotificationBodyModel notification) {
super.fillMiraklProofIdentityOrBusinessFlagStatus(notification);
}
}
| 5,394 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/converters/KYCDocumentNotificationModelToMiraklFieldTypeCodesConverter.java | package com.paypal.kyc.incomingnotifications.services.converters;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.incomingnotifications.model.KYCDocumentNotificationModel;
import com.paypal.kyc.sellersdocumentextraction.model.KYCProofOfAddressEnum;
import com.paypal.kyc.sellersdocumentextraction.model.KYCProofOfBusinessEnum;
import com.paypal.kyc.documentextractioncommons.model.KYCProofOfIdentityEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.EnumUtils;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
/**
* Converts {@link KYCDocumentNotificationModel} into its corresponding Mirakl fields
*/
@Slf4j
@Service
public class KYCDocumentNotificationModelToMiraklFieldTypeCodesConverter
implements Converter<KYCDocumentNotificationModel, List<String>> {
/**
* {@inheritDoc}
*/
@Override
public List<String> convert(final KYCDocumentNotificationModel document) {
final KYCProofOfIdentityEnum kycProofOfIdentity = EnumUtils.getEnum(KYCProofOfIdentityEnum.class,
document.getDocumentType().toString());
final KYCProofOfAddressEnum kycProofOfAddress = EnumUtils.getEnum(KYCProofOfAddressEnum.class,
document.getDocumentType().toString());
final KYCProofOfBusinessEnum kycProofOfBusiness = EnumUtils.getEnum(KYCProofOfBusinessEnum.class,
document.getDocumentType().toString());
if (Optional.ofNullable(kycProofOfAddress).isPresent()) {
return KYCProofOfAddressEnum.getMiraklFields();
}
else if (Optional.ofNullable(kycProofOfIdentity).isPresent()) {
return KYCProofOfIdentityEnum.getMiraklFields(kycProofOfIdentity);
}
else if (Optional.ofNullable(kycProofOfBusiness).isPresent()) {
return KYCProofOfBusinessEnum.getMiraklFields();
}
return List.of();
}
}
| 5,395 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/converters/HyperWalletObjectToKYCBusinessStakeholderStatusNotificationBodyModelConverter.java | package com.paypal.kyc.incomingnotifications.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.hyperwallet.clientsdk.model.HyperwalletWebhookNotification;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.incomingnotifications.model.KYCBusinessStakeholderStatusNotificationBodyModel;
import com.paypal.kyc.incomingnotifications.model.KYCUserStatusNotificationBodyModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.EnumUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Optional;
/**
* Converts Notification object into {@link KYCUserStatusNotificationBodyModel}
*/
@Slf4j
@Service
public class HyperWalletObjectToKYCBusinessStakeholderStatusNotificationBodyModelConverter
implements Converter<HyperwalletWebhookNotification, KYCBusinessStakeholderStatusNotificationBodyModel> {
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public KYCBusinessStakeholderStatusNotificationBodyModel convert(final HyperwalletWebhookNotification source) {
if (source.getObject() instanceof Map) {
final Map<String, Object> notificationDetails = (Map<String, Object>) source.getObject();
//@formatter:off
final KYCBusinessStakeholderStatusNotificationBodyModel.KYCBusinessStakeholderStatusNotificationBodyModelBuilder<?, ?> builder
= KYCBusinessStakeholderStatusNotificationBodyModel.builder();
Optional.ofNullable((Boolean) notificationDetails.get("isDirector")).ifPresent(builder::isDirector);
Optional.ofNullable((Boolean) notificationDetails.get("isBusinessContact")).ifPresent(builder::isBusinessContact);
Optional.ofNullable((String) notificationDetails.get("verificationStatus"))
.map(verificationStatus -> EnumUtils.getEnum(HyperwalletUser.VerificationStatus.class, verificationStatus))
.ifPresent(builder::verificationStatus);
Optional.ofNullable((String) notificationDetails.get("profileType"))
.map(profileType -> EnumUtils.getEnum(HyperwalletUser.ProfileType.class, profileType))
.ifPresent(builder::profileType);
Optional.ofNullable((String) notificationDetails.get("token")).ifPresent(builder::token);
Optional.ofNullable((String) notificationDetails.get("userToken")).ifPresent(builder::userToken);
Optional.ofNullable(source.getType()).ifPresent(builder::hyperwalletWebhookNotificationType);
return builder.build();
//@formatter:on
}
log.warn("The notification body looks empty");
return null;
}
}
| 5,396 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/converters/HyperWalletObjectToKYCDocumentNotificationModelsConverter.java | package com.paypal.kyc.incomingnotifications.services.converters;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.documentextractioncommons.model.KYCDocumentCategoryEnum;
import com.paypal.kyc.incomingnotifications.model.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.EnumUtils;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Converts Documents Notification object into {@link KYCDocumentNotificationModel} list
*/
@Slf4j
@Service
public class HyperWalletObjectToKYCDocumentNotificationModelsConverter
implements Converter<Object, List<KYCDocumentNotificationModel>> {
@Override
public List<KYCDocumentNotificationModel> convert(final Object notificationObject) {
if (notificationObject instanceof Map) {
final Map<String, Object> notificationDetails = (Map<String, Object>) notificationObject;
final List<Map<String, Object>> documents = Optional
.ofNullable((List<Map<String, Object>>) notificationDetails.get("documents"))
.orElse(Collections.emptyList());
return documents.stream().map(document -> KYCDocumentNotificationModel.builder()
.documentStatus(EnumUtils.getEnum(KYCDocumentStatusEnum.class, (String) document.get("status")))
.documentType(EnumUtils.getEnum(KYCDocumentTypeEnum.class, (String) document.get("type")))
.createdOn(LocalDateTime.parse((String) document.get("createdOn")))
.documentCategory(
EnumUtils.getEnum(KYCDocumentCategoryEnum.class, (String) document.get("category")))
.documentRejectedReasons(getRejectedReasons(
Optional.ofNullable((List<Map<String, String>>) document.get("reasons")).orElse(List.of())))
.build()).collect(Collectors.toList());
}
return List.of();
}
private List<KYCDocumentRejectedReasonEnum> getRejectedReasons(final List<Map<String, String>> reasons) {
return Optional.ofNullable(reasons).orElseGet(List::of).stream()
.map(reason -> EnumUtils.getEnum(KYCDocumentRejectedReasonEnum.class, reason.get("name")))
.collect(Collectors.toList());
}
}
| 5,397 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/converters/HyperWalletObjectToKYCUserDocumentFlagsNotificationBodyModelConverter.java | package com.paypal.kyc.incomingnotifications.services.converters;
import com.hyperwallet.clientsdk.Hyperwallet;
import com.hyperwallet.clientsdk.HyperwalletException;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService;
import com.paypal.kyc.incomingnotifications.model.KYCUserDocumentFlagsNotificationBodyModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.EnumUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Optional;
/**
* Converts Notification Object into {@link KYCUserDocumentFlagsNotificationBodyModel}
*/
@Slf4j
@Service
public class HyperWalletObjectToKYCUserDocumentFlagsNotificationBodyModelConverter
implements Converter<Object, KYCUserDocumentFlagsNotificationBodyModel> {
@Value("#{'${hmc.hyperwallet.programs.names}'}")
private String hyperwalletPrograms;
private final UserHyperwalletSDKService userHyperwalletSDKService;
public HyperWalletObjectToKYCUserDocumentFlagsNotificationBodyModelConverter(
final UserHyperwalletSDKService userHyperwalletSDKService) {
this.userHyperwalletSDKService = userHyperwalletSDKService;
}
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public KYCUserDocumentFlagsNotificationBodyModel convert(final Object source) {
if (source instanceof Map) {
final Map<String, String> notificationDetails = (Map<String, String>) source;
//@formatter:off
return KYCUserDocumentFlagsNotificationBodyModel.builder()
.userToken(Optional.ofNullable(notificationDetails.get("token"))
.orElse(null))
.profileType(EnumUtils.getEnum(HyperwalletUser.ProfileType.class,
Optional.ofNullable(notificationDetails.get("profileType")).
orElse(null)))
.clientUserId(Optional.ofNullable(notificationDetails.get("clientUserId"))
.orElse(null))
.businessStakeholderVerificationStatus(EnumUtils.getEnum(HyperwalletUser.BusinessStakeholderVerificationStatus.class,
Optional.ofNullable(notificationDetails.get("businessStakeholderVerificationStatus"))
.orElse(null)))
.verificationStatus(EnumUtils.getEnum(HyperwalletUser.VerificationStatus.class,
Optional.ofNullable(notificationDetails.get("verificationStatus"))
.orElse(null)))
.hyperwalletProgram(Optional.ofNullable(notificationDetails.get("programToken"))
.map(this::getHyperwalletProgramForProgramToken)
.orElse(null))
.build();
//@formatter:on
}
log.warn("The notification body looks empty");
return null;
}
private String getHyperwalletProgramForProgramToken(final String programToken) {
for (final String program : getHyperwalletPrograms().split(",")) {
try {
final Hyperwallet instance = userHyperwalletSDKService
.getHyperwalletInstanceByHyperwalletProgram(program);
instance.getProgram(programToken);
return program;
}
catch (final HyperwalletException e) {
// Program not found for token, continue until one is found
}
}
log.info("No programs were found for program token {}", programToken);
return null;
}
protected String getHyperwalletPrograms() {
return hyperwalletPrograms;
}
}
| 5,398 |
0 | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services | Create_ds/mirakl-hyperwallet-connector/hmc-kyc/src/main/java/com/paypal/kyc/incomingnotifications/services/converters/HyperWalletObjectToKYCUserStatusNotificationBodyModelConverter.java | package com.paypal.kyc.incomingnotifications.services.converters;
import com.hyperwallet.clientsdk.model.HyperwalletUser;
import com.paypal.infrastructure.support.converter.Converter;
import com.paypal.kyc.incomingnotifications.model.KYCDocumentNotificationModel;
import com.paypal.kyc.incomingnotifications.model.KYCUserStatusNotificationBodyModel;
import com.paypal.kyc.incomingnotifications.services.KYCRejectionReasonService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.EnumUtils;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* Converts Notification object into {@link KYCUserStatusNotificationBodyModel}
*/
@Slf4j
@Service
public class HyperWalletObjectToKYCUserStatusNotificationBodyModelConverter
implements Converter<Object, KYCUserStatusNotificationBodyModel> {
private final KYCRejectionReasonService kycRejectionReasonService;
private final Converter<Object, List<KYCDocumentNotificationModel>> objectKYCDocumentNotificationModelListConverter;
public HyperWalletObjectToKYCUserStatusNotificationBodyModelConverter(
final KYCRejectionReasonService kycRejectionReasonService,
final Converter<Object, List<KYCDocumentNotificationModel>> objectKYCDocumentNotificationModelListConverter) {
this.kycRejectionReasonService = kycRejectionReasonService;
this.objectKYCDocumentNotificationModelListConverter = objectKYCDocumentNotificationModelListConverter;
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public KYCUserStatusNotificationBodyModel convert(final Object source) {
if (source instanceof Map) {
final Map<String, Object> notificationDetails = (Map<String, Object>) source;
//@formatter:off
return KYCUserStatusNotificationBodyModel.builder()
.profileType(EnumUtils.getEnum(HyperwalletUser.ProfileType.class,
Optional.ofNullable((String) notificationDetails.get("profileType")).
orElse(null)))
.clientUserId(Optional.ofNullable((String) notificationDetails.get("clientUserId"))
.orElse(null))
.verificationStatus(EnumUtils.getEnum(HyperwalletUser.VerificationStatus.class,
Optional.ofNullable((String) notificationDetails.get("verificationStatus"))
.orElse(null)))
.businessStakeholderVerificationStatus(EnumUtils.getEnum(HyperwalletUser.BusinessStakeholderVerificationStatus.class,
Optional.ofNullable((String) notificationDetails.get("businessStakeholderVerificationStatus"))
.orElse(null)))
.letterOfAuthorizationStatus(EnumUtils.getEnum(HyperwalletUser.LetterOfAuthorizationStatus.class,
Optional.ofNullable((String) notificationDetails.get("letterOfAuthorizationStatus"))
.orElse(null)))
.reasonsType(kycRejectionReasonService.getReasonTypes(source))
.documents(objectKYCDocumentNotificationModelListConverter.convert(source))
.build();
//@formatter:on
}
log.warn("The notification body looks empty");
return null;
}
}
| 5,399 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.