You are here

public function WpsController::wpsComplete in Ubercart 8.4

Handles a complete PayPal Payments Standard sale.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse A redirect to the cart or checkout complete page.

1 string reference to 'WpsController::wpsComplete'
uc_paypal.routing.yml in payment/uc_paypal/uc_paypal.routing.yml
payment/uc_paypal/uc_paypal.routing.yml

File

payment/uc_paypal/src/Controller/WpsController.php, line 20

Class

WpsController
Returns responses for PayPal routes.

Namespace

Drupal\uc_paypal\Controller

Code

public function wpsComplete(OrderInterface $uc_order) {

  // If the order ID specified in the return URL is not the same as the one in
  // the user's session, we need to assume this is either a spoof or that the
  // user tried to adjust the order on this side while at PayPal. If it was a
  // legitimate checkout, the IPN will still come in from PayPal so the order
  // gets processed correctly. We'll leave an ambiguous message just in case.
  $session = \Drupal::service('session');
  if (!$session
    ->has('cart_order') || intval($session
    ->get('cart_order')) != $uc_order
    ->id()) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Thank you for your order! PayPal will notify us once your payment has been processed.'));
    return $this
      ->redirect('uc_cart.cart');
  }

  // Ensure the payment method is PayPal WPS.
  $method = \Drupal::service('plugin.manager.uc_payment.method')
    ->createFromOrder($uc_order);
  if (!$method instanceof PayPalPaymentsStandard) {
    return $this
      ->redirect('uc_cart.cart');
  }

  // This lets us know it's a legitimate access of the complete page.
  $session = \Drupal::service('session');
  $session
    ->set('uc_checkout_complete_' . $uc_order
    ->id(), TRUE);
  return $this
    ->redirect('uc_cart.checkout_complete');
}