News:

Looking for documentation? Take a look on our wiki

Main Menu

Passing Cart Details to PayPal for Payment

Started by apex2apex, June 22, 2008, 19:32:50 PM

Previous topic - Next topic

apex2apex

I recently set up a new virtuemart cart and am using paypal for all payments.  Currently when users click "confirm order" and are sent to paypal, virtuemart only sends an order number along with the payment total.

How can I make virtuemart pass the cart details and not just a total price and order number?

john dowling


apex2apex

#2
I found this posted in another thread and its been working for me

copy everything below into the payment extra info box in the configuration tab for paypal
remember to edit the put-your-domain-here.com part


<?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);
$description = "PUT-YOUR-DOMAIN-HERE.COM";
$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_final_price"),2);
    $i++;
}

// "item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": ". $db->f("order_id"),

// insert paypal url here
$url = "https://www.paypal.com/cgi-bin/webscr";

$tax_total = $db->f("order_tax") + $db->f("order_shipping_tax");
$post_variables = Array(
    "cmd" => "_cart",
    "upload" => "1",
    "business" => PAYPAL_EMAIL,
    "receiver_email" => PAYPAL_EMAIL,
    // "item_name_1" => "Basket total for your order: ". $db->f("order_id"),
    "order_id" => $db->f("order_id"),
    "invoice" => $db->f("order_number"),
    // "amount_1" => round( $db->f("order_subtotal")+$tax_total, 2),
    "shipping_1" => sprintf("%.2f", $db->f("order_shipping")),
    "currency_code" => $_SESSION['vendor_currency'],
    "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" => "",
    "no_shipping" => "1",
    "no_note" => "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>';

}

?>


john dowling

I just noticed that this does work but I am now not getting any sales tax charges sent to paypal?

apex2apex

there's a line that shows
// "amount_1" => round( $db->f("order_subtotal")+$tax_total, 2),

try removing everything before the "amount in that line and see if that works.

stevevm

Same for me no tax

I change
// "amount_1" => round( $db->f("order_subtotal")+$tax_total, 2),
to
"amount_1" => round( $db->f("order_subtotal")+$tax_total, 2),


Have you any idea what parameter I should  changed to make possible taxes on paypal.

Thx


MrBoza

Guys are you tell me that this code displays the product name?
How can it be if the line  $db->f("order_id"), actually calles for the order number...
Iwas hoping to dislay a list of product names and the shipping cost...

any idea?

Thanks