'directdebit', 'name' => t('Direct Debit'), 'title' => t('Direct Debit'), 'desc' => t('Allow us to withdraw money from your bankaccount.'), 'callback' => 'uc_directdebit_payment_method_callback', 'weight' => 3, 'checkout' => TRUE, 'backend' => TRUE, ); return $methods; } /** * Implementation of hook_order() * * The return values depend on the given operator * * @see http://www.ubercart.org/docs/api * * @param $op operator to use on the given order object/array * @param $arg1 object/array object or array representing the cart/order * @param $arg2 new order status ID when applicable * * @return depend on $op $a */ function uc_directdebit_order($op, &$arg1, $arg2) { $order_id = is_object($arg1) ?$arg1->order_id : $arg1['order_id']; watchdog( "uc_dd_order", "$op ($order_id) $arg2" . gettype($arg1)); switch ($op) { case 'can_delete': // Yes it can be deleted all the time return TRUE; case 'delete': db_query("DELETE FROM {uc_directdebit} WHERE order_id = %d", $arg1->order_id); break; case 'load': if ($arg1->payment_method == 'directdebit') { $result = db_query("SELECT data FROM {uc_directdebit} WHERE order_id = %d", $arg1->order_id); if ($row = db_fetch_array($result)) { $data= unserialize( $row['data']); $value= implode("; ", $data); watchdog( "uc_dd_order", "$op: '$value'"); } else { watchdog( "uc_dd_callback", "$op no data found " . $arg1->order_id); $data= array(); } $arg1->payment_details = $data; } break; case 'new': // Nothing to do. break; case 'save': if ($arg1->payment_method == 'directdebit') { db_query( "DELETE FROM {uc_directdebit} WHERE order_id= %d", $arg1->order_id); $payment_details= $arg1->payment_details; watchdog( "uc_dd_order", "$op " . implode("; ", $payment_details)); $data = serialize($payment_details); db_query( "INSERT INTO {uc_directdebit} (order_id, data) VALUE (%d, '%s')", $arg1->order_id, $data); } break; case 'total': // there are no order total modifications // TODO: return 0 ? break; default: // oeps //TODO: can_update, new, update, submit watchdog( "uc_dd_order", "$op ($order_id) missed"); } } /** * Handle the bank deposit payment method. * * There are a few operator types available: * - cart : customer is using the cart * - order : customer is using the cart or shop admin is acting on the order * - settings : shop admin is making settings changes * * @param $op operator do act upon * @param $arg1 the order object to use or manipulate */ function uc_directdebit_payment_method_callback($op, &$arg1) { $order_id = is_object($arg1) ?$arg1->order_id : $arg1['order_id']; //watchdog( "uc_dd_callback", "$op ($order_id) " . gettype($arg1)); switch ($op) { case 'cart-details': case 'order-details': // this is an ajax callback return uc_strip_form(drupal_get_form('directdebit_form', $arg1)); case 'cart-review': return _uc_directdebit_cart_review( $arg1->payment_details); case 'cart-process': // let drupal just validate (there's no submit) the form $form_errors = drupal_execute('directdebit_form', $_POST); $payment_details= directdebit_process_post(); $arg1->payment_details = $payment_details; return count($form_errors); case 'edit-process': // let drupal just validate (there's no submit) the form $form_errors = drupal_execute('directdebit_form', $_POST); $payment_details= directdebit_process_post(); $changes= array(); $changes['payment_details'] = $payment_details; return $changes; /* case 'order-load': // Nothing to do break; case 'order-save': // Nothing to do break; */ case 'order-view': $data = $arg1->payment_details; return theme('uc_directdebit_order_view', $data); break; case 'settings': $options= directdebit_api_extract( '#description'); foreach ($options as $key => $details) { $options[$key] = "$key [$details]"; } $form['directdebit_field_list'] = array( '#type' => 'checkboxes', '#title' => t('What fields do you want to use'), '#description' => t('These fields will be presented in the checkout form'), '#default_value' => variable_get('directdebit_field_list', array( 'directdebit_bank_name')), '#rows' => 4, '#options' => $options, ); return $form; default: // Oeps watchdog( "uc_dd_callback", "$op missed"); } } /** * Renders the payment data while reviewing the cart * * @param $payment_data */ function _uc_directdebit_cart_review($payment_data) { $result = array(); $field_names = directdebit_api_extract('#title'); $fields_to_use = variable_get('directdebit_field_list', array( 'directdebit_bank_withdraw_permission')); foreach ($fields_to_use as $key => $value) { if ( $value) { $data = $payment_data[$key]; $result[] = array( 'title' => $field_names[$key], 'data' => $data); } } return $result; } function theme_uc_directdebit_order_view( $payment_data) { $result = ""; $field_names = directdebit_api_extract('#title'); $fields_to_use = variable_get('directdebit_field_list', array( 'directdebit_bank_name')); foreach ($fields_to_use as $key => $value) { if ( $value) { $result .= '
'. $field_names[$key] .':'. $payment_data[$key] .''; } } return $result; }