Search in sources :

Example 1 with HyperwalletException

use of com.hyperwallet.clientsdk.HyperwalletException in project mirakl-hyperwallet-connector by paypal.

the class KYCReadyForReviewServiceImpl method notifyBstkReadyForReview.

protected void notifyBstkReadyForReview(final Map.Entry<String, List<KYCDocumentInfoModel>> entry) {
    final String token = entry.getKey();
    final HyperwalletUser user = new HyperwalletUser();
    user.setToken(token);
    user.setBusinessStakeholderVerificationStatus(HyperwalletUser.BusinessStakeholderVerificationStatus.READY_FOR_REVIEW);
    try {
        final Optional<String> hyperwalletProgramOptional = getHyperwalletProgram(entry.getValue());
        if (hyperwalletProgramOptional.isPresent()) {
            final String hyperwalletProgram = hyperwalletProgramOptional.get();
            final Hyperwallet hyperwallet = hyperwalletSDKService.getHyperwalletInstance(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", getClientId(entry.getValue()));
        }
    } catch (final HyperwalletException e) {
        // @formatter:off
        final String clientUserId = CollectionUtils.emptyIfNull(entry.getValue()).stream().map(KYCDocumentInfoModel::getClientUserId).findAny().orElse("undefined");
        // @formatter:on
        log.error("Error notifying to Hyperwallet that all documents were sent: [{}]", HyperwalletLoggingErrorsUtil.stringify(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", clientUserId, HyperwalletLoggingErrorsUtil.stringify(e)));
    }
}
Also used : HyperwalletUser(com.hyperwallet.clientsdk.model.HyperwalletUser) Hyperwallet(com.hyperwallet.clientsdk.Hyperwallet) HyperwalletException(com.hyperwallet.clientsdk.HyperwalletException)

Example 2 with HyperwalletException

use of com.hyperwallet.clientsdk.HyperwalletException in project mirakl-hyperwallet-connector by paypal.

the class KYCReadyForReviewServiceMockImpl method notifyBstkReadyForReview.

@Override
protected void notifyBstkReadyForReview(final Map.Entry<String, List<KYCDocumentInfoModel>> entry) {
    final String token = entry.getKey();
    final HyperwalletUser user = new HyperwalletUser();
    user.setToken(token);
    user.setBusinessStakeholderVerificationStatus(HyperwalletUser.BusinessStakeholderVerificationStatus.READY_FOR_REVIEW);
    final String postURL = HYPERWALLET_NOTIFY_USER.replace("{userToken}", token);
    try {
        final Gson gsonConverter = new Gson();
        restTemplate.put(getMockServerUrl() + postURL, gsonConverter.toJson(user), Object.class);
        log.info("Pushed successfully to mockserver business stakeholder notification update shopId [{}]", entry.getValue().stream().map(KYCDocumentInfoModel::getClientUserId).findAny().orElse(null));
    } catch (HyperwalletException e) {
        final String clientUserId = Optional.ofNullable(entry.getValue().get(0)).orElse(KYCDocumentBusinessStakeHolderInfoModel.builder().build()).getClientUserId();
        log.error("Error notifying to Hyperwallet that all documents were sent: [{}]", HyperwalletLoggingErrorsUtil.stringify(e));
        getKycMailNotificationUtil().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", clientUserId, HyperwalletLoggingErrorsUtil.stringify(e)));
    }
}
Also used : HyperwalletUser(com.hyperwallet.clientsdk.model.HyperwalletUser) HyperwalletException(com.hyperwallet.clientsdk.HyperwalletException) Gson(com.google.gson.Gson)

Example 3 with HyperwalletException

use of com.hyperwallet.clientsdk.HyperwalletException in project mirakl-hyperwallet-connector by paypal.

the class HyperwalletBusinessStakeholderExtractServiceMockImpl method callHyperwalletAPI.

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

Example 4 with HyperwalletException

use of com.hyperwallet.clientsdk.HyperwalletException in project mirakl-hyperwallet-connector by paypal.

the class HyperwalletSellerExtractServiceImpl method callHyperwalletAPI.

/**
 * {@inheritDoc}
 */
protected KYCDocumentSellerInfoModel callHyperwalletAPI(final Map.Entry<KYCDocumentSellerInfoModel, List<HyperwalletVerificationDocument>> entry) {
    final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel = entry.getKey();
    final String documentsToUpload = entry.getValue().stream().map(hyperwalletVerificationDocument -> hyperwalletVerificationDocument.getUploadFiles().keySet()).flatMap(Collection::stream).collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR));
    try {
        final Hyperwallet hyperwallet = hyperwalletSDKService.getHyperwalletInstance(kycDocumentSellerInfoModel.getHyperwalletProgram());
        hyperwallet.uploadUserDocuments(kycDocumentSellerInfoModel.getUserToken(), entry.getValue());
        log.info("Documents [{}] uploaded for shop with id [{}]", documentsToUpload, kycDocumentSellerInfoModel.getClientUserId());
        return kycDocumentSellerInfoModel;
    } catch (final HyperwalletException e) {
        log.error("Error uploading document to hyperwallet: [{}]", HyperwalletLoggingErrorsUtil.stringify(e));
        kycMailNotificationUtil.sendPlainTextEmail("Issue detected pushing documents into Hyperwallet", String.format("Something went wrong pushing documents to Hyperwallet for shop Id [%s]%n%s", kycDocumentSellerInfoModel.getClientUserId(), HyperwalletLoggingErrorsUtil.stringify(e)));
        return null;
    }
}
Also used : Hyperwallet(com.hyperwallet.clientsdk.Hyperwallet) HyperwalletException(com.hyperwallet.clientsdk.HyperwalletException) KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel)

Example 5 with HyperwalletException

use of com.hyperwallet.clientsdk.HyperwalletException in project mirakl-hyperwallet-connector by paypal.

the class HyperwalletSellerExtractServiceMockImpl method callHyperwalletAPI.

@Override
protected KYCDocumentSellerInfoModel callHyperwalletAPI(final Map.Entry<KYCDocumentSellerInfoModel, List<HyperwalletVerificationDocument>> entry) {
    final KYCDocumentSellerInfoModel kycDocumentSellerInfoModel = entry.getKey();
    final List<HyperwalletVerificationDocument> hyperwalletVerificationDocuments = entry.getValue();
    final String postURL = HYPERWALLET_PUSH_DOCUMENTS.replace("{userToken}", kycDocumentSellerInfoModel.getUserToken());
    try {
        if (checkFailingFiles(hyperwalletVerificationDocuments)) {
            throw new HyperwalletException("Something bad happened");
        }
        Gson gsonConverter = new Gson();
        restTemplate.postForObject(getMockServerUrl() + postURL, gsonConverter.toJson(entry.getValue()), Object.class);
        log.info("Pushed successfully to mockserver documents for shopId  [{}]", kycDocumentSellerInfoModel.getClientUserId());
        return kycDocumentSellerInfoModel;
    } catch (HyperwalletException ex) {
        log.error("Error uploading document to hyperwallet: [{}]", HyperwalletLoggingErrorsUtil.stringify(ex));
        getKycMailNotificationUtil().sendPlainTextEmail("Issue detected pushing documents into Hyperwallet", String.format("Something went wrong pushing documents to Hyperwallet for shop Id [%s]%n%s", String.join(",", kycDocumentSellerInfoModel.getClientUserId()), HyperwalletLoggingErrorsUtil.stringify(ex)));
        return null;
    }
}
Also used : HyperwalletVerificationDocument(com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument) HyperwalletException(com.hyperwallet.clientsdk.HyperwalletException) KYCDocumentSellerInfoModel(com.paypal.kyc.model.KYCDocumentSellerInfoModel) Gson(com.google.gson.Gson)

Aggregations

HyperwalletException (com.hyperwallet.clientsdk.HyperwalletException)36 Test (org.junit.jupiter.api.Test)15 Hyperwallet (com.hyperwallet.clientsdk.Hyperwallet)7 MiraklAdditionalFieldValue (com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue)6 KYCDocumentBusinessStakeHolderInfoModel (com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)6 HyperwalletUser (com.hyperwallet.clientsdk.model.HyperwalletUser)5 HyperwalletVerificationDocument (com.hyperwallet.clientsdk.model.HyperwalletVerificationDocument)5 KYCDocumentSellerInfoModel (com.paypal.kyc.model.KYCDocumentSellerInfoModel)5 IOException (java.io.IOException)5 Response (cc.protea.util.http.Response)4 Test (org.testng.annotations.Test)4 Gson (com.google.gson.Gson)3 HyperwalletPayment (com.hyperwallet.clientsdk.model.HyperwalletPayment)3 JOSEException (com.nimbusds.jose.JOSEException)3 File (java.io.File)3 ParseException (java.text.ParseException)3 HyperwalletBusinessStakeholder (com.hyperwallet.clientsdk.model.HyperwalletBusinessStakeholder)2 KYCDocumentModel (com.paypal.kyc.model.KYCDocumentModel)2 List (java.util.List)2 Map (java.util.Map)2