You are here

protected function PaymentAddForm::buildPaymentMethodForm in Commerce Core 8.2

Builds the payment method form for the selected payment option.

Parameters

array $form: The form.

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

\Drupal\commerce_payment\PaymentOption $payment_option: The payment option.

Return value

array The modified form.

1 call to PaymentAddForm::buildPaymentMethodForm()
PaymentAddForm::buildPaymentGatewayForm in modules/payment/src/Form/PaymentAddForm.php
Builds the form for selecting a payment gateway.

File

modules/payment/src/Form/PaymentAddForm.php, line 246

Class

PaymentAddForm
Provides the payment add form.

Namespace

Drupal\commerce_payment\Form

Code

protected function buildPaymentMethodForm(array $form, FormStateInterface $form_state, PaymentOption $payment_option) {
  if ($payment_option
    ->getPaymentMethodId() && !$payment_option
    ->getPaymentMethodTypeId()) {

    // Editing payment methods at checkout is not supported.
    return $form;
  }

  /** @var \Drupal\commerce_payment\PaymentMethodStorageInterface $payment_method_storage */
  $payment_method_storage = $this->entityTypeManager
    ->getStorage('commerce_payment_method');
  $payment_method = $payment_method_storage
    ->create([
    'type' => $payment_option
      ->getPaymentMethodTypeId(),
    'payment_gateway' => $payment_option
      ->getPaymentGatewayId(),
    'uid' => $this->order
      ->getCustomerId(),
    'billing_profile' => $this->order
      ->getBillingProfile(),
  ]);
  $inline_form = $this->inlineFormManager
    ->createInstance('payment_gateway_form', [
    'operation' => 'add-payment-method',
  ], $payment_method);
  $form['add_payment_method'] = [
    '#parents' => [
      'add_payment_method',
    ],
  ];
  $form['add_payment_method'] = $inline_form
    ->buildInlineForm($form['add_payment_method'], $form_state);
  return $form;
}