You are here

public function Braintree3DSReview::validatePaneForm in Commerce Braintree 8

Validates the pane form.

Parameters

array $pane_form: The pane form.

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

array $complete_form: The complete form structure.

Overrides CheckoutPaneBase::validatePaneForm

File

src/Plugin/Commerce/CheckoutPane/Braintree3DSReview.php, line 147

Class

Braintree3DSReview
Adds 3DS authentication for Braintree vaulted/stored payment methods.

Namespace

Drupal\commerce_braintree\Plugin\Commerce\CheckoutPane

Code

public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
  $error_step_id = $this
    ->getErrorStepId();
  $values = $form_state
    ->getValue($pane_form['#parents']);
  if (empty($values['payment_method_nonce'])) {
    $this->logger
      ->error('Missing payment method nonce.');
    $message = $this
      ->t('We encountered an unexpected error processing your payment method. Please try again later.');
    $this
      ->messenger()
      ->addError($message);
    $this->checkoutFlow
      ->redirectToStep($error_step_id);
  }
  $braintree_plugin = $this->order
    ->get('payment_gateway')->entity
    ->getPlugin();
  $configuration = $braintree_plugin->configuration;
  try {
    $paymentMethodNonce = $braintree_plugin
      ->findPaymentMethodNonce($values['payment_method_nonce']);
    $result = $paymentMethodNonce->threeDSecureInfo;
    $required = isset($configuration['3d_secure']) && $configuration['3d_secure'] == 'required';
    ErrorHelper::handleErrors3ds($result, $required);
  } catch (\Braintree\Exception $e) {
    ErrorHelper::handleException($e);
  } catch (PaymentGatewayException $e) {
    $this->logger
      ->error($e
      ->getMessage());
    $message = $this
      ->t('We encountered an unexpected error processing your payment method. Please try again later.');
    $this
      ->messenger()
      ->addError($message);
    $this->checkoutFlow
      ->redirectToStep($error_step_id);
  }
}