You are here

function commerce_paypal_ec_settings_form in Commerce PayPal 7.2

Payment method callback: settings form.

File

modules/ec/commerce_paypal_ec.module, line 276
Implements PayPal Express Checkout in Drupal Commerce checkout.

Code

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

  // Merge default settings into the stored settings array.
  $settings = (array) $settings + commerce_paypal_ec_default_settings();
  $form['service_description'] = array(
    '#markup' => '<div>' . commerce_paypal_ec_service_description() . ' ' . t('Refer to the <a href="!url" target="_blank">module documentation</a> to find your API credentials and ensure your payment method and account settings are configured properly.', array(
      '!url' => 'http://drupal.org/node/1901466',
    )) . '</div>',
  );
  $form['api_username'] = array(
    '#type' => 'textfield',
    '#title' => t('API username'),
    '#default_value' => $settings['api_username'],
  );
  $form['api_password'] = array(
    '#type' => 'textfield',
    '#title' => t('API password'),
    '#default_value' => $settings['api_password'],
  );
  $form['api_signature'] = array(
    '#type' => 'textfield',
    '#title' => t('Signature'),
    '#default_value' => $settings['api_signature'],
  );
  $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['currency_code'] = array(
    '#type' => 'select',
    '#title' => t('Default currency'),
    '#description' => t('Transactions in other currencies will be converted to this currency, so multi-currency sites must be configured to use appropriate conversion rates.'),
    '#options' => commerce_paypal_currencies('paypal_ec'),
    '#default_value' => $settings['currency_code'],
  );
  $form['allow_supported_currencies'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow transactions to use any currency in the options list above.'),
    '#description' => t('Transactions in unsupported currencies will still be converted into the default currency.'),
    '#default_value' => $settings['allow_supported_currencies'],
  );
  $form['txn_type'] = array(
    '#type' => 'radios',
    '#title' => t('Default transaction type'),
    '#description' => t('The default will be used to process transactions during checkout.'),
    '#options' => array(
      COMMERCE_CREDIT_AUTH_CAPTURE => t("Sale (direct debit from the customer's PayPal account)"),
      COMMERCE_CREDIT_AUTH_ONLY => t('Authorization only (requires manual or automated capture after checkout)'),
    ),
    '#default_value' => $settings['txn_type'],
  );
  $form['ec_mode'] = array(
    '#type' => 'radios',
    '#title' => t('Express Checkout mode'),
    '#description' => t('Express Checkout Account Optional (ECAO) where PayPal accounts are not required for payment may not be available in all markets.'),
    '#options' => array(
      'Mark' => t('Require a PayPal account (this is the standard configuration).'),
      'SoleLogin' => t('Allow PayPal AND credit card payments, defaulting to the PayPal form.'),
      'SoleBilling' => t('Allow PayPal AND credit card payments, defaulting to the credit card form.'),
    ),
    '#default_value' => $settings['ec_mode'],
  );
  $form['shipping_prompt'] = array(
    '#type' => 'radios',
    '#title' => t('Shipping address collection'),
    '#description' => t('Express Checkout will only request a shipping address if the Shipping module is enabled to store the address in the order.'),
    '#options' => array(
      '0' => t('Do not ask for a shipping address at PayPal.'),
    ),
    '#default_value' => '0',
  );
  if (module_exists('commerce_shipping')) {
    $form['shipping_prompt']['#options'] += array(
      '1' => t('Ask for a shipping address at PayPal if the order does not have one yet.'),
      '2' => t('Ask for a shipping address at PayPal even if the order already has one.'),
    );
    $form['shipping_prompt']['#default_value'] = $settings['shipping_prompt'];
  }
  $form['log'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Log the following messages for debugging'),
    '#options' => array(
      'request' => t('API request messages'),
      'response' => t('API response messages'),
    ),
    '#default_value' => $settings['log'],
  );
  $form['ipn_logging'] = array(
    '#type' => 'radios',
    '#title' => t('IPN logging'),
    '#options' => array(
      'notification' => t('Log notifications during IPN validation and processing.'),
      'full_ipn' => t('Log notifications with the full IPN during validation and processing (used for debugging).'),
    ),
    '#default_value' => $settings['ipn_logging'],
  );
  $form['receiver_emails'] = array(
    '#type' => 'textfield',
    '#title' => t('PayPal receiver e-mail addresses'),
    '#description' => t('Enter the primary e-mail address for your PayPal account where you receive Express Checkout payments or a comma separated list of valid e-mail addresses.') . '<br />' . t('IPNs that originate from payments made to a PayPal account whose e-mail address is not in this list will not be processed.'),
    '#default_value' => $settings['receiver_emails'],
  );
  $form['reference_transactions'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable reference transactions for payments captured through Express Checkout.'),
    '#description' => t('Contact PayPal if you are unsure if this option is available to you.'),
    '#default_value' => $settings['reference_transactions'],
  );
  $form['ba_desc'] = array(
    '#type' => 'textfield',
    '#title' => t('Express Checkout billing agreement description'),
    '#description' => t('If you have a PayPal account that supports reference transactions and need them, you must specify a billing agreement description.'),
    '#default_value' => $settings['ba_desc'],
  );
  $form['show_payment_instructions'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show a message on the checkout form when PayPal EC is selected telling the customer to "Continue with checkout to complete payment via PayPal."'),
    '#default_value' => $settings['show_payment_instructions'],
  );
  $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 (module_exists('commerce_shipping')) {
    $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'],
    );
  }

  // Add that scripts that manage the PayPal Credit popin.
  drupal_add_library('system', 'ui.dialog');
  $form['enable_bml'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable the PayPal Credit button on the shopping cart page.'),
    '#description' => t('By selecting PayPal, you also receive PayPal Credit absolutely FREE. PayPal Credit enables customers to buy now and pay over time. Still not sure? <a href="#" class="paypal-bml-popin">Learn more</a>.'),
    '#default_value' => $settings['enable_bml'],
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'commerce_paypal_ec') . '/theme/commerce_paypal_ec.popin.js',
      ),
    ),
  );
  $form['paypal_bml_help_text'] = array(
    '#markup' => commerce_paypal_ec_bml_help_text(),
  );
  $form['enable_on_cart'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show the PayPal Express Checkout button on the cart form.'),
    '#default_value' => $settings['enable_on_cart'],
  );
  return $form;
}