Search in sources :

Example 1 with MiraklApiException

use of com.mirakl.client.core.exception.MiraklApiException in project mirakl-hyperwallet-connector by paypal.

the class MiraklBankAccountExtractServiceImpl method updateBankAccountToken.

/**
 * {@inheritDoc}
 */
@Override
public void updateBankAccountToken(final SellerModel sellerModel, final HyperwalletBankAccount hyperwalletBankAccount) {
    final MiraklUpdateShop miraklUpdateShop = new MiraklUpdateShop();
    final String shopId = sellerModel.getClientUserId();
    miraklUpdateShop.setShopId(Long.valueOf(shopId));
    final MiraklSimpleRequestAdditionalFieldValue userTokenCustomField = new MiraklSimpleRequestAdditionalFieldValue();
    userTokenCustomField.setCode(HYPERWALLET_BANK_ACCOUNT_TOKEN);
    userTokenCustomField.setValue(hyperwalletBankAccount.getToken());
    miraklUpdateShop.setAdditionalFieldValues(List.of(userTokenCustomField));
    final MiraklUpdateShopsRequest request = new MiraklUpdateShopsRequest(List.of(miraklUpdateShop));
    log.info("Updating bank account token for shop [{}]", shopId);
    try {
        miraklOperatorClient.updateShops(request);
        log.info("Bank account token updated for shop [{}]", shopId);
    } catch (final MiraklApiException ex) {
        log.error("Something went wrong updating information of shop [{}]", shopId);
        sellerMailNotificationUtil.sendPlainTextEmail("Issue detected updating bank token in Mirakl", String.format(ERROR_MESSAGE_PREFIX + "Something went wrong updating bank token of shop [%s]%n%s", shopId, MiraklLoggingErrorsUtil.stringify(ex)));
    }
}
Also used : MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop) MiraklSimpleRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue)

Example 2 with MiraklApiException

use of com.mirakl.client.core.exception.MiraklApiException in project mirakl-hyperwallet-connector by paypal.

the class MiraklInvoicesExtractServiceImplTest method extractAccountingDocument_whenMiraklExceptionIsThrown_shouldSendEmailNotification.

@Test
void extractAccountingDocument_whenMiraklExceptionIsThrown_shouldSendEmailNotification() {
    final LocalDateTime now = LocalDateTime.now();
    TimeMachine.useFixedClockAt(now);
    final Date nowAsDate = DateUtil.convertToDate(now, ZoneId.systemDefault());
    final InvoiceModel invoiceOne = InvoiceModel.builder().shopId(SHOP_ID_ONE).destinationToken(TOKEN_1).hyperwalletProgram(HYPERWALLET_PROGRAM).build();
    final List<InvoiceModel> invoiceList = List.of(invoiceOne);
    doReturn(invoiceList).when(testObj).getAccountingDocuments(nowAsDate);
    final MiraklApiException miraklApiException = new MiraklApiException(new MiraklErrorResponseBean(1, "Something went wrong"));
    doThrow(miraklApiException).when(miraklMarketplacePlatformOperatorApiClientMock).getShops(any(MiraklGetShopsRequest.class));
    testObj.extractAccountingDocument(nowAsDate);
    verify(mailNotificationUtilMock).sendPlainTextEmail("Issue detected getting shops in Mirakl", String.format("Something went wrong getting information of " + "shops" + " [2000]%n%s", MiraklLoggingErrorsUtil.stringify(miraklApiException)));
}
Also used : LocalDateTime(java.time.LocalDateTime) MiraklErrorResponseBean(com.mirakl.client.core.error.MiraklErrorResponseBean) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) Date(java.util.Date) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Test(org.junit.jupiter.api.Test)

Example 3 with MiraklApiException

use of com.mirakl.client.core.exception.MiraklApiException in project mirakl-hyperwallet-connector by paypal.

the class MiraklSellersExtractServiceImplCustomFieldsTest method updateUserToken_shouldSendEmailNotification_whenMiraklExceptionIsThrown.

@Test
void updateUserToken_shouldSendEmailNotification_whenMiraklExceptionIsThrown() {
    when(hyperwalletUserMock.getToken()).thenReturn(TOKEN_VALUE);
    when(hyperwalletUserMock.getClientUserId()).thenReturn("12345");
    final MiraklApiException miraklApiException = new MiraklApiException(new MiraklErrorResponseBean(1, "Something went wrong"));
    doThrow(miraklApiException).when(miraklMarketplacePlatformOperatorApiClientMock).updateShops(any(MiraklUpdateShopsRequest.class));
    testObj.updateUserToken(hyperwalletUserMock);
    verify(mailNotificationUtilMock).sendPlainTextEmail(eq("Issue detected getting shop information in Mirakl"), eq(String.format(ERROR_MESSAGE_PREFIX + "Something went wrong getting information of shop [12345]%n%s", MiraklLoggingErrorsUtil.stringify(miraklApiException))));
}
Also used : MiraklErrorResponseBean(com.mirakl.client.core.error.MiraklErrorResponseBean) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) Test(org.junit.jupiter.api.Test)

Example 4 with MiraklApiException

use of com.mirakl.client.core.exception.MiraklApiException in project mirakl-hyperwallet-connector by paypal.

the class MiraklSellersExtractServiceImplTest method extractSellers_shouldSendEmailNotification_whenMiraklExceptionIsThrownAndShopIdsAreReceived.

@Test
void extractSellers_shouldSendEmailNotification_whenMiraklExceptionIsThrownAndShopIdsAreReceived() {
    final MiraklApiException miraklApiException = new MiraklApiException(new MiraklErrorResponseBean(1, "Something went wrong"));
    doThrow(miraklApiException).when(miraklMarketplacePlatformOperatorApiClientMock).getShops(any(MiraklGetShopsRequest.class));
    testObj.extractSellers(List.of(INDIVIDUAL_SHOP, PROFESSIONAL_SHOP_ID));
    verify(mailNotificationUtilMock).sendPlainTextEmail("Issue detected getting shop information in Mirakl", String.format(ERROR_MESSAGE_PREFIX + "Something went wrong getting shop information with ids [[individualShop, professionalShop]]%n%s", MiraklLoggingErrorsUtil.stringify(miraklApiException)));
}
Also used : MiraklErrorResponseBean(com.mirakl.client.core.error.MiraklErrorResponseBean) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) Test(org.junit.jupiter.api.Test)

Example 5 with MiraklApiException

use of com.mirakl.client.core.exception.MiraklApiException in project mirakl-hyperwallet-connector by paypal.

the class MiraklBusinessStakeholderExtractServiceImpl method updateBusinessStakeholderToken.

@Override
public void updateBusinessStakeholderToken(final String clientUserId, final List<BusinessStakeHolderModel> businessStakeHolderModels) {
    if (CollectionUtils.isEmpty(businessStakeHolderModels)) {
        log.info("No data for business stakeholders on store [{}]", clientUserId);
        return;
    }
    final MiraklUpdateShop miraklUpdateShop = createMiraklUpdateFieldRequestForStakeholders(clientUserId, businessStakeHolderModels);
    final MiraklUpdateShopsRequest request = new MiraklUpdateShopsRequest(List.of(miraklUpdateShop));
    try {
        miraklOperatorClient.updateShops(request);
    } catch (final MiraklApiException ex) {
        log.error("Something went wrong getting information of shop [{}]", clientUserId);
        sellerMailNotificationUtil.sendPlainTextEmail(EMAIL_SUBJECT_MESSAGE, String.format(ERROR_MESSAGE_PREFIX + "Something went wrong getting information of shop [%s]%n%s", clientUserId, MiraklLoggingErrorsUtil.stringify(ex)));
    }
}
Also used : MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop)

Aggregations

MiraklApiException (com.mirakl.client.core.exception.MiraklApiException)13 MiraklErrorResponseBean (com.mirakl.client.core.error.MiraklErrorResponseBean)8 Test (org.junit.jupiter.api.Test)8 MiraklUpdateShopsRequest (com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest)7 MiraklGetShopsRequest (com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest)6 MiraklUpdateShop (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop)3 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)2 MiraklSimpleRequestAdditionalFieldValue (com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue)2 LocalDateTime (java.time.LocalDateTime)2 Date (java.util.Date)2 CreditNoteModel (com.paypal.invoices.invoicesextract.model.CreditNoteModel)1 InvoiceModel (com.paypal.invoices.invoicesextract.model.InvoiceModel)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1