You are here

public function PaymentMethodAddForm::submitConfigurationForm in Commerce PayPal 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PaymentMethodAddForm::submitConfigurationForm

File

src/PluginForm/Checkout/PaymentMethodAddForm.php, line 93

Class

PaymentMethodAddForm

Namespace

Drupal\commerce_paypal\PluginForm\Checkout

Code

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

  /** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
  $payment_method = $this->entity;
  $payment_method
    ->setReusable(FALSE);

  // When the gateway is configured to display "Smart payment buttons", the
  // buttons are not injected in the payment information pane but in the
  // "review" step, which means the payment method creation should be skipped.
  if ($this
    ->shouldInjectForm($payment_method
    ->getPaymentGateway()
    ->getPlugin())) {
    parent::submitConfigurationForm($form, $form_state);
  }
  else {

    // Since we're not calling the parent submitConfigurationForm() method
    // we need to duplicate the logic for setting the billing profile

    /** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OnsitePaymentGatewayInterface $payment_gateway_plugin */
    $payment_gateway_plugin = $this->plugin;

    /** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
    $payment_method = $this->entity;
    if ($payment_gateway_plugin
      ->collectsBillingInformation()) {

      /** @var \Drupal\commerce\Plugin\Commerce\InlineForm\EntityInlineFormInterface $inline_form */
      $inline_form = $form['billing_information']['#inline_form'];

      /** @var \Drupal\profile\Entity\ProfileInterface $billing_profile */
      $billing_profile = $inline_form
        ->getEntity();
      $payment_method
        ->setBillingProfile($billing_profile);
    }
  }
}