You are here

public function PaymentInformation::buildPaneSummary in Commerce Core 8.2

Builds a summary of the pane values.

Important: The review pane shows summaries for both visible and non-visible panes. To skip showing a summary for a non-visible pane, check isVisible() and return an empty array.

Return value

array A render array containing the summary of the pane values.

Overrides CheckoutPaneBase::buildPaneSummary

File

modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php, line 106

Class

PaymentInformation
Provides the payment information pane.

Namespace

Drupal\commerce_payment\Plugin\Commerce\CheckoutPane

Code

public function buildPaneSummary() {
  $billing_profile = $this->order
    ->getBillingProfile();
  if ($this->order
    ->isPaid() || $this->order
    ->getTotalPrice()
    ->isZero()) {
    if ($billing_profile) {

      // Only the billing information was collected.
      $view_builder = $this->entityTypeManager
        ->getViewBuilder('profile');
      $summary = [
        '#title' => $this
          ->t('Billing information'),
        'profile' => $view_builder
          ->view($billing_profile, 'default'),
      ];
      return $summary;
    }
  }
  $summary = [];

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = $this->order
    ->get('payment_gateway')->entity;
  if (!$payment_gateway) {
    return $summary;
  }
  $payment_method = $this->order
    ->get('payment_method')->entity;
  if ($payment_method) {
    $view_builder = $this->entityTypeManager
      ->getViewBuilder('commerce_payment_method');
    $summary = $view_builder
      ->view($payment_method, 'default');
  }
  else {
    $summary = [
      'payment_gateway' => [
        '#markup' => $payment_gateway
          ->getPlugin()
          ->getDisplayLabel(),
      ],
    ];
    if ($billing_profile) {
      $view_builder = $this->entityTypeManager
        ->getViewBuilder('profile');
      $summary['profile'] = $view_builder
        ->view($billing_profile, 'default');
    }
  }
  return $summary;
}