function commerce_braintree_form_commerce_cardonfile_update_form_alter in Commerce Braintree 7.3
Same name and namespace in other branches
- 7 commerce_braintree.module \commerce_braintree_form_commerce_cardonfile_update_form_alter()
- 7.2 commerce_braintree.module \commerce_braintree_form_commerce_cardonfile_update_form_alter()
Implements hook_form_FORM_ID_alter().
File
- ./
commerce_braintree.module, line 739 - Integrates Braintree Transparent Redirect with Drupal Commerce.
Code
function commerce_braintree_form_commerce_cardonfile_update_form_alter(&$form, &$form_state) {
// @todo Do not hard code a requirement on a specific payment method instance.
$payment_method = commerce_payment_method_instance_load('braintree_tr|commerce_payment_braintree_tr');
commerce_braintree_initialize($payment_method);
// Adjust the names of form elements to match the requirements of Braintree's
// Transparent Redirect API.
$form['credit_card']['owner']['#name'] = 'credit_card[cardholder_name]';
$form['credit_card']['number']['#name'] = 'credit_card[number]';
$form['credit_card']['exp_month']['#name'] = 'credit_card[expiration_month]';
$form['credit_card']['exp_year']['#name'] = 'credit_card[expiration_year]';
// Pass the return redirect URL and stored credit card token to Braintree.
$form['tr_data'] = array(
'#type' => 'hidden',
'#name' => 'tr_data',
'#default_value' => Braintree_TransparentRedirect::updateCreditCardData(array(
'redirectUrl' => url('user/commerce_braintree/update_card', array(
'absolute' => TRUE,
)),
'paymentMethodToken' => $form['card_data']['#value']->remote_id,
)),
);
// Submit this form directly to the Braintree server.
$form['#action'] = Braintree_TransparentRedirect::url();
}