You are here

protected function AcceptJs::getLineItems in Commerce Authorize.Net 8

Gets the line items from order.

Parameters

\Drupal\commerce_order\Entity\OrderInterface $order: The order.

Return value

\CommerceGuys\AuthNet\DataTypes\LineItem[] An array of line items.

Overrides OnsiteBase::getLineItems

1 call to AcceptJs::getLineItems()
AcceptJs::createPayment in src/Plugin/Commerce/PaymentGateway/AcceptJs.php
Creates a payment.

File

src/Plugin/Commerce/PaymentGateway/AcceptJs.php, line 819

Class

AcceptJs
Provides the Accept.js payment gateway.

Namespace

Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway

Code

protected function getLineItems(OrderInterface $order) {
  $line_items = [];
  foreach ($order
    ->getItems() as $order_item) {
    $name = $order_item
      ->label();
    $name = strlen($name) > 31 ? substr($name, 0, 28) . '...' : $name;
    $line_items[] = new LineItem([
      'itemId' => $order_item
        ->id(),
      'name' => $name,
      'quantity' => $order_item
        ->getQuantity(),
      'unitPrice' => $order_item
        ->getUnitPrice()
        ->getNumber(),
    ]);
  }
  return $line_items;
}