You are here

function commerce_paypal_checkout_settings_form in Commerce PayPal 7.2

Payment method callback: settings form.

File

modules/checkout/commerce_paypal_checkout.module, line 258
Implements PayPal Checkout in Drupal Commerce checkout.

Code

function commerce_paypal_checkout_settings_form($settings = array()) {
  $form = array();

  // Merge default settings into the stored settings array.
  $settings = (array) $settings + commerce_paypal_checkout_default_settings();
  $shipping_module_enabled = module_exists('commerce_shipping');
  $form['client_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Client ID'),
    '#maxlength' => 255,
    '#default_value' => $settings['client_id'],
    '#required' => TRUE,
  );
  $form['secret'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret'),
    '#maxlength' => 255,
    '#default_value' => $settings['secret'],
    '#required' => TRUE,
  );
  $form['server'] = array(
    '#type' => 'radios',
    '#title' => t('PayPal server'),
    '#options' => array(
      'sandbox' => 'Sandbox - use for testing, requires a PayPal Sandbox account',
      'live' => 'Live - use for processing real transactions',
    ),
    '#default_value' => $settings['server'],
  );
  $form['intent'] = array(
    '#type' => 'radios',
    '#title' => t('Transaction type'),
    '#options' => array(
      'capture' => t('Capture'),
      'authorize' => t('Authorize'),
    ),
    '#default_value' => $settings['intent'],
  );
  $form['disable_funding'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Disable funding sources'),
    '#description' => t('The disabled funding sources for the transaction. Any funding sources passed are not displayed in the Smart payment buttons. By default, funding source eligibility is smartly decided based on a variety of factors.'),
    '#options' => array(
      'card' => t('Credit or Debit Cards'),
      'credit' => t('PayPal Credit'),
      'sepa' => t('SEPA-Lastschrift'),
    ),
    '#default_value' => $settings['disable_funding'],
    '#element_validate' => array(
      'commerce_paypal_checkout_disable_funding_validate',
    ),
  );
  $form['disable_card'] = array(
    '#title' => t('Disable card types'),
    '#description' => t('The disabled cards for the transaction. Any cards passed do not display in the Smart payment buttons. By default, card eligibility is smartly decided based on a variety of factors.'),
    '#type' => 'checkboxes',
    '#options' => array(
      'visa' => t('Visa'),
      'mastercard' => t('Mastercard'),
      'amex' => t('American Express'),
      'discover' => t('Discover'),
      'dinersclub' => t('Diners Club'),
      'unionpay' => t('UnionPay'),
      'jcb' => t('JCB'),
      'elo' => t('Elo'),
      'hiper' => t('Hiper'),
    ),
    '#default_value' => $settings['disable_card'],
    '#element_validate' => array(
      'commerce_paypal_checkout_disable_card_validate',
    ),
  );
  $form['shipping_preference'] = array(
    '#type' => 'radios',
    '#title' => t('Shipping address collection'),
    '#description' => t('PayPal Checkout will only request a shipping address if the Shipping module is enabled to store the address in the order.'),
    '#options' => array(
      'no_shipping' => t('Do not ask for a shipping address at PayPal.'),
    ),
    '#default_value' => 'no_shipping',
  );
  if ($shipping_module_enabled) {
    $form['shipping_preference']['#options'] += array(
      'get_from_file' => t('Ask for a shipping address at PayPal even if the order already has one.'),
      'set_provided_address' => t('Ask for a shipping address at PayPal if the order does not have one yet.'),
    );
    $form['shipping_preference']['#default_value'] = $settings['shipping_preference'];
  }
  $form['update_billing_profiles'] = array(
    '#type' => 'checkbox',
    '#title' => t('Update billing customer profiles with address information the customer enters at PayPal.'),
    '#default_value' => $settings['update_billing_profiles'],
  );
  if ($shipping_module_enabled) {
    $form['update_shipping_profiles'] = array(
      '#type' => 'checkbox',
      '#title' => t('Update shipping customer profiles with address information the customer enters at PayPal.'),
      '#default_value' => $settings['update_shipping_profiles'],
    );
  }
  $form['customize_buttons'] = array(
    '#type' => 'checkbox',
    '#title' => t('Smart button style'),
    '#default_value' => !empty($settings['style']),
    '#title_display' => 'before',
    '#field_suffix' => t('Customize'),
    '#description_display' => 'before',
    '#element_validate' => array(
      'commerce_paypal_checkout_customize_buttons_validate',
    ),
  );
  $form['style'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#description' => t('For more information, please visit <a href="@url" target="_blank">customize the PayPal buttons</a>.', array(
      '@url' => 'https://developer.paypal.com/docs/checkout/integration-features/customize-button/#layout',
    )),
    '#states' => array(
      'visible' => array(
        ':input[name="parameter[payment_method][settings][payment_method][settings][customize_buttons]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Define some default values for the style configuration.
  $settings['style'] += [
    'layout' => 'vertical',
    'color' => 'gold',
    'shape' => 'rect',
    'label' => 'paypal',
    'tagline' => FALSE,
  ];
  $form['style']['layout'] = array(
    '#type' => 'select',
    '#title' => t('Layout'),
    '#default_value' => $settings['style']['layout'],
    '#options' => array(
      'vertical' => t('Vertical (Recommended)'),
      'horizontal' => t('Horizontal'),
    ),
  );
  $form['style']['color'] = array(
    '#type' => 'select',
    '#title' => t('Color'),
    '#options' => array(
      'gold' => t('Gold (Recommended)'),
      'blue' => t('Blue'),
      'silver' => t('Silver'),
    ),
    '#default_value' => $settings['style']['color'],
  );
  $form['style']['shape'] = array(
    '#type' => 'select',
    '#title' => t('Shape'),
    '#options' => array(
      'rect' => t('Rect (Default)'),
      'pill' => t('Pill'),
    ),
    '#default_value' => $settings['style']['shape'],
  );
  $form['style']['label'] = array(
    '#type' => 'select',
    '#title' => t('Label'),
    '#options' => array(
      'paypal' => t('Displays the PayPal logo (Default)'),
      'checkout' => t('Displays the PayPal Checkout button'),
      'pay' => t('Displays the Pay With PayPal button and initializes the checkout flow'),
    ),
    '#default_value' => $settings['style']['label'],
  );
  $form['style']['tagline'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display tagline'),
    '#default_value' => $settings['style']['tagline'],
    '#states' => array(
      'visible' => array(
        ':input[name="parameter[payment_method][settings][payment_method][settings][style][layout]"]' => array(
          'value' => 'horizontal',
        ),
      ),
    ),
  );
  $form['enable_on_cart'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show the Smart payment buttons on the cart form.'),
    '#default_value' => $settings['enable_on_cart'],
  );
  return $form;
}