News:

Looking for documentation? Take a look on our wiki

Main Menu

Send Product Name and Attributes to Paypal

Started by kontrolfreek, December 20, 2008, 08:12:49 AM

Previous topic - Next topic

kontrolfreek

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.

kontrolfreek

just found out this code is not sending product discount to paypal AGH

kontrolfreek

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>';
}
?>

boruchsiper

This is exactly what I was looking for. Can you post the code with the  shipping info. Thanks

pkthunder

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?

brandonjp

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]

ajredding

#6
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]
RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com

nuwud

#7
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!
All your base are belong to us!

pashis

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

ajredding

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.
RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com

ajredding

#10
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:

  • Added "Item Number" (SKU) - This displays nicely in PayPal
  • Added code to detect if an alternate ship to address was used.  If it was used then it will transfer that to paypal automagically
  • I commented out the email variable.  My thought on this is that although the buyer has registered an email account on the site it might not be their paypal email address.  Or maybe they don't have a paypal account yet and they need to sign up?  So why force it in the fields?
  • Changed the "invoice" to use the Invoice number from VirtueMart instead of the MD5 code that was being used before (OK ONE NOTE ABOUT THIS YOU WILL NEED TO UPDATE THE NOTIFY.PHP SCRIPT TO REFLECT THIS CHANGE INFO AT BOTTOM OF POST)

Items that I'm going to tackle next:

  • Proper entry of phone number (although if this is transfered from VirtueMart to PayPal it will override what is entered into the PayPal account)  Thoughts on this?
  • Add into the config a spot to define custom checkout pages.  This is more of a advanced paypal users option but I figure if it's an option on PayPal it should be an option here.

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]
RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com

actionsprite

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

cinos

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?  :)


ajredding

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.
RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com