You are here

abstract class UPSRequest in Commerce UPS 8.3

UPS API Service.

@package Drupal\commerce_ups

Hierarchy

Expanded class hierarchy of UPSRequest

File

src/UPSRequest.php, line 10

Namespace

Drupal\commerce_ups
View source
abstract class UPSRequest implements UPSRequestInterface {

  /**
   * The configuration array from a CommerceShippingMethod.
   *
   * @var array
   */
  protected $configuration;

  /**
   * {@inheritdoc}
   */
  public function setConfig(array $configuration) {
    $this->configuration = $configuration;
  }

  /**
   * Returns authentication array for a request.
   *
   * @return array
   *   An array of authentication parameters.
   *
   * @throws \Exception
   */
  public function getAuth() {

    // Verify necessary configuration is available.
    if (empty($this->configuration['api_information']['access_key']) || empty($this->configuration['api_information']['user_id']) || empty($this->configuration['api_information']['password'])) {
      throw new \Exception('Configuration is required.');
    }
    return [
      'access_key' => $this->configuration['api_information']['access_key'],
      'user_id' => $this->configuration['api_information']['user_id'],
      'password' => $this->configuration['api_information']['password'],
    ];
  }

  /**
   * Determine if integration mode (test or live) should be used.
   *
   * @return bool
   *   Integration mode (ie: test) is the default.
   */
  public function useIntegrationMode() {

    // If live mode is enabled, do not use integration mode.
    if (!empty($this->configuration['api_information']['mode']) && $this->configuration['api_information']['mode'] == 'live') {
      return FALSE;
    }

    // Use integration mode by default.
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UPSRequest::$configuration protected property The configuration array from a CommerceShippingMethod. 1
UPSRequest::getAuth public function Returns authentication array for a request.
UPSRequest::setConfig public function Set the request configuration. Overrides UPSRequestInterface::setConfig
UPSRequest::useIntegrationMode public function Determine if integration mode (test or live) should be used.