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);
    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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.