/** * 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 }
/** * 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 }
/** * The actualiser for a manually triggered transaction. * * @return tempcode The result of execution. */ function _trigger() { $title = get_page_title('MANUAL_TRANSACTION'); $item_name = post_param('item_name'); breadcrumb_set_parents(array(array('_SELF:_SELF:ecom_usage', do_lang_tempcode('ECOMMERCE')), array('_SELF:_SELF:trigger', do_lang_tempcode('PRODUCT')), array('_SELF:_SELF:trigger:item_name=' . $item_name, do_lang_tempcode('MANUAL_TRANSACTION')))); $purchase_id = post_param('purchase_id', ''); $memo = post_param('memo'); $mc_gross = post_param('amount', ''); $object = find_product($item_name); $products = $object->get_products(true); if ($mc_gross == '') { $mc_gross = $products[$item_name][1]; } $payment_status = 'Completed'; $reason_code = ''; $pending_reason = ''; $mc_currency = get_option('currency'); $txn_id = 'manual-' . substr(uniqid('', true), 0, 10); $parent_txn_id = ''; /*if ($products[$item_name][0]==PRODUCT_SUBSCRIPTION) { $payment_status='SCancelled'; }*/ $_item_name = $products[$item_name][4]; if ($products[$item_name][0] == PRODUCT_SUBSCRIPTION) { if ($purchase_id == '') { $purchase_id = strval($GLOBALS['SITE_DB']->query_insert('subscriptions', array('s_type_code' => $item_name, 's_member_id' => get_member(), 's_state' => 'new', 's_amount' => $products[$item_name][1], 's_special' => $purchase_id, 's_time' => time(), 's_auto_fund_source' => '', 's_auto_fund_key' => '', 's_via' => 'manual'), true)); } $_item_name = ''; // Flag for handle_confirmed_transaction to know it's a subscription } handle_confirmed_transaction($purchase_id, $_item_name, $payment_status, $reason_code, $pending_reason, $memo, $mc_gross, $mc_currency, $txn_id, $parent_txn_id); $url = get_param('redirect', NULL); if (!is_null($url)) { return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); } return inform_screen($title, do_lang_tempcode('SUCCESS')); }
function testHandleTransaction() { $purchase_id = $GLOBALS['SITE_DB']->query_value('shopping_order', 'max(id)', array()); $item_name = 'Test field value'; $payment_status = 'Completed'; $reason_code = ''; $pending_reason = 'bar'; $memo = 'foo'; $mc_gross = 68.34999999999999; $mc_currency = get_option('currency'); $txn_id = '0'; $parent_txn_id = '0'; $via = 'paypal'; handle_confirmed_transaction($purchase_id, $item_name, $payment_status, $reason_code, $pending_reason, $memo, $mc_gross, $mc_currency, $txn_id, $parent_txn_id, $via, post_param('period3', '')); }
/** * Handle IPN's. * * @return ID_TEXT The ID of the purchase-type (meaning depends on item_name) */ function handle_transaction_script() { $via = get_param('from', get_option('payment_gateway')); require_code('hooks/systems/ecommerce_via/' . filter_naughty_harsh($via)); $object = object_factory('Hook_' . $via); ob_start(); $test = false; if (!$test) { list($purchase_id, $item_name, $payment_status, $reason_code, $pending_reason, $memo, $mc_gross, $mc_currency, $txn_id, $parent_txn_id) = $object->handle_transaction(); } else { $purchase_id = '15'; $item_name = do_lang('CUSTOM_PRODUCT_OTHER'); $payment_status = 'Completed'; $reason_code = ''; $pending_reason = 'bar'; $memo = 'foo'; $mc_gross = '0.01'; $mc_currency = get_option('currency'); $txn_id = '0'; $parent_txn_id = '0'; } handle_confirmed_transaction($purchase_id, $item_name, $payment_status, $reason_code, $pending_reason, $memo, $mc_gross, $mc_currency, $txn_id, $parent_txn_id, $via, post_param('period3', '')); return $purchase_id; //my_exit(do_lang('SUCCESS')); }