View source
<?php
define('UC_CREDIT_AUTH_ONLY', 'authorize');
define('UC_CREDIT_PRIOR_AUTH_CAPTURE', 'prior_auth_capture');
define('UC_CREDIT_AUTH_CAPTURE', 'auth_capture');
define('UC_CREDIT_REFERENCE_SET', 'reference_set');
define('UC_CREDIT_REFERENCE_TXN', 'reference_txn');
define('UC_CREDIT_REFERENCE_REMOVE', 'reference_remove');
define('UC_CREDIT_REFERENCE_CREDIT', 'reference_credit');
define('UC_CREDIT_CREDIT', 'credit');
define('UC_CREDIT_VOID', 'void');
define('UC_CREDIT_KEYFILE_NAME', 'uc_credit.key');
function uc_credit_help($path, $arg) {
switch ($path) {
case 'admin/store/orders/%/credit':
return '<p>' . t('Use this terminal to process credit card payments through your default gateway.') . '</p>';
}
}
function uc_credit_menu() {
$items['cart/checkout/credit/cvv_info'] = array(
'title' => 'CVV information',
'page callback' => 'uc_credit_cvv_info',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'uc_credit.pages.inc',
);
$items['admin/store/orders/%uc_order/credit'] = array(
'title callback' => 'uc_credit_terminal_title',
'title arguments' => array(
3,
),
'description' => 'Displays a form to process a credit card payment.',
'page callback' => 'uc_credit_terminal',
'page arguments' => array(
3,
),
'access arguments' => array(
'process credit cards',
),
'file' => 'uc_credit.admin.inc',
);
return $items;
}
function uc_credit_permission() {
return array(
'administer credit cards' => array(
'title' => t('Administer credit cards'),
'restrict access' => TRUE,
),
'process credit cards' => array(
'title' => t('Process credit cards'),
),
'view cc details' => array(
'title' => t('View credit card details'),
),
);
}
function uc_credit_theme() {
return array(
'uc_credit_cvv_help' => array(
'file' => 'uc_credit.theme.inc',
),
);
}
function uc_credit_init() {
global $conf;
$conf['i18n_variables'][] = 'uc_credit_fail_message';
$conf['i18n_variables'][] = 'uc_credit_policy';
}
function uc_credit_form_uc_cart_checkout_form_alter(&$form, &$form_state) {
if (isset($_SESSION['sescrd'])) {
uc_credit_cache('save', $_SESSION['sescrd']);
$form['payment_details_data'] = array(
'#type' => 'hidden',
'#value' => $_SESSION['sescrd'],
);
unset($_SESSION['sescrd']);
}
unset($_SESSION['cc_pay']);
}
function uc_credit_form_uc_cart_checkout_review_form_alter(&$form, &$form_state) {
if (isset($_SESSION['cc_pay']) && !isset($_SESSION['sescrd']) && empty($_POST['sescrd'])) {
drupal_set_message(t('To protect our customers from identity theft, credit card details are erased when a browser refreshes on the checkout review page. Please enter your card details again and re-submit the form.'), 'error');
$_SESSION['clear_cc'] = TRUE;
unset($_SESSION['cc_pay']);
drupal_goto('cart/checkout');
}
if (isset($_SESSION['sescrd'])) {
uc_credit_cache('save', $_SESSION['sescrd']);
$form['sescrd'] = array(
'#type' => 'hidden',
'#value' => base64_encode($_SESSION['sescrd']),
);
}
else {
$form['sescrd'] = array(
'#type' => 'hidden',
'#value' => '',
);
}
$form['actions']['back']['#submit'][] = 'uc_credit_cart_review_back_submit';
$submit = array_merge(array(
'uc_credit_cart_review_pre_form_submit',
), $form['#submit']);
$submit[] = 'uc_credit_cart_review_post_form_submit';
$form['#submit'] = $submit;
unset($_SESSION['sescrd']);
}
function uc_credit_exit() {
if (isset($_SESSION['sescrd'])) {
if (isset($_GET['q'])) {
$args = explode('/', $_GET['q']);
if (!isset($args[1]) || $args[1] != 'checkout') {
unset($_SESSION['sescrd']);
}
}
else {
unset($_SESSION['sescrd']);
}
}
}
function uc_credit_uc_store_status() {
if ($key = uc_credit_encryption_key()) {
$statuses[] = array(
'status' => 'ok',
'title' => t('Credit card encryption'),
'desc' => t('Credit card data is encrypted during checkout for maximum security.'),
);
}
else {
$statuses[] = array(
'status' => 'error',
'title' => t('Credit card encryption'),
'desc' => t('You must review your <a href="!url">credit card security settings</a> and enable encryption before you can accept credit card payments.', array(
'!url' => url('admin/store/settings/payment/method/credit'),
)),
);
}
return $statuses;
}
function uc_credit_uc_order($op, $order, $arg2) {
if (isset($order->payment_method) && $order->payment_method == 'credit' && ($op == 'save' || $op == 'load')) {
if (!uc_credit_encryption_key()) {
watchdog('uc_credit', 'Credit card encryption must be set up to process credit cards.');
}
}
switch ($op) {
case 'submit':
if (isset($order->payment_method) && $order->payment_method == 'credit') {
unset($_SESSION['cc_pay']);
$gateway_id = uc_credit_default_gateway();
$data = array(
'txn_type' => variable_get('uc_pg_' . $gateway_id . '_cc_txn_type', UC_CREDIT_AUTH_CAPTURE),
);
$order->payment_details = uc_credit_cache('load');
$pass = uc_payment_process_payment('credit', $order->order_id, $order->order_total, $data, TRUE, NULL, FALSE);
if (!$pass) {
$message = variable_get('uc_credit_fail_message', t('We were unable to process your credit card payment. Please verify your details and try again. If the problem persists, contact us to complete your order.'));
return array(
array(
'pass' => FALSE,
'message' => $message,
),
);
}
}
break;
case 'save':
if (isset($order->payment_method) && $order->payment_method == 'credit' && !empty($order->payment_details)) {
_uc_credit_save_cc_data_to_order($order->payment_details, $order->order_id);
}
break;
case 'load':
if (isset($order->payment_method) && $order->payment_method == 'credit') {
$order->payment_details = uc_credit_cache('load');
if (empty($order->payment_details) && isset($order->data['cc_data'])) {
$order->payment_details = uc_credit_cache('save', $order->data['cc_data']);
}
}
break;
}
}
function uc_credit_uc_payment_method() {
if (arg(0) == 'cart' && uc_credit_encryption_key() === FALSE) {
return;
}
$path = base_path() . drupal_get_path('module', 'uc_credit');
$title = t('Credit card:');
$cc_types = array(
'visa' => t('Visa'),
'mastercard' => t('MasterCard'),
'discover' => t('Discover'),
'amex' => t('American Express'),
);
foreach ($cc_types as $type => $label) {
if (variable_get('uc_credit_' . $type, TRUE)) {
$title .= ' ' . theme('image', array(
'path' => drupal_get_path('module', 'uc_credit') . '/images/' . $type . '.gif',
'alt' => $label,
'attributes' => array(
'class' => array(
'uc-credit-cctype',
'uc-credit-cctype-' . $type,
),
),
));
}
}
$methods['credit'] = array(
'name' => t('Credit card'),
'title' => $title,
'desc' => t('Pay by credit card.'),
'callback' => 'uc_payment_method_credit',
'weight' => 2,
'checkout' => TRUE,
);
return $methods;
}
function uc_payment_method_credit($op, &$order, $form = NULL, &$form_state = NULL) {
switch ($op) {
case 'cart-details':
$details = uc_payment_method_credit_form(array(), $form_state, $order);
return $details;
case 'cart-process':
if (!isset($form_state['values']['panes']['payment']['details']['cc_number'])) {
return;
}
$cc_data = $form_state['values']['panes']['payment']['details'];
$cc_data['cc_number'] = str_replace(' ', '', $cc_data['cc_number']);
array_walk($cc_data, 'check_plain');
if (isset($form_state['values']['panes']['payment']['details']['payment_details_data'])) {
$cache = uc_credit_cache('save', $form_state['values']['panes']['payment']['details']['payment_details_data']);
}
if (substr($cc_data['cc_number'], 0, strlen(t('(Last4)'))) == t('(Last4)')) {
if (isset($cache['cc_number'])) {
$cc_data['cc_number'] = $cache['cc_number'];
}
else {
$cc_data['cc_number'] = '';
}
}
if (!empty($cc_data['cc_cvv']) && $cc_data['cc_cvv'] == str_repeat('-', strlen($cc_data['cc_cvv']))) {
if (isset($cache['cc_cvv'])) {
$cc_data['cc_cvv'] = $cache['cc_cvv'];
}
else {
$cc_data['cc_cvv'] = '';
}
}
$order->payment_details = $cc_data;
$return = TRUE;
if (variable_get('uc_credit_owner_enabled', FALSE) && empty($cc_data['cc_owner'])) {
form_set_error('panes][payment][details][cc_owner', t('Enter the owner name as it appears on the card.'));
$return = FALSE;
}
if (variable_get('uc_credit_validate_numbers', TRUE) && !_uc_credit_valid_card_number($cc_data['cc_number']) || !ctype_digit($cc_data['cc_number'])) {
form_set_error('panes][payment][details][cc_number', t('You have entered an invalid credit card number.'));
$return = FALSE;
}
if (variable_get('uc_credit_start_enabled', FALSE) && !_uc_credit_valid_card_start($cc_data['cc_start_month'], $cc_data['cc_start_year'])) {
form_set_error('panes][payment][details][cc_start_month', t('The start date you entered is invalid.'));
form_set_error('panes][payment][details][cc_start_year');
$return = FALSE;
}
if (!_uc_credit_valid_card_expiration($cc_data['cc_exp_month'], $cc_data['cc_exp_year'])) {
form_set_error('panes][payment][details][cc_exp_month', t('The credit card you entered has expired.'));
form_set_error('panes][payment][details][cc_exp_year');
$return = FALSE;
}
if (variable_get('uc_credit_issue_enabled', FALSE) && !_uc_credit_valid_card_issue($cc_data['cc_issue'])) {
form_set_error('panes][payment][details][cc_issue', t('The issue number you entered is invalid.'));
$return = FALSE;
}
if (variable_get('uc_credit_cvv_enabled', TRUE) && !_uc_credit_valid_cvv($cc_data['cc_cvv'])) {
form_set_error('panes][payment][details][cc_cvv', t('You have entered an invalid CVV number.'));
$return = FALSE;
}
if (variable_get('uc_credit_bank_enabled', FALSE) && empty($cc_data['cc_bank'])) {
form_set_error('panes][payment][details][cc_bank', t('You must enter the issuing bank for that card.'));
$return = FALSE;
}
$key = uc_credit_encryption_key();
$crypt = new UbercartEncryption();
$_SESSION['sescrd'] = $crypt
->encrypt($key, base64_encode(serialize($order->payment_details)));
uc_store_encryption_errors($crypt, 'uc_credit');
if ($return) {
$_SESSION['cc_pay'] = TRUE;
}
return $return;
case 'cart-review':
if (variable_get('uc_credit_type_enabled', FALSE)) {
$review[] = array(
'title' => t('Card type'),
'data' => check_plain($order->payment_details['cc_type']),
);
}
if (variable_get('uc_credit_owner_enabled', FALSE)) {
$review[] = array(
'title' => t('Card owner'),
'data' => check_plain($order->payment_details['cc_owner']),
);
}
$review[] = array(
'title' => t('Card number'),
'data' => uc_credit_display_number($order->payment_details['cc_number']),
);
if (variable_get('uc_credit_start_enabled', FALSE)) {
$start = $order->payment_details['cc_start_month'] . '/' . $order->payment_details['cc_start_year'];
$review[] = array(
'title' => t('Start date'),
'data' => strlen($start) > 1 ? $start : '',
);
}
$review[] = array(
'title' => t('Expiration'),
'data' => $order->payment_details['cc_exp_month'] . '/' . $order->payment_details['cc_exp_year'],
);
if (variable_get('uc_credit_issue_enabled', FALSE)) {
$review[] = array(
'title' => t('Issue number'),
'data' => $order->payment_details['cc_issue'],
);
}
if (variable_get('uc_credit_bank_enabled', FALSE)) {
$review[] = array(
'title' => t('Issuing bank'),
'data' => check_plain($order->payment_details['cc_bank']),
);
}
return $review;
case 'order-view':
$build = array();
if (user_access('view cc details')) {
$rows = array();
if (!empty($order->payment_details['cc_type'])) {
$rows[] = t('Card type') . ': ' . check_plain($order->payment_details['cc_type']);
}
if (!empty($order->payment_details['cc_owner'])) {
$rows[] = t('Card owner') . ': ' . check_plain($order->payment_details['cc_owner']);
}
if (!empty($order->payment_details['cc_number'])) {
$rows[] = t('Card number') . ': ' . uc_credit_display_number($order->payment_details['cc_number']);
}
if (!empty($order->payment_details['cc_start_month']) && !empty($order->payment_details['cc_start_year'])) {
$rows[] = t('Start date') . ': ' . $order->payment_details['cc_start_month'] . '/' . $order->payment_details['cc_start_year'];
}
if (!empty($order->payment_details['cc_exp_month']) && !empty($order->payment_details['cc_exp_year'])) {
$rows[] = t('Expiration') . ': ' . $order->payment_details['cc_exp_month'] . '/' . $order->payment_details['cc_exp_year'];
}
if (!empty($order->payment_details['cc_issue'])) {
$rows[] = t('Issue number') . ': ' . check_plain($order->payment_details['cc_issue']);
}
if (!empty($order->payment_details['cc_bank'])) {
$rows[] = t('Issuing bank') . ': ' . check_plain($order->payment_details['cc_bank']);
}
$build['cc_info'] = array(
'#prefix' => '<a href="#" onclick="jQuery(this).hide().next().show();">' . t('Show card details') . '</a><div style="display: none;">',
'#markup' => implode('<br />', $rows),
'#suffix' => '</div>',
);
if (user_access('process credit cards')) {
$build['terminal'] = drupal_get_form('uc_credit_order_view_form', $order->order_id);
}
}
return $build;
case 'customer-view':
$build = array();
if (!empty($order->payment_details['cc_number'])) {
$build['#markup'] = t('Card number') . ':<br />' . uc_credit_display_number($order->payment_details['cc_number']);
}
return $build;
case 'order-details':
return t('Use the terminal available through the<br />%button button on the View tab to<br />process credit card payments.', array(
'%button' => t('Process card'),
));
case 'settings':
form_load_include($form_state, 'inc', 'uc_credit', 'uc_credit.admin');
return uc_credit_settings_form($form, $form_state);
}
}
function uc_payment_method_credit_form($form, &$form_state, $order) {
if (!empty($form_state['values']['payment_details_data']) && arg(0) == 'cart') {
$order->payment_details = uc_credit_cache('save', $form_state['values']['payment_details_data']);
}
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,
);
}
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'])) {
$default_num = $order->payment_details['cc_number'];
}
else {
$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)) {
if (empty($order->payment_details['cc_issue'])) {
$default_card_issue = NULL;
}
elseif (!_uc_credit_valid_card_issue($order->payment_details['cc_issue'])) {
$default_card_issue = $order->payment_details['cc_issue'];
}
else {
$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)) {
if (isset($_SESSION['clear_cc']) || empty($order->payment_details['cc_cvv'])) {
$default_cvv = NULL;
}
elseif (!_uc_credit_valid_cvv($order->payment_details['cc_cvv'])) {
$default_cvv = $order->payment_details['cc_cvv'];
}
else {
$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;
}
function uc_credit_order_view_form($form, &$form_state, $order_id) {
$form['order_id'] = array(
'#type' => 'hidden',
'#value' => $order_id,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Process card'),
);
return $form;
}
function uc_credit_order_view_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/store/orders/' . $form_state['values']['order_id'] . '/credit';
}
function uc_credit_display_number($number) {
if (strlen($number) == 4) {
return t('(Last 4) ') . $number;
}
return str_repeat('-', 12) . substr($number, -4);
}
function uc_credit_cache($op, $data = NULL, $encrypted = TRUE) {
static $cc_cache = array();
if ($op == 'save') {
if ($encrypted) {
$key = uc_credit_encryption_key();
$crypt = new UbercartEncryption();
$data = $crypt
->decrypt($key, $data);
if (strpos($data, ':') === FALSE) {
$data = base64_decode($data);
}
$cc_cache = @unserialize($data);
}
else {
$cc_cache = $data;
}
}
elseif ($op == 'clear') {
$cc_cache = array();
}
return $cc_cache;
}
function uc_credit_cart_review_back_submit($form, &$form_state) {
$session_card_data = base64_decode($_POST['sescrd']);
$_SESSION['sescrd'] = $session_card_data;
uc_credit_cache('save', $session_card_data);
}
function uc_credit_cart_review_pre_form_submit($form, &$form_state) {
$session_card_data = base64_decode($_POST['sescrd']);
$_SESSION['sescrd'] = $session_card_data;
uc_credit_cache('save', $session_card_data);
}
function uc_credit_cart_review_post_form_submit($form, &$form_state) {
if (!empty($_SESSION['uc_checkout'][$_SESSION['cart_order']]['do_complete'])) {
unset($_SESSION['sescrd']);
}
}
function _uc_credit_valid_cvv($cvv) {
$digits = array();
if (variable_get('uc_credit_visa', TRUE) || variable_get('uc_credit_mastercard', TRUE) || variable_get('uc_credit_discover', TRUE)) {
$digits[] = 3;
}
if (variable_get('uc_credit_amex', TRUE)) {
$digits[] = 4;
}
if (!is_numeric($cvv) || count($digits) > 0 && !in_array(strlen($cvv), $digits)) {
return FALSE;
}
return TRUE;
}
function _uc_credit_valid_card_number($number) {
$id = substr($number, 0, 1);
if ($id == 3 && !variable_get('uc_credit_amex', TRUE) || $id == 4 && !variable_get('uc_credit_visa', TRUE) || $id == 5 && !variable_get('uc_credit_mastercard', TRUE) || $id == 6 && !variable_get('uc_credit_discover', TRUE) || !ctype_digit($number)) {
return FALSE;
}
$total = 0;
for ($i = 0; $i < strlen($number); $i++) {
$digit = substr($number, $i, 1);
if ((strlen($number) - $i - 1) % 2) {
$digit *= 2;
if ($digit > 9) {
$digit -= 9;
}
}
$total += $digit;
}
if ($total % 10 != 0) {
return FALSE;
}
return TRUE;
}
function _uc_credit_valid_card_start($month, $year) {
if (empty($month) && empty($year)) {
return TRUE;
}
if (empty($month) || empty($year)) {
return FALSE;
}
if ($year > date('Y')) {
return FALSE;
}
elseif ($year == date('Y')) {
if ($month > date('n')) {
return FALSE;
}
}
return TRUE;
}
function _uc_credit_valid_card_expiration($month, $year) {
if ($year < date('Y')) {
return FALSE;
}
elseif ($year == date('Y')) {
if ($month < date('n')) {
return FALSE;
}
}
return TRUE;
}
function _uc_credit_valid_card_issue($issue) {
if (empty($issue) || is_numeric($issue) && $issue > 0) {
return TRUE;
}
return FALSE;
}
function uc_credit_encryption_key() {
static $key = FALSE;
if (empty($key)) {
$key_file = variable_get('uc_credit_encryption_path', '') . '/' . UC_CREDIT_KEYFILE_NAME;
$contents = @file_get_contents($key_file);
if (strlen($contents) == 32) {
$key = $contents;
}
}
return $key;
}
function _uc_credit_save_cc_data_to_order($cc_data, $order_id) {
$cc_data['cc_number'] = substr($cc_data['cc_number'], -4);
unset($cc_data['cc_cvv']);
$data = db_query("SELECT data FROM {uc_orders} WHERE order_id = :id", array(
':id' => $order_id,
))
->fetchField();
$data = unserialize($data);
$crypt = new UbercartEncryption();
$data['cc_data'] = $crypt
->encrypt(uc_credit_encryption_key(), base64_encode(serialize($cc_data)));
uc_store_encryption_errors($crypt, 'uc_credit');
db_update('uc_orders')
->fields(array(
'data' => serialize($data),
))
->condition('order_id', $order_id)
->execute();
}
function uc_credit_transaction_types() {
$types = array(
UC_CREDIT_AUTH_ONLY => t('Authorization only'),
UC_CREDIT_PRIOR_AUTH_CAPTURE => t('Prior authorization capture'),
UC_CREDIT_AUTH_CAPTURE => t('Authorize and capture immediately'),
UC_CREDIT_REFERENCE_TXN => t('Reference transaction'),
);
return $types;
}
function uc_credit_default_gateway() {
$gateways = _uc_payment_gateway_list('credit', TRUE);
if (empty($gateways)) {
return FALSE;
}
$default = variable_get('uc_payment_credit_gateway', 'none');
$gateway = isset($gateways[$default]) ? $gateways[$default] : reset($gateways);
return function_exists($gateway['credit']) ? $gateway['id'] : FALSE;
}
function uc_credit_log_authorization($order_id, $auth_id, $amount) {
$data = db_query("SELECT data FROM {uc_orders} WHERE order_id = :id", array(
':id' => $order_id,
))
->fetchField();
$data = unserialize($data);
$data['cc_txns']['authorizations'][$auth_id] = array(
'amount' => $amount,
'authorized' => REQUEST_TIME,
);
db_update('uc_orders')
->fields(array(
'data' => serialize($data),
))
->condition('order_id', $order_id)
->execute();
return $data;
}
function uc_credit_log_prior_auth_capture($order_id, $auth_id) {
$data = db_query("SELECT data FROM {uc_orders} WHERE order_id = :id", array(
':id' => $order_id,
))
->fetchField();
$data = unserialize($data);
if (empty($data['cc_txns']['authorizations'][$auth_id])) {
return FALSE;
}
$data['cc_txns']['authorizations'][$auth_id]['captured'] = REQUEST_TIME;
db_update('uc_orders')
->fields(array(
'data' => serialize($data),
))
->condition('order_id', $order_id)
->execute();
return $data;
}
function uc_credit_log_reference($order_id, $ref_id, $cc_number) {
$data = db_query("SELECT data FROM {uc_orders} WHERE order_id = :id", array(
':id' => $order_id,
))
->fetchField();
$data = unserialize($data);
$data['cc_txns']['references'][$ref_id] = array(
'card' => substr($cc_number, -4),
'created' => REQUEST_TIME,
);
db_update('uc_orders')
->fields(array(
'data' => serialize($data),
))
->condition('order_id', $order_id)
->execute();
return $data;
}
function uc_credit_gateway_txn_types($gateway) {
$types = array();
$types = _uc_payment_gateway_data($gateway, 'credit_txn_types');
if (empty($types)) {
if (!is_null(_uc_payment_gateway_data($gateway, 'credit'))) {
$types = array(
UC_CREDIT_AUTH_CAPTURE,
);
}
else {
$types = array();
}
}
return $types;
}
function uc_credit_terminal_title($order) {
return t('Credit card terminal: Order @order_id', array(
'@order_id' => $order->order_id,
));
}