Commit fdda3df8 authored by Niels de Feyter's avatar Niels de Feyter
Browse files

#3274198 by sjerdo, ndf: InvalidArgumentException when notify callback is called twice

parent b16997f0
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -227,6 +227,8 @@ class Mollie extends OffsitePaymentGatewayBase implements HasPaymentInstructions
        // Capture payment.
        $payment_transition = $payment->getState()->getWorkflow()->getTransition('authorize_capture');
        $payment->getState()->applyTransition($payment_transition);
        $payment->setRemoteState($mollie_payment_remote_object->status);
        $payment->save();
        break;

      case MolliePaymentStatus::STATUS_CANCELED:
@@ -235,12 +237,16 @@ class Mollie extends OffsitePaymentGatewayBase implements HasPaymentInstructions
        $payment->getState()->applyTransition($payment_transition);
        $payment_transition = $payment->getState()->getWorkflow()->getTransition('void');
        $payment->getState()->applyTransition($payment_transition);
        $payment->setRemoteState($mollie_payment_remote_object->status);
        $payment->save();
        break;

      case MolliePaymentStatus::STATUS_OPEN:
        // Authorize payment.
        $payment_transition = $payment->getState()->getWorkflow()->getTransition('authorize');
        $payment->getState()->applyTransition($payment_transition);
        $payment->setRemoteState($mollie_payment_remote_object->status);
        $payment->save();
        break;

      case MolliePaymentStatus::STATUS_FAILED:
@@ -249,6 +255,8 @@ class Mollie extends OffsitePaymentGatewayBase implements HasPaymentInstructions
        $payment->getState()->applyTransition($payment_transition);
        $payment_transition = $payment->getState()->getWorkflow()->getTransition('void');
        $payment->getState()->applyTransition($payment_transition);
        $payment->setRemoteState($mollie_payment_remote_object->status);
        $payment->save();
        break;

      case MolliePaymentStatus::STATUS_EXPIRED:
@@ -257,11 +265,10 @@ class Mollie extends OffsitePaymentGatewayBase implements HasPaymentInstructions
        $payment->getState()->applyTransition($payment_transition);
        $payment_transition = $payment->getState()->getWorkflow()->getTransition('expire');
        $payment->getState()->applyTransition($payment_transition);
        break;
    }

        $payment->setRemoteState($mollie_payment_remote_object->status);
        $payment->save();
        break;
    }

    // Return empty response with 200 status code.
    return new JsonResponse();
+30 −0
Original line number Diff line number Diff line
@@ -200,6 +200,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
    // First call onNotify().
    $this->helperCallOnNotifyWebhook();

    // Second call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();

    // Then do onReturn() (go back to website).
    $this->drupalGet('mollie_return/1');
    $this->assertSession()->addressEquals('checkout/1/complete');
@@ -214,6 +217,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
      'commerce_payment_status' => 'completed',
      'commerce_payment_remoteStatus' => MolliePaymentStatus::STATUS_PAID,
    ]);

    // Third call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();
  }

  /**
@@ -247,6 +253,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
    // First call onNotify().
    $this->helperCallOnNotifyWebhook();

    // Second call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();

    // Then do onReturn() (go back to website).
    $this->drupalGet('mollie_return/1');
    $this->assertSession()->addressEquals('checkout/1/review');
@@ -260,6 +269,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
      'commerce_payment_status' => 'authorization_voided',
      'commerce_payment_remoteStatus' => MolliePaymentStatus::STATUS_CANCELED,
    ]);

    // Third call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();
  }

  /**
@@ -295,6 +307,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
    // First call onNotify().
    $this->helperCallOnNotifyWebhook();

    // Second call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();

    // Then do onReturn() (go back to website).
    $this->drupalGet('mollie_return/1');
    $this->assertSession()->addressEquals('mollie_return/1');
@@ -308,6 +323,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
      'commerce_payment_status' => 'authorization',
      'commerce_payment_remoteStatus' => MolliePaymentStatus::STATUS_OPEN,
    ]);

    // Third call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();
  }

  /**
@@ -345,6 +363,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
    // First call onNotify().
    $this->helperCallOnNotifyWebhook();

    // Second call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();

    // Then do onReturn() (go back to website).
    $this->drupalGet('mollie_return/1');
    $this->assertSession()->addressEquals('checkout/1/review');
@@ -359,6 +380,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
      'commerce_payment_status' => 'authorization_voided',
      'commerce_payment_remoteStatus' => MolliePaymentStatus::STATUS_FAILED,
    ]);

    // Third call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();
  }

  /**
@@ -398,6 +422,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
    // First call onNotify().
    $this->helperCallOnNotifyWebhook();

    // Second call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();

    // Then do onReturn() (go back to website).
    $this->drupalGet('mollie_return/1');
    $this->assertSession()->addressEquals('checkout/1/review');
@@ -412,6 +439,9 @@ class MolliePaymentOffsiteFormTest extends CommerceBrowserTestBase {
      'commerce_payment_status' => 'authorization_expired',
      'commerce_payment_remoteStatus' => MolliePaymentStatus::STATUS_EXPIRED,
    ]);

    // Third call onNotify(). Nothing should happen.
    $this->helperCallOnNotifyWebhook();
  }

  /**