VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Payment VM 1.1 => PayPal / PayPal Pro VM 1.1 => Topic started by: hrhsii on August 17, 2011, 15:20:00 PM

Title: paypal (New API) script in Payment Extra Info:" is charging cards twice
Post by: hrhsii on August 17, 2011, 15:20:00 PM
Whem authorization is set, it takes all the card details at PayPal, and charges the card, leaving the seller to capture the payment. Fine.

It then goes to PayPal again, and takes card payment details again, but this time the payment is taken immediately. Have I set something somewhere that is triggering this double charging?

Using VirtueMart 1.1.9 stable , Joomla Version 1.5.23

script from Payment Extra Info:

<?php
 
$url 
"https://www.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();
 
 
 
//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();
 
 
 
//logic for applying discounts to multiple items
 
$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;
 
}
 
//query to optain product attributes
 
while($dboi->next_record()) {
 
 
 
  
$prod_attrib $dboi->f("product_attribute");
 
  
$supp_var['item_name_' $i] = strip_tags($VM_LANG->_('PHPSHOP_ORDER_LIST_ID') . " " $db->f("order_id").": "$dboi->f("order_item_name"));
 
 
 
  if(
$prod_attrib ''){
 
    
$attributes_array explode('
'
,$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++;
 
}
 
 
 
 
 
//Query used to find whether to use Bill Address or Ship 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);
 
 
 
 
 
  
$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_2_code");
 
  
$zip $dboui->f("zip");
 
  
$H_PhoneNumber $dboui->f("phone_1");
 
 
 
 
 
// Builds array for the form
 
$post_variables = Array(
 
"charset" => "utf8",
 
"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_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",
 
"no_shipping" => "1",
 
"no_note" => "1",
 
"email" => $dbb->f("user_email"),
 
"address_override" => "1",//change this to 0 if you have - Paypal does not allow your country of residence to ship to the country you wish to - errors
 
"first_name" => $first_name,
 
"last_name" => $last_name,
 
"address1" => $address1,
 
"address2" => $address2,
 
"city" => $city,
 
"state" => $state,
 
"country" => $address_country,
 
"zip" => $zip,
 
"night_phone_b" => $H_PhoneNumber
 
);
 
//add and send the new variables
 
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!">';
 
//Change the above image url for different languages and countries
 
  
echo '</form>';
 
}
 
?>


Title: Re: paypal (New API) script in Payment Extra Info:" is charging cards twice
Post by: hrhsii on August 18, 2011, 18:58:00 PM
Just an update, I have set Payment Type to Sale, and it all works fine! This leads me to believe it may not be a problem with PayPal but a bug in the PayPal API.
Title: Re: paypal (New API) script in Payment Extra Info:" is charging cards twice
Post by: jk15060 on August 18, 2011, 21:23:10 PM
HRHSII--
I am very new to VirtueMart, so forgive the very basic questions that follow.

This is the first forum post I've seen that has the same version of VM and Joomla, so I'm hoping you can help me with the PayPal configuration portion of VM.  I've been reading and reading, but just cannot find the IPN location in PayPal.  Should I be setting something in API link (in PayPal)??

Also, I read in a much older post that I need to modify the notify.php file by adding the URL for the listener.  While that may appear to be in English, I'm not sure what that means.  Maybe it's the old way of configuring PayPal.

Sure hope you can help.  The PayPal stuff is the only thing I'm not quite sure how to configure.

One last question, if I may.  Is there any way to add PayPal's percentage to the cost of the purchase?  My client wants that passed on to the customer.  I suggested raising prices slightly, but they didn't like that answer. So here I am asking this question too.

Thank you for any help that's out there in the VM world today!
Title: Re: paypal (New API) script in Payment Extra Info:" is charging cards twice
Post by: jk15060 on August 18, 2011, 21:41:03 PM
UPDATE:  Ok, one stupid question is out of the way.  I finally found the IPN Preferences in PayPal.  (Had to go to Classic View)

And another big major DUH - the listener URL is the link to the notify.php file! 

Now I'm on the hunt for the VAT in PayPal.  Maybe that one will drop on my head like the other two. 
Title: Re: paypal (New API) script in Payment Extra Info:" is charging cards twice
Post by: jk15060 on August 18, 2011, 22:07:44 PM
UPDATE #2:  Did not find VALUE ADDED TAX in PayPal, but found what I needed under SALES TAX.  I also got this message:  "You have successfully saved your preferences. Please use the following identity token when setting up Payment Data Transfer on your website."  It included a really long token number.  Not sure if I need to do anything with it though.

Now I'm muddling my way through the shipping in VM.  So close...................and yet so far away.