Ejemplo n.º 1
0
 @Override
 public void run() {
   ru.technonikol.ws.orders.Order integrationOrder = null;
   // convert order
   try {
     integrationOrder = convert(order);
   } catch (final ConversionException ex) {
     LOG.error(
         "Error when trying to convert de.hybris.platform.core.model.order.OrderModel to ru.technonikol.ws.orders.Order",
         ex);
     order.setStatus(OrderStatus.SENT_TO_SERVER_ERROR);
     modelService.save(order);
     return;
   }
   // send to service
   try {
     createOrderIntegrationService.ordersCreateRequestOutSyn(integrationOrder);
   } catch (WebServiceException exception) {
     // if service is unavailable
     if (exception.getCause() instanceof ConnectException
         || exception.getCause() instanceof SocketTimeoutException) {
       order.setStatus(OrderStatus.RESEND_TO_SERVER);
       modelService.save(order);
       return;
       // service data processing errors
     } else {
       order.setStatus(OrderStatus.SENT_TO_SERVER_ERROR);
       modelService.save(order);
     }
     return;
   }
   order.setStatus(OrderStatus.SENT_TO_SERVER_OK);
   modelService.save(order);
 }
  protected Transition executeAction(final OrderProcessModel process) {
    ServicesUtil.validateParameterNotNull(process, "Process cannot be null");
    LOG.info("Process: " + process.getCode() + " in step " + getClass().getSimpleName());

    final OrderModel order = process.getOrder();
    ServicesUtil.validateParameterNotNull(order, "Order in process cannot be null");
    ServicesUtil.validateParameterNotNull(
        order.getFraudulent(), "Fraudulent value in order cannot be null");

    final OrderHistoryEntryModel historyLog =
        createHistoryLog("Order Manually checked by CSA - Fraud = " + order.getFraudulent(), order);
    modelService.save(historyLog);

    LOG.info(
        "The fraud condition of the order "
            + order.getCode()
            + " is "
            + order.getFraudulent().booleanValue());
    if (order.getFraudulent().booleanValue()) {
      order.setStatus(OrderStatus.SUSPENDED);
      getModelService().save(order);
      return Transition.NOK;
    } else {
      order.setStatus(OrderStatus.FRAUD_CHECKED);
      getModelService().save(order);
      return Transition.OK;
    }
  }
  @Override
  public Transition executeAction(final OrderProcessModel process) {
    LOG.info("Process: " + process.getCode() + " in step " + getClass());
    ServicesUtil.validateParameterNotNull(process, "Process can not be null");
    ServicesUtil.validateParameterNotNull(process.getOrder(), "Order can not be null");

    final double scoreLimit =
        Double.parseDouble(
            Config.getParameter(
                HybrisTestFulfilmentProcessConstants.EXTENSIONNAME + ".fraud.scoreLimitExternal"));
    final double scoreTolerance =
        Double.parseDouble(
            Config.getParameter(
                HybrisTestFulfilmentProcessConstants.EXTENSIONNAME
                    + ".fraud.scoreToleranceExternal"));

    final OrderModel order = process.getOrder();
    final FraudServiceResponse response =
        getFraudService().recognizeOrderSymptoms(getProviderName(), order);
    final double score = response.getScore();
    if (score < scoreLimit) {
      final FraudReportModel fraudReport =
          createFraudReport(providerName, response, order, FraudStatus.OK);
      final OrderHistoryEntryModel historyEntry =
          createHistoryLog(providerName, order, FraudStatus.OK, null);
      order.setFraudulent(Boolean.FALSE);
      order.setPotentiallyFraudulent(Boolean.FALSE);
      order.setStatus(OrderStatus.FRAUD_CHECKED);
      modelService.save(fraudReport);
      modelService.save(historyEntry);
      modelService.save(order);
      return Transition.OK;
    } else if (score < scoreLimit + scoreTolerance) {
      final FraudReportModel fraudReport =
          createFraudReport(providerName, response, order, FraudStatus.CHECK);
      final OrderHistoryEntryModel historyEntry =
          createHistoryLog(providerName, order, FraudStatus.CHECK, fraudReport.getCode());
      order.setFraudulent(Boolean.FALSE);
      order.setPotentiallyFraudulent(Boolean.TRUE);
      order.setStatus(OrderStatus.FRAUD_CHECKED);
      modelService.save(fraudReport);
      modelService.save(historyEntry);
      modelService.save(order);
      return Transition.POTENTIAL;
    } else {
      final FraudReportModel fraudReport =
          createFraudReport(providerName, response, order, FraudStatus.FRAUD);
      final OrderHistoryEntryModel historyEntry =
          createHistoryLog(providerName, order, FraudStatus.FRAUD, fraudReport.getCode());
      order.setFraudulent(Boolean.TRUE);
      order.setPotentiallyFraudulent(Boolean.FALSE);
      order.setStatus(OrderStatus.FRAUD_CHECKED);
      modelService.save(fraudReport);
      modelService.save(historyEntry);
      modelService.save(order);
      return Transition.FRAUD;
    }
  }
  @Test
  public void testExecute() throws RetryLaterException, Exception {

    final OrderProcessModel orderProcess = new OrderProcessModel();
    final OrderModel order = new OrderModel();
    order.setStatus(OrderStatus.CREATED);
    orderProcess.setOrder(order);
    prepareOrderForManualCheck.executeAction(orderProcess);
    Assert.assertEquals(OrderStatus.WAIT_FRAUD_MANUAL_CHECK, orderProcess.getOrder().getStatus());
  }
  protected Transition executeAction(final OrderProcessModel process) {
    ServicesUtil.validateParameterNotNull(process, "Process cannot be null");

    final OrderModel order = process.getOrder();
    ServicesUtil.validateParameterNotNull(order, "Order in process cannot be null");
    if (order.getFraudulent() != null) {
      final OrderHistoryEntryModel historyLog =
          createHistoryLog(
              "Order Manually checked by CSA - Fraud = " + order.getFraudulent(), order);
      modelService.save(historyLog);
      if (order.getFraudulent().booleanValue()) {
        order.setStatus(OrderStatus.SUSPENDED);
        getModelService().save(order);
        return Transition.NOK;
      }
      return Transition.OK;
    }
    return Transition.UNDEFINED;
  }
  @Override
  public Transition executeAction(final OrderProcessModel process) {
    final OrderModel order = process.getOrder();

    if (order != null) {
      if (order.getPaymentInfo() instanceof InvoicePaymentInfoModel) {
        return Transition.OK;
      } else {
        for (final PaymentTransactionModel transaction : order.getPaymentTransactions()) {
          for (final PaymentTransactionEntryModel entry : transaction.getEntries()) {
            if (entry.getType().equals(PaymentTransactionType.AUTHORIZATION)
                && TransactionStatus.ACCEPTED.name().equals(entry.getTransactionStatus())) {
              order.setStatus(OrderStatus.PAYMENT_AUTHORIZED);
              modelService.save(order);
              return Transition.OK;
            }
          }
        }
      }
    }
    return Transition.NOK;
  }
 @Override
 protected void onSiteEvent(final OrderCompletedEvent orderCompletedEvent) {
   final OrderModel orderModel = orderCompletedEvent.getProcess().getOrder();
   orderModel.setStatus(OrderStatus.COMPLETED);
   getModelService().save(orderModel);
 }