You are here

public function SimpleCheckoutForm::submitForm in Stripe 2.x

Same name and namespace in other branches
  1. 8 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 84

Class

SimpleCheckoutForm
Class SimpleCheckout.

Namespace

Drupal\stripe_examples\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Display result.
  foreach ($form_state
    ->getValues() as $key => $value) {
    if ($key == 'card') {
      $this
        ->messenger()
        ->addStatus('card/payment_intent: ' . $value['payment_intent'] ?? '');
      continue;
    }
    if ($key == 'button') {
      $this
        ->messenger()
        ->addStatus('button/payment_intent: ' . $value['payment_intent'] ?? '');
      continue;
    }
    $this
      ->messenger()
      ->addStatus($key . ': ' . $value);
  }
  $config = \Drupal::config('stripe.settings');
  $apikeySecret = $config
    ->get('apikey.' . $config
    ->get('environment') . '.secret');

  // Quick test of subscription creation
  $stripe = new \Stripe\StripeClient($apikeySecret);

  // $customer = $stripe->customer->create([
  //   'customer' => 'cus_J4sMTZH5VcpNxu',
  //   'items' => [
  //     ['price' => 'price_1ISibg2Jih6Bdv92IyZkqVu7'],
  //   ],
  // ]);
  // $stripe->subscriptions->create([
  //   'customer' => 'cus_J4sMTZH5VcpNxu',
  //   'items' => [
  //     ['price' => 'price_1ISibg2Jih6Bdv92IyZkqVu7'],
  //   ],
  // ]);
}