public function SimpleCheckoutForm::buildForm in Stripe 2.x
Same name and namespace in other branches
- 8 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 28
Class
- SimpleCheckoutForm
- Class SimpleCheckout.
Namespace
Drupal\stripe_examples\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$link_generator = \Drupal::service('link_generator');
$form['#theme'] = 'stripe-examples-simple-checkout';
$form['button'] = [
'#type' => 'stripe_paymentrequest',
'#title' => $this
->t('Pay with a button'),
'#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')),
]),
'#stripe_paymentintent_unique' => TRUE,
];
$form['first'] = [
'#type' => 'textfield',
'#title' => $this
->t('First name'),
'#description' => $this
->t('Anything other than "John" would give a validation error to test different scenarios.'),
];
$form['last'] = [
'#type' => 'textfield',
'#title' => $this
->t('Last name'),
];
$form['card'] = [
'#type' => 'stripe',
'#title' => $this
->t('Credit card'),
'#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')),
]),
'#stripe_paymentintent_unique' => TRUE,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
$form['submit']['#value'] = $this
->t('Pay $25');
$form['#attached']['library'][] = 'stripe_examples/stripe_examples';
return $form;
}