function commerce_braintree_dropin_submit_form_elements in Commerce Braintree 7.2
Same name and namespace in other branches
- 7.3 modules/commerce_braintree_dropin/commerce_braintree_dropin.module \commerce_braintree_dropin_submit_form_elements()
Returns the common FAPI form elements for all Drop-in UI implementations.
Parameters
$payment_method: The payment method being used.
array $arguments: An array of arguments to be passed Braintree token method.
Return value
array An array of form elements for the drop-in ui.
4 calls to commerce_braintree_dropin_submit_form_elements()
- commerce_braintree_dropin_cardonfile_form in modules/
commerce_braintree_dropin/ commerce_braintree_dropin.module - Form callback for commerce_cardonfile entities.
- commerce_braintree_dropin_form_commerce_payment_order_transaction_add_form_alter in modules/
commerce_braintree_dropin/ commerce_braintree_dropin.module - Implements hook_form_FORM_ID_alter().
- commerce_braintree_dropin_submit_form in modules/
commerce_braintree_dropin/ commerce_braintree_dropin.module - Form callback for Braintree Drop-in payment method.
- commerce_braintree_js_cardonfile_form in ./
commerce_braintree.module - Form callback for commerce_cardonfile entities.
File
- modules/
commerce_braintree_dropin/ commerce_braintree_dropin.module, line 158 - Provides integration with Braintree Drop-in UI.
Code
function commerce_braintree_dropin_submit_form_elements($payment_method, $arguments = array()) {
global $user;
$form = array();
// Initialize Braintree and create a token.
commerce_braintree_initialize($payment_method);
$js_settings = array(
'environment' => $payment_method['settings']['environment'],
'clientToken' => Braintree_ClientToken::generate($arguments),
);
// Allow other modules to alter the JS settings.
drupal_alter('commerce_braintree_dropin_js', $js_settings, $payment_method);
// The custom token is required to generate the Drop-in payment form.
$form['#attached']['js'][] = array(
'data' => array(
'commerceBraintreeDropin' => $js_settings,
),
'type' => 'setting',
);
// Make sure the Drop-in javascript api is included.
$form['#attached']['js'][] = array(
'data' => 'https://js.braintreegateway.com/v2/braintree.js',
'type' => 'external',
);
// Attach our own javascript to handle the Drop-in form generation.
$form['#attached']['js'][] = drupal_get_path('module', 'commerce_braintree_dropin') . '/js/commerce_braintree_dropin.js';
// Include a container div for the Drop-in form to attach to.
$form['braintree_dropin'] = array(
'#markup' => '<div id="commerce-braintree-dropin-container"></div>',
);
// Add option to save card on file for authenticated users.
if (!empty($payment_method['settings']['cardonfile']) && !empty($user->uid)) {
$storage = variable_get('commerce_cardonfile_storage', 'opt-in');
if ($storage !== 'required') {
$form['cardonfile'] = array(
'#type' => 'checkbox',
'#title' => t('Securely save this payment method for next time.'),
'#default_value' => $storage == 'opt-in' ? FALSE : TRUE,
);
}
else {
$form['cardonfile'] = array(
'#type' => 'value',
'#value' => TRUE,
);
}
}
return $form;
}