VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Payment VM 1.1 => PayPal / PayPal Pro VM 1.1 => Topic started by: filterit on June 16, 2008, 19:43:36 PM

Title: PayPal UK and order Item details (Code attached)
Post by: filterit on June 16, 2008, 19:43:36 PM
Found this code in the 1.0.X part of the site.  Tried it but got error that some required fields were missing.
Going through the PayPal API document to see what is missing

Any one had any job at getting items sent through to the UK?


<?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 "your shop";
$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 this one uses the uk sand box
$url "https://www.paypal.com/uk/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'],
"email" => $dbbt->f('user_email'),
"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" => $user->state,
"country" => $dbbt->f('country'),
"night_phone_c" => $dbbt->f('phone_1'),
    
"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" => "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>';

}

?>
Title: Re: PayPal UK and order Item details (Code attached)
Post by: khawaib on June 17, 2008, 13:35:12 PM
Hi,

Try these two as they are working for me.

This one passes multiple items to paypal page so user can see all items. But I am having problem with it when user returns back to site they are sent to home page instead of thank you page.
<?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.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,
"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"),
"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) ."&";
}
}

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


This one show one total for all items but user are sent back to thank you page properly.
<?php
$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" => "_xclick",
"business" => PAYPAL_EMAIL,
"receiver_email" => PAYPAL_EMAIL,
"item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": "$db->f("order_id"),
"order_id" => $db->f("order_id"),
"invoice" => $db->f("order_number"),
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"shipping" => sprintf("%.2f"$db->f("order_shipping")),
"currency_code" => $_SESSION['vendor_currency'],
"first_name" => $dbbt->f('first_name'),
"last_name" => $dbbt->f('last_name'),
"address_street" => $dbbt->f('address_1'),
"address_zip" => $dbbt->f('zip'),
"address_city" => $dbbt->f('city'),
"address_state" => $dbbt->f('state'),
"address_country" => $dbbt->f('country'),
"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" => "1"
);
if( 
$page == "checkout.thankyou" ) {
$query_string "?";
foreach( $post_variables 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."\" />\n";
}
echo '</form>';
}
?>


I also have discovered that testing with Sandbox does not provide confirmation for order status. Hope this helps.

Ahmed
Title: Re: PayPal UK and order Item details (Code attached) - country codes
Post by: cvoogt on July 23, 2008, 23:54:42 PM
Thanks for the code. I've used it and have extended it to select the 2-character VM country code rather than the 3-digit one. I had problems with the shipping address not being passed to PayPal ... it just defaulted to United States. I looked at the source HTML for the PayPal page, and they use "country_code" as the variable (in my case anyway) and expect a 2 (not 3) character country code, so I set both "country" and "country_code" variables to the 2-character country code from VM's database.

I am using US PayPal so you may need to change the payment URL.

Here's the code:

<?php
$dbcountrytemp 
$dbbt->f('country');
$dboic = new ps_DB;
$q_oic "SELECT country_2_code FROM #__vm_country ";
$q_oic .= "WHERE #__vm_country.country_3_code='$dbcountrytemp'";
$dboic->query($q_oic);
$row_numc $dboic->num_rows();
while(
$dboic->next_record()) {
 
$usercountry $dboic->f("country_2_code");
}

$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();
$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++;
}
//if(($user->country != 'USA') && ($user->country != 'Canada')){
if(($dbbt->f('country') != 'USA') && ($dbbt->f('country') != 'CAN')){
//$surcharge = '20';
 
$supp_var['item_name_' $i] = "International Postage Supplement";
    
$supp_var['quantity_' $i] = "1";
    
$supp_var['amount_' $i] = "20.00";
}
// "item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": ". $db->f("order_id"),

// insert paypal url here this one uses the us one
$url "https://www.paypal.com/us/cgi-bin/webscr";

$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$post_variables = Array(
    
"cmd" => "_cart",
    
"upload" => "1",
    
"business" => "your@email.com",
    
"receiver_email" => "your@email..com",
    
// "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'],
"email" => $dbbt->f('user_email'),
"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" => $user->state,
//"country" => $dbbt->f('country'),
        
"country" => $usercountry,
        
"country_code" => $usercountry,
"night_phone_c" => $dbbt->f('phone_1'),
        
"H_PhoneNumber" => $dbbt->f('phone_1'),
    
//"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" => "4UXZK24C297M6",
    
"no_shipping" => "0",
    
"no_note" => "0"
);
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: PayPal UK and order Item details (Code attached)
Post by: pravin_bluebird on November 06, 2008, 12:37:04 PM
Any solution
for having
both facility together.....

when i use multiple items to paypal it do not let me on the page which i provide in "return"...it redirects to home page.....

and when i user the default code it do not include all items information.....

i use the same code posted by khawaib

any help please

regards
Title: Re: PayPal UK and order Item details (Code attached)
Post by: pravin_bluebird on November 20, 2008, 07:02:33 AM
Any One Please
Title: Re: PayPal UK and order Item details (Code attached)
Post by: okstated on December 11, 2008, 07:11:18 AM
An answer to this would be nice. Shipping is also missing from the code that transfers individual items.

It makes no sense whatsoever why anyone would want to use code that correctly separates product items but doesn't transfer shipping properly or another code that transfers the shipping but combines all products into one.

So many people use this with PayPal. Does no one have a solution that combines these two??????