News:

Support the VirtueMart project and become a member

Main Menu

Send Product Name and Attributes to Paypal

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

Previous topic - Next topic

mackavi

J1.5 VM 1.13 PHP 5.29

Mizpah

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

TurnTex

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.

ajredding

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

mackavi

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
J1.5 VM 1.13 PHP 5.29

kyndhi

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!!!

kyndhi

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"

stephengrenfell


virtuemart_craig

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

helenbn

#39
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.
I use Virtue Mart 1.1.3 & Joomla 1.5.10

helenbn

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.
I use Virtue Mart 1.1.3 & Joomla 1.5.10

helenbn

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
I use Virtue Mart 1.1.3 & Joomla 1.5.10

helenbn

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.
I use Virtue Mart 1.1.3 & Joomla 1.5.10

helenbn

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.
I use Virtue Mart 1.1.3 & Joomla 1.5.10

martin09

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