You are here

public function StripeGateway::validateConfigurationForm in Ubercart Stripe 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Ubercart/PaymentMethod/StripeGateway.php \Drupal\uc_stripe\Plugin\Ubercart\PaymentMethod\StripeGateway::validateConfigurationForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PaymentMethodPluginBase::validateConfigurationForm

File

src/Plugin/Ubercart/PaymentMethod/StripeGateway.php, line 78

Class

StripeGateway
Stripe Ubercart gateway payment method.

Namespace

Drupal\uc_stripe\Plugin\Ubercart\PaymentMethod

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  $elements = [
    'test_secret_key',
    'test_publishable_key',
    'live_secret_key',
    'live_publishable_key',
  ];
  foreach ($elements as $element_name) {
    $raw_key = $form_state
      ->getValue([
      'settings',
      $element_name,
    ]);
    $sanitized_key = $this
      ->trimKey($raw_key);
    $form_state
      ->setValue([
      'settings',
      $element_name,
    ], $sanitized_key);
    if (!$this
      ->validateKey($form_state
      ->getValue([
      'settings',
      $element_name,
    ]))) {
      $form_state
        ->setError($form[$element_name], t('@name does not appear to be a valid stripe key', array(
        '@name' => $element_name,
      )));
    }
  }
  parent::validateConfigurationForm($form, $form_state);
}