function uc_payment_method_credit_form in Ubercart 7.3
Same name and namespace in other branches
- 5 payment/uc_credit/uc_credit.module \uc_payment_method_credit_form()
- 6.2 payment/uc_credit/uc_credit.module \uc_payment_method_credit_form()
Displays the credit card details form on the checkout screen.
2 calls to uc_payment_method_credit_form()
- uc_credit_terminal_form in payment/
uc_credit/ uc_credit.admin.inc - Displays the credit card terminal form for administrators.
- uc_payment_method_credit in payment/
uc_credit/ uc_credit.module - Callback function for the Credit Card payment method.
File
- payment/
uc_credit/ uc_credit.module, line 545 - Defines the credit card payment method and hooks in payment gateways.
Code
function uc_payment_method_credit_form($form, &$form_state, $order) {
// Normally the CC data is posted in via AJAX.
if (!empty($form_state['values']['payment_details_data']) && arg(0) == 'cart') {
$order->payment_details = uc_credit_cache('save', $form_state['values']['payment_details_data']);
}
// But we have to accommodate failed checkout form validation here.
if (isset($_SESSION['sescrd'])) {
$order->payment_details = uc_credit_cache('save', $_SESSION['sescrd']);
unset($_SESSION['sescrd']);
}
if (!isset($order->payment_details) && isset($form_state['values']['panes']['payment']['details'])) {
$order->payment_details = $form_state['values']['panes']['payment']['details'];
$order->payment_details['cc_number'] = str_replace(' ', '', $order->payment_details['cc_number']);
}
if (!isset($order->payment_details)) {
$order->payment_details = array();
}
$form['cc_policy'] = array(
'#prefix' => '<p>',
'#markup' => variable_get('uc_credit_policy', t('Your billing information must match the billing address for the credit card entered below or we will be unable to process your payment.')),
'#suffix' => '</p>',
);
$types = variable_get('uc_credit_accepted_types', implode("\r\n", array(
t('Visa'),
t('Mastercard'),
t('Discover'),
t('American Express'),
)));
if (variable_get('uc_credit_type_enabled', FALSE) && $types) {
$form['cc_type'] = array(
'#type' => 'select',
'#title' => t('Card type'),
'#options' => drupal_map_assoc(explode("\r\n", $types)),
'#default_value' => isset($order->payment_details['cc_type']) ? $order->payment_details['cc_type'] : NULL,
);
}
if (variable_get('uc_credit_owner_enabled', FALSE)) {
$form['cc_owner'] = array(
'#type' => 'textfield',
'#title' => t('Card owner'),
'#default_value' => isset($order->payment_details['cc_owner']) ? $order->payment_details['cc_owner'] : '',
'#attributes' => array(
'autocomplete' => 'off',
),
'#size' => 32,
'#maxlength' => 64,
);
}
// Set up the default CC number on the credit card form.
if (isset($_SESSION['clear_cc']) || !isset($order->payment_details['cc_number'])) {
$default_num = NULL;
}
elseif (variable_get('uc_credit_validate_numbers', TRUE) && !_uc_credit_valid_card_number($order->payment_details['cc_number'])) {
// Display the number as is if it does not validate so it can be corrected.
$default_num = $order->payment_details['cc_number'];
}
else {
// Otherwise default to the last 4 digits.
$default_num = t('(Last 4) ') . substr($order->payment_details['cc_number'], -4);
}
$form['cc_number'] = array(
'#type' => 'textfield',
'#title' => t('Card number'),
'#default_value' => $default_num,
'#attributes' => array(
'autocomplete' => 'off',
),
'#size' => 20,
'#maxlength' => 19,
);
if (variable_get('uc_credit_start_enabled', FALSE)) {
$month = isset($order->payment_details['cc_start_month']) ? $order->payment_details['cc_start_month'] : NULL;
$year = isset($order->payment_details['cc_start_year']) ? $order->payment_details['cc_start_year'] : NULL;
$form['cc_start_month'] = uc_select_month(t('Start date'), $month, TRUE);
$form['cc_start_year'] = uc_select_year(t('Start year'), $year, date('Y') - 10, date('Y'), TRUE);
$form['cc_start_year']['#field_suffix'] = t('(if present)');
}
$month = isset($order->payment_details['cc_exp_month']) ? $order->payment_details['cc_exp_month'] : 1;
$year = isset($order->payment_details['cc_exp_year']) ? $order->payment_details['cc_exp_year'] : date('Y');
$form['cc_exp_month'] = uc_select_month(t('Expiration date'), $month);
$form['cc_exp_year'] = uc_select_year(t('Expiration year'), $year);
if (variable_get('uc_credit_issue_enabled', FALSE)) {
// Set up the default Issue Number on the credit card form.
if (empty($order->payment_details['cc_issue'])) {
$default_card_issue = NULL;
}
elseif (!_uc_credit_valid_card_issue($order->payment_details['cc_issue'])) {
// Display the Issue Number as is if it does not validate so it can be
// corrected.
$default_card_issue = $order->payment_details['cc_issue'];
}
else {
// Otherwise mask it with dashes.
$default_card_issue = str_repeat('-', strlen($order->payment_details['cc_issue']));
}
$form['cc_issue'] = array(
'#type' => 'textfield',
'#title' => t('Issue number'),
'#default_value' => $default_card_issue,
'#attributes' => array(
'autocomplete' => 'off',
),
'#size' => 2,
'#maxlength' => 2,
'#field_suffix' => t('(if present)'),
);
}
if (variable_get('uc_credit_cvv_enabled', TRUE)) {
// Set up the default CVV on the credit card form.
if (isset($_SESSION['clear_cc']) || empty($order->payment_details['cc_cvv'])) {
$default_cvv = NULL;
}
elseif (!_uc_credit_valid_cvv($order->payment_details['cc_cvv'])) {
// Display the CVV as is if it does not validate so it can be corrected.
$default_cvv = $order->payment_details['cc_cvv'];
}
else {
// Otherwise mask it with dashes.
$default_cvv = str_repeat('-', strlen($order->payment_details['cc_cvv']));
}
$form['cc_cvv'] = array(
'#type' => 'textfield',
'#title' => t('CVV'),
'#default_value' => $default_cvv,
'#attributes' => array(
'autocomplete' => 'off',
),
'#size' => variable_get('uc_credit_amex', TRUE) ? 4 : 3,
'#maxlength' => variable_get('uc_credit_amex', TRUE) ? 4 : 3,
'#field_suffix' => theme('uc_credit_cvv_help'),
);
}
if (variable_get('uc_credit_bank_enabled', FALSE)) {
$form['cc_bank'] = array(
'#type' => 'textfield',
'#title' => t('Issuing bank'),
'#default_value' => isset($order->payment_details['cc_bank']) ? $order->payment_details['cc_bank'] : '',
'#attributes' => array(
'autocomplete' => 'off',
),
'#size' => 32,
'#maxlength' => 64,
);
}
unset($_SESSION['clear_cc']);
return $form;
}