You are here

public function Payment::view in Ubercart 8.4

Returns the contents of an order pane as a store administrator.

Parameters

\Drupal\uc_order\OrderInterface $order: The order that is being viewed.

string $view_mode: The view mode that is being used to render the order.

Return value

array A render array showing order data.

Overrides OrderPanePluginInterface::view

File

payment/uc_payment/src/Plugin/Ubercart/OrderPane/Payment.php, line 35

Class

Payment
Specify and collect payment for an order.

Namespace

Drupal\uc_payment\Plugin\Ubercart\OrderPane

Code

public function view(OrderInterface $order, $view_mode) {
  if ($view_mode != 'customer') {
    $build['balance'] = [
      '#markup' => $this
        ->t('Balance: @balance', [
        '@balance' => uc_currency_format(uc_payment_balance($order)),
      ]),
    ];
    $account = \Drupal::currentUser();
    if ($account
      ->hasPermission('view payments')) {
      $build['view_payments'] = [
        '#type' => 'link',
        '#prefix' => ' (',
        '#title' => $this
          ->t('View'),
        '#url' => Url::fromRoute('uc_payments.order_payments', [
          'uc_order' => $order
            ->id(),
        ]),
        '#suffix' => ')',
      ];
    }
    $method = \Drupal::service('plugin.manager.uc_payment.method')
      ->createFromOrder($order);
    $build['method'] = [
      '#markup' => $this
        ->t('Method: @payment_method', [
        '@payment_method' => $method
          ->cartReviewTitle(),
      ]),
      '#prefix' => '<br />',
    ];
    $method_output = $method
      ->orderView($order);
    if (!empty($method_output)) {
      $build['output'] = $method_output + [
        '#prefix' => '<br />',
      ];
    }
  }
  else {
    $method = \Drupal::service('plugin.manager.uc_payment.method')
      ->createFromOrder($order);
    $build['method'] = [
      '#markup' => $this
        ->t('Method: @payment_method', [
        '@payment_method' => $method
          ->cartReviewTitle(),
      ]),
    ];
    $method_output = $method
      ->customerView($order);
    if (!empty($method_output)) {
      $build['output'] = $method_output + [
        '#prefix' => '<br />',
      ];
    }
  }
  return $build;
}