/** * Show my invoices. * * @return tempcode The interface. */ function my() { $title = get_page_title('MY_INVOICES'); $member_id = get_member(); if (has_specific_permission(get_member(), 'assume_any_member')) { $member_id = get_param_integer('id', $member_id); } $invoices = array(); $rows = $GLOBALS['SITE_DB']->query_select('invoices', array('*'), array('i_member_id' => $member_id)); foreach ($rows as $row) { $product = $row['i_type_code']; $object = find_product($product); if (is_null($object)) { continue; } $products = $object->get_products(false, $product); $invoice_title = $products[$product][4]; $time = get_timezoned_date($row['i_time'], true, false, false, true); $payable = $row['i_state'] == 'new'; $deliverable = $row['i_state'] == 'paid'; $state = do_lang('PAYMENT_STATE_' . $row['i_state']); if (perform_local_payment()) { $transaction_button = hyperlink(build_url(array('page' => '_SELF', 'type' => 'pay', 'id' => $row['id']), '_SELF'), do_lang_tempcode('MAKE_PAYMENT')); } else { $transaction_button = make_transaction_button(substr(get_class($object), 5), $invoice_title, strval($row['id']), floatval($row['i_amount']), get_option('currency')); } $invoices[] = array('TRANSACTION_BUTTON' => $transaction_button, 'INVOICE_TITLE' => $invoice_title, 'ID' => strval($row['id']), 'AMOUNT' => $row['i_amount'], 'TIME' => $time, 'STATE' => $state, 'DELIVERABLE' => $deliverable, 'PAYABLE' => $payable, 'NOTE' => $row['i_note'], 'TYPE_CODE' => $row['i_type_code']); } if (count($invoices) == 0) { inform_exit(do_lang_tempcode('NO_ENTRIES')); } return do_template('ECOM_INVOICES_SCREEN', array('_GUID' => '144a893d93090c105eecc48fa58921a7', 'TITLE' => $title, 'CURRENCY' => get_option('currency'), 'INVOICES' => $invoices)); }
/** * Finish step. * * @return tempcode The result of execution. */ function finish() { $title = get_page_title('_PURCHASE_FINISHED'); breadcrumb_set_parents(array(array('_SELF:catalogues:misc:ecommerce=1', do_lang_tempcode('CATALOGUES')), array('_SELF:_SELF:misc', do_lang_tempcode('SHOPPING')))); $message = get_param('message', NULL, true); // TODO: Assumption, needs to really go through the payment gateway API if (get_param_integer('cancel', 0) == 0) { //Empty cart. $where = array(); if (is_guest()) { $where['session_id'] = get_session_id(); } else { $where['ordered_by'] = get_member(); } $GLOBALS['SITE_DB']->query_delete('shopping_cart', $where); log_cart_actions('Completed payment'); if (perform_local_payment()) { $trans_id = post_param('trans_id'); $transaction_rows = $GLOBALS['SITE_DB']->query_select('trans_expecting', array('*'), array('id' => $trans_id), '', 1); if (!array_key_exists(0, $transaction_rows)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $transaction_row = $transaction_rows[0]; $amount = $transaction_row['e_amount']; $length = $transaction_row['e_length']; $length_units = $transaction_row['e_length_units']; $via = get_option('payment_gateway'); require_code('hooks/systems/ecommerce_via/' . filter_naughty_harsh($via)); $object = object_factory('Hook_' . $via); $name = post_param('name'); $card_number = post_param('card_number'); $expiry_date = str_replace('/', '', post_param('expiry_date')); $issue_number = post_param_integer('issue_number', NULL); $start_date = str_replace('/', '', post_param('start_date')); $card_type = post_param('card_type'); $cv2 = post_param('cv2'); list($success, , $message, $message_raw) = $object->do_transaction($trans_id, $name, $card_number, $amount, $expiry_date, $issue_number, $start_date, $card_type, $cv2, $length, $length_units); if ($success || !is_null($length)) { $status = !is_null($length) && !$success ? 'SCancelled' : 'Completed'; handle_confirmed_transaction($transaction_row['e_purchase_id'], $transaction_row['e_item_name'], $status, $message_raw, '', '', $amount, get_option('currency'), $trans_id, '', $via, is_null($length) ? '' : strtolower(strval($length) . ' ' . $length_units)); } if ($success) { $member_id = $transaction_row['e_member_id']; require_code('notifications'); dispatch_notification('payment_received', NULL, do_lang('PAYMENT_RECEIVED_SUBJECT', $trans_id), do_lang('PAYMENT_RECEIVED_BODY', float_format(floatval($amount)), get_option('currency'), get_site_name()), array($member_id), A_FROM_SYSTEM_PRIVILEGED); } } attach_message(do_lang_tempcode('SUCCESS'), 'inform'); if (count($_POST) != 0) { $order_id = handle_transaction_script(); $object = find_product(do_lang('CART-ORDER', $order_id)); if (method_exists($object, 'get_finish_url')) { return redirect_screen($title, $object->get_finish_url(), $message); } } return $this->wrap(do_template('PURCHASE_WIZARD_STAGE_FINISH', array('TITLE' => $title, 'MESSAGE' => $message)), $title, NULL); } if (!is_null($message)) { return $this->wrap(do_template('PURCHASE_WIZARD_STAGE_FINISH', array('TITLE' => $title, 'MESSAGE' => $message)), $title, NULL); } warn_exit(do_lang_tempcode('PRODUCT_PURCHASE_CANCEL')); return new ocp_tempcode(); // Will never get here }
/** * Payment step. * * @return tempcode The result of execution. */ function payment_form() { require_code('ecommerce'); $title = get_page_title('PAYMENT_HEADING'); $cart_items = find_products_in_cart(); $purchase_id = NULL; $tax_opt_out = get_order_tax_opt_out_status(); if (count($cart_items) > 0) { $insert = array('c_member' => get_member(), 'session_id' => get_session_id(), 'add_date' => time(), 'tot_price' => 0, 'order_status' => 'ORDER_STATUS_awaiting_payment', 'notes' => '', 'purchase_through' => 'cart', 'transaction_id' => '', 'tax_opted_out' => $tax_opt_out); if (is_null($GLOBALS['SITE_DB']->query_value_null_ok('shopping_order', 'id'))) { $insert['id'] = hexdec('1701D'); // Start offset } $order_id = $GLOBALS['SITE_DB']->query_insert('shopping_order', $insert, true); } else { $order_id = NULL; } $total_price = 0; foreach ($cart_items as $item) { $product = $item['product_id']; $hook = $item['product_type']; require_code('hooks/systems/ecommerce/' . filter_naughty_harsh($hook), true); $object = object_factory('Hook_' . filter_naughty_harsh($hook), true); if (is_null($object)) { continue; } $temp = $object->get_products(false, $product); if ($temp[$product][0] == PRODUCT_SUBSCRIPTION) { continue; } //Subscription type skipped. $price = $temp[$product][1]; $item_name = $temp[$product][4]; if (method_exists($object, 'set_needed_fields')) { $purchase_id = $object->set_needed_fields($product); } else { $purchase_id = strval(get_member()); } $length = NULL; $length_units = ''; if (method_exists($object, 'calculate_product_price')) { $price = $object->calculate_product_price($item['price'], $item['price_pre_tax'], $item['product_weight']); } else { $price = $item['price']; } if (method_exists($object, 'calculate_tax') && $tax_opt_out == 0) { $tax = round($object->calculate_tax($item['price'], $item['price_pre_tax']), 2); } else { $tax = 0.0; } $GLOBALS['SITE_DB']->query_insert('shopping_order_details', array('p_id' => $item['product_id'], 'p_name' => $item['product_name'], 'p_code' => $item['product_code'], 'p_type' => $item['product_type'], 'p_quantity' => $item['quantity'], 'p_price' => $price, 'included_tax' => $tax, 'order_id' => $order_id, 'dispatch_status' => ''), true); $total_price += $price * $item['quantity']; } $GLOBALS['SITE_DB']->query_update('shopping_order', array('tot_price' => $total_price), array('id' => $order_id), '', 1); if (!perform_local_payment()) { $result = make_cart_payment_button($order_id, get_option('currency')); } else { if (!tacit_https() && !ecommerce_test_mode()) { warn_exit(do_lang_tempcode('NO_SSL_SETUP')); } if (is_null($order_id)) { $fields = new ocp_tempcode(); $hidden = new ocp_tempcode(); } else { list($fields, $hidden) = get_transaction_form_fields(NULL, strval($order_id), $item_name, float_to_raw_string($price), NULL, ''); } /*$via =get_option('payment_gateway'); require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via)); $object=object_factory('Hook_'.$via); $ipn_url=$object->get_ipn_url();*/ $finish_url = build_url(array('page' => 'purchase', 'type' => 'finish'), get_module_zone('purchase')); $result = do_template('PURCHASE_WIZARD_STAGE_TRANSACT', array('FIELDS' => $fields, 'HIDDEN' => $hidden)); require_javascript('javascript_validation'); return do_template('PURCHASE_WIZARD_SCREEN', array('TITLE' => $title, 'CONTENT' => $result, 'URL' => $finish_url)); } return $result; }
/** * Finish step. * * @param tempcode The page title. * @return tempcode The result of execution. */ function finish($title) { breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('PURCHASING')))); $message = get_param('message', NULL, true); if (get_param_integer('cancel', 0) == 0) { if (perform_local_payment()) { $trans_id = post_param('trans_id'); $transaction_rows = $GLOBALS['SITE_DB']->query_select('trans_expecting', array('*'), array('id' => $trans_id), '', 1); if (!array_key_exists(0, $transaction_rows)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $transaction_row = $transaction_rows[0]; $amount = $transaction_row['e_amount']; $length = $transaction_row['e_length']; $length_units = $transaction_row['e_length_units']; $via = get_option('payment_gateway'); require_code('hooks/systems/ecommerce_via/' . filter_naughty_harsh($via)); $object = object_factory('Hook_' . $via); $name = post_param('name'); $card_number = post_param('card_number'); $expiry_date = str_replace('/', '', post_param('expiry_date')); $issue_number = post_param_integer('issue_number', NULL); $start_date = str_replace('/', '', post_param('start_date')); $card_type = post_param('card_type'); $cv2 = post_param('cv2'); list($success, , $message, $message_raw) = $object->do_transaction($trans_id, $name, $card_number, $amount, $expiry_date, $issue_number, $start_date, $card_type, $cv2, $length, $length_units); if ($success || !is_null($length)) { $status = !is_null($length) && !$success ? 'SCancelled' : 'Completed'; handle_confirmed_transaction($transaction_row['e_purchase_id'], $transaction_row['e_item_name'], $status, $message_raw, '', '', $amount, get_option('currency'), $trans_id, '', $via, is_null($length) ? '' : strtolower(strval($length) . ' ' . $length_units)); } if ($success) { $member_id = $transaction_row['e_member_id']; require_code('notifications'); dispatch_notification('payment_received', NULL, do_lang('PAYMENT_RECEIVED_SUBJECT', $trans_id), do_lang('PAYMENT_RECEIVED_BODY', float_format(floatval($amount)), get_option('currency'), get_site_name()), array($member_id), A_FROM_SYSTEM_PRIVILEGED); } } $product = get_param('product', ''); if ($product != '') { if (count($_POST) != 0) { handle_transaction_script(); } attach_message(do_lang_tempcode('SUCCESS'), 'inform'); $object = find_product($product); if (method_exists($object, 'get_finish_url')) { return redirect_screen($title, $object->get_finish_url($product), $message); } } return $this->wrap(do_template('PURCHASE_WIZARD_STAGE_FINISH', array('_GUID' => '43f706793719ea893c280604efffacfe', 'TITLE' => $title, 'MESSAGE' => $message)), $title, NULL); } if (!is_null($message)) { return $this->wrap(do_template('PURCHASE_WIZARD_STAGE_FINISH', array('_GUID' => '859c31e8f0f02a2a46951be698dd22cf', 'TITLE' => $title, 'MESSAGE' => $message)), $title, NULL); } inform_exit(do_lang_tempcode('PRODUCT_PURCHASE_CANCEL')); return new ocp_tempcode(); // Will never get here }