You are here

public function Braintree3DSReview::submitPaneForm in Commerce Braintree 8

Handles the submission of an 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::submitPaneForm

File

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

Class

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

Namespace

Drupal\commerce_braintree\Plugin\Commerce\CheckoutPane

Code

public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
  $values = $form_state
    ->getValue($pane_form['#parents']);

  /** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
  $payment_method = $this->order
    ->get('payment_method')->entity;

  // The payment method nonce should be used for this one time purchase and
  // the previous tokenized payment method should be kept for future
  // purchases.
  $three_d_payment_method = $payment_method
    ->createDuplicate();
  $three_d_payment_method
    ->setRemoteId($values['payment_method_nonce']);
  $three_d_payment_method
    ->setReusable(FALSE);
  $three_d_payment_method
    ->save();
  $this->order
    ->set('payment_method', $payment_method);
}