You are here

public function StripeSettingsForm::buildForm in Stripe 8

Same name and namespace in other branches
  1. 2.x src/Form/StripeSettingsForm.php \Drupal\stripe\Form\StripeSettingsForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/StripeSettingsForm.php, line 34

Class

StripeSettingsForm
Class StripeConfig.

Namespace

Drupal\stripe\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('stripe.settings');
  $live_test_description = $this
    ->t('<p><strong>Important:</strong> Bear in mind that this configuration will be exported in plain text and likely kept under version control. We recommend providing these settings through your settings.php file, directly on the environment and safe from prying eyes.</p>') . $this
    ->t('<a href=":uri">Stripe dashboard</a>', [
    ':uri' => 'https://dashboard.stripe.com/account/apikeys',
  ]);
  $form['environment'] = [
    '#type' => 'radios',
    '#options' => [
      'test' => $this
        ->t('Test'),
      'live' => $this
        ->t('Live'),
    ],
    '#title' => $this
      ->t('Environment'),
    '#default_value' => $config
      ->get('environment'),
    '#required' => TRUE,
  ];
  $form['apikey_test'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Test'),
    '#description' => $live_test_description,
  ];
  $form['apikey_test']['apikey_public_test'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Publishable'),
    '#default_value' => $config
      ->get('apikey')['test']['public'],
  ];
  $form['apikey_test']['apikey_secret_test'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Secret'),
    '#placeholder' => $config
      ->get('apikey')['test']['secret'] ? str_repeat('●', 32) : '',
  ];
  $form['apikey_test']['apikey_webhook_test'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Webhook secret'),
    '#placeholder' => $config
      ->get('apikey')['test']['webhook'] ? str_repeat('●', 32) : '',
    '#description' => $this
      ->t('Use the <a href=":uri">webhook signature</a> to validate it, otherwise it will be validated by checking back with stripe.', [
      ':uri' => 'https://stripe.com/docs/webhooks#signatures',
    ]),
  ];
  $form['apikey_live'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Live'),
    '#description' => $live_test_description,
  ];
  $form['apikey_live']['apikey_public_live'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Publishable'),
    '#default_value' => $config
      ->get('apikey')['live']['public'],
  ];
  $form['apikey_live']['apikey_secret_live'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Secret'),
    '#placeholder' => $config
      ->get('apikey')['live']['secret'] ? str_repeat('●', 32) : '',
  ];
  $form['apikey_live']['apikey_webhook_live'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Webhook secret'),
    '#placeholder' => $config
      ->get('apikey')['live']['webhook'] ? str_repeat('●', 32) : '',
    '#description' => $this
      ->t('Use the <a href=":uri">webhook signature</a> to validate it, otherwise it will be validated by checking back with stripe.', [
      ':uri' => 'https://stripe.com/docs/webhooks#signatures',
    ]),
  ];
  return parent::buildForm($form, $form_state);
}