You are here

public function PayPalPaymentsStandard::buildConfigurationForm in Ubercart 8.4

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\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().

Return value

array The form structure.

Overrides PayPalPaymentMethodPluginBase::buildConfigurationForm

File

payment/uc_paypal/src/Plugin/Ubercart/PaymentMethod/PayPalPaymentsStandard.php, line 89

Class

PayPalPaymentsStandard
Defines the PayPal Payments Standard payment method.

Namespace

Drupal\uc_paypal\Plugin\Ubercart\PaymentMethod

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['wps_email'] = [
    '#type' => 'email',
    '#title' => $this
      ->t('PayPal e-mail address'),
    '#description' => $this
      ->t('The e-mail address you use for the PayPal account you want to receive payments.'),
    '#default_value' => $this->configuration['wps_email'],
  ];
  $languages = [
    'AU',
    'DE',
    'FR',
    'IT',
    'GB',
    'ES',
    'US',
  ];
  $form['wps_language'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('PayPal login page language'),
    '#options' => array_combine($languages, $languages),
    '#default_value' => $this->configuration['wps_language'],
  ];
  $form['wps_server'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('PayPal server'),
    '#description' => $this
      ->t('Sign up for and use a Sandbox account for testing.'),
    '#options' => [
      'https://www.sandbox.paypal.com/cgi-bin/webscr' => 'Sandbox',
      'https://www.paypal.com/cgi-bin/webscr' => 'Live',
    ],
    '#default_value' => $this->configuration['wps_server'],
  ];
  $form['wps_payment_action'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Payment action'),
    '#description' => $this
      ->t('"Complete sale" will authorize and capture the funds at the time the payment is processed.<br />"Authorization" will only reserve funds on the card to be captured later through your PayPal account.'),
    '#options' => [
      'Sale' => $this
        ->t('Complete sale'),
      'Authorization' => $this
        ->t('Authorization'),
    ],
    '#default_value' => $this->configuration['wps_payment_action'],
  ];
  $form['wps_submit_method'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('PayPal cart submission method'),
    '#options' => [
      'single' => $this
        ->t('Submit the whole order as a single line item.'),
      'itemized' => $this
        ->t('Submit an itemized order showing each product and description.'),
    ],
    '#default_value' => $this->configuration['wps_submit_method'],
  ];
  $form['wps_no_shipping'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Shipping address prompt in PayPal'),
    '#options' => [
      '1' => $this
        ->t('Do not show shipping address prompt at PayPal.'),
      '0' => $this
        ->t('Prompt customer to include a shipping address.'),
      '2' => $this
        ->t('Require customer to provide a shipping address.'),
    ],
    '#default_value' => $this->configuration['wps_no_shipping'],
  ];
  $form['wps_address_override'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Submit address information to PayPal to override PayPal stored addresses.'),
    '#description' => $this
      ->t('Works best with the first option above.'),
    '#default_value' => $this->configuration['wps_address_override'],
  ];
  $form['wps_address_selection'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Sent address selection'),
    '#options' => [
      'billing' => $this
        ->t('Send billing address to PayPal.'),
      'delivery' => $this
        ->t('Send shipping address to PayPal.'),
    ],
    '#default_value' => $this->configuration['wps_address_selection'],
  ];
  $form['wps_debug_ipn'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show debug info in the logs for Instant Payment Notifications.'),
    '#default_value' => $this->configuration['wps_debug_ipn'],
  ];
  return $form;
}