You are here

final class PaymentOption in Commerce Core 8.2

Represents a payment option.

Hierarchy

Expanded class hierarchy of PaymentOption

See also

\Drupal\commerce_payment\PaymentOptionsBuilderInterface::buildOptions()

3 files declare their use of PaymentOption
PaymentAddForm.php in modules/payment/src/Form/PaymentAddForm.php
PaymentInformation.php in modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php
PaymentMethodAddForm.php in modules/payment/src/Form/PaymentMethodAddForm.php

File

modules/payment/src/PaymentOption.php, line 10

Namespace

Drupal\commerce_payment
View source
final class PaymentOption {

  /**
   * The ID.
   *
   * @var string
   */
  protected $id;

  /**
   * The label.
   *
   * @var string
   */
  protected $label;

  /**
   * The payment gateway ID.
   *
   * @var string
   */
  protected $paymentGatewayId;

  /**
   * The payment method ID, when known.
   *
   * @var string
   */
  protected $paymentMethodId;

  /**
   * The payment method type ID, when known.
   *
   * @var string
   */
  protected $paymentMethodTypeId;

  /**
   * Constructs a new PaymentOption object.
   *
   * @param array $definition
   *   The definition.
   */
  public function __construct(array $definition) {
    foreach ([
      'id',
      'label',
      'payment_gateway_id',
    ] as $required_property) {
      if (empty($definition[$required_property])) {
        throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $required_property));
      }
    }
    $this->id = $definition['id'];
    $this->label = $definition['label'];
    $this->paymentGatewayId = $definition['payment_gateway_id'];
    if (isset($definition['payment_method_id'])) {
      $this->paymentMethodId = $definition['payment_method_id'];
    }
    if (isset($definition['payment_method_type_id'])) {
      $this->paymentMethodTypeId = $definition['payment_method_type_id'];
    }
  }

  /**
   * Gets the ID.
   *
   * @return string
   *   The ID.
   */
  public function getId() : string {
    return $this->id;
  }

  /**
   * Gets the label.
   *
   * @return string
   *   The label.
   */
  public function getLabel() : string {
    return $this->label;
  }

  /**
   * Gets the payment gateway ID.
   *
   * @return string
   *   The payment gateway ID.
   */
  public function getPaymentGatewayId() : string {
    return $this->paymentGatewayId;
  }

  /**
   * Gets the payment method ID.
   *
   * Only available when selecting existing payment methods.
   *
   * @return string|null
   *   The payment method ID, or NULL if not known.
   */
  public function getPaymentMethodId() {
    return $this->paymentMethodId;
  }

  /**
   * Gets the payment method type ID.
   *
   * Only available when adding payment methods.
   *
   * @return string|null
   *   The payment method type ID, or NULL if not known.
   */
  public function getPaymentMethodTypeId() {
    return $this->paymentMethodTypeId;
  }

  /**
   * Gets the array representation of the payment option.
   *
   * @return array
   *   The array representation of the payment option.
   */
  public function toArray() : array {
    return [
      'id' => $this->id,
      'label' => $this->label,
      'payment_gateway_id' => $this->paymentGatewayId,
      'payment_method_id' => $this->paymentMethodId,
      'payment_method_type_id' => $this->paymentMethodTypeId,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentOption::$id protected property The ID.
PaymentOption::$label protected property The label.
PaymentOption::$paymentGatewayId protected property The payment gateway ID.
PaymentOption::$paymentMethodId protected property The payment method ID, when known.
PaymentOption::$paymentMethodTypeId protected property The payment method type ID, when known.
PaymentOption::getId public function Gets the ID.
PaymentOption::getLabel public function Gets the label.
PaymentOption::getPaymentGatewayId public function Gets the payment gateway ID.
PaymentOption::getPaymentMethodId public function Gets the payment method ID.
PaymentOption::getPaymentMethodTypeId public function Gets the payment method type ID.
PaymentOption::toArray public function Gets the array representation of the payment option.
PaymentOption::__construct public function Constructs a new PaymentOption object.