function commerce_stripe_settings_form in Commerce Stripe 7.3
Same name and namespace in other branches
- 7 commerce_stripe.module \commerce_stripe_settings_form()
- 7.2 commerce_stripe.module \commerce_stripe_settings_form()
Payment method settings form.
Parameters
$settings: Default settings provided from rules
Return value
array Settings form array
File
- ./
commerce_stripe.module, line 222 - This module provides Stripe (http://stripe.com/) payment gateway integration to Commerce. Commerce Stripe offers a PCI-compliant way to process payments straight from you Commerce shop.
Code
function commerce_stripe_settings_form($settings) {
$settings = (array) $settings + commerce_stripe_default_settings();
$form = array();
$currencies = commerce_currencies(TRUE);
$currency_list = array();
$supported_currencies = commerce_stripe_payment_currencies();
// Ensure we only include currencies we support.
foreach ($currencies as $currency_code => $currency) {
if (in_array(strtolower($currency_code), $supported_currencies)) {
$currency_list[$currency_code] = $currency['name'];
}
}
$form['public_key'] = array(
'#type' => 'textfield',
'#title' => t('Publishable Key'),
'#description' => t('Publishable API Key. Get your key from https://stripe.com/'),
'#default_value' => $settings['public_key'],
'#required' => TRUE,
);
$form['secret_key'] = array(
'#type' => 'textfield',
'#title' => t('Secret Key'),
'#description' => t('Secret API Key. Get your key from https://stripe.com/'),
'#default_value' => $settings['secret_key'],
'#required' => TRUE,
);
// If the site has the Commerce Stripe Connect submodule enabled and has
// connected to a site-wide Stripe Standard account, adjust the settings so
// that account's API keys can be used instead of directly inputted here.
if (module_exists('commerce_stripe_connect')) {
$connect_settings = commerce_stripe_connect_get_settings();
if (!empty($connect_settings['connected_account_id'])) {
// Add radio button options as first form element.
$form['use_connected_account'] = array(
'#type' => 'radios',
'#title' => t('API Credentials'),
'#options' => array(
'none' => t('Input API credentials for this payment method.'),
'site account' => t('Use the site-wide account identified via Stripe Connect.'),
),
'#default_value' => $settings['use_connected_account'],
'#weight' => -10,
);
unset($form['secret_key']['#required']);
$form['secret_key']['#states'] = array(
'visible' => array(
':input[name="parameter[payment_method][settings][payment_method][settings][use_connected_account]"]' => array(
'value' => 'none',
),
),
'required' => array(
':input[name="parameter[payment_method][settings][payment_method][settings][use_connected_account]"]' => array(
'value' => 'none',
),
),
);
unset($form['public_key']['#required']);
$form['public_key']['#states'] = array(
'visible' => array(
':input[name="parameter[payment_method][settings][payment_method][settings][use_connected_account]"]' => array(
'value' => 'none',
),
),
'required' => array(
':input[name="parameter[payment_method][settings][payment_method][settings][use_connected_account]"]' => array(
'value' => 'none',
),
),
);
}
}
$form['stripe_currency'] = array(
'#type' => 'select',
'#title' => t('Currency'),
'#options' => $currency_list,
'#description' => t('Select the currency that you are using.'),
'#default_value' => !empty($settings['stripe_currency']) ? $settings['stripe_currency'] : 'USD',
);
$form['display_title'] = array(
'#type' => 'textfield',
'#title' => t('Payment method display title'),
'#description' => t('Payment method display title'),
'#default_value' => !empty($settings['display_title']) ? $settings['display_title'] : t('Stripe'),
);
$form['receipt_email'] = array(
'#type' => 'checkbox',
'#title' => t('Email receipts'),
'#description' => t('When selected, customers will receive email receipts from Stripe.'),
'#default_value' => isset($settings['receipt_email']) ? $settings['receipt_email'] : 0,
);
$form['integration_type'] = array(
'#type' => 'select',
'#title' => t('Integration type'),
'#description' => t('Choose Stripe integration method: Stripe.js makes it easy to collect credit card (and other similarly sensitive) details without having the information touch your server. Checkout is an embeddable iframe for desktop, tablet, and mobile devices.'),
'#options' => array(
'elements' => t('Elements'),
'stripejs' => t('stripe.js'),
'checkout' => t('checkout'),
),
'#default_value' => !empty($settings['integration_type']) ? $settings['integration_type'] : COMMERCE_STRIPE_DEFAULT_INTEGRATION,
);
// Stripe Checkout specific settings.
// @see: https://stripe.com/docs/checkout#integration-custom
$form['checkout_settings'] = array(
'#type' => 'fieldset',
'#title' => t('These settings are specific to "checkout" integration type.'),
'#states' => array(
'visible' => array(
':input[name$="[integration_type]"]' => array(
'value' => 'checkout',
),
),
),
);
// Highly recommended checkout options:
// Name
$form['checkout_settings']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('The name of your company or website.'),
'#default_value' => isset($settings['checkout_settings']['name']) ? $settings['checkout_settings']['name'] : variable_get('site_name', ''),
);
// Description
$form['checkout_settings']['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#description' => t('A description of the product or service being purchased.'),
'#default_value' => isset($settings['checkout_settings']['description']) ? $settings['checkout_settings']['description'] : '',
);
// Image
$form['checkout_settings']['image'] = array(
'#type' => 'managed_file',
'#title' => t('Image'),
'#progress_message' => t('Please wait...'),
'#progress_indicator' => 'bar',
'#description' => t('Click "Browse..." to select an image to upload.'),
'#required' => FALSE,
'#upload_location' => 'public://commerce_stripe/checkout_images/',
'#default_value' => isset($settings['checkout_settings']['image']) ? $settings['checkout_settings']['image']['fid'] : '',
'#element_validate' => array(
'commerce_stripe_settings_form_image_validate',
),
);
// Optional checkout options:
// panelLabel
$form['checkout_settings']['panelLabel'] = array(
'#type' => 'textfield',
'#title' => t('Payment button label'),
'#description' => t('The label of the payment button in the Checkout form (e.g. "Subscribe", "Pay {{amount}}", etc.). If you include {{amount}}, it will be replaced by the provided amount. Otherwise, the amount will be appended to the end of your label.'),
'#default_value' => isset($settings['checkout_settings']['panelLabel']) ? $settings['checkout_settings']['panelLabel'] : "Pay {{amount}}",
);
// zipCode
$form['checkout_settings']['zipCode'] = array(
'#type' => 'checkbox',
'#title' => t('ZIP code verification'),
'#description' => t('Specify whether Checkout should validate the billing ZIP code.'),
'#default_value' => isset($settings['checkout_settings']['zipCode']) ? $settings['checkout_settings']['zipCode'] : 0,
);
// allowRememberMe
$form['checkout_settings']['allowRememberMe'] = array(
'#type' => 'checkbox',
'#title' => t('Show "Remember Me" option'),
'#description' => t('Specify whether Checkout should allow the user to store their credit card for faster checkout.'),
'#default_value' => isset($settings['checkout_settings']['allowRememberMe']) ? $settings['checkout_settings']['allowRememberMe'] : 0,
);
// bitcoin
$form['checkout_settings']['bitcoin'] = array(
'#type' => 'checkbox',
'#title' => t('Accept Bitcoin'),
'#description' => t('When checked, Stripe Checkout will accept Bitcoin as payment.') . l(t('Must be enabled in your Stripe account.'), 'https://dashboard.stripe.com/account/bitcoin/enable'),
'#default_value' => isset($settings['checkout_settings']['bitcoin']) ? $settings['checkout_settings']['bitcoin'] : 0,
);
// billingAddress (Undocumented option)
$form['checkout_settings']['billingAddress'] = array(
'#type' => 'checkbox',
'#title' => t('Billing address'),
'#description' => t('Specify whether to enable billing address collection in Checkout.'),
'#default_value' => isset($settings['checkout_settings']['billingAddress']) ? $settings['checkout_settings']['billingAddress'] : 0,
);
// shippingAddress (Undocumented option)
$form['checkout_settings']['shippingAddress'] = array(
'#type' => 'checkbox',
'#title' => t('Shipping address'),
'#description' => t('Specify whether to enable shipping address collection in Checkout.'),
'#default_value' => isset($settings['checkout_settings']['shippingAddress']) ? $settings['checkout_settings']['shippingAddress'] : 0,
);
if (module_exists('commerce_cardonfile')) {
$form['cardonfile'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Card on File functionality.'),
'#default_value' => isset($settings['cardonfile']) ? $settings['cardonfile'] : 0,
);
}
else {
$form['cardonfile'] = array(
'#type' => 'markup',
'#markup' => t('To enable Card on File functionality, download and install the Commerce Card on File module.'),
);
}
$form['txn_type'] = array(
'#type' => 'radios',
'#title' => t('Default credit card transaction type'),
'#description' => t('The default will be used to process transactions during checkout.'),
'#options' => array(
COMMERCE_CREDIT_AUTH_CAPTURE => t('Authorization and capture'),
COMMERCE_CREDIT_AUTH_ONLY => t('Authorization only (requires manual capture after checkout)'),
),
'#default_value' => isset($settings['txn_type']) ? $settings['txn_type'] : COMMERCE_CREDIT_AUTH_CAPTURE,
);
$form['commerce_stripe_api_version'] = array(
'#type' => 'select',
'#title' => t('Stripe API Version'),
'#options' => array(
COMMERCE_STRIPE_API_LATEST_TESTED => 'Latest Tested (2017-08-15)',
COMMERCE_STRIPE_API_ACCOUNT_DEFAULT => 'Account Default',
COMMERCE_STRIPE_API_VERSION_CUSTOM => 'Custom',
),
'#empty_option' => COMMERCE_STRIPE_API_ACCOUNT_DEFAULT,
'#empty_value' => 'Account Default',
'#default_value' => $settings['commerce_stripe_api_version'],
'#description' => t('Specify the API version to use for requests.
Defaults to the version configured in your <a href="@dash">Stripe Account</a>.', array(
'@dash' => 'http://dashboard.stripe.com/account/apikeys',
)),
);
$form['commerce_stripe_api_version_custom'] = array(
'#type' => 'textfield',
'#title' => t('Specify an API Version'),
'#description' => t('Useful for testing API Versioning before committing to an upgrade. See the <a href="@docs">API Docs</a> and your <a href="@changelog">API Changelog</a>.', array(
'@docs' => 'https://stripe.com/docs/upgrades',
'@changelog' => 'https://stripe.com/docs/upgrades#api-changelog',
)),
'#default_value' => !empty($settings['commerce_stripe_api_version_custom']) ? $settings['commerce_stripe_api_version_custom'] : '',
'#size' => 12,
'#states' => array(
'visible' => array(
':input[name$="[commerce_stripe_api_version]"]' => array(
'value' => COMMERCE_STRIPE_API_VERSION_CUSTOM,
),
),
),
);
return $form;
}