You are here

public function PaymentMethodAddForm::buildPayPalForm in Commerce Braintree 8

Builds the PayPal form.

Empty by default because there is no generic PayPal form, it's always payment gateway specific (and usually JS based).

Parameters

array $element: The target element.

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

Return value

array The built credit card form.

Overrides PaymentMethodAddForm::buildPayPalForm

1 call to PaymentMethodAddForm::buildPayPalForm()
PaymentMethodAddForm::buildConfigurationForm in src/PluginForm/HostedFields/PaymentMethodAddForm.php
Form constructor.

File

src/PluginForm/HostedFields/PaymentMethodAddForm.php, line 28

Class

PaymentMethodAddForm
Provides the HostedFields payment method add form.

Namespace

Drupal\commerce_braintree\PluginForm\HostedFields

Code

public function buildPayPalForm(array $element, FormStateInterface $form_state) {

  /** @var \Drupal\commerce_braintree\Plugin\Commerce\PaymentGateway\HostedFieldsInterface $plugin */
  $plugin = $this->plugin;
  $element['#attached']['library'][] = 'commerce_braintree/paypal';
  $element['#attached']['drupalSettings']['commerceBraintree'] = [
    'clientToken' => $plugin
      ->generateClientToken(),
    'integration' => 'paypal',
    'paypalButton' => 'paypal-button',
    'environment' => $plugin
      ->getMode() == 'test' ? 'sandbox' : 'production',
    'paymentMethodType' => $this->entity
      ->bundle(),
  ];
  $element['#attributes']['class'][] = 'braintree-form';
  $element['paypal_button'] = [
    '#type' => 'container',
    '#id' => 'paypal-button',
  ];

  // Populated by the JS library.
  $element['payment_method_nonce'] = [
    '#type' => 'hidden',
    '#attributes' => [
      'class' => [
        'braintree-nonce',
      ],
    ],
  ];

  // Put the PayPal button below the billing address.
  $element['#weight'] = 50;
  return $element;
}