You are here

public function SimpleCheckoutForm::buildForm in Stripe 8

Same name and namespace in other branches
  1. 2.x modules/stripe_examples/src/Form/SimpleCheckoutForm.php \Drupal\stripe_examples\Form\SimpleCheckoutForm::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 FormInterface::buildForm

File

modules/stripe_examples/src/Form/SimpleCheckoutForm.php, line 29

Class

SimpleCheckoutForm
Class SimpleCheckout.

Namespace

Drupal\stripe_examples\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $link_generator = \Drupal::service('link_generator');
  $form['first'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('First name'),
  ];
  $form['last'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Last name'),
  ];
  $form['stripe'] = [
    '#type' => 'stripe',
    '#title' => $this
      ->t('Credit card'),
    // The selectors are gonna be looked within the enclosing form only.
    "#stripe_selectors" => [
      'first_name' => ':input[name="first"]',
      'last_name' => ':input[name="last"]',
    ],
    '#description' => $this
      ->t('You can use test card numbers and tokens from @link.', [
      '@link' => $link_generator
        ->generate('stripe docs', Url::fromUri('https://stripe.com/docs/testing')),
    ]),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  if ($this
    ->checkTestStripeApiKey()) {
    $form['submit']['#value'] = $this
      ->t('Pay $25');
  }
  $form['#attached']['library'][] = 'stripe_examples/stripe_examples';
  return $form;
}