VirtueMart Forum

VirtueMart Dev/Coding Central: VM1 (old version) => Development Projects, Modifications, Hacks & Tweaks. VM1.1 => Payment Modules => Topic started by: Axel on October 26, 2006, 16:54:43 PM

Title: how to have cart items fully displayed in paypal with details
Post by: Axel on October 26, 2006, 16:54:43 PM
Here's the code I use i n order to have all items listed in the cart. It allows to have a fully described cart on many lines, and no more only one line with the total amount.

tax & tax_cart are both defined. I think only tax_cart is enough, I didn't take time to check that.
Off course, adapt the code to fit your needs!

I think it would be great if this code would be insert in a wiki or examples, or doc.


<?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] = $dboi->f("order_item_name");
    
$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.sandbox.paypal.com/cgi-bin/webscr";
$tax_total round($db->f("order_tax") + $db->f("order_shipping_tax"),2);
$discount_total $db->f("coupon_discount") + $db->f("order_discount");
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"business" => 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"),
"shipping" => sprintf("%.2f"$db->f("order_shipping")),
"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",

"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"),
"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) ."&";
}
}


mosRedirect$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>';

}
?>



Feel free to make any suggestions!
Axel
Title: Re: how to have cart items fully displayed in payp
Post by: nzeone on October 29, 2006, 02:16:03 AM
Thanks, Axel.
Where does it go?
Title: Re: how to have cart items fully displayed in paypal with details
Post by: MyMusicVid on November 09, 2006, 00:06:57 AM
nzeone

Go to Components/Virtuemart

Then Store/List Payment Methods. Click on Paypal, then on the configuration tab. Copy and paste the code above into that configuration screen. Save and that'll do it.

Note that the code above is set up to use the Paypal sandbox.
Title: Re: how to have cart items fully displayed in paypal with details
Post by: MyMusicVid on November 09, 2006, 00:10:18 AM
Oh, and Axel - thanks for this mod!
Title: Re: how to have cart items fully displayed in payp
Post by: Grady on December 07, 2006, 04:22:41 AM
Hey Axel,

First of all, let me say what you did here was awesome.

I have noticed a small problem, though.  Now my customized header/logo for PayPal doesn't appear.  I noticed it seems to have *something* to do with you using "cmd" => "_cart" instead of "cmd" => "_xclick"

I would be very happy if I could use your modification to show detailed items in PayPal and have my customized PayPal header/logo continue to show.

Any ideas?

Grady
Title: Re: how to have cart items fully displayed in paypal with details
Post by: Michael on December 07, 2006, 13:36:31 PM
Axel,

Awesome Script really Appreciate it I too have the Question about the _xclick?

Thansk Again
Title: Re: how to have cart items fully displayed in paypal with details
Post by: Eliyahna on February 09, 2007, 18:54:21 PM
Axl,

I tried this and it didn't work for me. Paypal came with an error saying missing information. I would be glad to pay you if you would consider helping me fix my cart?

http://www.torahwomen.com (http://www.torahwomen.com)
eliyahna@torahwomen.com
Title: Re: how to have cart items fully displayed in payp
Post by: Stephen Giguere on February 25, 2007, 13:38:48 PM
Hey Eliyahna,

In the example above Axel put

<pre>
$q = "SELECT * FROM jos_vm_user_info ";
</pre>

That's kind of slack.  He's assuming we all use the default 'jos' database prefix.  He should have stuck to the standard and used the line


<pre>
$q = "SELECT * FROM #__vm_user_info ";
</pre>

to keep it independent of the database being used.  You'll see the syntax used at the top for the original database query.  Stuff like this is annoying because it's just sloppy stuff that ends up costing people time.  If you're going to post stuff on the forum please make sure you don't cripple an otherwise excellent solution like this with hardcoded stuff like that. 

All that said...that code should be put in a glass case under armed guard if not made part of the standard VM release.  Great work.
Title: Re: how to have cart items fully displayed in paypal with details
Post by: salbini on September 17, 2008, 18:43:55 PM
I've changed the address from "https://www.sandbox.paypal.com/cgi-bin/webscr  to "https://www.paypal.com/cgi-bin/webscr and everything works great, logo included and everything else.

thanks, great suggestion