Comments

Vishalghyv created an issue. See original summary.

vishalghyv’s picture

  • Slight change in Stop order check box
  • Addition of warning message when stop order changed to true
vishalghyv’s picture

Status: Active » Needs review
derekcresswell’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/CommerceFraudSettingsForm.php
    @@ -55,7 +55,8 @@ class CommerceFraudSettingsForm extends ConfigFormBase {
    +      '#title' => t('Stop Fraudulent Order'),
    +      '#description' => $this
             ->t('Activate this to stop the blocklisted orders from completeing checkout'),
    

    "Stop fraudulent orders"

    And make sure descriptions end with a period.

  2. +++ b/src/Form/CommerceFraudSettingsForm.php
    @@ -89,6 +90,12 @@ class CommerceFraudSettingsForm extends ConfigFormBase {
    +    if ($form_state->getValue('stop_order') && (\Drupal::state()->get('stop_order') != $form_state->getValue('stop_order'))) {
    

    There are un-needed brackets around the right part of the and statement.
    As well, you are called get('stop_order') many times, why not assign it to a variable once instead.

I do not think this is the really the right way to go about this. First, we are adding two warnings despite it really only being one message. It also highly discourages the usage of this feature, even though it is perfectly fine to use. It also implies that there is a double confirmation before activating the feature.
A much better idea is to just add a description to the 'stop_order' option that warns that the feature will not allow any blocked orders to be completed.

vishalghyv’s picture

  • Fixed title
  • Removed not required warning message

I was wondering if it is stopping orders from completing shouldn't there be more than description to set that feature.
It might incur real loss if the feature fails.
Your insight on this?

derekcresswell’s picture

The point of the module is to notify and stop fraudulent orders. It seems reasonable to have the ability to block orders that seem fraudulent.

Yes, it is possible for the module to be wrong and stop a good order. But the site owner should have the ability to control which rules to check so they can set up how rigorous the checks should be and therefore have control over this possible loss.

I think there are two things to do :

1. Make the description read :

'Activate this to stop the blocklisted orders from being completed.
Warning, this may cause a lost orders if enabled.'

Or similar.

2. When a order is blocked by this setting (not completed) :
Print a message for the user saying "This order is suspected to be fraudulent and cannot be completed. Contact the administrators for more info and help. {email address}"

This way the users know why they can't complete the order and have a way to sort things out if this is a false positive.

vishalghyv’s picture

  • Added better description and message
vishalghyv’s picture

Status: Needs work » Needs review

The last submitted patch, 5: commerce_fraud-warning_message_for_stopping_order_feature-3156768_5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vishalghyv’s picture

Status: Needs review » Needs work
vishalghyv’s picture

Status: Needs work » Needs review
vishalghyv’s picture

Status: Needs review » Needs work
vishalghyv’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
vishalghyv’s picture

  • Test passing
derekcresswell’s picture

Status: Needs review » Needs work
+++ b/src/EventSubscriber/CommerceFraudSubscriber.php
@@ -169,6 +169,9 @@ class CommerceFraudSubscriber implements EventSubscriberInterface {
+    $this->messenger->addMessage(t('This order is suspected to be fraudulent and cannot be completed. Contact the administrators for more info and help. Email - @email', [

This should add a warning, not message.

When testing this myself I noticed a few things.

1. On the message displayed to the user let's ditch the email part. The site should have contact forms and such so telling them to contact should be ok.

1.1. I think this could open up the idea of making a "fraud appeal contact form" in the future. I am open to an opinion on that. This would than produce a link, or maybe redirect, to a contact form with some default data that gets attached such as order ID. Not for this issue, just for discussion later.

2. While I got the message about the order being fraudulent, I also got the message that a message was sent to the admins. This needs to be removed as the user should not see it. These messages should instead be logged.

The culprit within CommerceFraudSubscriber

    // Setting a message about the mail.
    if ($result['result']) {
      $this->messenger->addMessage(t('Message about the order has been sent.'));
      return;
    }
    $this->messenger->addWarning(t('There was a problem sending message and it was not sent.'), MessengerInterface::TYPE_WARNING);

vishalghyv’s picture

Status: Needs work » Needs review
StatusFileSize
new7.37 KB
  • Changed message type
  • Replaced messgae with log
derekcresswell’s picture

Title: Add a confirmation form for the settings when stop order settings is changed » Add notifications when orders are marked as fraudulent
Status: Needs review » Needs work
  1. +++ b/src/EventSubscriber/CommerceFraudSubscriber.php
    @@ -164,11 +183,11 @@ class CommerceFraudSubscriber implements EventSubscriberInterface {
    +    $this->messenger->addWarning(t('This order is suspected to be fraudulent and cannot be completed. Contact the administrators for more info and help.'));
    

    Use the StringTranslationTrait and $this->t() for this.

  2. +++ b/src/EventSubscriber/CommerceFraudSubscriber.php
    @@ -195,12 +214,12 @@ class CommerceFraudSubscriber implements EventSubscriberInterface {
    -    // Setting a message about the mail.
    +    // Logging message about mail.
         if ($result['result']) {
    -      $this->messenger->addMessage(t('Message about the order has been sent.'));
    +      $this->logStorage->generate($order, 'fraud_mail_success')->save();
           return;
         }
    -    $this->messenger->addWarning(t('There was a problem sending message and it was not sent.'), MessengerInterface::TYPE_WARNING);
    +    $this->logStorage->generate($order, 'fraud_mail_failure')->save();
    

    These probably are better suited as just normal site logs. The commerce_log is for specifics to the order and while these pertain to the order they feel a little off from what other things are logged here.

    If the message fails to send, that is not (shouldn't be) to do with the order, it's a problem with some other configuration in the site.
    I guess I'd be ok with the success one being kept on the order if you think it fits there.

vishalghyv’s picture

Status: Needs work » Needs review
StatusFileSize
new7.24 KB
  • Using stringtranslationtrait and removed failure message

  • DerekCresswell committed 187acb0 on 2.x
    Issue #3156768 by Vishalghyv, DerekCresswell: Add notifications when...
derekcresswell’s picture

Status: Needs review » Fixed

Removed some excess logging. Things like the mail system will log errors for us, as for success, I decided that since the admins will be getting an email about it there is not much reason to log it.
Corrected some spelling / grammar as well.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.