Score:0

onNotify called 3 times on error returned

kn flag

I'm using the OffsetRedirect.php file to handle the return of my bank when the user pay his order.

Inside this file, i use the onNotify() method

  public function onNotify(Request $request)
  {
    $erreur = $request->get('error');
    $response = NULL;
    //check some logic
    if ($erreur === '00000') {
      //create payment
    } else {
      $erreur_paiement_route = Url::fromRoute('mycommerce.on_payment_error', [])->toString();
      $response = new RedirectResponse($erreur_paiement_route, 302);
      //send mail to notify the admin that an error occured
    }
    return $response;
  }

On error, I redirect to my OrderErrorController, which extends the CheckoutController (so that I can use the checkoutOrderManager. If there's an error, i want my user to be redirected to the review step (last one before payment)

class OrderErrorController extends CheckoutController
{
  /**
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   * @throws \Drupal\commerce\Response\NeedsRedirectException
   */
  public function index(RouteMatchInterface $route_match)
  {
    /** @var \Drupal\commerce_order\Entity\Order $order */
    $order = $route_match->getParameter('commerce_order');
    /** @var \Drupal\commerce_checkout\Entity\CheckoutFlow $checkoutFlow */
    $checkoutFlow = $this->checkoutOrderManager->getCheckoutFlow($order);
    $checkoutFlow->getPlugin()->redirectToStep('review');
    return parent::formPage($route_match);
  }
}

this is what I get :

If the command is successfuly done, the user is redirected to the complet step (that works)

if the command has an error, there's no redirection to the review page, the user is redirected to the complete page (the order has no payment, but has its state at completed and checkout_step at complete)

On top of that, when there's an error, my onNotify method if called 3 times in a row (so I have 3 times each error in my logs !)

I'm using this e-commerce platform, Drupal commerce 2.30 and drupal 9.5.2

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.