You are here

abstract class PayPalBasic in PayPal for Payment 2.0.x

Same name in this branch
  1. 2.0.x src/Plugin/Payment/MethodConfiguration/PayPalBasic.php \Drupal\paypal_payment\Plugin\Payment\MethodConfiguration\PayPalBasic
  2. 2.0.x src/Plugin/Payment/Method/PayPalBasic.php \Drupal\paypal_payment\Plugin\Payment\Method\PayPalBasic
Same name and namespace in other branches
  1. 8 src/Plugin/Payment/MethodConfiguration/PayPalBasic.php \Drupal\paypal_payment\Plugin\Payment\MethodConfiguration\PayPalBasic

Abstract class for PayPal payment method configurations.

Hierarchy

  • class \Drupal\paypal_payment\Plugin\Payment\MethodConfiguration\PayPalBasic extends \Drupal\payment\Plugin\Payment\MethodConfiguration\Basic

Expanded class hierarchy of PayPalBasic

File

src/Plugin/Payment/MethodConfiguration/PayPalBasic.php, line 13

Namespace

Drupal\paypal_payment\Plugin\Payment\MethodConfiguration
View source
abstract class PayPalBasic extends Basic {

  /**
   * Gets the setting for the production server.
   *
   * @return bool
   */
  public function isProduction() : bool {
    return !empty($this->configuration['production']);
  }

  /**
   * Gets the setting for logging the PayPal API traffic.
   *
   * @param $type
   *
   * @return bool
   */
  public function isLogging($type) : bool {
    return !empty($this->configuration['logging'][$type]);
  }

  /**
   * Gets the setting for the log level.
   *
   * @return string
   */
  public function getLogLevel() : string {
    return $this->configuration['loglevel'] ?? 'DEBUG';
  }

  /**
   * {@inheritdoc}
   */
  public function processBuildConfigurationForm(array &$element, FormStateInterface $form_state, array &$form) {
    parent::processBuildConfigurationForm($element, $form_state, $form);
    $element['paypal'] = [
      '#type' => 'container',
    ];
    $element['paypal']['production'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Production Server'),
      '#default_value' => $this
        ->isProduction(),
    ];
    $element['paypal']['logging'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Logging'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    ];
    $element['paypal']['logging']['loglevel'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Log Level'),
      '#options' => [
        'DEBUG' => $this
          ->t('Debugging'),
      ],
      '#default_value' => $this
        ->getLogLevel(),
    ];
    $element['paypal']['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_ADMIN] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Logging admin tasks'),
      '#default_value' => $this
        ->isLogging(PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_ADMIN),
    ];
    $element['paypal']['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_CREATE] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Logging when creating payment'),
      '#default_value' => $this
        ->isLogging(PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_CREATE),
    ];
    $element['paypal']['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_WEBHOOK] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Logging the webhooks'),
      '#default_value' => $this
        ->isLogging(PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_WEBHOOK),
    ];
    $element['paypal']['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_REDIRECT] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Logging the redirects back from PayPal'),
      '#default_value' => $this
        ->isLogging(PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_REDIRECT),
    ];
    return $element;
  }

  /**
   * {{@inheritdoc}}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);
    $parents = $form['plugin_form']['paypal']['#parents'];
    array_pop($parents);
    $values = $form_state
      ->getValues();
    $values = NestedArray::getValue($values, $parents);
    $this->configuration['production'] = !empty($values['paypal']['production']);
    $this->configuration['loglevel'] = $values['paypal']['logging']['loglevel'];
    $this->configuration['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_ADMIN] = !empty($values['paypal']['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_ADMIN]);
    $this->configuration['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_CREATE] = !empty($values['paypal']['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_CREATE]);
    $this->configuration['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_WEBHOOK] = !empty($values['paypal']['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_WEBHOOK]);
    $this->configuration['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_REDIRECT] = !empty($values['paypal']['logging'][PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_REDIRECT]);
  }

  /**
   * @return array
   */
  public function getDerivativeConfiguration() : array {
    return [
      'production' => $this
        ->isProduction(),
      'loglevel' => $this
        ->getLogLevel(),
      'logging' => [
        PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_ADMIN => $this
          ->isLogging(PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_ADMIN),
        PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_CREATE => $this
          ->isLogging(PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_CREATE),
        PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_WEBHOOK => $this
          ->isLogging(PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_WEBHOOK),
        PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_REDIRECT => $this
          ->isLogging(PayPalBasicMethod::PAYPAL_CONTEXT_TYPE_REDIRECT),
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PayPalBasic::getDerivativeConfiguration public function 2
PayPalBasic::getLogLevel public function Gets the setting for the log level.
PayPalBasic::isLogging public function Gets the setting for logging the PayPal API traffic.
PayPalBasic::isProduction public function Gets the setting for the production server.
PayPalBasic::processBuildConfigurationForm public function 2
PayPalBasic::submitConfigurationForm public function {} 2