You are here

final class Avatax in Drupal Commerce Connector for AvaTax 8

Same name in this branch
  1. 8 src/Avatax.php \Drupal\commerce_avatax\Avatax
  2. 8 src/Plugin/Commerce/TaxType/Avatax.php \Drupal\commerce_avatax\Plugin\Commerce\TaxType\Avatax

Hierarchy

  • class \Drupal\commerce_avatax\Avatax

Expanded class hierarchy of Avatax

1 file declares its use of Avatax
OrderSubscriber.php in src/EventSubscriber/OrderSubscriber.php

File

src/Avatax.php, line 9

Namespace

Drupal\commerce_avatax
View source
final class Avatax {

  /**
   * Gets the list of Tax exemption types.
   *
   * @return array
   *   The exemption types, keyed by code.
   */
  public static function getExemptionTypes() {
    return [
      'A' => new TranslatableMarkup('Federal government (United States)'),
      'B' => new TranslatableMarkup('State government (United States)'),
      'C' => new TranslatableMarkup('Tribe / Status Indian / Indian Band'),
      'D' => new TranslatableMarkup('Foreign diplomat'),
      'E' => new TranslatableMarkup('Charitable or benevolent org'),
      'F' => new TranslatableMarkup('Religious or educational org'),
      'G' => new TranslatableMarkup('Resale'),
      'H' => new TranslatableMarkup('Commercial agricultural production'),
      'I' => new TranslatableMarkup('Industrial production / manufacturer'),
      'J' => new TranslatableMarkup('Direct pay permit (United States)'),
      'K' => new TranslatableMarkup('Direct mail (United States)'),
      'L' => new TranslatableMarkup('Other'),
      'N' => new TranslatableMarkup('Local government (United States)'),
      'P' => new TranslatableMarkup('Commercial aquaculture (Canada)'),
      'Q' => new TranslatableMarkup('Commercial Fishery (Canada)'),
      'R' => new TranslatableMarkup('Non-resident (Canada)'),
    ];
  }

  /**
   * Check if the given order has AvaTax adjustments.
   *
   * @param \Drupal\commerce_order\Entity\OrderInterface $order
   *   The order.
   *
   * @return bool
   *   TRUE if the order has AvaTax adjustments, FALSE if not.
   */
  public static function hasAvataxAdjustments(OrderInterface $order) {

    /** @var \Drupal\commerce_order\Adjustment[] $avatax_adjustments */
    $avatax_adjustments = array_filter($order
      ->collectAdjustments(), function (Adjustment $adjustment) use ($order) {
      return $adjustment
        ->getType() == 'tax' && strpos($adjustment
        ->getSourceId(), 'avatax|') !== FALSE;
    });
    return !empty($avatax_adjustments);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Avatax::getExemptionTypes public static function Gets the list of Tax exemption types.
Avatax::hasAvataxAdjustments public static function Check if the given order has AvaTax adjustments.