You are here

class FedExRequest in Commerce FedEx 8

Manage FedEx API services.

@package Drupal\commerce_fedex

Hierarchy

Expanded class hierarchy of FedExRequest

2 files declare their use of FedExRequest
FedExUnitTestBase.php in tests/src/Unit/FedExUnitTestBase.php
TestFedExRequest.php in tests/modules/commerce_fedex_test/src/TestFedExRequest.php
1 string reference to 'FedExRequest'
commerce_fedex.services.yml in ./commerce_fedex.services.yml
commerce_fedex.services.yml
1 service uses FedExRequest
commerce_fedex.fedex_request in ./commerce_fedex.services.yml
Drupal\commerce_fedex\FedExRequest

File

src/FedExRequest.php, line 20

Namespace

Drupal\commerce_fedex
View source
class FedExRequest implements FedExRequestInterface {

  /**
   * {@inheritdoc}
   */
  public function __call($name, $arguments) {
    if (strpos($name, "get") !== 0) {
      throw new \Exception("Method {$name} not found");
    }
    $name = substr($name, 3);
    $configuration = $arguments[0];
    if (strpos($name, "Service") !== FALSE) {
      if (!class_exists("\\NicholasCreativeMedia\\FedExPHP\\Services\\{$name}")) {
        throw new \Exception("FedEx service {$name} not found");
      }
      $wsdl_options = $arguments[1] ?: [];
      $reset_soap_client = isset($arguments[2]) ? $arguments[2] : TRUE;
      return new $name($wsdl_options, $reset_soap_client, $this
        ->getMode($configuration));
    }
    if (strpos($name, "Request") !== FALSE) {
      if (!class_exists("\\NicholasCreativeMedia\\FedExPHP\\Services\\{$name}")) {
        throw new \Exception("Request Type {$name} not found");
      }
      return new $name($this
        ->getWebAuthenticationDetail($configuration), $this
        ->getClientDetail($configuration));
    }
    throw new \Exception("Method {$name} not found");
  }

  /**
   * {@inheritdoc}
   */
  public function getRateRequest(array $configuration) {
    $rate_request = new RateRequest($this
      ->getWebAuthenticationDetail($configuration), $this
      ->getClientDetail($configuration));
    return $rate_request;
  }

  /**
   * {@inheritdoc}
   */
  public function getRateService(array $configuration, array $wsdlOptions = [], $resetSoapClient = TRUE) {
    $rate_service = new RateService($wsdlOptions, $resetSoapClient, $this
      ->getMode($configuration));
    return $rate_service;
  }

  /**
   * {@inheritdoc}
   */
  public function getTrackRequest(array $configuration) {
    $track_request = new TrackRequest($this
      ->getWebAuthenticationDetail($configuration), $this
      ->getClientDetail($configuration));
    return $track_request;
  }

  /**
   * {@inheritdoc}
   */
  public function getTrackService(array $configuration, array $wsdlOptions = [], $resetSoapClient = TRUE) {
    $track_service = new TrackService($wsdlOptions, $resetSoapClient, $this
      ->getMode($configuration));
    return $track_service;
  }

  /**
   * {@inheritdoc}
   */
  public function getShipRequest(array $configuration) {
    $ship_request = new ProcessShipmentRequest($this
      ->getWebAuthenticationDetail($configuration), $this
      ->getClientDetail($configuration));
    return $ship_request;
  }

  /**
   * {@inheritdoc}
   */
  public function getShipService(array $configuration, array $wsdlOptions = [], $resetSoapClient = TRUE) {
    $ship_service = new ShipService($wsdlOptions, $resetSoapClient, $this
      ->getMode($configuration));
    return $ship_service;
  }

  /**
   * {@inheritdoc}
   */
  public function getWebAuthenticationDetail(array $configuration) {
    $web_authentication_detail = new WebAuthenticationDetail();
    $web_authentication_detail
      ->setUserCredential(new WebAuthenticationCredential($configuration['api_information']['api_key'], $configuration['api_information']['api_password']));
    return $web_authentication_detail;
  }

  /**
   * {@inheritdoc}
   */
  public function getClientDetail(array $configuration) {
    $client_detail = new ClientDetail($configuration['api_information']['account_number'], $configuration['api_information']['meter_number'], '123');
    return $client_detail;
  }

  /**
   * {@inheritdoc}
   */
  public function getVersion($service) {
    $class = '\\NicholasCreativeMedia\\FedExPHP\\Services\\' . $service;
    if (!class_exists($class)) {
      throw new \Exception("Service {$class} not found");
    }

    /** @var \NicholasCreativeMedia\FedExPHP\Services\FedExService $class */
    return $class::version();
  }

  /**
   * Gets the mode to use to connect.
   *
   * @param array $configuration
   *   The configuration array.
   *
   * @return string
   *   The mode (test or live).
   */
  protected function getMode(array $configuration) {
    $mode = 'test';
    if (!empty($configuration['api_information']['mode'])) {
      $mode = $configuration['api_information']['mode'];
    }
    return $mode;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FedExRequest::getClientDetail public function
FedExRequest::getMode protected function Gets the mode to use to connect.
FedExRequest::getRateRequest public function Gets a new rate request. Overrides FedExRequestInterface::getRateRequest
FedExRequest::getRateService public function Gets a new RateService. Overrides FedExRequestInterface::getRateService 1
FedExRequest::getShipRequest public function Gets a new ShipRequest. Overrides FedExRequestInterface::getShipRequest
FedExRequest::getShipService public function Gets a new ShipService. Overrides FedExRequestInterface::getShipService
FedExRequest::getTrackRequest public function Gets a new TrackRequest. Overrides FedExRequestInterface::getTrackRequest
FedExRequest::getTrackService public function Gets a new TrackService. Overrides FedExRequestInterface::getTrackService
FedExRequest::getVersion public function Return the current WSDL version of a service. Overrides FedExRequestInterface::getVersion
FedExRequest::getWebAuthenticationDetail public function
FedExRequest::__call public function