You are here

public function EcController::ecComplete in Ubercart 8.4

Completes the transaction for Express Checkout Mark Flow.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse A redirect to the order complete page (on success) or cart (on failure).

1 string reference to 'EcController::ecComplete'
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/EcController.php, line 19

Class

EcController
Returns responses for PayPal routes.

Namespace

Drupal\uc_paypal\Controller

Code

public function ecComplete() {
  $session = \Drupal::service('session');
  if (!$session
    ->has('TOKEN') || !($order = Order::load($session
    ->get('cart_order')))) {
    $session
      ->remove('cart_order');
    $session
      ->remove('TOKEN');
    $session
      ->remove('PAYERID');
    $this
      ->messenger()
      ->addMessage($this
      ->t('An error has occurred in your PayPal payment. Please review your cart and try again.'));
    return $this
      ->redirect('uc_cart.cart');
  }

  // Get the payer ID from PayPal.
  $plugin = \Drupal::service('plugin.manager.uc_payment.method')
    ->createFromOrder($order);
  $response = $plugin
    ->sendNvpRequest([
    'METHOD' => 'GetExpressCheckoutDetails',
    'TOKEN' => $session
      ->get('TOKEN'),
  ]);
  $session
    ->set('PAYERID', $response['PAYERID']);

  // Immediately complete the order.
  $plugin
    ->orderSubmit($order);

  // Redirect to the order completion page.
  $session
    ->remove('uc_checkout_review_' . $order
    ->id());
  $session
    ->set('uc_checkout_complete_' . $order
    ->id(), TRUE);
  return $this
    ->redirect('uc_cart.checkout_complete');
}