You are here

public function CreditCardPaymentMethodBase::orderView in Ubercart 8.4

Called when an order is being viewed by an administrator.

Parameters

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

Return value

array A render array.

Overrides PaymentMethodPluginBase::orderView

File

payment/uc_credit/src/CreditCardPaymentMethodBase.php, line 371

Class

CreditCardPaymentMethodBase
Defines a base credit card payment method plugin implementation.

Namespace

Drupal\uc_credit

Code

public function orderView(OrderInterface $order) {
  $build = [];

  // Add the hidden span for the CC details if possible.
  $account = \Drupal::currentUser();
  if ($account
    ->hasPermission('view cc details')) {
    $rows = [];
    if (!empty($order->payment_details['cc_type'])) {
      $rows[] = $this
        ->t('Card type: @type', [
        '@type' => $order->payment_details['cc_type'],
      ]);
    }
    if (!empty($order->payment_details['cc_owner'])) {
      $rows[] = $this
        ->t('Card owner: @owner', [
        '@owner' => $order->payment_details['cc_owner'],
      ]);
    }
    if (!empty($order->payment_details['cc_number'])) {
      $rows[] = $this
        ->t('Card number: @number', [
        '@number' => $this
          ->displayCardNumber($order->payment_details['cc_number']),
      ]);
    }
    if (!empty($order->payment_details['cc_start_month']) && !empty($order->payment_details['cc_start_year'])) {
      $rows[] = $this
        ->t('Start date: @date', [
        '@date' => $order->payment_details['cc_start_month'] . '/' . $order->payment_details['cc_start_year'],
      ]);
    }
    if (!empty($order->payment_details['cc_exp_month']) && !empty($order->payment_details['cc_exp_year'])) {
      $rows[] = $this
        ->t('Expiration: @expiration', [
        '@expiration' => $order->payment_details['cc_exp_month'] . '/' . $order->payment_details['cc_exp_year'],
      ]);
    }
    if (!empty($order->payment_details['cc_issue'])) {
      $rows[] = $this
        ->t('Issue number: @number', [
        '@number' => $order->payment_details['cc_issue'],
      ]);
    }
    if (!empty($order->payment_details['cc_bank'])) {
      $rows[] = $this
        ->t('Issuing bank: @bank', [
        '@bank' => $order->payment_details['cc_bank'],
      ]);
    }
    $build['cc_info'] = [
      '#markup' => implode('<br />', $rows) . '<br />',
    ];
  }

  // Add the form to process the card if applicable.
  if ($account
    ->hasPermission('process credit cards')) {
    $build['terminal'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Process card'),
      '#url' => Url::fromRoute('uc_credit.terminal', [
        'uc_order' => $order
          ->id(),
        'uc_payment_method' => $order
          ->getPaymentMethodId(),
      ]),
    ];
  }
  return $build;
}