I'd like to share the following code
<?php
// Get ship_to information
if( $db->f("user_info_id") != $dbbt->f("user_info_id"))
{
$q2 = "SELECT * FROM #__vm_user_info WHERE user_info_id='".$db->f("user_info_id")."'";
$dbst = new ps_DB;
$dbst->setQuery($q2);
$dbst->query();
$dbst->next_record();
} else {
$dbst = $dbbt;
}
$q3 = "SELECT * FROM #__vm_order_item WHERE user_info_id='".$db->f("user_info_id")."'";
$dbcprod = new ps_DB;
$dbcprod->setQuery($q3);
$dbcprod->query();
$dbcprod->next_record();
//sort out user orders
for($i = 0; $i < count($dbcprod->record); $i++){ $orders[$i] = $dbcprod->record[$i]->order_id; }
arsort($orders);
$this_order_id = current($orders); //sets most recent order number for user
//gets all product info entries for this order number
for($i = 0; $i < count($dbcprod->record); $i++)
{
if($dbcprod->record[$i]->order_id == $this_order_id) { $this_order[$i] = $dbcprod->record[$i]; }
}
sort($this_order);
//2co c_prods to send
//creates 2co c_prod parameters
for($i = 0; $i < count($this_order); $i++)
{
$twoco_prod_info["c_prod_$i"] = $this_order[$i]->order_item_sku .",". $this_order[$i]->product_quantity;
$twoco_prod_info["c_name_$i"] = $this_order[$i]->order_item_name;
$twoco_prod_info["c_price_$i"] = $this_order[$i]->product_final_price;
$twoco_prod_info["c_description_$i"] = $this_order[$i]->order_item_name .",". $this_order[$i]->product_attribute;
}
//Authnet vars to send
$formdata = array (
'x_login' => TWOCO_LOGIN,
'x_email_merchant' => ((TWOCO_MERCHANT_EMAIL == 'True') ? 'TRUE' : 'FALSE'),
'id_type' => 1, //added for c_prod compliance
// Customer Name and Billing Address
'x_first_name' => $dbbt->f("first_name"),
'x_last_name' => $dbbt->f("last_name"),
'x_company' => $dbbt->f("company"),
'x_address' => $dbbt->f("address_1"),
'x_city' => $dbbt->f("city"),
'x_state' => $dbbt->f("state"),
'x_zip' => $dbbt->f("zip"),
'x_country' => $dbbt->f("country"),
'x_phone' => $dbbt->f("phone_1"),
'x_fax' => $dbbt->f("fax"),
'x_email' => $dbbt->f("email"),
// Customer Shipping Address
'x_ship_to_first_name' => $dbst->f("first_name"),
'x_ship_to_last_name' => $dbst->f("last_name"),
'x_ship_to_company' => $dbst->f("company"),
'x_ship_to_address' => $dbst->f("address_1"),
'x_ship_to_city' => $dbst->f("city"),
'x_ship_to_state' => $dbst->f("state"),
'x_ship_to_zip' => $dbst->f("zip"),
'x_ship_to_country' => $dbst->f("country"),
'x_invoice_num' => $db->f("order_id"),
'x_receipt_link_url' => SECUREURL."2checkout_notify.php"
);
$formdata = array_merge($twoco_prod_info, $formdata); //combine formdata with twoco_prod_info so c_prod info gets sent to 2co
if( TWOCO_TESTMODE == "Y" )
$formdata['demo'] = "Y";
$version = "2";
$url = "https://www2.2checkout.com/2co/buyer/purchase";
//Convert the currency
$my_2co_default_currency = 'USD';
$order_total = $db->f("order_total");
if ($db->f('order_currency') != $my_2co_default_currency )
{
$order_total = $GLOBALS['CURRENCY']->convert( $db->f("order_total") , $db->f('order_currency'), $my_2co_default_currency );
}
$formdata['x_amount'] = number_format($order_total, 2, '.', '');
if( $page == "checkout.thankyou" )
{
$query_string = "?";
foreach( $formdata as $name => $value )
{
$query_string .= $name. "=" . urlencode($value) ."&";
}
vmRedirect( $url . $query_string );
} else {
//build the post string
$poststring = '';
foreach($formdata AS $key => $val)
{
$poststring .= "<input type='hidden' name='$key' value='$val' />
";
}
//old buy logo: https://www.2checkout.com/images/buy_logo.gif
?>
<form id="cho" action="<?php echo $url ?>" method="post" target="_blank">
<?php echo $poststring; ?>
<p><font size=+1>Click on the Image below to pay...</font></p>
<input type="image" name="submit" src="https://www2.2checkout.com/static/checkout/CheckoutButton2COCards.gif" border="0" alt="Make payments with 2Checkout, it's fast and secure!" title="Pay your Order with 2Checkout, it's fast and secure!" />
</form>
<?php
}
?>
Its a compilation of existing codes and includes the following features:
- proper item name and desc transferred to 2CO web
- proper & full contact info sent to 2CO
- currency conversion
- quick link to 2CO (no image clicking to pay)
regards to all who contributed & hope it'll save somebody a couple of days