function commerce_braintree_credit_card_form in Commerce Braintree 7
Same name and namespace in other branches
- 7.3 commerce_braintree.module \commerce_braintree_credit_card_form()
- 7.2 commerce_braintree.module \commerce_braintree_credit_card_form()
Helper function. Build the credit card form.
2 calls to commerce_braintree_credit_card_form()
- commerce_braintree_cof_redirect_form in ./
commerce_braintree.commerce_braintree_cof.inc - Payment method callback: redirect form.
- commerce_braintree_redirect_form in ./
commerce_braintree.commerce_braintree.inc - Payment method callback: redirect form.
File
- ./
commerce_braintree.module, line 301 - Implementations of the Braintree payment gateway (http://braintreepayments.com) for drupal commerce.
Code
function commerce_braintree_credit_card_form($payment_method) {
// Merge default values into the default array.
$default = array(
'start_month' => '',
'start_year' => date('Y') - 5,
'exp_month' => date('m'),
'exp_year' => date('Y'),
);
$form['commerce_payment']['payment_method']['#default_value'] = $payment_method['instance_id'];
$current_year_2 = date('y');
$current_year_4 = date('Y');
$form['commerce_payment']['payment_details']['credit_card'] = array(
'#tree' => TRUE,
'#attached' => array(
'css' => array(
drupal_get_path('module', 'commerce_payment') . '/theme/commerce_payment.theme.css',
),
),
);
// Add a field for the credit card number.
$form['commerce_payment']['payment_details']['credit_card']['number'] = array(
'#type' => 'textfield',
'#title' => t('Card number'),
'#default_value' => '',
'#attributes' => array(
'autocomplete' => 'off',
),
'#required' => TRUE,
'#maxlength' => 19,
'#size' => 20,
'#name' => 'transaction[credit_card][number]',
);
// Add a field for the credit card number.
$form['commerce_payment']['payment_details']['credit_card']['owner'] = array(
'#type' => 'textfield',
'#title' => t('Card owner'),
'#default_value' => '',
'#attributes' => array(
'autocomplete' => 'off',
),
'#required' => TRUE,
'#size' => 50,
'#name' => 'transaction[credit_card][cardholder_name]',
);
// Add fields for the credit card expiration date.
$form['commerce_payment']['payment_details']['credit_card']['exp_month'] = array(
'#type' => 'select',
'#title' => t('Expiration'),
'#options' => drupal_map_assoc(array_keys(commerce_months())),
'#default_value' => strlen($default['exp_month']) == 1 ? '0' . $default['exp_month'] : $default['exp_month'],
'#required' => TRUE,
'#prefix' => '<div class="commerce-credit-card-expiration">',
'#suffix' => '<span class="commerce-month-year-divider">/</span>',
'#name' => 'transaction[credit_card][expiration_month]',
);
// Build a year select list that uses a 4 digit key with a 2 digit value.
$options = array();
for ($i = 0; $i < 20; $i++) {
$options[$current_year_4 + $i] = str_pad($current_year_2 + $i, 2, '0', STR_PAD_LEFT);
}
$form['commerce_payment']['payment_details']['credit_card']['exp_year'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $default['exp_year'],
'#suffix' => '</div>',
'#name' => 'transaction[credit_card][expiration_year]',
);
$form['commerce_payment']['payment_details']['credit_card']['code'] = array(
'#type' => 'textfield',
'#title' => t('Security code'),
'#default_value' => '',
'#attributes' => array(
'autocomplete' => 'off',
),
'#required' => TRUE,
'#maxlength' => 4,
'#size' => 4,
'#name' => 'transaction[credit_card][cvv]',
);
return $form;
}