You are here

public function PayflowLink::buildConfigurationForm in Commerce PayPal 8

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 PaymentGatewayBase::buildConfigurationForm

File

src/Plugin/Commerce/PaymentGateway/PayflowLink.php, line 124

Class

PayflowLink
Provides the PayPal Payflow Link payment gateway.

Namespace

Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $form['service_description'] = [
    '#markup' => $this
      ->t('Accept payment securely on your site via credit card, debit card, or PayPal using a merchant account of your choice. This payment gateway requires a PayPal Payflow Link account. <a href="@url">Sign up here</a> and edit these settings to start accepting payments.', [
      '@url' => 'https://www.paypal.com/webapps/mpp/referral/paypal-payflow-link?partner_id=VZ6B9QLQ8LZEE',
    ]),
    '#weight' => '-100',
  ];
  $form['partner'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Partner'),
    '#default_value' => $this->configuration['partner'],
    '#required' => TRUE,
    '#description' => $this
      ->t('Either PayPal or the name of the reseller who registered your Payflow Link account.'),
  ];
  $form['vendor'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Vendor'),
    '#default_value' => $this->configuration['vendor'],
    '#required' => TRUE,
    '#description' => $this
      ->t('The merchant login ID you chose when you created your Payflow Link account.'),
  ];
  $form['user'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('User'),
    '#default_value' => $this->configuration['user'],
    '#required' => TRUE,
    '#description' => $this
      ->t('The name of the user on the account you want to use to process transactions or the merchant login if you have not created users.'),
  ];
  $form['password'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Password'),
    '#default_value' => $this->configuration['password'],
    '#required' => TRUE,
    '#description' => $this
      ->t('The password created for the user specified in the previous textfield.'),
  ];
  $form['trxtype'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default transaction type'),
    '#default_value' => $this->configuration['trxtype'],
    '#required' => TRUE,
    '#options' => [
      'S' => $this
        ->t('Sale - authorize and capture the funds at the time the payment is processed'),
      'A' => $this
        ->t('Authorization - reserve funds on the card to be captured later through your PayPal account'),
    ],
  ];
  $form['redirect_mode'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Checkout redirect mode'),
    '#description' => $this
      ->t('Your payment processor and Payflow Link account settings may limit which of these payment options are actually available on the payment form.'),
    '#default_value' => $this->configuration['redirect_mode'],
    '#required' => TRUE,
    '#options' => [
      'post' => $this
        ->t('Redirect to the hosted checkout page via POST through an automatically submitted form'),
      'get' => $this
        ->t('Redirect to the hosted checkout page immediately with a GET request'),
    ],
  ];
  $form['reference_transactions'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable reference transactions for payments captured through this Payflow Link account.'),
    '#description' => $this
      ->t('Contact PayPal if you are unsure if this option is available to you.'),
    '#default_value' => $this->configuration['reference_transactions'],
  ];
  $form['emailcustomer'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Instruct PayPal to e-mail payment receipts to your customers upon payment.'),
    '#default_value' => $this->configuration['emailcustomer'],
  ];

  // Add the logging configuration form elements.
  $form['log'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Log the following messages for debugging'),
    '#options' => [
      'request' => $this
        ->t('API request messages'),
      'response' => $this
        ->t('API response messages'),
    ],
    '#default_value' => $this->configuration['log'],
  ];
  return $form;
}