public function SimpleCheckoutForm::submitForm in Stripe 8
Same name and namespace in other branches
- 2.x modules/stripe_examples/src/Form/SimpleCheckoutForm.php \Drupal\stripe_examples\Form\SimpleCheckoutForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- modules/
stripe_examples/ src/ Form/ SimpleCheckoutForm.php, line 68
Class
- SimpleCheckoutForm
- Class SimpleCheckout.
Namespace
Drupal\stripe_examples\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this
->checkTestStripeApiKey()) {
// Make test charge if we have test environment and api key.
$stripe_token = $form_state
->getValue('stripe');
$charge = $this
->createCharge($stripe_token, 25);
if ($charge) {
$this
->messenger()
->addStatus('Charge status: ' . $charge->status);
if ($charge->status == 'succeeded') {
$link_generator = \Drupal::service('link_generator');
$this
->messenger()
->addStatus($this
->t('Please check payments in @link.', [
'@link' => $link_generator
->generate('stripe dashboard', Url::fromUri('https://dashboard.stripe.com/test/payments')),
]));
}
}
}
// Display result.
foreach ($form_state
->getValues() as $key => $value) {
$this
->messenger()
->addStatus($key . ': ' . $value);
}
}