예제 #1
0
/**
 * 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;
}
예제 #2
0
 /**
  * Show my invoices.
  *
  * @return tempcode	The interface.
  */
 function pay()
 {
     $id = get_param_integer('id');
     if (!tacit_https() && !ecommerce_test_mode()) {
         warn_exit(do_lang_tempcode('NO_SSL_SETUP'));
     }
     $title = get_page_title('MAKE_PAYMENT');
     $post_url = build_url(array('page' => 'purchase', 'type' => 'finish'), get_module_zone('purchase'));
     $rows = $GLOBALS['SITE_DB']->query_select('invoices', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $row = $rows[0];
     $product = $row['i_type_code'];
     $object = find_product($product);
     $products = $object->get_products(false, $product);
     $invoice_title = $products[$product][4];
     list($fields, $hidden) = get_transaction_form_fields(NULL, strval($id), $invoice_title, float_to_raw_string($row['i_amount']), NULL, '');
     $text = do_lang_tempcode('TRANSACT_INFO');
     return do_template('FORM_SCREEN', array('_GUID' => 'e90a4019b37c8bf5bcb64086416bcfb3', 'TITLE' => $title, 'SKIP_VALIDATION' => '1', 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => $text, 'HIDDEN' => $hidden, 'SUBMIT_NAME' => do_lang_tempcode('MAKE_PAYMENT')));
 }
예제 #3
0
 /**
  * Payment step.
  *
  * @param  tempcode	The page title.
  * @return tempcode	The result of execution.
  */
 function pay($title)
 {
     $product = get_param('product');
     $object = find_product($product);
     if (method_exists($object, 'is_available') && !$object->is_available($product, get_member())) {
         warn_exit(do_lang_tempcode('PRODUCT_UNAVAILABLE'));
     }
     $temp = $object->get_products(true, $product);
     $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());
     }
     if ($temp[$product][0] == PRODUCT_SUBSCRIPTION) {
         $_purchase_id = $GLOBALS['SITE_DB']->query_value_null_ok('subscriptions', 'id', array('s_type_code' => $product, 's_member_id' => get_member(), 's_state' => 'new'));
         if (is_null($_purchase_id)) {
             $purchase_id = strval($GLOBALS['SITE_DB']->query_insert('subscriptions', array('s_type_code' => $product, 's_member_id' => get_member(), 's_state' => 'new', 's_amount' => $temp[$product][1], 's_special' => $purchase_id, 's_time' => time(), 's_auto_fund_source' => '', 's_auto_fund_key' => '', 's_via' => get_option('payment_gateway')), true));
         } else {
             $purchase_id = strval($_purchase_id);
         }
         $length = array_key_exists('length', $temp[$product][3]) ? $temp[$product][3]['length'] : 1;
         $length_units = array_key_exists('length_units', $temp[$product][3]) ? $temp[$product][3]['length_units'] : 'm';
     } else {
         $length = NULL;
         $length_units = '';
         //Add cataloue item order to shopping_orders
         if (method_exists($object, 'add_purchase_order')) {
             $purchase_id = strval($object->add_purchase_order($product, $temp[$product]));
         }
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('PURCHASING'))));
     if ($price == '0') {
         $payment_status = 'Completed';
         $reason_code = '';
         $pending_reason = '';
         $mc_currency = get_option('currency');
         $txn_id = 'manual-' . substr(uniqid('', true), 0, 10);
         $parent_txn_id = '';
         $memo = 'Free';
         $mc_gross = '';
         handle_confirmed_transaction($purchase_id, $item_name, $payment_status, $reason_code, $pending_reason, $memo, $mc_gross, $mc_currency, $txn_id, $parent_txn_id);
         return inform_screen($title, do_lang_tempcode('FREE_PURCHASE'));
     }
     if (!array_key_exists(4, $temp[$product])) {
         $item_name = do_lang('CUSTOM_PRODUCT_' . $product, NULL, NULL, NULL, get_site_default_lang());
     }
     if (!perform_local_payment()) {
         if ($temp[$product][0] == PRODUCT_SUBSCRIPTION) {
             $transaction_button = make_subscription_button($product, $item_name, $purchase_id, floatval($price), $length, $length_units, get_option('currency'));
         } else {
             $transaction_button = make_transaction_button($product, $item_name, $purchase_id, floatval($price), get_option('currency'));
         }
         $tpl = $temp[$product][0] == PRODUCT_SUBSCRIPTION ? 'PURCHASE_WIZARD_STAGE_SUBSCRIBE' : 'PURCHASE_WIZARD_STAGE_PAY';
         $logos = method_exists($object, 'get_logos') ? $object->get_logos() : new ocp_tempcode();
         $result = do_template($tpl, array('LOGOS' => $logos, 'TRANSACTION_BUTTON' => $transaction_button, 'CURRENCY' => get_option('currency'), 'ITEM_NAME' => $item_name, 'TITLE' => $title, 'LENGTH' => is_null($length) ? '' : strval($length), 'LENGTH_UNITS' => $length_units, 'PURCHASE_ID' => $purchase_id, 'PRICE' => float_to_raw_string(floatval($price))));
     } else {
         if (!tacit_https() && !ecommerce_test_mode()) {
             warn_exit(do_lang_tempcode('NO_SSL_SETUP'));
         }
         $fields = get_transaction_form_fields(NULL, $purchase_id, $item_name, float_to_raw_string($price), $temp[$product][0] == PRODUCT_SUBSCRIPTION ? intval($length) : NULL, $temp[$product][0] == PRODUCT_SUBSCRIPTION ? $length_units : '');
         /*$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' => '_SELF', 'type' => 'finish'), '_SELF');
         $result = do_template('PURCHASE_WIZARD_STAGE_TRANSACT', array('_GUID' => '15cbba9733f6ff8610968418d8ab527e', 'FIELDS' => $fields));
         return $this->wrap($result, $title, $finish_url);
     }
     return $this->wrap($result, $title, NULL);
 }