You are here

public function PaymentCheckoutController::returnPage in Commerce Core 8.2

Provides the "return" checkout payment page.

Redirects to the next checkout page, completing checkout.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

1 string reference to 'PaymentCheckoutController::returnPage'
commerce_payment.routing.yml in modules/payment/commerce_payment.routing.yml
modules/payment/commerce_payment.routing.yml

File

modules/payment/src/Controller/PaymentCheckoutController.php, line 82

Class

PaymentCheckoutController
Provides checkout endpoints for off-site payments.

Namespace

Drupal\commerce_payment\Controller

Code

public function returnPage(Request $request, RouteMatchInterface $route_match) {

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $route_match
    ->getParameter('commerce_order');
  $step_id = $route_match
    ->getParameter('step');
  $this
    ->validateStepId($step_id, $order);

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = $order
    ->get('payment_gateway')->entity;
  $payment_gateway_plugin = $payment_gateway
    ->getPlugin();
  if (!$payment_gateway_plugin instanceof OffsitePaymentGatewayInterface) {
    throw new AccessException('The payment gateway for the order does not implement ' . OffsitePaymentGatewayInterface::class);
  }

  /** @var \Drupal\commerce_checkout\Entity\CheckoutFlowInterface $checkout_flow */
  $checkout_flow = $order
    ->get('checkout_flow')->entity;
  $checkout_flow_plugin = $checkout_flow
    ->getPlugin();
  try {
    $payment_gateway_plugin
      ->onReturn($order, $request);
    $redirect_step_id = $checkout_flow_plugin
      ->getNextStepId($step_id);
  } catch (PaymentGatewayException $e) {
    $this->logger
      ->error($e
      ->getMessage());
    $this->messenger
      ->addError(t('Payment failed at the payment server. Please review your information and try again.'));
    $redirect_step_id = $checkout_flow_plugin
      ->getPreviousStepId($step_id);
  }
  $checkout_flow_plugin
    ->redirectToStep($redirect_step_id);
}