VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Payment VM 1.1 => PayPal / PayPal Pro VM 1.1 => Topic started by: kontrolfreek on December 20, 2008, 08:12:49 AM

Title: Send Product Name and Attributes to Paypal
Post by: kontrolfreek on December 20, 2008, 08:12:49 AM
Ok, I think there are a ton of you out there like me who wants to send your product info up to paypal so you can see what you ordered.  Well, I have finaly got it working after a full day of pulling my hair out.  One note here, I do not use the shipping tool in VM so i have removed the shipping code from my code, there were two lines i removed, you will need to add them if you ship with vm and i have not tested with shipping but for now, back up your php for paypal and then give this a shot.

Setting up product
The way I set up my products is simple.  I created a product (SpeedFreek for example) then I added attributes to it in the product status tab.  The product SpeedFreek comes in 2 colors and is offered in a 2 pack or a 4 pack.  So here is my set up.

Attribute List:
Title: Qty Per Pack
Property:  2 -    (you might ask why the -, ill explain later)  Price (blank)
Property:  4 -  Price +7.51

Title: Color
Property:  White
Property:  Black

Now, that is how I set mine up, you might do yours different so I dont know if it will work the same or not.  Now for the code.

Go to store and list payment methods, click on the word paypal then on the configuration tab.  Here is my full code for the page and i will put a small clip under it and explain the 2 - from the attributes.

<?php
//"item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": ". $db->f("order_id")
$order_id $db->f("order_id");
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);
$description "Inscriptions";
$row_num $dboi->num_rows();
$i=1;
while(
$dboi->next_record()) {
   
   
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name").", "$dboi->f("product_attribute"));
    
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
    
$supp_var['amount_' $i] = round($dboi->f("product_item_price"),2);
    
$i++;
}
$dbb = new ps_DB;
$q "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();
/*
"cmd" => "_ext-enter",
"redirect_cmd" => "_xclick",

*/

$url "https://www.paypal.com/cgi-bin/webscr";
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"business" => PAYPAL_EMAIL,
"receiver_email" => PAYPAL_EMAIL,
"item_name" => $description,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"receiver_email" => PAYPAL_EMAIL,
"order_id" => $db->f("order_id"),
"invoice" => $db->f("order_number"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"undefined_quantity" => "0",

"test_ipn" => PAYPAL_DEBUG,
"pal" => "NRUBJXESJTY24",
"no_note" => "0",

"email" => $dbb->f("user_email"),
"first_name" => $dbb->f("first_name"),
"last_name" => $dbb->f("last_name"),
"address1" => $dbb->f("address_1"),
"address2" => $dbb->f("address_2"),
"city" => $dbb->f("city"),
"state" => $dbb->f("state"),
"address_country" => $dbbt->f('country'),
"zip" => $dbb->f("zip"),
"H_PhoneNumber" => $dbb->f("phone_1")
);
if( 
$page == "checkout.thankyou" ) {
$query_string "?";

foreach( 
$post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
$query_string .= $name"=" urlencode($value) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';
echo 
'<input type="image" name="submit" src="http://images.paypal.com/images/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';

foreach( 
$post_variables as $name => $value ) {
echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
}
echo 
'</form>';
}
?>



while($dboi->next_record()) {
   
   $supp_var['item_name_' . $i] = strip_tags($dboi->f("order_item_name").", ". $dboi->f("product_attribute"));
    $supp_var['quantity_' . $i] = $dboi->f("product_quantity");
    $supp_var['amount_' . $i] = round($dboi->f("product_item_price"),2);
    $i++;
}


Ok, the code right above here tells VM to send the item name, qty and amount to paypal.  if you look in the item name line, you will see i am sending the order_item_name and the product_attribute.  I also added a , between them.  The problem i do have is with 2 or more attributes, it doesnt seperate them to well so in the attribute i put a - to seperate them.  here is what my description looks like in paypal.  SpeedFreek, Qty Per Pack: 2 - Color: White

Now i am trying to figure out how to get paypal to print this on my shipping label which is the ebay style label, one lable on a 8.5 x 11 paper, if you have insight on this, let me know.  hope this helps and i hope i didnt leave out anything, be sure to back up everything first and you might have to mess around with settings but i think this works well for my site.  www.kontrolfreek.com/content you can view my shop here to see the attributes in action.
Title: Re: Send Product Name and Attributes to Paypal
Post by: kontrolfreek on December 20, 2008, 19:57:55 PM
just found out this code is not sending product discount to paypal AGH
Title: Re: Send Product Name and Attributes to Paypal
Post by: kontrolfreek on December 21, 2008, 00:11:51 AM
with the help of metricton, we fixed the problem with the discounts not working.  What he did was coded this to take the cart total discount and divide it up between the number of items in the cart.  so now this code will actually post the correct description of the product with attributes and will do discounts correctly , here is the code.  Thanks metric, you da bomb

<?php
//"item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": ". $db->f("order_id")
$order_id $db->f("order_id");
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);
$description "Inscriptions";
$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

$dbb = new ps_DB;
$q "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();
/*
"cmd" => "_ext-enter",
"redirect_cmd" => "_xclick",

*/

$url "https://www.paypal.com/cgi-bin/webscr";
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
if($discount_totalCP 0)
{
$disc_perItem round($discount_totalCP $t_quantity2);
}
else
{
$disc_perItem 0;
}
}
else
{
$disc_perItem 0;
}

while(
$dboi->next_record()) {
   
   
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name").", "$dboi->f("product_attribute"));
    
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
    
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
    
$i++;
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"business" => PAYPAL_EMAIL,
"receiver_email" => PAYPAL_EMAIL,
"item_name" => $description,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"receiver_email" => PAYPAL_EMAIL,
"order_id" => $db->f("order_id"),
"invoice" => $db->f("order_number"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"undefined_quantity" => "0",

"test_ipn" => PAYPAL_DEBUG,
"pal" => "NRUBJXESJTY24",
"no_note" => "0",

"email" => $dbb->f("user_email"),
"first_name" => $dbb->f("first_name"),
"last_name" => $dbb->f("last_name"),
"address1" => $dbb->f("address_1"),
"address2" => $dbb->f("address_2"),
"city" => $dbb->f("city"),
"state" => $dbb->f("state"),
"address_country" => $dbbt->f('country'),
"zip" => $dbb->f("zip"),
"H_PhoneNumber" => $dbb->f("phone_1")
);
if( 
$page == "checkout.thankyou" ) {
$query_string "?";

foreach( 
$post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
$query_string .= $name"=" urlencode($value) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';
echo 
'<input type="image" name="submit" src="http://images.paypal.com/images/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';

foreach( 
$post_variables as $name => $value ) {
echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
}
echo 
'</form>';
}
?>
Title: Re: Send Product Name and Attributes to Paypal
Post by: boruchsiper on January 04, 2009, 21:51:01 PM
This is exactly what I was looking for. Can you post the code with the  shipping info. Thanks
Title: Re: Send Product Name and Attributes to Paypal
Post by: pkthunder on January 05, 2009, 21:13:05 PM
thanks this works great!!! but is there a way to show the Order number/Invoice Number as well like in the default Paypal Configuration code?
Title: Re: Send Product Name and Attributes to Paypal
Post by: brandonjp on February 06, 2009, 06:51:29 AM
Quote from: kontrolfreek on December 21, 2008, 00:11:51 AM
with the help of metricton, we fixed the problem with the discounts not working.  What he did was coded this to take the cart total discount and divide it up between the number of items in the cart.  so now this code will actually post the correct description of the product with attributes and will do discounts correctly , here is the code.  Thanks metric, you da bomb


Yeah!  This is really great...VERY close, but it's not passing the Order Number or Shipping Amount to PayPal (so my customers are getting free shipping).   I modified it to fit my needs so now on the PayPal page it includes each ordered item like this:

Description                         Price      Qty      Amount
Order #138: Teacher Guide -         $3.00      2        $6.00
Order #138: Student Booklet -       $5.00      3        $15.00



So here's my new code....
<?php
//"item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": ". $db->f("order_id")
$order_id $db->f("order_id");
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);
$description "Inscriptions";
$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

$dbb = new ps_DB;
$q "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();
/*
"cmd" => "_ext-enter",
"redirect_cmd" => "_xclick",

*/

$url "https://www.paypal.com/cgi-bin/webscr";
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
if($discount_totalCP 0)
{
$disc_perItem round($discount_totalCP $t_quantity2);
}
else
{
$disc_perItem 0;
}
}
else
{
$disc_perItem 0;
}

while(
$dboi->next_record()) {
   
   
$supp_var['item_name_' $i] = strip_tags("Order #"$db->f("order_id").": "$dboi->f("order_item_name")." - "$dboi->f("product_attribute"));
    
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
    
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
    
$i++;
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"business" => PAYPAL_EMAIL,
"receiver_email" => PAYPAL_EMAIL,
"item_name" => $description,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"shipping" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"receiver_email" => PAYPAL_EMAIL,
"order_id" => $db->f("order_id"),
"invoice" => $db->f("order_number"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"undefined_quantity" => "0",

"test_ipn" => PAYPAL_DEBUG,
"pal" => "NRUBJXESJTY24",
"no_shipping" => "1",
"no_note" => "0",

"address_override" => "1",
"email" => $dbb->f("user_email"),
"first_name" => $dbb->f("first_name"),
"last_name" => $dbb->f("last_name"),
"address1" => $dbb->f("address_1"),
"address2" => $dbb->f("address_2"),
"city" => $dbb->f("city"),
"state" => $dbb->f("state"),
"address_country" => $dbbt->f('country'),
"zip" => $dbb->f("zip"),
"H_PhoneNumber" => $dbb->f("phone_1")
);
if( 
$page == "checkout.thankyou" ) {
$query_string "?";

foreach( 
$post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
$query_string .= $name"=" urlencode($value) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';
echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';

foreach( 
$post_variables as $name => $value ) {
echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
}
echo 
'</form>';
}
?>


It works fine at passing the ORDER NUMBER, ITEM NAMES & QUANTITIES....does everything I wish it would (including passing the billing address)....BUT.... I still can't get it to pass the shipping info to PayPal...if anyone has suggestions/help.  Please let me know.  So this seems to be doing all right - MUCH thanks kontrolfreek and metric.

--bp

[attachment cleanup by admin]
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on February 13, 2009, 07:30:36 AM
So I took this problem a step further because the title matched what I needed to get done with a site that I'm working and fixed how the attributes are displayed.  I have tested this a bunch of times and so far the results have been exactly right.  So I made many modifications to the code that was listed in this post so rather than point out each line I changed I've just posted the entire code.

Right now the URL is set to post the transcations to the "SANDBOX" at paypal.  This is a great tool for diagnosing checkout!  I have some more details that I'd like to add to this code of data that gets transfered to PayPal just for tracking purposes, this will come later for now I'm posted my major revision of this.

The only thing I have not tried fully is processing the order all the way through to see if the IPN is working properly or if it's now broken because of the extra entries in the code.


Oh and I included the shipping charge fix as indicated in another post.


<?php
//"item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": ". $db->f("order_id")
$order_id $db->f("order_id");
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);
$description "Inscriptions";
$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

$dbb = new ps_DB;
$q "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();
/*
"cmd" => "_ext-enter",
"redirect_cmd" => "_xclick",

*/

$url "https://www.sandbox.paypal.com/cgi-bin/webscr";
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
if($discount_totalCP 0)
{
$disc_perItem round($discount_totalCP $t_quantity2);
}
else
{
$disc_perItem 0;
}
}
else
{
$disc_perItem 0;
}

while(
$dboi->next_record()) {

    
$prod_attrib $dboi->f("product_attribute");
              
    
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name"));
    if(
$prod_attrib ''){
      
$attributes_array explode('<br/>',$prod_attrib);
      
$v 0;
      
$z 1;
      foreach ( 
$attributes_array as $attributes_value){
        
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
        
$supp_var['on' $z '_' $i] = $attrib_name;
        
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value': ')), ""02));
        
$supp_var['os' $z '_' $i] = $attrib_sel;
        
$v++;
        
$z++;
        unset(
$attributes_value);
      }
    }
    
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
    
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
    
$i++;
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"business" => PAYPAL_EMAIL,
"receiver_email" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"receiver_email" => PAYPAL_EMAIL,
"order_id" => $db->f("order_id"),
"invoice" => $db->f("order_number"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"undefined_quantity" => "0",

"test_ipn" => PAYPAL_DEBUG,
"pal" => "NRUBJXESJTY24",
"no_shipping" => "1",
"no_note" => "0",

"address_override" => "1",
"email" => $dbb->f("user_email"),
"first_name" => $dbb->f("first_name"),
"last_name" => $dbb->f("last_name"),
"address1" => $dbb->f("address_1"),
"address2" => $dbb->f("address_2"),
"city" => $dbb->f("city"),
"state" => $dbb->f("state"),
"address_country" => $dbbt->f('country'),
"zip" => $dbb->f("zip"),
"H_PhoneNumber" => $dbb->f("phone_1")
);
if( 
$page == "checkout.thankyou" ) {
$query_string "?";

foreach( 
$post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
$query_string .= $name"=" urlencode($value) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';
echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';

foreach( 
$post_variables as $name => $value ) {
echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
}
echo 
'</form>';
}
?>



[attachment cleanup by admin]
Title: Re: Send Product Name and Attributes to Paypal
Post by: nuwud on February 20, 2009, 19:15:56 PM
Thanks ajredding! That was the ticket! Now, why isn't that part of the core?

Also, thanks for all the forum links to this spot. Found it in 2 other articles and inexorably brought me here. Very helpful!
Title: Re: Send Product Name and Attributes to Paypal
Post by: pashis on February 22, 2009, 20:44:45 PM
I change the code in the configurations tab but when i try to proceed with an order to paypal, i get the following error:

Error Detected
Some required information is missing or incomplete. Please correct your entries and try again.
Some required information is missing or incomplete. Please correct your entries and try again.

Am i supposed to make more changes that the change of code stated?

Thanks a lot
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on February 25, 2009, 08:16:56 AM
Well one thing that would help us help you is to post a screenshot of the error that you are getting.  Also I had left a line of code that I posted above that posts the transactions to PayPal's "SANDBOX".  This Sandbox is great for customizing your code and making sure that the orders are properly posting to paypal.  Although it is a little rough to get used to how the sandbox works it's something to use if you are taking the customization a little further than what has already been done.
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on February 25, 2009, 11:26:06 AM
Ok maybe we can get the mods to pin this here soon!!

But I was reading through some other posts where people were wanting certain things to show up on PayPal when the cart is sent or certain things weren't working.  So here is my latest creation.

I'll try to list all the changes to the code so you can know if this is something you want to grab.

I did a little code management and took out some lines that either did nothing because PayPal probably changed their variables or they were duplicates.

Items changed/updated:

Items that I'm going to tackle next:

So here is the code, I tried to comment a few thing to make it easier to figure out where something is going wrong or needs to be changed.

***NOTE: In the code below I have the form posting to the PAYPAL Sandbox.  If you are going to use this on a live site DO NOT forget to change this to the default PAYPAL address ***

<?php
$order_id 
$db->f("order_id");

$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

$dbb = new ps_DB;
$q "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

$url "https://www.sandbox.paypal.com/cgi-bin/webscr";
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  //New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
if($discount_totalCP 0)
{
$disc_perItem round($discount_totalCP $t_quantity2);
}
else
{
$disc_perItem 0;
}
}
else
{
$disc_perItem 0;
}

while(
$dboi->next_record()) {

    
$prod_attrib $dboi->f("product_attribute");
              
    
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name"));
    if(
$prod_attrib ''){
      
$attributes_array explode('<br/>',$prod_attrib);
      
$v 0;
      
$z 1;
      foreach ( 
$attributes_array as $attributes_value){
        
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
        
$supp_var['on' $z '_' $i] = $attrib_name;
        
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value': ')), ""02));
        
$supp_var['os' $z '_' $i] = $attrib_sel;
        
$v++;
        
$z++;
        unset(
$attributes_value);
      }
    }
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
    
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
    
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
    
$i++;
}
//End New Code

//Start New Code - Ship to Address Versus Bill To Address

$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$first_name $dbb->f("first_name");
  
$last_name $dbb->f("last_name");
  
$address1 $dbb->f("address_1");
  
$address2 $dbb->f("address_2");
  
$city $dbb->f("city");
  
$state $dbb->f("state");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else
{
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
"no_note" => "1",
//"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip
);

if( 
$page == "checkout.thankyou" ) {
$query_string "?";

foreach( 
$post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
$query_string .= $name"=" urlencode($value) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';

foreach( 
$post_variables as $name => $value ) {
echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
}
echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
echo 
'</form>';
}
?>



The attached images show the results of the changes in the code.

As Promised the change needed to the Notify.PHP file (if you forgot the path /administrator/components/com_virtuemart)

Approx line 341 you will need to change the 'order_number' to 'order_id' in the "WHERE" statement (last line of the code below.

     
// Get the Order Details from the database     
      $qv = "SELECT `order_id`, `order_number`, `user_id`, `order_subtotal`,
                    `order_total`, `order_currency`, `order_tax`,
                    `order_shipping_tax`, `coupon_discount`, `order_discount`
                FROM `#__{vm}_orders`
                WHERE `order_id`='".$invoice."'";





[attachment cleanup by admin]
Title: Re: Send Product Name and Attributes to Paypal
Post by: actionsprite on February 25, 2009, 12:56:02 PM
Hi AJ, you kindly shared this information on a relevant post of mine, however, I think there is still an issue in that it now auto fills paypal's "billing information" form with the shipping information. a link to the post:
http://forum.virtuemart.net/index.php?topic=48976.msg169011#msg169011
Title: Re: Send Product Name and Attributes to Paypal
Post by: cinos on March 07, 2009, 13:36:00 PM
Many thanks for the code ajredding.

I am having a few problems though that maybe you (or someone else) could help with.

Firstly when the order is taken through to Paypal it displays part of the order total as "Sales Tax" and the individual items are displayed minus this tax thereby making them cheaper then they actually are.

I don't actually charge tax in my shop, but I use the Tax feature in virtuemart to quickly modify prices of products all in one go. As such is there a way that I can restore the individual 'tax' to each item and have the "Sales Tax" field removed in paypal?

I've tried commenting out:

"tax_cart" => $tax_total,

but that (understandably) just makes the order total cheaper in Paypal then in my own shop. Since tax seems to have been removed entirely.

I can't seem to find where I can add the tax to each item in an order.  ???


Secondly when the order is actually processed I am finding that instead of being sent to an order confirmation page, I am merely sent back to the homepage of my site. Also notify.php doesn't appear to be updated for some reason.

This all works perfectly with the original Paypal code, so I am at a loss as to why it doesn't work with your new code. As far as I can see, the relevent parts are the same.

Any thoughts?  :)
Title: Re: Send Product Name and Attributes to Paypal
Post by: cinos on March 17, 2009, 15:35:48 PM
Anything at all?
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on March 29, 2009, 23:11:21 PM
Sorry I have been consumed with a major project for work.  But let me see if I understand what you are doing with your virtuemart setup.

So you are wanting to have the "tax" charged to each item rather than to the whole order? 

I'll try experimenting with this type of setup on my test site and post my findings here.  I know that paypal will accept tax for each item but I'm not sure what the ending results will be.

As far as it going back to the homepage instead of a confirmation page I'll have to check into that.
Title: Re: Send Product Name and Attributes to Paypal
Post by: cinos on March 30, 2009, 16:47:39 PM
Hi AJ

Yeah. It's so that I can modify all the products in one go. For instance when VAT goes back up to 17.5% I can just change the 15% tax rate to 17.5% and all the prices will update themselves.

I am however not allowed to charge tax, which means to say that my prices can be the same as if they had tax on them, but I cannot show any tax in my invoices, products and checkout.

So ideally it would be grand if say someone bought a product for £9.99, it then went through to Paypal and the price of the product still remained at £9.99 with no mention of tax whatsoever.

Is this possible?

It would be great if you also managed to find a cause behind the homepage redirect, as that one has me completely stumped. :? Not to mention the fact that the notify.php (automated status update from Paypal) doesn't work with this new code. I've trawled through the code that you have written and I can't find a suitable cause for either. :/

If you can help I would be very grateful. :)
Title: Re: Send Product Name and Attributes to Paypal
Post by: parrahouse on April 07, 2009, 04:52:53 AM
Hello all --

okay, the last script that ajredding posted came closer than anything I've tried yet at passing everything necessary to paypal --all the cart details are coming through fine

Except a shipping address.  Or more accurately the address is kinda-sorta getting passed.  If I click to pay with a credit card (instead of logging in) the bill-to address is populating the cc form:

(http://img.skitch.com/20090407-gh7fq7rjdj91w84hpk51g482th.preview.jpg) (http://skitch.com/michaelparra/bk47n/billing-information-paypal)
Click for full size (http://skitch.com/michaelparra/bk47n/billing-information-paypal)

But if I login to paypal no address is displayed --just an email.  This results in an order with no shipping address -- denying seller protection to the purchase and making label printing a pain:

(http://img.skitch.com/20090407-m7dnc6fsbqhry61gmrgj4t54ct.preview.jpg) (http://skitch.com/michaelparra/bk47x/loading-review-your-payment-paypal)
Click for full size (http://skitch.com/michaelparra/bk47x/loading-review-your-payment-paypal)

What's going on?  I've heard that paypal will ignore addresses that are missing or otherwise imperfect. Where should I start troubleshooting this?

Any help appreciated.

Big thanks to ajredding for the great work.

PS -- my shop is configured for NO REGISTRATION. Does this have anything to do with the problems passing shipping info?
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on April 07, 2009, 11:11:37 AM
Quote from: cinos on March 30, 2009, 16:47:39 PM
Hi AJ

Yeah. It's so that I can modify all the products in one go. For instance when VAT goes back up to 17.5% I can just change the 15% tax rate to 17.5% and all the prices will update themselves.

I am however not allowed to charge tax, which means to say that my prices can be the same as if they had tax on them, but I cannot show any tax in my invoices, products and checkout.

So ideally it would be grand if say someone bought a product for £9.99, it then went through to Paypal and the price of the product still remained at £9.99 with no mention of tax whatsoever.

Is this possible?


Ok lets try this post again...

Couple of quick questions...

But quickly looking at how a few things are stored in the DB, it looks like this can be done but it's going to require editing the paypal config file also to add a variable in there to toggle this ability on and off. 

I'll rough something together and give it a few test runs.
Title: Re: Send Product Name and Attributes to Paypal
Post by: cinos on April 07, 2009, 19:36:06 PM
In answer to your questions:


Thankyou so much for your help with this. It means alot.  :D
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on April 08, 2009, 08:07:35 AM
Ok I've got it worked out, but instead of posting all the code changes I'm going to post a zipped file that you can just extract to your site root.  The files are in the correct path for the site. 

AS A WARNING: I would suggest backing up your site before uploading these just in case! 

What I did is added an option in the paypal config to allow for this to be turned off and on.  So once you have uploaded the code you will need to open the payment method and click over the configuration and change the new option to "yes"

Below is the new "Payment Extra Info" code to take advantage of the new option.

<?php
$order_id 
$db->f("order_id");

$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

$url "https://www.paypal.com/cgi-bin/webscr";
if(
PAYPAL_CHARGE_TAX == 1) {
$tax_total '0.00';

else {
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
}


$discount_total $db->f("coupon_discount") + $db->f("order_discount");&#160; //New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
if($discount_totalCP 0) {
$disc_perItem round($discount_totalCP $t_quantity2);
}
else {
$disc_perItem 0;
}
}
else {
$disc_perItem 0;
}

while(
$dboi->next_record()) {

&
#160; &#160; $prod_attrib = $dboi->f("product_attribute");
&#160; &#160; &#160; &#160; &#160; &#160; &#160; 
&#160; &#160; $supp_var['item_name_' . $i] = strip_tags($dboi->f("order_item_name"));

&#160; &#160; if($prod_attrib > ''){
&#160; &#160; &#160; $attributes_array = explode('<br/>',$prod_attrib);
&#160; &#160; &#160; $v = 0;
&#160; &#160; &#160; $z = 1;
&#160; &#160; &#160; foreach ( $attributes_array as $attributes_value){
&#160; &#160; &#160; &#160; $attrib_name = trim(substr($attributes_value, 0, strpos($attributes_value, ':')), " ");
&#160; &#160; &#160; &#160; $supp_var['on' . $z . '_' . $i] = $attrib_name;
&#160; &#160; &#160; &#160; $attrib_sel = trim(substr_replace(substr_replace($attributes_value, "", 0, strrpos($attributes_value, ': ')), "", 0, 2));
&#160; &#160; &#160; &#160; $supp_var['os' . $z . '_' . $i] = $attrib_sel;
&#160; &#160; &#160; &#160; $v++;
&#160; &#160; &#160; &#160; $z++;
&#160; &#160; &#160; &#160; unset($attributes_value);
&#160; &#160; &#160; }
&#160; &#160; }
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
&
#160; &#160; $supp_var['quantity_' . $i] = $dboi->f("product_quantity");
if(PAYPAL_CHARGE_TAX == 1) {
$supp_var['amount_' $i] = round(($dboi->f("product_final_price") - $disc_perItem),2);

else {
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
}
&
#160; &#160; $i++;
}
//End New Code

//Start New Code - Ship to Address Versus Bill To Address

$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
&
#160; $first_name = $dbb->f("first_name");
&#160; $last_name = $dbb->f("last_name");
&#160; $address1 = $dbb->f("address_1");
&#160; $address2 = $dbb->f("address_2");
&#160; $city = $dbb->f("city");
&#160; $state = $dbb->f("state");
&#160; $address_country = $dbbt->f("country");
&#160; $zip = $dbb->f("zip");
&#160; $H_PhoneNumber = $dbb->f("phone_1");
}
else
{
&
#160; $first_name = $dboui->f("first_name");
&#160; $last_name = $dboui->f("last_name");
&#160; $address1 = $dboui->f("address_1");
&#160; $address2 = $dboui->f("address_2");
&#160; $city = $dboui->f("city");
&#160; $state = $dboui->f("state");
&#160; $address_country = $dboui->f("country");
&#160; $zip = $dboui->f("zip");
&#160; $H_PhoneNumber = $dboui->f("phone_1");
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$db->f("order_tax")-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
"no_note" => "1",
//"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip
);

if( 
$page == "checkout.thankyou" ) {
$query_string "?";

foreach( 
$post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
$query_string .= $name"=" urlencode($value) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';

foreach( 
$post_variables as $name => $value ) {
echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
}
echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
echo 
'</form>';
}
?>


On the "administration / configuration" board I posted a topic about implementing a change like this at the cart level. 

Ok so the attachments isn't working on the board right now so I've posted them right in the post.
(http://www.rawmediagroup.com/images/VirtueMart/VirtueMart-Tax-Charge-CFG.png)
Configuration Option

(http://www.rawmediagroup.com/images/VirtueMart/VirtueMart-Tax-Dont-Charge.png)
If the option is set to "NO"

(http://www.rawmediagroup.com/images/VirtueMart/VirtueMart-Tax-Charge.png)
If the option is set to "YES"

(http://www.rawmediagroup.com/images/VirtueMart/VirtueMart-Tax-Charge-Discount.png)
If the option is set to "YES" and a Discount/Coupon is applied

Hope this is what you are looking for.

Oh Yeah one last note the Original price of the product is 6.95 and the "tax" is 8.25% which totals $7.52.

Crap forgot to link to the files since the attachments isn't working.
http://www.rawmediagroup.com/download/VirtueMart/Tax-Hack.zip (http://www.rawmediagroup.com/download/VirtueMart/Tax-Hack.zip)

One Last Edit here @parrahouse  I found that in one of the SQL statements it was declaring a table instead of using the "prefix" variable.  I've been doing this on my dev server and I didn't use the standard Joomla table prefix so that's how I discovered this mistake.

If you don't want to implement all of the changes above here is what you need to do

BAD CODE SECTION

$dbb = new ps_DB;
$q = "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();


Should Read

$dbb = new ps_DB;
$q = "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();


It's near the top.
Title: Re: Send Product Name and Attributes to Paypal
Post by: ads4it on April 08, 2009, 09:02:19 AM
hey

thx you for aj.

i just fixed little bit of your code.
so in paypal, it can obtain address, phone#, email.

here it is.

always backup ur original file before do something.

<?php
$order_id 
$db->f("order_id");

$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

$dbb = new ps_DB;
$q "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

$url "https://www.paypal.com/cgi-bin/webscr";
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  //New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
if($discount_totalCP 0)
{
$disc_perItem round($discount_totalCP $t_quantity2);
}
else
{
$disc_perItem 0;
}
}
else
{
$disc_perItem 0;
}

while(
$dboi->next_record()) {

    
$prod_attrib $dboi->f("product_attribute");
              
    
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name"));
    if(
$prod_attrib ''){
      
$attributes_array explode('<br/>',$prod_attrib);
      
$v 0;
      
$z 1;
      foreach ( 
$attributes_array as $attributes_value){
        
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
        
$supp_var['on' $z '_' $i] = $attrib_name;
        
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value': ')), ""02));
        
$supp_var['os' $z '_' $i] = $attrib_sel;
        
$v++;
        
$z++;
        unset(
$attributes_value);
      }
    }
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
    
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
    
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
    
$i++;
}
//End New Code

//Start New Code - Ship to Address Versus Bill To Address

$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$first_name $dbb->f("first_name");
  
$last_name $dbb->f("last_name");
  
$address1 $dbb->f("address_1");
  
$address2 $dbb->f("address_2");
  
$city $dbb->f("city");
  
$state $dbb->f("state");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else
{
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $dbbt->f('first_name'),
"last_name" => $dbbt->f('last_name'),
"address1" => $dbbt->f('address_1'),
"address2" => $dbbt->f('address_2'),
"zip" => $dbbt->f('zip'),
"city" => $dbbt->f('city'),
"state" => $dbbt->f('state'),
"address_country" => $address_country,
"night_phone_b" => $dbbt->f('phone_1'),
);

if( 
$page == "checkout.thankyou" ) {
$query_string "?";

foreach( 
$post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
$query_string .= $name"=" urlencode($value) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';

foreach( 
$post_variables as $name => $value ) {
echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
}
echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
echo 
'</form>';
}
?>
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on April 08, 2009, 09:07:26 AM
Thanks for pointing that out.

I was working on a different problem for another user and had commented the email line out and well I just totally missed putting the phone line in there.

I've updated my code so that any build from here on out will have that in there.

Ok acutally I went through and did some formatting and found a few other things that needed to be corrected.

So here is an official posting of the latest known working code.


<?php
$url 
"https://www.paypal.com/cgi-bin/webscr";
$order_id $db->f("order_id");
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  

// Query for Order Items
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

// Query to get User Info
$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
  
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
  if(
$discount_totalCP 0) {
    
$disc_perItem round($discount_totalCP $t_quantity2);
  }
  else {
    
$disc_perItem 0;
  }
}
else {
  
$disc_perItem 0;
}

while(
$dboi->next_record()) {

  
$prod_attrib $dboi->f("product_attribute");
  
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name"));
  
  if(
$prod_attrib ''){
    
$attributes_array explode('<br/>',$prod_attrib);
    
$v 0;
    
$z 1;
    foreach ( 
$attributes_array as $attributes_value){
      
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
      
$supp_var['on' $z '_' $i] = $attrib_name;
      
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value':')), ""02));
      
$supp_var['os' $z '_' $i] = $attrib_sel;
      
$v++;
      
$z++;
      unset(
$attributes_value);
    }
  }

  
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
  
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
  
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
  
$i++;
}
//End New Code


//Start New Code - Ship to Address Versus Bill To Address

//Query used to compare Bill to versus Shipp to address
$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$first_name $dbb->f("first_name");
  
$last_name $dbb->f("last_name");
  
$address1 $dbb->f("address_1");
  
$address2 $dbb->f("address_2");
  
$city $dbb->f("city");
  
$state $dbb->f("state");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else {
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

// Builds array for the form
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip,
"night_phone_b" => $H_PhoneNumber
);

if( 
$page == "checkout.thankyou" ) {
  
$query_string "?";

  foreach( 
$post_variables as $name => $value ) {
    
$query_string .= $name"=" urlencode($value) ."&";
  }

  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      
$query_string .= $name"=" urlencode($value) ."&";
    }
  }

  
vmRedirect$url $query_string );

else {
  echo 
'<form action="'.$url.'" method="post" target="_blank">';

  foreach( 
$post_variables as $name => $value ) {
    echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
  }
  
  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
    }
  }
  echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
  echo 
'</form>';
}
?>

Title: Re: Send Product Name and Attributes to Paypal
Post by: ads4it on April 08, 2009, 10:13:32 AM
AJ last code was really clean and smooth.

this is little add for aj's last code.

i just added little string

so in paypal you can get oder number, product name.

if you don't like order number's to display don't get this one.

and thx to aj for this hack.

and please respect coders!

always backup your original.

<?php
$url 
"https://www.paypal.com/cgi-bin/webscr";
$order_id $db->f("order_id");
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  

// Query for Order Items
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

// Query to get User Info
$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
  
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
  if(
$discount_totalCP 0) {
    
$disc_perItem round($discount_totalCP $t_quantity2);
  }
  else {
    
$disc_perItem 0;
  }
}
else {
  
$disc_perItem 0;
}

while(
$dboi->next_record()) {

  
$prod_attrib $dboi->f("product_attribute");
  
$supp_var['item_name_' $i] = strip_tags("Order #"$db->f("order_id").": "$dboi->f("order_item_name"));
  
  if(
$prod_attrib ''){
    
$attributes_array explode('<br/>',$prod_attrib);
    
$v 0;
    
$z 1;
    foreach ( 
$attributes_array as $attributes_value){
      
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
      
$supp_var['on' $z '_' $i] = $attrib_name;
      
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value':')), ""02));
      
$supp_var['os' $z '_' $i] = $attrib_sel;
      
$v++;
      
$z++;
      unset(
$attributes_value);
    }
  }

  
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
  
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
  
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
  
$i++;
}
//End New Code


//Start New Code - Ship to Address Versus Bill To Address

//Query used to compare Bill to versus Shipp to address
$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$first_name $dbb->f("first_name");
  
$last_name $dbb->f("last_name");
  
$address1 $dbb->f("address_1");
  
$address2 $dbb->f("address_2");
  
$city $dbb->f("city");
  
$state $dbb->f("state");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else {
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

// Builds array for the form
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip,
"night_phone_b" => $H_PhoneNumber
);

if( 
$page == "checkout.thankyou" ) {
  
$query_string "?";

  foreach( 
$post_variables as $name => $value ) {
    
$query_string .= $name"=" urlencode($value) ."&";
  }

  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      
$query_string .= $name"=" urlencode($value) ."&";
    }
  }

  
vmRedirect$url $query_string );

else {
  echo 
'<form action="'.$url.'" method="post" target="_blank">';

  foreach( 
$post_variables as $name => $value ) {
    echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
  }
  
  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
    }
  }
  echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
  echo 
'</form>';
}
?>
Title: Re: Send Product Name and Attributes to Paypal
Post by: cinos on April 08, 2009, 12:35:50 PM
Wow Aj, thankyou so much!

I will test this tonight and let you know how it goes. :)

Thanks again, I really appreciate the effort you went through to help me out. You are the best.
Title: Re: Send Product Name and Attributes to Paypal
Post by: cinos on April 08, 2009, 12:37:27 PM
Thanks to ads4it too! :)
Title: Re: Send Product Name and Attributes to Paypal
Post by: mackavi on April 09, 2009, 16:08:30 PM
Cheers for this.  But one small problem, the return now goes to index page of the site instead of normal purchase message.  All I did was replace the original code with the PHP above - did I miss something :-?
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on April 09, 2009, 19:31:44 PM
I noticed that on the sandbox site but I haven't tested it on a client's live site 100% yet.  So I'm not sure if there is something different between the two.

But here is what I noticed.

When I have ran through a complete order on the sandbox site and you are ready to click on the link to return to your site from paypal the URL string listed has the HTML CODED "&" (&amp;) injected to the URL string.  This is causing problems with virtuemart. 

Like I said I'm not sure if it's just the sandbox site doing this or if it's also a problem on paypal's live site also.

If any of you have all this code and changes implemented on your live site and can run through a sale all the way.  Could you post the URL that gets returned to your browser when you click on the "Return to Merchant" button.

Title: Re: Send Product Name and Attributes to Paypal
Post by: afink on April 09, 2009, 22:51:53 PM
Nice work AJ. Thanks so much. Everything seems to be working fine when the user logs onto their PayPal account.

However, I am seeing a similar symptom that was posted by parrahouse on April 7th.

If the user decides to pay with a credit card without logging onto a PayPal account, the credit card screen is getting populated with the "alternate shipping address" information (instead of the billing address).
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on April 09, 2009, 23:03:14 PM
There is a slight trade off with this whole thing.

I think this was discussed on another topic but basically what it boils down to is paypal doesn't allow you to send both a billing and ship to address when processing an order. 

So what the code ("Payment Extra Info") is designed to do is send the "ship to" address to paypal.  Once you are at paypal and the user doesn't login to paypal and uses a CC the Billing info has the ship to, but if they just change it to the correct billing info then (if I remember correctly) once they move on to the confirm page it will show the ship to as what was entered as the ship to on VirtueMart. (did that make sense?)

The payment extra info code is looking to see if there is a ship to address entered if so it sends that.  If not it'll send the billing info.

Like I said last time I checked what I have stated above worked.  Programming late at night after working a full time job is sometimes rough and you don't remember everything.
Title: Re: Send Product Name and Attributes to Paypal
Post by: afink on April 09, 2009, 23:39:25 PM
Got it. That makes perfect sense.

Too bad PayPal doesn't allow for passing both a billing and a shipping address.

Thanks again for your good work (and late night coding). 
Title: Re: Send Product Name and Attributes to Paypal
Post by: mackavi on April 11, 2009, 00:28:27 AM
Cheers AJ.
Title: Re: Send Product Name and Attributes to Paypal
Post by: Mizpah on April 12, 2009, 18:56:41 PM
Thank AJ,

Am back to implementing this, and as indeed I will need to use product details et all, am using the code from this posting.

I note that you have the line:

https://www.paypal.com/en_US/i/btn/x-click-but6.gif

As a GB based shop hev changed it to:

https://www.paypal.com/en_GB/i/btn/x-click-but6.gif

I dont know if this makes any practical difference (just wondering if secure pages might complain about more than once source?), but am listing it here just in case it does to anyone in UK land!

Cheers,

Mizpah
Title: Re: Send Product Name and Attributes to Paypal
Post by: TurnTex on April 23, 2009, 07:26:46 AM
I have read through this entire thread and am just a little bit confused.  I am new to all of this so please excuse my ignorance!

Question...do I just copy the last code that AJ grascously shared and paste it into the paypal config section as is?  Do I need to do anything else with some other config file shown earlier in this thread?

I tried the code as is without modifing any other files but it did not pass any sku or order numbers to Paypal.  Any help would be appreciated.
Title: Re: Send Product Name and Attributes to Paypal
Post by: ajredding on April 24, 2009, 08:47:06 AM
What is the versions of software you are using?

PHP / Joomla / VirtueMart??

When you hit save did it properly save that "paypal extra info" code?

was there any change in how the cart is shown in paypal?

If you have screenshots or links available to show us what it's doing that would help figure out what is going on.
Title: Re: Send Product Name and Attributes to Paypal
Post by: mackavi on April 24, 2009, 12:22:43 PM
Hi AJ,

Just an update.  I tried the last full script and it send products details etc as part of the order but was having problems with it not returning to the right place after paying - all this in the sandbox.

I tried it on a live system today and it the details and everything went across but it still fails to confirm an order and returns to the main page of my site.

I switched back to the original script supplied with the module and everything works perfectly except now all I get is the standard order ## rather than product name etc.

I saw in another post that you said you'd need to changed the notify script if the paypal script was changed but what to?

Regards,

Mack

J1.5 VM 1.13 PHP 5.29
Title: Re: Send Product Name and Attributes to Paypal
Post by: kyndhi on April 26, 2009, 03:34:42 AM
Hi, I used the code provided by ajredding. Thank you!!!
but after payment when I click on the "return" buttom on paypal
it returns to the "home page" not to "thank you" page
I am using the sandbox.

Whit the original code provided by paypal module it goes to the thank you page but it does not allow to show the order detail.

I have been testing and seems to be the variable "cmd"
original code has "_ext-enter"
code using has "_cart"

Any idea how can show the order detail (products) on paypal and return to thank you page after payment in the sandbox.

Thank you!!!
Title: Re: Send Product Name and Attributes to Paypal
Post by: kyndhi on April 26, 2009, 03:58:59 AM
using virtuemart 1.1.3 and joomla 1.5.9
I read about some modifications to "notify.php", but mine seems to be right.
on virtuemart - paypal configuration, test mode set to "No"
Title: Re: Send Product Name and Attributes to Paypal
Post by: stephengrenfell on April 27, 2009, 18:33:08 PM
Hi,

I have added the code as provided by AJREDDING (thanks) into paypal extra info & modified line 337 in the Nofify.php file. It worked OK a few times under test with the papyapl site, but now doesn't work with eitehr paypal or sandbox.  Instead I get an error saying "Bad Request
Your browser sent a request that this server could not understand.
Size of a request header field exceeds server limit."

This is what the broswer is sending to paypal:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ext-enter&redirect_cmd=_xclick&upload=1&business=stephen%40future-innovations.fr&receiver_email=stephen%40future-innovations.fr&item_name=Order+Number%3A+22&order_id=22&invoice=56_7fd986d0202169f33bd300768aa72&amount=10.22&shipping=9.50&currency_code=EUR&address_override=1&first_name=test&last_name=test&address1=54+rue+de+test&address2=&zip=01234&city=test&state=-&country=FR&email=stephen%40test.com&night_phone_b=01234567&cpp_header_image=http%3A%2F%2Flocalhost%2Fjoomla%2Fcomponents%2Fcom_virtuemart%2Fshop_image%2Fvendor%2FFuture_innovatio_49ef3e43c8493.gif&return=http%3A%2F%2Flocalhost%2Fjoomla%2Findex.php%3Foption%3Dcom_virtuemart%26page%3Dcheckout.result%26order_id%3D22&notify_url=http%3A%2F%2Flocalhost%2Fjoomla%2Fadministrator%2Fcomponents%2Fcom_virtuemart%2Fnotify.php&cancel_return=http%3A%2F%2Flocalhost%2Fjoomla%2Findex.php&undefined_quantity=0&test_ipn=0&pal=NRUBJXESJTY24&no_shipping=1&no_note=1&

Any ideas greatfully received.
Title: Re: Send Product Name and Attributes to Paypal
Post by: virtuemart_craig on May 23, 2009, 04:36:15 AM
AJ,

Thanks for the code. I also had a problem with the status of the account not changing and being redirected to the home page. I just wanted to post my solution.

"cmd" => "_cart", //does not pass variables with return
"cmd" => "_ext-enter", //will pass variables with return

PapPal allows you to use "custom" to pass any variables that you need after the customer has made their payment. Since I use SEF url, I just set up a hidden menu link that sets the option to com_virtuemart and the page=checkout.result. Then just use that url for the return file name. In my case it's:
"return" => SECUREURL ."paypal-return.html",

Then it's just a matter of extracting the order_id from the custom string that you originally sent to paypal.

The reason that the status wasn't updating was because the invoice needs to use
"invoice" => $db->f("order_number"),
not
"invoice" => $db->f("order_id"),
I believe that order_number is padded with leading zeros.

Here is the code for Payment Extra Info:

<?php
$url 
"https://www.sandbox.paypal.com/cgi-bin/webscr";
$order_id $db->f("order_id");
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  

// Query for Order Items
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

// Query to get User Info
$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
  
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
  if(
$discount_totalCP 0) {
    
$disc_perItem round($discount_totalCP $t_quantity2);
  }
  else {
    
$disc_perItem 0;
  }
}
else {
  
$disc_perItem 0;
}

while(
$dboi->next_record()) {

  
$prod_attrib $dboi->f("product_attribute");
  
$supp_var['item_name_' $i] = strip_tags("Order #"$db->f("order_id").": "$dboi->f("order_item_name"));
  
  if(
$prod_attrib ''){
    
$attributes_array explode('<br/>',$prod_attrib);
    
$v 0;
    
$z 1;
    foreach ( 
$attributes_array as $attributes_value){
      
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
      
$supp_var['on' $z '_' $i] = $attrib_name;
//      $attrib_sel = trim(substr_replace(substr_replace($attributes_value, "", 0, strrpos($attributes_value, ':')), //"", 0, 2)); I do not want to strip all colons
      
$attrib_sel trim(substr($attributes_valuestrpos($attributes_value':')+1));
      
$supp_var['os' $z '_' $i] = $attrib_sel;
      
$v++;
      
$z++;
      unset(
$attributes_value);
    }
  }

  
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
  
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
  
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
  
$i++;
}
//End New Code


//Start New Code - Ship to Address Versus Bill To Address

//Query used to compare Bill to versus Shipp to address
$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$first_name $dbb->f("first_name");
  
$last_name $dbb->f("last_name");
  
$address1 $dbb->f("address_1");
  
$address2 $dbb->f("address_2");
  
$city $dbb->f("city");
  
$state $dbb->f("state");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else {
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

// Builds array for the form
$post_variables = Array(
"cmd" => "_cart"//does not pass variables with return
//"cmd" => "_ext-enter", //will pass variables with return
"redirect_cmd" => "_xclick",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_number"),
//"myvar" => 'hello', paypal does not pass odd variables just custom
//"order_id" => $db->f("order_id"), order_id seems to be reserved in paypal
"image_url" => $vendor_image_url,
//"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"return" => SECUREURL ."paypal-return.html",
"custom" => "option=com_virtuemart,page=checkout.result,order_id=".$order_id,
//you don't need to pass the option or page variables here use a menu link instead
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip,
"night_phone_b" => $H_PhoneNumber,
"test_ipn" => PAYPAL_DEBUG,
"pal" => "NRUBJXESJTY24"
);

if( 
$page == "checkout.thankyou" ) {
  
$query_string "?";

  foreach( 
$post_variables as $name => $value ) {
    
$query_string .= $name"=" urlencode($value) ."&";
  }

  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      
$query_string .= $name"=" urlencode($value) ."&";
    }
  }

  
vmRedirect$url $query_string );

else {
  echo 
'<form action="'.$url.'" method="post" target="_blank">';

  foreach( 
$post_variables as $name => $value ) {
    echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
  }
  
  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
    }
  }
  echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
  echo 
'</form>';
}
?>



Here is the modifed
administrator/components/com_virtuemart/html/checkout.result.php
page that extracts the invoice_id:
<?php
if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
* PayPal IPN Result Checker
*
* @version $Id: checkout.result.php 1394 2008-05-04 19:05:15Z soeren_nb $
* @package VirtueMart
* @subpackage html
* @copyright Copyright (C) 2004-2007 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/
mm_showMyFileName__FILE__ );

if( !isset( 
$_REQUEST["order_id"] ) || empty( $_REQUEST["order_id"] )) {
if( isset( $_REQUEST["custom"] )) {
$a explode(',',$_REQUEST["custom"]);
foreach ($a as $av)
{
$t explode('='$av);
$a[$t[0]] = $t[1];
}
}
else if( isset( $_REQUEST["cm"] )) {
$a explode(',',$_REQUEST["cm"]);
foreach ($a as $av)
{
$t explode('='$av);
$a[$t[0]] = $t[1];
}
}

if (isset($a['order_id']))
$order_id $a['order_id'];
else
{
echo $VM_LANG->_('VM_CHECKOUT_ORDERIDNOTSET');
return;
}
}
else {
$order_id intvalvmGet$_REQUEST"order_id" ));
}
include( CLASSPATH"payment/ps_paypal.cfg.php" );
//$order_id = intval( vmGet( $_REQUEST, "order_id" ));

$q "SELECT order_status FROM #__{vm}_orders WHERE ";
$q .= "#__{vm}_orders.user_id= " $auth["user_id"] . " ";
$q .= "AND #__{vm}_orders.order_id= $order_id ";
$db->query($q);
if ($db->next_record()) {
$order_status $db->f("order_status");
if($order_status == PAYPAL_VERIFIED_STATUS
      
|| $order_status == PAYPAL_PENDING_STATUS) {  ?>

        <img src="<?php echo VM_THEMEURL ?>images/button_ok.png" align="middle" alt="<?php echo $VM_LANG->_('VM_CHECKOUT_SUCCESS'); ?>" border="0" />
        <h2><?php echo $VM_LANG->_('PHPSHOP_PAYPAL_THANKYOU'?></h2>
   
    <?php
      
}
      else { 
?>

        <img src="<?php echo VM_THEMEURL ?>images/button_cancel.png" align="middle" alt="<?php echo $VM_LANG->_('VM_CHECKOUT_FAILURE'); ?>" border="0" />
        <span class="message"><?php echo $VM_LANG->_('PHPSHOP_PAYPAL_ERROR'?></span>
   
    <?php
    
?>

    <br />
     <p><a href="index.php?option=com_virtuemart&page=account.order_details&order_id=<?php echo $order_id ?>">
     <?php echo $VM_LANG->_('PHPSHOP_ORDER_LINK'?></a>
     </p>
    <?php
}
else {
echo $VM_LANG->_('VM_CHECKOUT_ORDERNOTFOUND') . '!';
}
?>



Here is a good article about how PayPal returns data:
http://www.pdncommunity.com/pdn/board/message?board.id=basicpayments&message.id=368
Craig
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on May 29, 2009, 00:55:52 AM
J 1.5.10
VM 1.1.3

My cart on WAMP using sandbox likes AJ's code posted Feb. 25 but none of the ones posted there after. I get an Error message from PayPal saying that I am missing some information...

"Some required information is missing or incomplete. Please correct your entries and try again."

When I check the url it actually is pulling the second address in my store customer address book, which is not the default address and in this case not the one selected.

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1&page_style=paypal&business=helen_1218484638_biz%40prettygooddesigns.com&currency_code=USD&amount=78.75&handling_cart=5.95&tax=3.75&tax_cart=3.75&invoice=34&image_url=http%3A%2F%2Flocalhost%2Fgingersjewelryvm%2Fcomponents%2Fcom_virtuemart%2Fshop_image%2Fvendor%2FGinger_s_Jewelry_4a1c3e6ce9900.jpg&return=http%3A%2F%2Flocalhost%2Fgingersjewelryvm%2Findex.php%3Foption%3Dcom_virtuemart%26page%3Dcheckout.result%26order_id%3D34&notify_url=http%3A%2F%2Flocalhost%2Fgingersjewelryvm%2Fadministrator%2Fcomponents%2Fcom_virtuemart%2Fnotify.php&cancel_return=http%3A%2F%2Flocalhost%2Fgingersjewelryvm%2Findex.php&no_shipping=1&no_note=1&email=&address_override=1&first_name=Eileen&last_name=Test&address1=123+Anywhere+St.&address2=&city=Seattle&state=WA&address_country=USA&zip=98101&night_phone_b=1234567890&item_name_1=Magnetic+Cross&on1_1=Metal&os1_1=%3B&item_number_1=mc-s-59&quantity_1=1&amount_1=75&

Any help would be appreciated.

EDIT: Put the Feb. 25 code back in: the option to pay without PayPal fields populate with alt shipping address as billing address (also not the correct ship to address - just an alt that was not selected). Then I followed it into PayPal: It also loads the same incorrect ship to record rather than the default in my database which is the one I chose.

Also, my products are items with sometimes 4 attributes. I only see one attribute name in the cart load without a value. So if the attribute is Metal and the value is Sterling Silver, I see "Metal ()," and that's it.
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on May 30, 2009, 00:54:32 AM
I ended up switching the if / then programming for the shipping and got the two to reverse successfully. I don't have the billing info pre-populated in the credit card area when the purchase is not the default, but that's ok.

Still need help with the full attribute info inclusion.
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on May 31, 2009, 19:05:36 PM
Further testing update.

I added another ship to address. Now the billing and shipping address is the previous ship to address and not the one selected.

For example:

I am the shopper and my ship to is address #1
I have another shipping address - address #2

I select address #1, Paypal shipping and cc billing showed address #2 -- wrong

switched programming, loads #1 in both places -- correct
selected address #2, PayPal shipping correct, cc billing blank -- close enough

added address #3 and selected for shipping.
PayPal shipping and CC billing show address #2 -- wrong
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on June 01, 2009, 16:00:50 PM
Update on attribute inclusion:

I have around 4 attributes per product. I get the attribute name for the first attribute and the attribute value for the last attribute, but nothing in between.
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on June 02, 2009, 22:10:17 PM
Update on billing / shipping:

Commented out that part of the code.

Now when looking at the Account Maintenance area, Alt shipping Name only replaces default, address variables correct. If delete alt shipping info, default name shows.
Title: Re: Send Product Name and Attributes to Paypal
Post by: martin09 on June 03, 2009, 04:30:10 AM
I tried to use the code with its modifications and testing it with sandbox, everything goes well but when I change it to live URL: https://www.paypal.com/cgi-bin/webscr, I get the following error.
===========
Error Detected

The seller accepts encrypted website payments only. You cannot pay the seller through un-encrypted buttons. Please contact your seller for more details.

===============

Do you know what is causing this problem? I appreciate any help
Title: Re: Send Product Name and Attributes to Paypal
Post by: hellodave on June 03, 2009, 07:01:22 AM
I think that is a setting in your paypal profile.
Go to My Account > Profile > Website Payment Preferences
Check off next to "Block Non-encrypted Website Payment".
If it is already off then I dunno  :-\
Title: Re: Send Product Name and Attributes to Paypal
Post by: fire2 on June 03, 2009, 17:03:41 PM
Hi there,
   I tried using the last code posted by virtuemart_craig in the sandbox mode and it works pretty good but I'm facing two issues:

- The order status does not update to "confirmed" after successful payments
- The PayPal fee/discount (-3.5% in my case) is not being sent to PayPal, it is not included in the Total Amount when you are redirected to PayPal even though it is included through the checkout until you click Confirm Order and you are redirected to PayPal.

Does anyone know how to fix these issues? I am running a live site and just switched to test mode to see if this code was better but if I can't get the payment method fee i'll have to switch back to the default code.

Does anyone really know how to fix the problem of the order status not updating? I've seen so many topics about this, but nobody has the answer... I found a solution in this forum: http://forum.virtuemart.net/index.php?topic=27261.0 but it is for VM 1.0 and I don't know if this will work in VM 1.1

Thanks in advance.
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on June 05, 2009, 21:15:45 PM
Hi Yosia,

I get confirmed status, but never in sandbox. Has to do with the notify.php. So, if your site is live, did you by chance use htaccess to lock down your administrator directory? If so, you need to allow the notify.php file.

I can't remember but I think my discount was showing up in the preview in PayPal, but my receipt from PayPal does not list it separate but just a reduced subtotal.

New problem for me:

My VM customer receipt is fine.
My PayPal customer receipt shows Subtotal, Tax and Payment, but no Shipping or Handling. - I would like to see either Shipping or Handling...
My PayPal business transaction details shows Subtotal and tax, but puts my "shipping and handling" into "handling" and no shipping fee - and I want it put into "shipping" and no "handling" fee.

I read this post http://forum.virtuemart.net/index.php?topic=46397.0 (http://forum.virtuemart.net/index.php?topic=46397.0) and see the problem, but in my case, and the auditors, PayPal and VM and Quickbooks need to agree. But 2 out of 3 isn't bad!
Title: Re: Send Product Name and Attributes to Paypal
Post by: fire2 on June 06, 2009, 00:05:43 AM
Hi helenb, thankyou for your response.
I haven't used an .htaccess to lock down the administrator directory. Somehow I thought in the sandbox mode the status should also update to confirmed, but it didn't. With the default notify.php file and the default paypal config it didn't update either.
One thing is clear, the payment method fee is not being sent to PayPal. PayPal is only charging for the subtotal and shipping handling, but not the 3.5% fee i configured to the PayPal payment method. I attach the screenshots so you can see it clearer.

Greetings.

[attachment deleted by admin]

[attachment cleanup by admin]
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on June 06, 2009, 00:58:11 AM
The paypal sandbox fix to get the notify to work never worked for me. So I used the sandbox IPN checker and it passed.

I don't think there is a line of code to cover the PayPal fee. And I don't know enough to create one for you.   :(
Title: Re: Send Product Name and Attributes to Paypal
Post by: fire2 on June 06, 2009, 04:57:17 AM
Virtuemart_craig or Ajredding, do any of you know what line covers the payment fee/discount or where it should be?
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on June 06, 2009, 14:15:18 PM
yosia, my best guess after reading this very useful page https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables (https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables) is that you would have to pull the value and add it in this line
"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),
as you can see it takes the discount off the total. If you know the call for the fee, you might be able to add it after the discount, but I don't think it can be listed on a separate line in PayPal after consulting that page referenced above, just as the discount cannot.

But I'm the blind leading the blind here.  8)
Title: Re: Send Product Name and Attributes to Paypal
Post by: fire2 on June 06, 2009, 23:36:24 PM
I don't necessarily need that fee/discount to be in another line. I just want PayPal to charge it, because this config for the PayPal payment method is not charging it. The default PayPal gateway in VM 1.1.3 includes that fee to the "Item Total" and then shows the "Shipping and Handling" in another line. That's fine for me, but I liked the idea of PayPal showing you the products you ordered and their price, as this code does. So I just want PayPal to charge that fee even if it is not shown in another line.

And, where should I add this line? Does it matter?

Thanx.
Title: Re: Send Product Name and Attributes to Paypal
Post by: joannah on August 04, 2009, 09:17:46 AM
Hi
I have asked this question tons of times. 

How can I add the short description to show up on the paypal receipt as this is to be used as an E-ticket? Or what are my alternatives!?

This is urgent I am about to get in a lot of strive if we don't get an answer soon,
thanks in advance to any help at all!
Jo
Title: Re: Send Product Name and Attributes to Paypal
Post by: helenbn on August 04, 2009, 13:16:14 PM
By PayPal receipt, do you mean the email that PayPal issues to the customer? or do you mean the top of the Payment page you hit once you leave the store site?
Title: Re: Send Product Name and Attributes to Paypal
Post by: undersun on November 29, 2009, 02:12:23 AM
Quote from: martin09 on June 03, 2009, 04:30:10 AM
I tried to use the code with its modifications and testing it with sandbox, everything goes well but when I change it to live URL: https://www.paypal.com/cgi-bin/webscr, I get the following error.
===========
Error Detected

The seller accepts encrypted website payments only. You cannot pay the seller through un-encrypted buttons. Please contact your seller for more details.

===============

Do you know what is causing this problem? I appreciate any help

Yes, log into your paypal acc't, and under "profile," then "website payment preferences," change the "Encrypted Website Payments" setting from "Block Non-encrypted" to "Website Payment" OFF.  That should do it!
Title: Re: Send Product Name and Attributes to Paypal
Post by: hotelathome on December 07, 2009, 03:38:46 AM
Is there anyone that might be able to help me with this?
http://forum.virtuemart.net/index.php?topic=63776.0
I just want my paypal customers to see the same thing that they do at check-out and when they loggin to look at their orders.

I want them to see the order number

I want them to see the item descriptions with the price including tax.

I want them to be able to see the discount they recieved (as a total amount).
My discounts come off the whole order (but not the shipping) and this then reduces the amount of tax paid too.

I want them to see the shipping costs including tax

I want it to all add up to the same amount they were shown at checkout and then have the tax component shown at the bottom.

eg:

1 x shoe (inc tax)  $10.00
1 x book (inc tax)  $70.00
subtotal (inc tax)  $80.00
less 10% discount
                  - $8.00
shipping (inc tax)  $10.00
TOTAL    (inc tax)  $82.00
tax paid             $6.54

my items and my shipping include 10% tax.

I have altered my paypal extra so that it just shows the total amount paid in full and nothing else as it was the only fix I came accross that at least made the amounts the same as the checkout.
I would love to know how to fix this.
I dont know enough about coding to combine the best bits from each, but I know I am so close to finding a solution.

******SOLVED FOR ME AT LEAST*******
From this website
http://www.exps.ca/solutions
My situation is a little different from the solutions available from here, but if you send Micah a message, he is sure to help you.
if you click on solutions/virtuemart, you may even find the fix already done for you.
Title: Re: Send Product Name and Attributes to Paypal
Post by: tracer on December 14, 2009, 21:58:28 PM
wow .. I just about have this working .. you folks that've posted code .. THANK YOU

I think I've compiled all the updates that've been in this post -- including the order status getting updated correctly

i had/have 2 outstanding problems
1.) the code that's been here (not sure how old) didn't have an "item_name" param, to sand to paypal -- seems more to be used as an order description. I found it, and added it back .. but what i'd really like is a way to concatenate item#'s into the string .. i can probably figure that out

2.) tax! .. tax seemed to be applied twice. i don't have "Show "(including XX% tax)" when applicable?" enabled, it was correct on the order in VM, but when it got to paypal, tax was totaled into the item AND as a line item -- i can't find why!?!? arghhh

I have Joomla 1.5.15 and VM 1.1.4

here's my code .. any help? (for now .. I had to revert to the default paypal code .. which is sooo lacking .. agkkk!)

<?php
$url 
"https://www.paypal.com/cgi-bin/webscr";
$order_id $db->f("order_id");
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  

// Query for Order Items
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

// Query to get User Info
$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
  
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
  if(
$discount_totalCP 0) {
    
$disc_perItem round($discount_totalCP $t_quantity2);
  }
  else {
    
$disc_perItem 0;
  }
}
else {
  
$disc_perItem 0;
}

while(
$dboi->next_record()) {

  
$prod_attrib $dboi->f("product_attribute");
  
$supp_var['item_name_' $i] = strip_tags("Order #"$db->f("order_id").": "$dboi->f("order_item_name"));
  
  if(
$prod_attrib ''){
    
$attributes_array explode('<br/>',$prod_attrib);
    
$v 0;
    
$z 1;
    foreach ( 
$attributes_array as $attributes_value){
      
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
      
$supp_var['on' $z '_' $i] = $attrib_name;
      
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value':')), ""02));
      
$supp_var['os' $z '_' $i] = $attrib_sel;
      
$v++;
      
$z++;
      unset(
$attributes_value);
    }
  }

  
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
  
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
  
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
  
$i++;
}
//End New Code


//Start New Code - Ship to Address Versus Bill To Address

//Query used to compare Bill to versus Shipp to address
$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$first_name $dbb->f("first_name");
  
$last_name $dbb->f("last_name");
  
$address1 $dbb->f("address_1");
  
$address2 $dbb->f("address_2");
  
$city $dbb->f("city");
  
$state $dbb->f("state");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else {
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

// Builds array for the form
$post_variables = Array(
"cmd" => "_ext-enter",
"redirect_cmd" => "_xclick",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"receiver_email" => PAYPAL_EMAIL,
"item_name" => "AWEBand.com ".$VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_NUMBER').": "$db->f("order_id"),
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"invoice" => $db->f("order_number"),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip,
"night_phone_b" => $H_PhoneNumber,

"cpp_header_image" => $vendor_image_url
);

if( 
$page == "checkout.thankyou" ) {
  
$query_string "?";

  foreach( 
$post_variables as $name => $value ) {
    
$query_string .= $name"=" urlencode($value) ."&";
  }

  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      
$query_string .= $name"=" urlencode($value) ."&";
    }
  }

  
vmRedirect$url $query_string );

else {
  echo 
'<form action="'.$url.'" method="post" target="_blank">';

  foreach( 
$post_variables as $name => $value ) {
    echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
  }
  
  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
    }
  }
  echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
  echo 
'</form>';
}
?>
Title: Re: Send Product Name and Attributes to Paypal
Post by: MacAcer on January 19, 2010, 13:29:49 PM
Is there a complete working "PayPal Extra info" code out there? It works out of the box, but the customer doesn't get any accurate info with PayPal, just charged for the same amount. It would be nice if the customer could get an accurate receipt with paypal, including item, shipping and tax cost.

I am sure that tons of smart people already worked this out. Could anyone be so kind to share this code with a less enlightened one? :)

Thank you in advance!
Title: Re: Send Product Name and Attributes to Paypal
Post by: Seiko on April 16, 2010, 05:50:46 AM
I struggled a lot.
It was really pain working with paypal documents, sandbox and live server.
The sandbox or live server doesn't always behave as their documents.
Well, I think I finally nailed working condition script.
At least, as my test, it worked. But it doesn't guarantee it works for you.
Please always backup your original code and test on the sandbox (even it seems sometimes the sandbox and live server don't act as the same way).
I thank a lot to this topic's contributers and hope my script helps others.

- Seiko

[attachment cleanup by admin]
Title: Re: Send Product Name and Attributes to Paypal
Post by: scothern99 on April 28, 2010, 23:37:19 PM
This doesn't pass the Shipping zip code.  Plus it does actually add the tax to the product amount.
Title: Re: Send Product Name and Attributes to Paypal
Post by: scothern99 on April 29, 2010, 18:50:28 PM
Sorry, I was really tired.  The tax thing is a different issue with VM altogether and may be a config issue on my part.  But what I'm seeing, is after adding this most recent code to the paypal extensions in the VM admin, it works on the store side and goes to PayPal alright, but paypal is asking me to enter the zip code to verify the total.  The customer would then have to enter it again.  Is this not right because I do not remember ever having to do this before.
Title: Re: Send Product Name and Attributes to Paypal
Post by: Seiko on April 30, 2010, 04:22:05 AM
Hi scothern99,

Are you using the code I posted?
If so, is your paypal address and VM ship_to address match exactly?
Have you tested the code with PayPal sandbox?

- Seiko
Title: Re: Send Product Name and Attributes to Paypal
Post by: scothern99 on April 30, 2010, 16:26:00 PM
Yes sir I am.  I'm using my wifes paypal login to test and the address is the same exactly.  I'm not using the sandbox due to the variences in the sandbox and live.  I've tested sandbox before that doesn't work when live so I'm just testing live and canceling the order before processing it at paypal.
Title: Re: Send Product Name and Attributes to Paypal
Post by: Seiko on May 01, 2010, 00:41:29 AM
Hi scothern99,

I totally agree with there are variances in the sandbox and the live paypal server (and also their documents).
So that it's too difficult to find the causes.
But if you try with the sandbox first, we can still catch some issues.
I'm sorry that I can't give you much help since I can't ask detailed information about real paypal seller/buyer accounts.
I wish you good luck!

- Seiko
Title: Re: Send Product Name and Attributes to Paypal
Post by: scothern99 on May 01, 2010, 03:11:45 AM
I'm not sure what you mean about asking information about seller accounts.  I'm not sure any of that information would matter.  Its info being passed to paypal thats not right.  That shouldn't have anything to do with a seller account.  Before I found your PHP script, I tried a couple of the earlier ones.  Yours so far is the only one that is doing this.  This is happening before I even attempt to login to paypal, on the order info screen that is first displayed, above the sign-in form..
Title: Re: Send Product Name and Attributes to Paypal
Post by: Seiko on May 01, 2010, 15:19:48 PM
See 'Using Your PayPal Account Profile' (https://www.x.com/docs/DOC-1358)
and read 'Displaying the Shipping Charges that PayPal Calculates During Checkout'.
Is this happening to you?
PayPal account profile does matter for the PayPal behaviors.
Hope this helps you.
Title: Re: Send Product Name and Attributes to Paypal
Post by: scothern99 on May 01, 2010, 16:35:40 PM
I guess that would make sense, if we weren't passing this info to paypal from VM.  That info all appeared to relate to "payapl" shopping carts.  We don't have anythign set-up in paypal to handle shipping or anything because its all being passed to paypal via the API.

I know this has nothing to do with my account for certain.  See we have a store already up and running that uses paypal standard this same way.  Only difference is I didn't have to paste this stuff into a setting like in VM.  It doesn't prompt for again for the zip code so I know this has to do with the code that is in your PHP script.  I do not know PHP but I know someone who does, perhaps he will address this for me.
Title: Re: Send Product Name and Attributes to Paypal
Post by: Seiko on May 01, 2010, 20:51:21 PM
I'd very much welcome somebody can address/fix the issues in my code.
That is the one reason, I posted it here.

As I learned from previous contributer's posts and paypal developer site, '_cart' PayPal HTML variable is required to pass additional information to the PayPal.
Original virtuemart PayPal extra payment info code is using '_xclick' instead, and it works fine without problems.
So your problem must be related with using '_cart' and/or other variables in the code though...
I don't have any more clue since I'm not having same problem. ???

Title: Re: Send Product Name and Attributes to Paypal
Post by: scothern99 on May 08, 2010, 22:04:41 PM
I don't know either and it really isn't that big of a deal.  All the math appears right so if they have to verify their zip again, oh well.  Keep out the Fake spammers.
Title: Re: Send Product Name and Attributes to Paypal
Post by: nirajlama on May 14, 2010, 04:21:06 AM
I am using Paypal code submitted by ajredding earlier.
My problem is that the shipping and handling variable do not show up on the Payment Notification that I receive from Paypal. It is however included in the total. (See attachment)Curiously, I get to "insurance" shows up on the notification, which I can live without.
The shipping and handling variable but do show up on checkout on the Paypal page (see attachment#2).

The code I use:
*******************************************************************
<?php
$order_id = $db->f("order_id");

$dboi = new ps_DB;
$q_oi = "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num = $dboi->num_rows();

//New code Getting Cart Items
$auth = $_SESSION['auth'];
$cart = $_SESSION['cart'];
$t_quantity = 0;
$disc_perItem = 0;
$i=1;

$dbb = new ps_DB;
$q = "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

$url = "https://www.paypal.com/cgi-bin/webscr";
$tax_total = $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total = $db->f("coupon_discount") + $db->f("order_discount");  //New Code
$discount_totalCP = $db->f("coupon_discount") + $db->f("order_discount");

while($dboi->next_record()) {
        $t_quantity = $t_quantity + intval($dboi->f("product_quantity"));
}

$dboi = null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if($t_quantity > 0)
{
        if($discount_totalCP > 0)
        {
                $disc_perItem = round($discount_totalCP / $t_quantity, 2);
        }
        else
        {
                $disc_perItem = 0;
        }
}
else
{
        $disc_perItem = 0;
}

while($dboi->next_record()) {

    $prod_attrib = $dboi->f("product_attribute");
             
    $supp_var['item_name_' . $i] = strip_tags($dboi->f("order_item_name"));
    if($prod_attrib > ''){
      $attributes_array = explode('<br/>',$prod_attrib);
      $v = 0;
      $z = 1;
      foreach ( $attributes_array as $attributes_value){
        $attrib_name = trim(substr($attributes_value, 0, strpos($attributes_value, ':')), " ");
        $supp_var['on' . $z . '_' . $i] = $attrib_name;
        $attrib_sel = trim(substr_replace(substr_replace($attributes_value, "", 0, strrpos($attributes_value, ': ')), "", 0, 2));
        $supp_var['os' . $z . '_' . $i] = $attrib_sel;
        $v++;
        $z++;
        unset($attributes_value);
      }
    }
        $supp_var['item_number_' . $i] = $dboi->f("order_item_sku");
    $supp_var['quantity_' . $i] = $dboi->f("product_quantity");
    $supp_var['amount_' . $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
    $i++;
}
//End New Code

//Start New Code - Ship to Address Versus Bill To Address

$dboui = new ps_DB;
$q_oui = "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id = $dboui->f("order_info_id");

if($oui_id == $order_id){
  $first_name = $dbb->f("first_name");
  $last_name = $dbb->f("last_name");
  $address1 = $dbb->f("address_1");
  $address2 = $dbb->f("address_2");
  $city = $dbb->f("city");
  $state = $dbb->f("state");
  $address_country = $dbbt->f("country");
  $zip = $dbb->f("zip");
  $H_PhoneNumber = $dbb->f("phone_1");
}
else
{
  $first_name = $dboui->f("first_name");
  $last_name = $dboui->f("last_name");
  $address1 = $dboui->f("address_1");
  $address2 = $dboui->f("address_2");
  $city = $dboui->f("city");
  $state = $dboui->f("state");
  $address_country = $dboui->f("country");
  $zip = $dboui->f("zip");
  $H_PhoneNumber = $dboui->f("phone_1");
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),
"handling_cart" => sprintf("%.2f", $db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"image_url" => "https://www.darjeelingteaexclusive.com/images/mw_dte_logo.png",
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
"no_note" => "1",
//"email" => $dbb->f("user_email"),
"address_override" => "0",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip
);

if( $page == "checkout.thankyou" ) {
$query_string = "?";

foreach( $post_variables as $name => $value ) {
$query_string .= $name. "=" . urlencode($value) ."&";
}
if(is_array($supp_var) && count($supp_var)) {
        foreach($supp_var as $name => $value) {
                $query_string .= $name. "=" . urlencode($value) ."&";
                }
}

vmRedirect( $url . $query_string );
} else {
echo '<form action="'.$url.'" method="post" target="_blank">';

foreach( $post_variables as $name => $value ) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
if(is_array($supp_var) && count($supp_var)) {
        foreach($supp_var as $name => $value) {
                echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
                }
}
echo '<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
echo '</form>';
}
?>
***********************************

Further with each order I also get a mail on my Paypal registered email regarding Paypal IPN transaction. This comes from my own store's email. Many times even when there are no problems in receiving payments, the Paypal IPN transaction notifies errors. A recent example:

Subject: PayPal IPN Transaction on your site: Possible fraud‏
Error code 506. Possible fraud. Error with REMOTE IP ADDRESS = 216.113.188.202.
                        The remote address of the script posting to this notify script does not match a valid PayPal ip address

            These are the valid IP Addresses: 66.211.169.2,
66.211.169.65,
64.4.241.33,
64.4.241.49,
66.211.170.66,

           
            The Order ID received was: 141
******************************************
There was actually no problem with order ID 141.

Can someone please help me?
Why does the shipping and handling variable do not show in the payment notification?
How can I remove the variable insurance?
Why are some of the order generating IPN errors?

Thank you for your time.

[attachment cleanup by admin]
Title: Re: Send Product Name and Attributes to Paypal
Post by: stinga on May 14, 2010, 08:49:38 AM
G'day

[cpde]
Further with each order I also get a mail on my Paypal registered email regarding Paypal IPN transaction. This comes from my own store's email. Many times even when there are no problems in receiving payments, the Paypal IPN transaction notifies errors. A recent example:

Subject: PayPal IPN Transaction on your site: Possible fraud‏
Error code 506. Possible fraud. Error with REMOTE IP ADDRESS = 216.113.188.202.
                        The remote address of the script posting to this notify script does not match a valid PayPal ip address

            These are the valid IP Addresses: 66.211.169.2,
66.211.169.65,
64.4.241.33,
64.4.241.49,
66.211.170.66,


Either all the ip address to the list of valid one, making sure it is a paypal ip :-) or fix the thing forever by comparing against the paypal domain name and not the ip address's.

I don't understand you problem, those two screen shots don't match at all, should they?

I don't see where you re setting your shipping info to send to PP.

Have a look at
http://forum.virtuemart.net/index.php?topic=59668.msg199060#msg199060
That might help a bit.
I have posted my extra info on th site somewhere and I get options + all the relevant data to make it look nice.
Title: Re: Send Product Name and Attributes to Paypal
Post by: nirajlama on May 14, 2010, 16:15:36 PM
Thank you Stinga for your response.
I tried your extra info but it did not post the shipping and handling charges on checkout.
I am not able to follow your instructions: "Either all the ip address to the list of valid one, making sure it is a paypal ip :-) or fix the thing forever by comparing against the paypal domain name and not the ip address's."
Where can I make this fix?
About the snapshots I had posted: no they were not supposed to match. I was just showing that while Shipping and Handling charges do get posted on Paypal while checking out, it is missing in the Payment Notification. However, the total sum does include the Shipping Handling charges.
Title: Re: Send Product Name and Attributes to Paypal
Post by: stinga on May 14, 2010, 19:59:27 PM
G'day I have not read the whole thread, is this PayPal Pro or PayPal?
I am surprised it did not work, but maybe I have added some other bits.

If you want, you can point your paypal url to www.recovery-cd-disk.com/cgi-bin/data_dump.pl and it will dump out to your screen what you are sending to PayPal, you could then post that back here, that might show us what is going on.

Also this was for VM 1.1.2 maybe there is a difference for 1.1.4
Title: Re: Send Product Name and Attributes to Paypal
Post by: nirajlama on May 15, 2010, 19:22:28 PM
Sorry for delay in reverting back to you Stinga.
I am using the normal PayPal account and VM 1.1.3
I tried to use the url that you had sent to verify the data transfer. But I cannot open the page. Could it be because I am testing on localhost? 
Title: Re: Send Product Name and Attributes to Paypal
Post by: stinga on May 17, 2010, 19:30:19 PM
If PayPal works, then so should that URL, it just changes the the destination so that you can see what is being sent to PayPal. Did you gat an error message?
Title: Re: Send Product Name and Attributes to Paypal
Post by: nirajlama on May 17, 2010, 21:18:49 PM
Sorry Stinga...had forgotten to add "http://" before the url. I have pasted the required info below. But just to recap my issue before that: Shipping & Handling cost is reflected in the Paypal checkout page, but not in the Paypal payment notification.


Information passed to this script
Environment

SCRIPT_NAME=/cgi-bin/data_dump.pl
SERVER_NAME=www.recovery-cd-disk.com
HTTP_REFERER=http://localhost/joomla15/index.php?page=checkout.index&payment_method_id=4&ship_to_info_id=8d8d84e6406b49fce2a37c5733992e3f&shipping_rate_id=standard_shipping%257CFedEx%257C1%2Bweek%252C%2BZoneG%257C29.00%257C24&checkout_stage=4&option=com_virtuemart&Itemid=1
SERVER_ADMIN=domain@squangle.net
HTTP_ACCEPT_ENCODING=gzip,deflate
HTTP_CONNECTION=keep-alive
REQUEST_METHOD=GET
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
SCRIPT_URI=http://www.recovery-cd-disk.com/cgi-bin/data_dump.pl
SCRIPT_FILENAME=/home/www/recovery-cd-disk.com/cgi-bin/data_dump.pl
SERVER_SOFTWARE=Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.3 with Suhosin-Patch proxy_html/3.1.2 mod_perl/2.0.4 Perl/v5.10.0
HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7
QUERY_STRING=cmd=_cart&redirect_cmd=_ext-enter&upload=1&business=whereismary%40hotmail.com&receiver_email=whereismary%40hotmail.com&invoice=65_304d207020db88ab39cb8741ee0b6&amount=280&shipping_1=29.00&currency_code=USD&address_override=0&first_name=niraj&last_name=lama&address1=234+howell&address2=&zip=14103&city=medina&state=NY&country=US&email=niraj%40darjeelingteaexclusive.com&night_phone_b=5354678&return=%2Fjoomla15%2Findex.php%3Foption%3Dcom_virtuemart%26page%3Dcheckout.result%26order_id%3D139&notify_url=%2Fjoomla15%2Fadministrator%2Fcomponents%2Fcom_virtuemart%2Fnotify.php&cancel_return=%2Fjoomla15%2Findex.php%3Foption%3Dcom_virtuemart%26page%3Dcheckout.result%26order_id%3D139&undefined_quantity=0&test_ipn=0&pal=%3F%3F%3F%3F&no_shipping=1&no_note=1&item_name_1=Order+%23139%3A+Moonbeam&on1_1=-&os1_1=1kg%2C+2.2lb%3B&item_number_1=FF10_4a&quantity_1=1&amount_1=280&
REMOTE_PORT=1184
HTTP_USER_AGENT=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.1
SERVER_PORT=80
SERVER_SIGNATURE=
Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.3 with Suhosin-Patch proxy_html/3.1.2 mod_perl/2.0.4 Perl/v5.10.0 Server at www.recovery-cd-disk.com Port 80


HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5
REMOTE_ADDR=72.75.195.73
HTTP_KEEP_ALIVE=115
SERVER_PROTOCOL=HTTP/1.1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
REQUEST_URI=/cgi-bin/data_dump.pl?cmd=_cart&redirect_cmd=_ext-enter&upload=1&business=whereismary%40hotmail.com&receiver_email=whereismary%40hotmail.com&invoice=65_304d207020db88ab39cb8741ee0b6&amount=280&shipping_1=29.00&currency_code=USD&address_override=0&first_name=niraj&last_name=lama&address1=234+howell&address2=&zip=14103&city=medina&state=NY&country=US&email=niraj%40darjeelingteaexclusive.com&night_phone_b=5354678&return=%2Fjoomla15%2Findex.php%3Foption%3Dcom_virtuemart%26page%3Dcheckout.result%26order_id%3D139&notify_url=%2Fjoomla15%2Fadministrator%2Fcomponents%2Fcom_virtuemart%2Fnotify.php&cancel_return=%2Fjoomla15%2Findex.php%3Foption%3Dcom_virtuemart%26page%3Dcheckout.result%26order_id%3D139&undefined_quantity=0&test_ipn=0&pal=%3F%3F%3F%3F&no_shipping=1&no_note=1&item_name_1=Order+%23139%3A+Moonbeam&on1_1=-&os1_1=1kg%2C+2.2lb%3B&item_number_1=FF10_4a&quantity_1=1&amount_1=280&
GATEWAY_INTERFACE=CGI/1.1
SERVER_ADDR=91.197.33.52
HTTP_AUTHORIZATION=
SCRIPT_URL=/cgi-bin/data_dump.pl
DOCUMENT_ROOT=/home/www/recovery-cd-disk.com
HTTP_HOST=www.recovery-cd-disk.com

These Form-variables exists

redirect_cmd=_ext-enter
shipping_1=29.00
state=NY
night_phone_b=5354678
email=niraj@darjeelingteaexclusive.com
receiver_email=whereismary@hotmail.com
os1_1=1kg, 2.2lb;
business=whereismary@hotmail.com
item_number_1=FF10_4a
cmd=_cart
currency_code=USD
test_ipn=0
zip=14103
invoice=65_304d207020db88ab39cb8741ee0b6
address1=234 howell
no_shipping=1
last_name=lama
city=medina
address_override=0
no_note=1
on1_1=-
upload=1
pal=????
quantity_1=1
country=US
item_name_1=Order #139: Moonbeam
cancel_return=/joomla15/index.php?option=com_virtuemart&page=checkout.result&order_id=139
notify_url=/joomla15/administrator/components/com_virtuemart/notify.php
address2=
return=/joomla15/index.php?option=com_virtuemart&page=checkout.result&order_id=139
undefined_quantity=0
amount=280
amount_1=280
first_name=niraj




Title: Re: Send Product Name and Attributes to Paypal
Post by: stinga on May 18, 2010, 08:28:34 AM
G'day,
I will need to have a look and see what is wrong with shipping, but I can see that the cancel_return, return and notify_url are not going to work. They need http://<domain name>/

Have you got your PP account setup correctly. I think you can tell PP to apply it's shipping charges, in which case it might be ignoring what you send.

There is also something wrong with on_1 and os_1 these are related (somehow)
Title: Re: Send Product Name and Attributes to Paypal
Post by: nirajlama on May 18, 2010, 17:44:35 PM
Hi Stinga,
Thanks for the suggestions.
However, even without the domain my cancel_return url works fine. To be sure is this not the Paypal button that says "Cancel Order and Return to Store"?
I have looked around in my Paypal account. As far as I can see I have not activated Paypal Shipping. For my default Shipping Carrier in Paypal I have "no preference."
I am very grateful for your time.
Title: Re: Send Product Name and Attributes to Paypal
Post by: joepr on June 16, 2010, 07:54:27 AM
Hello everyone,
I have been looking for this modification however my site site do not required to have the item shipped. Does this script is able to process and transfer all the required info except the shipping option?

Thanks in advance
Title: Re: Send Product Name and Attributes to Paypal
Post by: stinga on June 16, 2010, 18:07:36 PM
Paypal does not care if ship or not.
If you don't have shipping then the shipping will be zero.
Title: Re: Send Product Name and Attributes to Paypal
Post by: joepr on June 16, 2010, 21:27:16 PM
Hello Stinga,
Thanks for the reply hope you can help me with my problem. Im using Joomla Version 1.5.18 and VM 1.1.4 . I disable the shipping option on the site since My products don't need to be shipped. (Screen shot attached) how ever after adding the item to the cart and proceeding to the checkout option I got the following paypal (using sandbox for the moment) error

Unable to process payment. Please contact the merchant as the shipping address provided by the merchant is invalid, and the merchant has requested that your order must be shipped to that address. (see image for more details)

Do you or anyone have an idea how this could be solved?

Note: I'm using the code PayPal_payment_extra_info.php provided by seiko at page 4 Thanks!!

-UPDATE-
To solve my issue I change the option on the code
"address_override" => "1", to "address_override" => "0",

[attachment cleanup by admin]
Title: Re: Send Product Name and Attributes to Paypal
Post by: consolecustoms on August 17, 2010, 22:34:24 PM
First off a huge thank you to kontrolfreek and ajredding. I have been looking for this for a while and with a little modification is exactly what I needed.

Incase it will be usefull to others I modified the last entry from ajredding to better suit my needs but also to mainly allow it tow work properly with Coupons and tax. using the last posted code would produce incorrect values in paypal when using coupons and when tax was added.

Therefore I made the following changes:

changed
$supp_var['amount_' . $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);

to

$supp_var['amount_' . $i] = round($dboi->f("product_item_price"),2);

This removes the per item discouting. later I add in sending the total discount from VM to Paypal.



changes to information sent to paypal

// Builds array for the form
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
//"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
//"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),
"amount" => round( $db->f("order_subtotal"), 2),
//"handling_cart" => sprintf("%.2f", $db->f("order_shipping")),
"shipping_1" => sprintf("%.2f", $db->f("order_shipping")),
//"tax" => $tax_total,
"tax_cart" => $tax_total,
"discount_amount_cart" => $discount_total,
"invoice" => $db->f("order_number"),
//"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
//"no_note" => "1",


In here I have commented out the page style because I just a page style in paypal. even if you don't use one it iwll still default to the "paypal" style.

Commented the original "amount line" this is what causes issues with coupons and tax because it is taking a pre-calculated amount to paypal and then paypal tries to do its own calculations. the new amount value right below it only send the original product subtotal no tax, no discounts, no shipping.

commented out "handling_cart" and added in "shipping_1" this allows paypal to add in and display the shipping amount from VM correctly.

commented out the "tax" line as right below is is "tax_cart" and this is the one that is used by paypal when sending "cmd" => "_cart".

Added "discount_amount_cart" this will send paypal the total discount from VM.

Changed "invoice" from Order_id to order_number to resolve IPN coming back with "Order ID not found" error.

Also commented out "no_note" because I like for people to be able to leave a note.


by removing the per item discount calculations, changing the "amount" line, adding the "shipping_1" and "discount_amount_cart" it is sending all the raw order information to paypal and allowing paypal to do all the adding and subtracting. It will also show fields in paypal for the discount amount, tax and shipping just like in Virtuemart.

Here is the full code:

<?php
$url 
"https://www.paypal.com/cgi-bin/webscr";
$order_id $db->f("order_id");
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  

// Query for Order Items
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

// Query to get User Info
$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
  
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
  if(
$discount_totalCP 0) {
    
$disc_perItem round($discount_totalCP $t_quantity2);
  }
  else {
    
$disc_perItem 0;
  }
}
else {
  
$disc_perItem 0;
}

while(
$dboi->next_record()) {

  
$prod_attrib $dboi->f("product_attribute");
  
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name"));
  
  if(
$prod_attrib ''){
    
$attributes_array explode('<br/>',$prod_attrib);
    
$v 0;
    
$z 1;
    foreach ( 
$attributes_array as $attributes_value){
      
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
      
$supp_var['on' $z '_' $i] = $attrib_name;
      
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value':')), ""02));
      
$supp_var['os' $z '_' $i] = $attrib_sel;
      
$v++;
      
$z++;
      unset(
$attributes_value);
    }
  }

//  $supp_var['item_number_' . $i] = $dboi->f("order_item_sku");
  
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
  
$supp_var['amount_' $i] = round($dboi->f("product_item_price"),2);
  
$i++;
}
//End New Code


//Start New Code - Ship to Address Versus Bill To Address

//Query used to compare Bill to versus Shipp to address
$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$first_name $dbb->f("first_name");
  
$last_name $dbb->f("last_name");
  
$address1 $dbb->f("address_1");
  
$address2 $dbb->f("address_2");
  
$city $dbb->f("city");
  
$state $dbb->f("state");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else {
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

// Builds array for the form
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
//"page_style" => "primary",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
//"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),
"amount" => round$db->f("order_subtotal"), 2),
//"handling_cart" => sprintf("%.2f", $db->f("order_shipping")),
"shipping_1" => sprintf("%.2f"$db->f("order_shipping")),
//"tax" => $tax_total,
"tax_cart" => $tax_total,
"discount_amount_cart" => $discount_total,
"invoice" => $db->f("order_number"),
//"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
//"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip,
"night_phone_b" => $H_PhoneNumber
);

if( 
$page == "checkout.thankyou" ) {
  
$query_string "?";

  foreach( 
$post_variables as $name => $value ) {
    
$query_string .= $name"=" urlencode($value) ."&";
  }

  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      
$query_string .= $name"=" urlencode($value) ."&";
    }
  }

  
vmRedirect$url $query_string );

else {
  echo 
'<form action="'.$url.'" method="post" target="_blank">';

  foreach( 
$post_variables as $name => $value ) {
    echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
  }
  
  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
    }
  }
  echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
  echo 
'</form>';
}
?>



I hope this can help others out there as well.

Chris
Title: Re: Send Product Name and Attributes to Paypal
Post by: Foothill Web Design on September 07, 2010, 19:35:31 PM
Hi, just want to say thanks to everyone who contributed. This definitely needs to be part of the module itself, perhaps using a drop-down box to choose from several layout configurations.
Title: Re: Send Product Name and Attributes to Paypal
Post by: MacAcer on November 14, 2010, 18:37:31 PM
Thank you for the PayPal extra info. It fixed the coupon discount problem I had and it also come out nicely on the receipt on PayPal with all the products, tax, discount and shipping listed. I used the code that Chris posted here with the additional line provided by seiko to determine country_2_code for PayPal.

I have encountered one problem though. Now when the extra info seem to leave the tax calculation to PayPal it does not round off the amount to always match the amount in Virtuemart. This is both slightly disturbing and problematic as after payment, the order status will stay in "Pending" instead of "Payed".

In my test order which should have been 105,00 SEK, PayPal calculated it as 104,99 SEK. Is there a way to set it to round off the amount to nearest whole number - no decimals.

Provided the complete PayPal Exta info that I'm using.

<?php
$url 
"https://www.paypal.com/cgi-bin/webscr";
$order_id $db->f("order_id");
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  

// Query for Order Items
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

// Query to get User Info
$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
  
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
  if(
$discount_totalCP 0) {
    
$disc_perItem round($discount_totalCP $t_quantity2);
  }
  else {
    
$disc_perItem 0;
  }
}
else {
  
$disc_perItem 0;
}

while(
$dboi->next_record()) {

  
$prod_attrib $dboi->f("product_attribute");
  
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name"));
  
  if(
$prod_attrib ''){
    
$attributes_array explode('<br/>',$prod_attrib);
    
$v 0;
    
$z 1;
    foreach ( 
$attributes_array as $attributes_value){
      
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
      
$supp_var['on' $z '_' $i] = $attrib_name;
      
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value':')), ""02));
      
$supp_var['os' $z '_' $i] = $attrib_sel;
      
$v++;
      
$z++;
      unset(
$attributes_value);
    }
  }

//  $supp_var['item_number_' . $i] = $dboi->f("order_item_sku");
  
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
  
$supp_var['amount_' $i] = round($dboi->f("product_item_price"),2);
  
$i++;
}
//End New Code


//Start New Code - Ship to Address Versus Bill To Address

//Query used to compare Bill to versus Shipp to address
$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$first_name $dbb->f("first_name");
  
$last_name $dbb->f("last_name");
  
$address1 $dbb->f("address_1");
  
$address2 $dbb->f("address_2");
  
$city $dbb->f("city");
  
$state $dbb->f("state");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else {
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

// seiko - adding to determine country_2_code for PayPal
$db1 = new ps_DB();
$q "SELECT country_2_code FROM #__vm_country WHERE country_3_code='".$address_country."' ORDER BY country_2_code ASC";
$db1->query($q);
$country2code $db1->f('country_2_code');
//End New Code

// Builds array for the form
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
//"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
//"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),
"amount" => round$db->f("order_subtotal"), 2),
//"handling_cart" => sprintf("%.2f", $db->f("order_shipping")),
"shipping_1" => sprintf("%.2f"$db->f("order_shipping")),
//"tax" => $tax_total,
"tax_cart" => $tax_total,
"discount_amount_cart" => $discount_total,
"invoice" => $db->f("order_number"),
//"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"no_shipping" => "1",
//"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip,
"night_phone_b" => $H_PhoneNumber,
"cpp_header_image" => $vendor_image_url,
);

if( 
$page == "checkout.thankyou" ) {
  
$query_string "?";

  foreach( 
$post_variables as $name => $value ) {
    
$query_string .= $name"=" urlencode($value) ."&";
  }

  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      
$query_string .= $name"=" urlencode($value) ."&";
    }
  }

  
vmRedirect$url $query_string );

else {
  echo 
'<form action="'.$url.'" method="post" target="_blank">';

  foreach( 
$post_variables as $name => $value ) {
    echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
  }
  
  if(
is_array($supp_var) && count($supp_var)) {
    foreach(
$supp_var as $name => $value) {
      echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
    }
  }
  echo 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
  echo 
'</form>';
}
?>


Your help is much appreciated.

Title: Re: Send Product Name and Attributes to Paypal
Post by: Shibumi on February 09, 2011, 00:00:03 AM
Quote from: kontrolfreek on December 20, 2008, 08:12:49 AM
Now, that is how I set mine up, you might do yours different so I dont know if it will work the same or not.  Now for the code.

Go to store and list payment methods, click on the word paypal then on the configuration tab.  Here is my full code for the page and i will put a small clip under it and explain the 2 - from the attributes....

I take it this mod is only for the old PayPal setup? Does anyone know or has anyone tried this with the new PayPal API?
Title: Re: Send Product Name and Attributes to Paypal
Post by: Shibumi on February 13, 2011, 14:41:56 PM
Has anyone discovered if there are any extra variables that can be passed through the paypal API?