'admin/store/settings/payment', 'title' => t('Payment settings'), 'callback' => 'uc_payment_settings_overview', 'access' => user_access('administer store'), 'description' => t('Configure the payment settings.'), ); $items[] = array( 'path' => 'admin/store/settings/payment/overview', 'title' => t('Overview'), 'access' => user_access('administer store'), 'description' => t('View the payment settings.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/store/settings/payment/edit', 'title' => t('Edit'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_payment_settings_form'), 'access' => user_access('administer store'), 'description' => t('Edit the payment settings.'), 'type' => MENU_LOCAL_TASK, 'weight' => -5, ); $items[] = array( 'path' => 'admin/store/settings/payment/edit/basic', 'title' => t('Payment settings'), 'access' => user_access('administer store'), 'description' => t('Edit the basic payment settings.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/store/settings/payment/edit/methods', 'title' => t('Payment methods'), 'access' => user_access('administer store'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_payment_methods_form'), 'description' => t('Edit the payment method settings.'), 'type' => MENU_LOCAL_TASK, 'weight' => -5, ); $items[] = array( 'path' => 'admin/store/settings/payment/edit/gateways', 'title' => t('Payment gateways'), 'access' => user_access('administer store'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_payment_gateways_form'), 'description' => t('Edit the payment gateway settings.'), 'type' => MENU_LOCAL_TASK, 'weight' => 0, ); $items[] = array( 'path' => 'admin/store/payment_methods', 'title' => t('Payment methods autocomplete'), 'callback' => '_uc_payment_methods_autocomplete', 'access' => user_access('edit orders'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'cart/checkout/line_items', 'title' => t('Return order totals'), 'callback' => 'uc_payment_get_totals', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); } else { $items[] = array( 'path' => 'cart/checkout/payment_details/'. arg(3), 'title' => t('Payment details'), 'description' => t('Add the payment details to the checkout pane.'), 'callback' => 'uc_payment_get_details', 'callback arguments' => array(arg(3)), 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); if (is_numeric(arg(3))) { $items[] = array( 'path' => 'admin/store/orders/'. arg(3) .'/payment_details/'. arg(5), 'title' => t('Payment details'), 'description' => t('Add the payment details to the order pane.'), 'callback' => 'uc_payment_get_details', 'callback arguments' => array(arg(5), 'order'), 'access' => user_access('edit orders'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/store/orders/'. arg(3) .'/receive_check', 'title' => t('Receive Check'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_payment_receive_check_form', arg(3)), 'access' => user_access('view all orders'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/store/orders/'. arg(3) .'/payments/select/'. arg(6), 'title' => t('Select Payment Gateway'), 'callback' => 'uc_payment_gateway_select', 'callback arguments' => array(arg(3), arg(6)), 'access' => user_access('view all orders'), 'type' => MENU_CALLBACK, ); if (variable_get('uc_payment_tracking', TRUE)) { $items[] = array( 'path' => 'admin/store/orders/'. arg(3) .'/payments', 'title' => t('payments'), 'callback' => 'uc_payment_by_order', 'callback arguments' => array(arg(3)), 'access' => user_access('view payments'), 'weight' => 5, 'type' => MENU_LOCAL_TASK ); } if (is_numeric(arg(5)) && arg(6) == 'delete' && variable_get('uc_payment_deleting', TRUE)) { $items[] = array( 'path' => 'admin/store/orders/'. arg(3) .'/payments/'. arg(5) .'/delete', 'title' => t('Delete payment?'), 'description' => t('Delete payment?'), 'callback' => 'uc_payment_delete_confirm', 'callback arguments' => array(arg(3), arg(5)), 'access' => user_access('delete payments'), 'type' => MENU_CALLBACK, ); } } } return $items; } /** * Implementation of hook_token_values(). (token.module) */ function uc_payment_token_values($type, $object = NULL) { switch ($type) { case 'uc_order': $order = $object; $values['order-payment-method'] = _payment_method_data($order->payment_method, 'name'); break; } return $values; } /** * Implementation of hook_token_list(). (token.module) */ function uc_payment_token_list($type = 'all') { if ($type == 'uc_order' || $type == 'ubercart' || $type == 'all') { $tokens['uc_order']['order-payment-method'] = t('The payment method of the order.'); } return $tokens; } /** * Implementation of hook_perm(). */ function uc_payment_perm() { return array('view payments', 'manual payments', 'delete payments'); } /******************************************************************************* * Hook Functions (TAPIr) ******************************************************************************/ /** * Implementation of hook_table_settings(). */ function uc_payment_table_settings() { $tables[] = array( 'id' => 'uc_payments_table', 'description' => t('The payments table on the order payments screen.'), 'path' => 'admin/store/settings/tables', 'access' => 'view all orders', 'preview' => FALSE, ); return $tables; } /******************************************************************************* * Hook Functions (Ubercart) ******************************************************************************/ /** * Implementation of hook_order(). */ function uc_payment_order($op, &$arg1) { switch ($op) { case 'submit': $func = _payment_method_data($arg1->payment_method, 'callback'); if (function_exists($func)) { /*if (substr(PHP_VERSION, 0, 1) == 4) { return $func('order-submit', &$arg1); } else { return uc_func_call($func, 'order-submit', $arg1); }*/ return $func('order-submit', $arg1); } break; case 'load': $func = _payment_method_data($arg1->payment_method, 'callback'); if (function_exists($func)) { /*if (substr(PHP_VERSION, 0, 1) == 4) { $func('order-load', &$arg1); } else { uc_func_call($func, 'order-load', $arg1); }*/ $func('order-load', $arg1); } break; case 'save': $func = _payment_method_data($arg1->payment_method, 'callback'); if (function_exists($func)) { /*if (substr(PHP_VERSION, 0, 1) == 4) { $func('order-save', &$arg1); } else { uc_func_call($func, 'order-save', $arg1); }*/ $func('order-save', $arg1); } break; case 'delete': db_query("DELETE FROM {uc_payment_receipts} WHERE order_id = %d", $arg1); // Call each payment method to delete method specific data from the database. $methods = _payment_method_list(); foreach ($methods as $method) { $func = $method['callback']; if (function_exists($func)) { $func('order-delete', $arg1); } } break; //#mic_start ADD--> case 'total': $csubtotal = 0; $citems = uc_cart_get_contents(); foreach ($citems as $item) { $ctotal = ($item->qty) ? $item->qty * $item->price : $item->price; $csubtotal += $ctotal; } $text_of_payment = ''; $cost_of_payment = 0; $cost_of_payment = variable_get('uc_payment_method_'. $arg1->payment_method .'_cost', ''); $mode = variable_get('uc_payment_method_'. $arg1->payment_method .'_mode', ''); db_query("DELETE FROM {uc_order_line_items} WHERE order_id = %d AND type = '%s'", $arg1->order_id, 'Cost of Payment'); if ($cost_of_payment != ""){ if ($mode == 'percent_plus') { $cost_of_payment = intval($cost_of_payment); $cost_of_payment = ($csubtotal / 100) * $cost_of_payment; } elseif ($mode == 'percent_minus') { $cost_of_payment = intval($cost_of_payment); $cost_of_payment = ($csubtotal / 100) * $cost_of_payment; $cost_of_payment *= -1; } elseif ($mode == 'static') { $cost_of_payment = $cost_of_payment; } $text_of_payment = variable_get('uc_payment_method_'. $arg1->payment_method .'_text', ''); uc_order_line_item_add($arg1->order_id, 'Cost of Payment', $text_of_payment, $cost_of_payment, 1); } return $cost_of_payment; //#mic_end <-- } } /** * Implementation of hook_checkout_pane(). */ function uc_payment_checkout_pane() { $panes[] = array( 'id' => 'payment', 'title' => t('Payment Method'), 'desc' => t('Select a payment method from the enabled payment modules.'), 'callback' => 'uc_checkout_pane_payment', 'weight' => 6, ); return $panes; } /** * Implementation of hook_order_pane(). */ function uc_payment_order_pane() { $panes[] = array( 'id' => 'payment', 'callback' => 'uc_order_pane_payment', 'title' => t('Payment'), 'desc' => t('Specify and collect payment for an order.'), 'class' => 'pos-left', 'weight' => 4, 'show' => array('view', 'edit', 'customer'), //, 'invoice', 'customer'), ); return $panes; } /** * Implementation of hook_payment_method(). */ function uc_payment_payment_method() { $methods[] = array( 'id' => 'check', 'name' => t('Check'), 'title' => t('Check or Money Order'), 'desc' => t('Pay by mailing a check or money order.'), 'callback' => 'uc_payment_method_check', 'weight' => 1, 'checkout' => TRUE, 'backend' => TRUE, ); $methods[] = array( 'id' => 'cod', 'name' => t('COD'), 'title' => t('Cash on Delivery'), 'desc' => t('Pay cash on delivery on pick-up.'), 'callback' => 'uc_payment_method_cod', 'weight' => 1, 'checkout' => FALSE, 'backend' => TRUE, ); $methods[] = array( 'id' => 'other', 'name' => t('Other'), 'title' => t('Other'), 'desc' => t('A generic payment method type.'), 'callback' => 'uc_payment_method_other', 'weight' => 10, 'checkout' => FALSE, 'backend' => TRUE, ); return $methods; } /******************************************************************************* * Callback Functions, Forms, and Tables ******************************************************************************/ /** * Display the payment settings overview. */ function uc_payment_settings_overview() { $sections[] = array( 'edit' => 'admin/store/settings/payment/edit', 'title' => t('Payment settings'), 'items' => array( t('Payment tracking is !status.', array('!status' => variable_get('uc_payment_tracking', TRUE) ? t('enabled') : t('disabled'))), t('Payments !status be deleted by approved users.', array('!status' => variable_get('uc_payment_deleting', TRUE) ? t('may') : t('may not'))), t('Payments are !status in the order logs.', array('!status' => variable_get('uc_payment_logging', TRUE) ? t('tracked') : t('not tracked'))), ), ); $methods = _payment_method_list(); foreach ($methods as $method) { $items[] = t('!title is !status for checkout.', array('!title' => $method['name'], '!status' => $method['checkout'] ? t('enabled') : t('disabled'))); } $sections[] = array( 'edit' => 'admin/store/settings/payment/edit/methods', 'title' => t('Payment methods'), 'items' => $items, ); $items = array(); $gateways = _payment_gateway_list(); foreach ($gateways as $gateway) { $items[] = t('!title is !status.', array('!title' => $gateway['title'], '!status' => $gateway['enabled'] ? t('enabled') : t('disabled'))); } $sections[] = array( 'edit' => 'admin/store/settings/payment/edit/gateways', 'title' => t('Payment gateways'), 'items' => $items, ); $output = theme('uc_settings_overview', $sections); return $output; } function uc_payment_settings_form() { $form['uc_payment_tracking'] = array( '#type' => 'checkbox', '#title' => t('Enable payment tracking.'), '#default_value' => variable_get('uc_payment_tracking', TRUE), ); $form['uc_payment_deleting'] = array( '#type' => 'checkbox', '#title' => t('Allow payments to be deleted by users with permission.'), '#default_value' => variable_get('uc_payment_deleting', TRUE), ); $form['uc_payment_logging'] = array( '#type' => 'checkbox', '#title' => t('Log payments entered and deleted to order log.'), '#default_value' => variable_get('uc_payment_logging', TRUE), ); return system_settings_form($form); } function uc_payment_methods_form() { $methods = _payment_method_list(); $form['methods_info'] = array( '#value' => '
'. t('Payment Methods') .'
' . t('The settings forms below are for the payment methods defined by enabled modules. Click a name to expand its options and adjust the settings accordingly. Methods are listed in order of appearance on the checkout screen, determined by the weight setting (current value shown in parentheses).') .'

', ); $form['pmtable'] = array( '#theme' => 'uc_payment_method_table', ); if (is_array($methods) && count($methods) > 0) { foreach ($methods as $method) { $form['pmtable'][$method['id']]['uc_payment_method_'. $method['id'] .'_checkout'] = array( '#type' => 'checkbox', '#default_value' => variable_get('uc_payment_method_'. $method['id'] .'_checkout', $method['checkout']), ); $form['pmtable'][$method['id']]['uc_payment_method_'. $method['id'] .'_backend'] = array( '#type' => 'checkbox', '#default_value' => variable_get('uc_payment_method_'. $method['id'] .'_backend', $method['backend']), ); $form['pmtable'][$method['id']]['name'] = array( '#value' => $method['name'], ); //#mic_start ADD--> $form['pmtable'][$method['id']]['uc_payment_method_'. $method['id'] .'_cost'] = array( '#type' => 'textfield', '#size' => '5', '#default_value' => variable_get('uc_payment_method_'. $method['id'] .'_cost', $method['cost']), ); //@todo Form Validation $form['pmtable'][$method['id']]['uc_payment_method_'. $method['id'] .'_mode'] = array( '#type' => 'select', '#options' => array ('percent_plus' => '%+', 'percent_minus' => '%-', 'static' => 'static'), '#default_value' => variable_get('uc_payment_method_'. $method['id'] .'_mode', 'none'), ); $form['pmtable'][$method['id']]['uc_payment_method_'. $method['id'] .'_text'] = array( '#type' => 'textfield', '#size' => '20', '#default_value' => variable_get('uc_payment_method_'. $method['id'] .'_text', $method['cost']), ); //@todo Form Validation //#mic_start <--- $form['pmtable'][$method['id']]['uc_payment_method_'. $method['id'] .'_weight'] = array( '#type' => 'weight', '#default_value' => variable_get('uc_payment_method_'. $method['id'] .'_weight', $method['weight']), ); $gateways = _payment_gateway_list($method['id'], TRUE); $options = array(); $default = FALSE; if (is_array($gateways)) { foreach ($gateways as $gateway) { if (!$default) { $default = $gateway['id']; } $options[$gateway['id']] = $gateway['title']; } } if (!$default) { $options = array('none' => t('None available.')); } $form['pmtable'][$method['id']]['uc_payment_'. $method['id'] .'_gateway'] = array( '#type' => 'select', '#options' => $options, '#default_value' => variable_get('uc_payment_'. $method['id'] .'_gateway', 'none'), ); $method_settings = $method['callback']('settings', $null); if (is_array($method_settings)) { $form['method_'. $method['id']] = array( '#type' => 'fieldset', '#title' => t('!method settings', array('!method' => $method['name'], '!weight' => $method['weight'])), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['method_'. $method['id']] = array_merge($form['method_'. $method['id']], $method_settings); } } } return system_settings_form($form); } function theme_uc_payment_method_table($form) { //#mic_start EDIT--> $header = array(t('Checkout'), t('Admin'), t('Payment method'), t('Cost'), t('Mode'), t('Text'), t('Weight'), t('Default gateway')); //#mic ORIGINAL $header = array(t('Checkout'), t('Admin'), t('Payment method'), t('Weight'), t('Default gateway')); //#mic_end <-- foreach (element_children($form) as $method) { $rows[] = array( array('data' => drupal_render($form[$method]['uc_payment_method_'. $method .'_checkout']), 'align' => 'center'), array('data' => drupal_render($form[$method]['uc_payment_method_'. $method .'_backend']), 'align' => 'center'), drupal_render($form[$method]['name']), //#mic_start ADD--> drupal_render($form[$method]['uc_payment_method_'. $method .'_cost']), drupal_render($form[$method]['uc_payment_method_'. $method .'_mode']), drupal_render($form[$method]['uc_payment_method_'. $method .'_text']), //#mic_end <-- drupal_render($form[$method]['uc_payment_method_'. $method .'_weight']), drupal_render($form[$method]['uc_payment_'. $method .'_gateway']), ); } if (empty($rows)) { $rows[] = array( array('data' => t('No payment methods founds.'), 'colspan' => 5), ); } return theme('table', $header, $rows) .'
'; } function uc_payment_gateways_form() { $gateways = _payment_gateway_list(); $methods = _payment_method_list(); if (is_array($gateways) && count($gateways) > 0) { $form['gateways_info'] = array( '#value' => '
'. t('Payment Gateways') .'
' . t('Payment gateways are web services that allow you to process various types of payments remotely. The settings forms below are for the payment gateways you have installed. Click a name to expand its options and adjust the settings accordingly.') .'
', ); foreach ($gateways as $gateway) { $prefix = 'uc_pg_'. $gateway['id']; $form[$prefix] = array( '#type' => 'fieldset', '#title' => t('!gateway_name settings', array('!gateway_name' => $gateway['title'])), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $supported_methods = array(); foreach ($methods as $method) { if (isset($gateway[$method['id']]) && function_exists($gateway[$method['id']])) { $supported_methods[] = $method['name']; } } $form[$prefix]['supported_methods'] = array( '#value' => '
'. t('This gateway supports the following payment methods:') .'
'. implode(',', $supported_methods) .'
', ); $form[$prefix][$prefix .'_enabled'] = array( '#type' => 'checkbox', '#title' => t('Enable this payment gateway for use.'), '#default_value' => variable_get($prefix .'_enabled', TRUE), ); if (function_exists($gateway['settings'])) { $gateway_settings = $gateway['settings'](); if (is_array($gateway_settings)) { $form[$prefix] = array_merge($form[$prefix], $gateway_settings); } } } } return system_settings_form($form); } function uc_payment_get_details($method_id, $view = 'cart') { if ($view == 'cart') { if (!($order = uc_order_load($_SESSION['cart_order']))) { $_SESSION['cart_order'] = NULL; $order = NULL; } if ($order->order_status != 0 || ($user->uid && $user->uid != $order->uid)) { $order = NULL; } } elseif ($view == 'order') { $order = uc_order_load(arg(3)); } $func = _payment_method_data($method_id, 'callback'); if (function_exists($func)) { $output = $func($view .'-details', $order); } print $output; exit(); } function uc_payment_get_totals() { foreach($_POST as $key => $value) { $totals[$key] = explode(';', $value); } usort($totals, '_total_sort'); $output = t('Order total preview:') .''; $grand_total = 0; foreach($totals as $line) { $output .= '' .''; $grand_total += $line[1]; } $output .= '' .'
'. $line[2] .':'. uc_currency_format($line[1]) .'
'. t('Order total:') .''. uc_currency_format($grand_total) .'
'; print $output; exit(); } function _total_sort($a, $b) { if ($a[0] == $b[0]) { return 0; } return ($a[0] < $b[0]) ? -1 : 1; } function uc_checkout_pane_payment($op, &$arg1, $arg2) { switch ($op) { case 'view': drupal_add_js(drupal_get_path('module', 'uc_payment') .'/uc_payment.js'); if (module_exists('uc_taxes')){ drupal_add_js(drupal_get_path('module', 'uc_taxes') .'/uc_taxes.js'); } $pane = uc_cart_checkout_new_pane('payment'); $pane->fields['pane']['current_total'] = array( '#type' => 'hidden', '#value' => $arg1->order_total > 0 ? $arg1->order_total : NULL, ); $pane->fields['pane']['shown_total'] = array( '#value' => '
'. t('Preparing order total preview...') .'
', '#weight' => -20, ); $pane->fields['pane']['description'] = uc_cart_checkout_pane_description('payment', t('Select a payment method from the following:')); $methods = _payment_method_list(); foreach ($methods as $method) { if ($method['checkout']) { $options[$method['id']] = $method['title']; //#mic_start ADD--> $text = variable_get('uc_payment_method_'. $method['id'] .'_text', ''); if ($text != "") $options[$method['id']] .= ' ('.$text.')'; //#mic_end <-- } } $pane->fields['pane']['payment_method'] = array( '#type' => 'radios', '#title' => t('Payment Method'), '#options' => $options, '#default_value' => $arg1->payment_method, '#required' => TRUE, '#attributes' => array('onclick' => "get_payment_details('". base_path() ."?q=cart/checkout/payment_details/' + this.value);"), ); drupal_add_js("\$(document).ready( function () { show_default_payment_details('". base_path() ."?q=cart/checkout/payment_details/'); } );", 'inline'); $pane->fields['pane']['details'] = array( '#value' => '', ); $pane->fields['pane']['continue'] = uc_cart_checkout_next_button('customer', $pane->next); return $pane; case 'process': $method = $arg2['pane']['payment_method']; $arg1->payment_method = $method; $func = _payment_method_data($method, 'callback'); if (function_exists($func)) { /*if (substr(PHP_VERSION, 0, 1) == 4) { $result = $func('cart-process', &$arg1); } else { $result = uc_func_call($func, 'cart-process', $arg1); }*/ $result = $func('cart-process', $arg1); if ($result === FALSE) { return FALSE; } } return TRUE; case 'review': $line_items = $arg1->line_items; $items = _line_item_list(); foreach ($items as $item) { if (isset($item['display_only']) && $item['display_only'] == TRUE) { $result = $item['callback']('display', $arg1); if (is_array($result)) { foreach ($result as $line) { $line_items[] = array( 'title' => $line['title'], 'amount' => $line['amount'], 'weight' => $item['weight'] ); } } } } usort($line_items, '_line_item_sort'); foreach ($line_items as $line_item) { $review[] = array('title' => $line_item['title'], 'data' => uc_currency_format($line_item['amount'])); } $review[] = array('border' => 'top', 'title' => t('Paying by'), 'data' => _payment_method_data($arg1->payment_method, 'name')); $func = _payment_method_data($arg1->payment_method, 'callback'); if (function_exists($func)) { $result = $func('cart-review', $arg1); if (is_array($result)) { $review = array_merge($review, $result); } } return $review; } } /** * Handle the Payment order pane. */ function uc_order_pane_payment($op, $arg1) { switch ($op) { case 'view': if (variable_get('uc_payment_tracking', TRUE)) { $output = t('Balance:') .' '. uc_currency_format(uc_payment_balance($arg1)); $output .= ' ('. l(t('View'), 'admin/store/orders/'. $arg1->order_id .'/payments') .')
'; } $output .= t('Method:') . _payment_method_data($arg1->payment_method, 'name'); $func = _payment_method_data($arg1->payment_method, 'callback'); if (function_exists($func)) { $method_output = $func('order-view', $arg1); if (!empty($method_output)) { $output .= '
'. $method_output; } } return $output; case 'customer': $output = t('Method:') .' '. _payment_method_data($arg1->payment_method, 'name'); $func = _payment_method_data($arg1->payment_method, 'callback'); if (function_exists($func)) { $method_output = $func('customer-view', $arg1); if (!empty($method_output)) { $output .= '
'. $method_output; } } return $output; case 'edit-form': $form['payment'] = array( '#type' => 'fieldset', '#title' => t("Modify 'Payment Info'"), '#collapsible' => TRUE, '#collapsed' => FALSE ); $methods = _payment_method_list(); foreach ($methods as $method) { if ($method['backend'] == TRUE) { $options[$method['id']] = $method['name']; } } $form['payment']['payment_method'] = array( '#type' => 'select', '#title' => t('Payment method'), '#default_value' => $arg1->payment_method, '#options' => (is_array($options)) ? $options : array(t('None available')), '#attributes' => array('onchange' => "get_payment_details('". base_path() ."?q=admin/store/orders/". $arg1->order_id ."/payment_details/' + this.value);"), '#disabled' => (is_array($options)) ? FALSE : TRUE, ); return $form; case 'edit-theme': drupal_add_js(drupal_get_path('module', 'uc_payment') .'/uc_payment.js'); $methods = _payment_method_list(); $js = 'var methods = {'; foreach ($methods as $method) { if ($method['backend'] == TRUE) { $js .= '"'. $method['name'] .'": "' . $method['id'] .'", '; } } $js = rtrim($js, ' ,') .'};'; drupal_add_js($js, 'inline'); drupal_add_js("\$(document).ready( function () { get_payment_details('". base_path() ."?q=admin/store/orders/' + \$('#edit-order-id').val() + '/payment_details/' + \$('#edit-payment-method').val()); } );", 'inline'); $output = ''; foreach (element_children($arg1['payment']) as $field) { $title = $arg1['payment'][$field]['#title']; $arg1['payment'][$field]['#title'] = NULL; $output .= ''; } $output .= '
'. $title .':' . drupal_render($arg1['payment'][$field]) .'
'; return $output; case 'edit-process': $changes['payment_method'] = $arg1['payment_method']; $func = _payment_method_data($arg1['payment_method'], 'callback'); if (function_exists($func) && ($return = $func('edit-process', $arg1)) != NULL && is_array($return)) { $changes = array_merge($changes, $return); } return $changes; } } function uc_payment_method_other($op, $arg1) { switch($op) { case 'order-view': case 'customer-view': $result = db_query("SELECT description FROM {uc_payment_other} WHERE " ."order_id = %d", $arg1->order_id); if ($row = db_fetch_object($result)) { $output = t('Type:') .' '. $row->description; } else { $output = t('Type:') .' '. t('Unknown'); } return $output; case 'order-details': $details = drupal_get_form('uc_payment_method_other_form', $arg1); return uc_strip_form($details); case 'edit-process': $changes['payment_details']['pm_other_description'] = check_plain($_POST['pm_other_description']); return $changes; case 'order-load': $result = db_query("SELECT description FROM {uc_payment_other} WHERE " ."order_id = %d", $arg1->order_id); if ($row = db_fetch_object($result)) { $arg1->payment_details['description'] = $row->description; } break; case 'order-save': db_query("DELETE FROM {uc_payment_other} WHERE order_id = %d", $arg1->order_id); if (strlen($arg1->payment_details['pm_other_description']) > 0) { db_query("INSERT INTO {uc_payment_other} (order_id, description) VALUES " ."(%d, '%s')", $arg1->order_id, $arg1->payment_details['pm_other_description']); } break; } } function uc_payment_method_other_form($order) { $form['pm_other_description'] = array( '#type' => 'textfield', '#size' => 32, '#maxlength' => 64, '#default_value' => $order->payment_details['description'], ); return $form; } function theme_uc_payment_method_other_form($form) { $output = '
' . t('Description:') .'' . drupal_render($form['pm_other_description']) .'
'; return $output; } function uc_payment_method_cod($op, &$arg1) { switch ($op) { case 'cart-details': $details = variable_get('uc_cod_policy', t('Full payment is expected upon delivery or prior to pick-up.')); if (($max = variable_get('uc_cod_max_order', 0)) > 0 && is_numeric($max)) { $details .= '

'. t('Orders totalling more than !number are not eligible for COD.', array('!number' => uc_currency_format($max))) .'

'; } if (variable_get('uc_cod_delivery_date', FALSE)) { $details .= uc_strip_form(drupal_get_form('uc_payment_method_cod_form', $arg1)); } return $details; case 'cart-process': if (variable_get('uc_cod_delivery_date', FALSE)) { $arg1->payment_details['delivery_month'] = intval($_POST['cod_delivery_month']); $arg1->payment_details['delivery_day'] = intval($_POST['cod_delivery_day']); $arg1->payment_details['delivery_year'] = intval($_POST['cod_delivery_year']); } return TRUE; case 'cart-review': if (variable_get('uc_cod_delivery_date', FALSE)) { $date = uc_date_format($arg1->payment_details['delivery_month'], $arg1->payment_details['delivery_day'], $arg1->payment_details['delivery_year']); $review[] = array('title' => t('Delivery Date'), 'data' => $date); } return $review; case 'order-view': if (variable_get('uc_cod_delivery_date', FALSE)) { $output = t('Desired delivery date:') .'
' . uc_date_format($arg1->payment_details['delivery_month'], $arg1->payment_details['delivery_day'], $arg1->payment_details['delivery_year']); } return $output; case 'order-details': if (variable_get('uc_cod_delivery_date', FALSE)) { $details .= uc_strip_form(drupal_get_form('uc_payment_method_cod_form', $arg1)); } return $details; case 'order-load': $result = db_query("SELECT * FROM {uc_payment_cod} WHERE order_id = %d", $arg1->order_id); if ($row = db_fetch_object($result)) { $arg1->payment_details['delivery_month'] = $row->delivery_month; $arg1->payment_details['delivery_day'] = $row->delivery_day; $arg1->payment_details['delivery_year'] = $row->delivery_year; } break; case 'order-submit': if ($arg1->payment_method == 'cod' && ($max = variable_get('uc_cod_max_order', 0)) > 0 && is_numeric($max) && $arg1->order_total > $max) { $result[] = array( 'pass' => FALSE, 'message' => t('Your final order total exceeds the maximum for COD payment. Please go back and select a different method of payment.') ); $_SESSION['expanded_panes'][] = 'payment'; return $result; } case 'order-save': db_query("DELETE FROM {uc_payment_cod} WHERE order_id = %d", $arg1->order_id); db_query("INSERT INTO {uc_payment_cod} VALUES (%d, %d, %d, %d)", $arg1->order_id, $arg1->payment_details['delivery_month'], $arg1->payment_details['delivery_day'], $arg1->payment_details['delivery_year']); break; case 'order-delete': db_query("DELETE FROM {uc_payment_cod} WHERE order_id = %d", $arg1); break; case 'settings': $form['uc_cod_max_order'] = array( '#type' => 'textfield', '#title' => t('Maximum order total eligible for COD'), '#default_value' => variable_get('uc_cod_max_order', 0), '#description' => t('Set to 0 for no maximum order limit.'), ); $form['uc_cod_delivery_date'] = array( '#type' => 'checkbox', '#title' => t('Let customers enter a desired delivery date.'), '#default_value' => variable_get('uc_cod_delivery_date', FALSE), ); return $form; } } function uc_payment_method_cod_form($order) { $form['table1'] = array('#value' => '
'); $month = (!empty($order->payment_details['delivery_month'])) ? $order->payment_details['delivery_month'] : date('n'); $form['cod_delivery_month'] = uc_select_month(NULL, $month); $form['table2'] = array('#value' => ''); $day = (!empty($order->payment_details['delivery_day'])) ? $order->payment_details['delivery_day'] : date('j'); $form['cod_delivery_day'] = uc_select_day(NULL, $day); $form['table3'] = array('#value' => ''); $year = (!empty($order->payment_details['delivery_year'])) ? $order->payment_details['delivery_year'] : date('Y'); $form['cod_delivery_year'] = uc_select_year(NULL, $year, date('Y'), date('Y') + 1); $form['table4'] = array('#value' => '
'); return $form; } function uc_payment_method_check($op, &$arg1) { switch ($op) { case 'cart-details': if (!variable_get('uc_check_mailing_street1', FALSE)) { $details = t('Checks should be made out to:') .'

' . uc_address_format(variable_get('uc_store_name', ''), NULL, variable_get('uc_store_company', ''), variable_get('uc_store_street1', ''), variable_get('uc_store_street2', ''), variable_get('uc_store_city', ''), variable_get('uc_store_zone', ''), variable_get('uc_store_postal_code', ''), variable_get('uc_store_country', 840)) .'

'. variable_get('uc_check_policy', '') .'

'; } else { $details = t('Checks should be made out to:') .'

' . uc_address_format(variable_get('uc_check_mailing_name', ''), NULL, variable_get('uc_check_mailing_company', ''), variable_get('uc_check_mailing_street1', ''), variable_get('uc_check_mailing_street2', ''), variable_get('uc_check_mailing_city', ''), variable_get('uc_check_mailing_zone', ''), variable_get('uc_check_mailing_postal_code', ''), variable_get('uc_store_country', 840)) .'

'. variable_get('uc_check_policy', '') .'

'; } return $details; case 'cart-review': if (!variable_get('uc_check_mailing_street1', FALSE)) { $review[] = array('title' => t('Mail to'), 'data' => uc_address_format(variable_get('uc_store_name', ''), NULL, variable_get('uc_store_company', ''), variable_get('uc_store_street1', ''), variable_get('uc_store_street2', ''), variable_get('uc_store_city', ''), variable_get('uc_store_zone', ''), variable_get('uc_store_postal_code', ''), variable_get('uc_store_country', 840))); } else { $review[] = array('title' => t('Mail to'), 'data' => uc_address_format(variable_get('uc_check_mailing_name', ''), NULL, variable_get('uc_check_mailing_company', ''), variable_get('uc_check_mailing_street1', ''), variable_get('uc_check_mailing_street2', ''), variable_get('uc_check_mailing_city', ''), variable_get('uc_check_mailing_zone', ''), variable_get('uc_check_mailing_postal_code', ''), variable_get('uc_store_country', 840))); } return $review; case 'order-view': if (!variable_get('uc_payment_tracking', TRUE)) { return ''; } $result = db_query("SELECT clear_date FROM {uc_payment_check} WHERE " ."order_id = %d ", $arg1->order_id); if ($check = db_fetch_object($result)) { $output = t('Clear Date:') .' '. date('m/d/Y', $check->clear_date); } else { $output = l(t('Receive Check'), 'admin/store/orders/'. $arg1->order_id .'/receive_check'); } $output .= '
'; return $output; case 'customer-view': if (!variable_get('uc_payment_tracking', TRUE)) { return ''; } $result = db_query("SELECT clear_date FROM {uc_payment_check} WHERE " ."order_id = %d ", $arg1->order_id); if ($check = db_fetch_object($result)) { $output = t('Check Received') .'
' . t('Expected Clear Date:') .'
'. date('m/d/Y', $check->clear_date); } return $output; case 'settings': $form['check_address_info'] = array( '#value' => '
'. t('Set the mailing address to display to customers who choose this payment method during checkout.') .'
', ); $form['uc_check_mailing_company'] = uc_textfield(uc_get_field_name('company'), variable_get('uc_check_mailing_company', ''), FALSE, NULL, 128); $form['uc_check_mailing_name'] = uc_textfield(t('Contact'), variable_get('uc_check_mailing_name', ''), FALSE, t('Direct checks to a person or department.'), 128); $form['uc_check_mailing_street1'] = uc_textfield(uc_get_field_name('street1'), variable_get('uc_check_mailing_street1', ''), FALSE, NULL, 128); $form['uc_check_mailing_street2'] = uc_textfield(uc_get_field_name('street2'), variable_get('uc_check_mailing_street2', ''), FALSE, NULL, 128); $form['uc_check_mailing_city'] = uc_textfield(uc_get_field_name('city'), variable_get('uc_check_mailing_city', ''), FALSE); $form['uc_check_mailing_zone'] = uc_zone_select(uc_get_field_name('zone'), variable_get('uc_check_mailing_zone', ''), FALSE); $form['uc_check_mailing_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), variable_get('uc_check_mailing_postal_code', ''), FALSE, NULL, 10, 10); $form['uc_check_country'] = uc_country_select(uc_get_field_name('country'), variable_get('uc_check_country', 840)); $form['uc_check_policy'] = array( '#type' => 'textarea', '#title' => t('Check Payment Policy'), '#description' => t('Instructions for customers on the checkout page.'), '#default_value' => variable_get('uc_check_policy', t('Personal and business checks will be held for up to 10 business days to ensure payment clears before an order is shipped.')), '#rows' => 3, ); return $form; } } /** * Receive a check for an order and put in a clear date. */ function uc_payment_receive_check_form($order_id) { $order = uc_order_load($order_id); if ($order === FALSE) { drupal_set_message(t('Order !order_id does not exist.', array('!order_id' => $order_id))); drupal_goto('admin/store/orders'); } $balance = uc_payment_balance($order); $form['balance'] = array('#value' => uc_currency_format($balance)); $form['order_id'] = array( '#type' => 'hidden', '#value' => $order_id, ); $form['check_exists'] = array( '#type' => 'checkbox', '#title' => t('Check has already been received.'), '#attributes' => array('onclick' => 'receive_check_toggle(this.checked);'), ); $form['amount'] = array( '#type' => 'textfield', '#title' => t('Amount'), '#description' => t('Do not include currency sign.'), '#default_value' => uc_currency_format($balance, FALSE, FALSE), '#size' => 10, ); $form['comment'] = array( '#type' => 'textfield', '#title' => t('Comment'), '#description' => t('Any notes about the check, like type or check number.'), '#size' => 64, '#maxlength' => 256, ); $form['clear_month'] = uc_select_month(NULL, date('n')); $form['clear_day'] = uc_select_day(NULL, date('j')); $form['clear_year'] = uc_select_year(NULL, date('Y'), date('Y'), date('Y') + 1); $form['submit'] = array( '#type' => 'submit', '#value' => t('Receive Check'), ); return $form; } function theme_uc_payment_receive_check_form($form) { drupal_add_js(drupal_get_path('module', 'uc_payment') .'/uc_payment.js'); $output = '

'. t('Use the form to enter the check into the payments system and set the expected clear date.') .'

'; $output .= '

'. t('Order Balance:') .' ' . drupal_render($form['balance']) .'

'; $output .= drupal_render($form['check_exists']) . drupal_render($form['amount']) . drupal_render($form['comment']); $output .= '
'. t('Expected clear date:') .'
'. drupal_render($form['clear_month']) .''. drupal_render($form['clear_day']) . '' . drupal_render($form['clear_year']) .'
'; $output .= drupal_render($form); return $output; } function uc_payment_receive_check_form_validate($form_id, $form_values) { if (!$form_values['check_exists'] && !is_numeric($form_values['amount'])) { form_set_error('amount', t('The amount must be a number.')); } } function uc_payment_receive_check_form_submit($form_id, $form_values) { global $user; uc_payment_enter($form_values['order_id'], _payment_method_data('check', 'name'), $form_values['amount'], $user->uid, '', $form_values['comment']); db_query("INSERT INTO {uc_payment_check} (check_id, order_id, clear_date) " ."VALUES (%d, %d, %d)", db_next_id('{uc_payment_check}_check_id'), $form_values['order_id'], mktime(12, 0, 0, $form_values['clear_month'], $form_values['clear_day'], $form_values['clear_year'])); drupal_set_message(t('Check received, expected clear date of !date.', array('!date' => $form_values['clear_month'] .'/' . $form_values['clear_day'] .'/' . $form_values['clear_year']))); drupal_goto('admin/store/orders/'. $form_values['order_id']); } /** * View a list of payments attached to an order. */ function uc_payment_by_order($order_id) { $output = '

'. drupal_get_form('uc_payment_by_order_form', $order_id) .'

'; return $output; } function uc_payment_by_order_form($order_id) { $order = uc_order_load($order_id); if ($order === FALSE) { drupal_set_message('Order '. $order_id .' does not exist.'); drupal_goto('admin/store/orders'); } $total = $order->order_total; $payments = uc_payment_load_payments($order_id); $form['order_total'] = array('#value' => uc_currency_format($total)); $form['payments'] = array('#tree' => TRUE); if ($payments !== FALSE) { foreach ($payments as $payment) { $form['payments'][$payment->receipt_id]['received'] = array( '#value' => date('m/d/YH:i:s', $payment->received), ); $form['payments'][$payment->receipt_id]['user'] = array( '#value' => uc_get_initials($payment->uid), ); $form['payments'][$payment->receipt_id]['method'] = array( '#value' => ($payment->method == '') ? t('Unknown') : $payment->method, ); $form['payments'][$payment->receipt_id]['amount'] = array( '#value' => uc_currency_format($payment->amount), ); $total -= $payment->amount; $form['payments'][$payment->receipt_id]['balance'] = array( '#value' => uc_currency_format($total), ); $form['payments'][$payment->receipt_id]['comment'] = array( '#value' => ($payment->comment == '') ? '-' : $payment->comment, ); if (variable_get('uc_payment_deleting', TRUE) && user_access('delete payments')) { $action_value = l(t('Delete'), 'admin/store/orders/'. $order_id .'/payments/' . $payment->receipt_id .'/delete'); } else { $action_value = '-'; } $form['payments'][$payment->receipt_id]['action'] = array( '#value' => $action_value, ); } } $form['balance'] = array('#value' => uc_currency_format($total)); $form['order_id'] = array( '#type' => 'hidden', '#value' => $order_id, ); if (user_access('manual payments')) { $form['payments']['new']['received'] = array( '#value' => '-', ); $form['payments']['new']['user'] = array( '#value' => '-', ); $methods = _payment_method_list(); foreach ($methods as $method) { $options[$method['id']] = $method['name']; } $form['payments']['new']['method'] = array( '#type' => 'select', '#options' => $options, ); $form['payments']['new']['amount'] = array( '#type' => 'textfield', '#size' => 6, ); $form['payments']['new']['balance'] = array( '#value' => '-', ); $form['payments']['new']['comment'] = array( '#type' => 'textfield', '#size' => 32, '#maxlength' => 256, ); $form['payments']['new']['action'] = array( '#type' => 'submit', '#value' => t('Enter'), ); } return $form; } function uc_payment_by_order_form_validate($form_id, $form_values) { if (!is_numeric($form_values['payments']['new']['amount'])) { form_set_error('payments][new][amount', t('You must enter a number for the amount.')); } return TRUE; } function uc_payment_by_order_form_submit($form_id, $form_values) { global $user; $payment = $form_values['payments']['new']; uc_payment_enter($form_values['order_id'], $payment['method'], $payment['amount'], $user->uid, '', $payment['comment']); drupal_set_message(t('Payment entered.')); } function theme_uc_payment_by_order_form($form) { $output = '

'. t('Order total:') .' '. drupal_render($form['order_total']) .'
'. t('Current Balance:') .' ' . drupal_render($form['balance']) .'

'; $output .= '

'. tapir_get_table('uc_payments_table', $form) .'

' . '

'. drupal_render($form['form_id']) . drupal_render($form['form_token']) .'

'; return $output; } function uc_payments_table($op, $form) { switch ($op) { case 'fields': $fields[] = array('name' => 'received', 'title' => t('Received'), 'weight' => 0, 'enabled' => TRUE); $fields[] = array('name' => 'user', 'title' => t('User'), 'weight' => 1, 'enabled' => TRUE); $fields[] = array('name' => 'method', 'title' => t('Method'), 'weight' => 2, 'enabled' => TRUE); $fields[] = array('name' => 'amount', 'title' => t('Amount'), 'weight' => 3, 'enabled' => TRUE); $fields[] = array('name' => 'balance', 'title' => t('Balance'), 'weight' => 4, 'enabled' => TRUE); $fields[] = array('name' => 'comment', 'title' => t('Comment'), 'weight' => 5, 'enabled' => TRUE); $fields[] = array('name' => 'action', 'title' => t('Action'), 'weight' => 6, 'enabled' => TRUE); return $fields; case 'data': foreach (element_children($form['payments']) as $i) { $data['received'][] = drupal_render($form['payments'][$i]['received']); $data['user'][] = drupal_render($form['payments'][$i]['user']); $data['method'][] = drupal_render($form['payments'][$i]['method']); $data['amount'][] = drupal_render($form['payments'][$i]['amount']); $data['balance'][] = drupal_render($form['payments'][$i]['balance']); $data['comment'][] = drupal_render($form['payments'][$i]['comment']); $data['action'][] = drupal_render($form['payments'][$i]['action']); } return $data; } } /** * Delete a payment from an order. */ function uc_payment_delete_confirm($order_id, $receipt_id) { $payment = uc_payment_load($receipt_id); if ($payment->order_id != $order_id) { drupal_set_message(t('An error loading the payment information occurred.')); drupal_goto('admin/store/orders/'. $order_id .'/payments'); } $output = '

'. t('Payment information:') .'
' . t('!method payment of !amount received on !date.', array('!method' => $payment->method, '!amount' => uc_currency_format($payment->amount), '!date' => date('m/d/Y', $payment->received))) .'

'; $output .= t('Are you sure you want to delete this payment?') .'

' . drupal_get_form('uc_payment_delete_confirm_form', $order_id, $receipt_id); return $output; } function uc_payment_delete_confirm_form($order_id, $receipt_id) { $form['order_id'] = array( '#type' => 'hidden', '#value' => $order_id ); $form['receipt_id'] = array( '#type' => 'hidden', '#value' => $receipt_id, ); $form['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), ); return $form; } function uc_payment_delete_confirm_form_submit($form_id, $form_values) { if ($form_values['op'] == t('Delete')) { uc_payment_delete($form_values['receipt_id']); drupal_set_message(t('Payment deleted.')); } drupal_goto('admin/store/orders/'. $form_values['order_id'] .'/payments'); } /** * Select a payment gateway to process a payment when multiple gateways * exist for a given payment method. */ function uc_payment_gateway_select($url_order_id) { $gateways = _payment_gateway_list($_SESSION['uc_payment_method'], TRUE); foreach($gateways as $gateway) { $options[$gateway['id']] = $gateway['title']; } $output = t('Please choose a payment gateway to use for that payment.'); $output .= drupal_get_form('uc_payment_gateway_select_form', $options, $_SESSION['uc_payment_method'], $_SESSION['uc_payment_order_id'], $_SESSION['uc_payment_amount'], $_SESSION['uc_payment_data']); return $output; } function uc_payment_gateway_select_form($options, $method, $order_id, $amount, $data) { $form['method'] = array( '#type' => 'hidden', '#value' => $method, ); $form['order_id'] = array( '#type' => 'hidden', '#value' => $order_id, ); $form['amount'] = array( '#type' => 'hidden', '#value' => $amount, ); $form['p_data'] = array( '#type' => 'hidden', '#value' => $data, ); $form['p_selected'] = array( '#type' => 'select', '#title' => t('Use Gateway'), '#options' => $options, '#default_value' => variable_get('uc_payment_'. $method .'_gateway', ''), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Process'), ); return $form; } function uc_payment_gateway_select_form_submit($form_id, $form_values) { unset($_SESSION['uc_payment_method']); unset($_SESSION['uc_payment_order_id']); unset($_SESSION['uc_payment_amount']); unset($_SESSION['uc_payment_data']); uc_payment_process($form_values['method'], $form_values['order_id'], $form_values['amount'], unserialize($form_values['p_data']), FALSE, $form_values['p_selected']); drupal_goto('admin/store/orders/'. $form_values['order_id']); } /******************************************************************************* * Module and Helper Functions ******************************************************************************/ /** * Process a payment through an enabled payment gateway. */ function uc_payment_process($method, $order_id, $amount, $data = NULL, $default = FALSE, $selected = NULL, $redirect = TRUE) { $gateways = _payment_gateway_list($method, TRUE); if (!is_array($gateways) || count($gateways) == 0) { if (!$default) { drupal_set_message(t('You are not able to process payments of type !type. ', array('!type' => ''. _payment_method_data($method, 'name') .''))); } return FALSE; } if (count($gateways) == 1) { if (function_exists($gateways[0][$method])) { $result = $gateways[0][$method]($order_id, $amount, $data); } else { if (user_access('administer store')) { drupal_set_message(t("Attempted to process payment but the gateway's function was not found.")); } } } else { $func = FALSE; foreach($gateways as $gateway) { if ($default && $gateway['id'] == variable_get('uc_payment_'. $method .'_gateway', '')) { $func = $gateway[$method]; } if (!is_null($selected) && $gateway['id'] == $selected) { $func = $gateway[$method]; } } if ($func !== FALSE) { if (function_exists($func)) { $result = $func($order_id, $amount, $data); } else { drupal_set_message(t('An error has occurred with your payment gateway. The charge function could not be found.')); $result['success'] = FALSE; } } else { $_SESSION['uc_payment_method'] = $method; $_SESSION['uc_payment_order_id'] = $order_id; $_SESSION['uc_payment_amount'] = $amount; $_SESSION['uc_payment_data'] = serialize($data); drupal_goto('admin/store/orders/'. $order_id .'/payments/select/'. $method); } } if ($result['success'] === TRUE) { if (!empty($result['uid'])) { $result['uid'] = 0; } uc_payment_enter($order_id, $method, $amount, $result['uid'], $result['data'], $result['comment']); } if (!empty($result['message']) && !$default) { drupal_set_message($result['message']); } if ($redirect) { drupal_goto('admin/store/orders/'. $order_id); } return $result['success']; } /** * Enter a payment for an order. */ function uc_payment_enter($order_id, $method, $amount, $uid, $data, $comment) { $method_name = _payment_method_data($method, 'name'); if (is_null($method_name)) { $method_name = t('Other'); } if (is_array($data)) { $data = serialize($data); } if (variable_get('uc_payment_logging', TRUE)) { global $user; $log_message = t('!method payment for !amount entered by !user.', array('!method' => $method_name, '!amount' => uc_currency_format($amount), '!user' => uc_get_initials($user->uid))); uc_order_log_changes($order_id, array($log_message)); } db_query("INSERT INTO {uc_payment_receipts} (receipt_id, order_id, method, " ."amount, uid, data, comment, received) VALUES (%d, %d, '%s', %f, " ."%d, '%s', '%s', %d)", db_next_id('{uc_payment_receipts}_receipt_id'), $order_id, $method_name, $amount, $uid, $data, $comment, time()); } /** * Delete a payment from the database. */ function uc_payment_delete($receipt_id) { if (!is_numeric($receipt_id)) { return FALSE; } if (variable_get('uc_payment_logging', TRUE)) { global $user; $payment = uc_payment_load($receipt_id); $log_message = t('!method payment for !amount deleted by !user.', array('!method' => $payment->method, '!amount' => uc_currency_format($payment->amount), '!user' => uc_get_initials($user->uid))); uc_order_log_changes($payment->order_id, array($log_message)); } db_query("DELETE FROM {uc_payment_receipts} WHERE receipt_id = %d", $receipt_id); } /** * Return the balance of payments on an order. */ function uc_payment_balance($order) { $total = $order->order_total; $payments = uc_payment_load_payments($order->order_id); if ($payments === FALSE) { return $total; } foreach ($payments as $payment) { $total -= $payment->amount; } return $total; } /** * Load a single payment from the database by receipt_id. */ function uc_payment_load($receipt_id) { if (!is_numeric($receipt_id)) { return FALSE; } $result = db_query("SELECT * FROM {uc_payment_receipts} WHERE receipt_id = %d ", $receipt_id); $payment = db_fetch_object($result); return $payment; } /** * Load an array of all the payments for order $order_id. */ function uc_payment_load_payments($order_id, $action = NULL) { $payments = array(); $result = db_query("SELECT * FROM {uc_payment_receipts} WHERE order_id = %d " ."ORDER BY received ASC", $order_id); while ($payment = db_fetch_object($result)) { $payments[] = $payment; } if (count($payments) == 0) { $payments = FALSE; } return $payments; } /** * Sort the payment methods by weight using this function with usort(). */ function _payment_method_sort($a, $b) { if ($a['weight'] == $b['weight']) { return 0; } return ($a['weight'] > $b['weight']) ? 1 : -1; } /** * Build a list of payment methods defined in the enabled modules. */ function _payment_method_list($action = NULL) { static $methods; if (count($methods) > 0 && $action !== 'rebuild') { return $methods; } $methods = module_invoke_all('payment_method'); for ($i = 0; $i < count($methods); $i++) { $methods[$i]['checkout'] = variable_get('uc_payment_method_'. $methods[$i]['id'] .'_checkout', $methods[$i]['checkout']); $methods[$i]['backend'] = variable_get('uc_payment_method_'. $methods[$i]['id'] .'_backend', $methods[$i]['backend']); $methods[$i]['weight'] = variable_get('uc_payment_method_'. $methods[$i]['id'] .'_weight', $methods[$i]['weight']); } usort($methods, 'uc_weight_sort'); return $methods; } /** * Return data from a payment method by method ID and the array key. */ function _payment_method_data($method_id, $key) { $methods = _payment_method_list(); foreach ($methods as $method) { if ($method['id'] == $method_id) { return $method[$key]; } } } /** * Build a list of payment gateways defined in the enabled modules. */ function _payment_gateway_list($filter = NULL, $enabled_only = FALSE) { $gateways = module_invoke_all('payment_gateway'); for ($i = 0, $j = count($gateways); $i < $j; $i++) { $gateways[$i]['enabled'] = variable_get('uc_pg_'. $gateways[$i]['id'] .'_enabled', TRUE); if ($filter != NULL) { if (!isset($gateways[$i][$filter]) || !function_exists($gateways[$i][$filter])) { unset($gateways[$i]); } } if ($enabled_only) { if (!variable_get('uc_pg_'. $gateways[$i]['id'] .'_enabled', TRUE)) { unset($gateways[$i]); } } } return $gateways; } /** * Return data from a payment gateway by gateway ID and the array key. */ function _payment_gateway_data($method_id, $key) { $gateways = _payment_gateway_list(); foreach ($gateways as $gateway) { if ($gateway['id'] == $gateway_id) { return $gateway[$key]; } } } /** * Retrieve a pipe delimited string of autocomplete suggestions for payment methods */ function _uc_payment_methods_autocomplete($string = '') { $matches = array(); $methods = _payment_method_list(); foreach($methods as $method) { if ($method['backend'] == TRUE) { $matches[$method['name']] = check_plain($method['name']); } } print drupal_to_js($matches); exit(); }