Latest News:
v1.2.0 Released Tonight!
on June 21, 2008, 05:12:05 PM [View]
Welcome, Guest. Please login or register.
July 24, 2008, 03:49:59 AM
Show Unread Posts | View Replies to Your Posts


Login with username, password and session length
cpCommerce Support  |  Version 1.x.x  |  Bug Reports  |  Resolved  |  Topic: paypal bug 0 Members and 1 Guest are viewing this topic.
Pages: [1] Send this topic Print
Author Topic: paypal bug  (Read 2889 times)
Tony_1
Intrigued Member
**
Offline Offline

Posts: 87


View Profile
« on: May 04, 2007, 03:56:33 PM »

i was testing to the point where it ask you for the password to login to the paypal account and noticed the shipping was added in the total and not displayed in shipping for paypal.  say the item was $12 and shipping was 3 the total would display as $15 and with 0 in shipping and handling from paypal.
Report to moderator   Logged
Jenius
Junior Member
*
Offline Offline

Posts: 25


View Profile WWW
« Reply #1 on: July 21, 2007, 05:02:14 PM »

Go in to cpcommerce>payment>paypal>review.php and replace

Code:
  $AMOUNT               = number_format($subtotal['total'], 2);

with

Code:
  $SHIPPING             = number_format($subtotal['shipping'], 2);
  $HANDLING             = number_format($subtotal['handling'], 2);
  $TAX                  = number_format($subtotal['taxes'], 2);
  $AMOUNT               = number_format($subtotal['subtotal'], 2);

and replace

Code:
  <input type="hidden" name="amount" value="<?php echo $AMOUNT?>" />

with

Code:
  <input type="hidden" name="shipping" value="<?php echo $SHIPPING?>" />
  <input type="hidden" name="handling" value="<?php echo $HANDLING?>" />
  <input type="hidden" name="tax" value="<?php echo $TAX?>" />
  <input type="hidden" name="amount" value="<?php echo $AMOUNT?>" />




You might also have to add

Code:
,'shipping','handling'

to $restrict = array(  located in cpcommerce>payment>paypal>response.php and cpcommerce>payment>paypal>ipn.php

Now Paypal will display the correct shipping, handling, and tax. I'm currently working on fixing the quantity and making the item name dynamic. I'll post a reply here if I get those working.
« Last Edit: July 21, 2007, 05:09:18 PM by Jenius » Report to moderator   Logged
Jenius
Junior Member
*
Offline Offline

Posts: 25


View Profile WWW
« Reply #2 on: July 22, 2007, 02:24:39 AM »

The quantity has to remain 1, but I did fix the item name and item number. Here's the combined code for all of the fixes I've listed so far.

Code:
<?php
  
if (!defined("CPCOMMERCE_LOADED"))
  {
    die(
"You are not allowed to access this script.");
  }
  
  
// Start Variable Setup
  
$subtotal         ShoppingCartStats();
  
$cpCart           base64_encode(serialize($_SESSION['cpCart']));
  
$cpPaymentInfo    base64_encode(serialize($_SESSION['cpPaymentInfo']));
  
  
// Store the Cart and the Checkout Information in a Temporary Table
  
$sql['temporary']   = "INSERT INTO `" $db_chooser->MethodsTemporary() . "` (`id_method`, " .
                        
"`cart`, `checkout`) VALUES (" .
                        
"{$_SESSION['cpPaymentInfo']['method']['id_method']}, '{$cpCart}', " .
                        
"'{$cpPaymentInfo}')";
  
$query['temporary'] = $db_chooser->sql_query($sql['temporary']);
  
$temporary_id       $db_chooser->sql_insert_id();
  
  
// Cycle through the contents of the Cart
  
foreach ($_SESSION['cpCart'] as $key => $val) {
  
// Quantity
  
$quantity $val['standard_quantity'] + $val['sale_quantity'];
  }
  
  
// Continue Variable Setup
  
$BUSINESS             "{$method['BUSINESS']}";
  
$RECEIVER_EMAIL       "{$method['BUSINESS']}";
  
$RECEIVER_ID          "{$method['REFERAL_ID']}";
  
$ITEM_NAME            "{$val['name']}";
  
$ITEM_NUMBER          "{$val['id_product']}";
  
$CURRENCY_CODE        "{$method['CURRENCY_CODE']}";
  
$TXN_TYPE             "web_accept";
  
$QUANTITY             1;
  
$CUSTOM               "{$temporary_id}";
  
$INVOICE              date("Ymdhis") . "-{$temporary_id}";
  
$SHIPPING             number_format($subtotal['shipping'], 2);
  
$HANDLING             number_format($subtotal['handling'], 2);
  
$TAX                  number_format($subtotal['taxes'], 2);
  
$AMOUNT               number_format($subtotal['subtotal'], 2);
  
$RETURN               "{$config['siteaddress']}{$config['maindir']}checkout.php?obj=finished";
  
$CANCEL_RETURN        "{$config['siteaddress']}{$config['maindir']}checkout.php?obj=finished";
  
$NOTIFY_URL           "{$config['siteaddress']}{$config['maindir']}" .
                          
"{$config['payment']}paypal/response.php?cpTempID={$temporary_id}";
  
$REDIRECT_CMD         "_xclick";
  
$FIRST_NAME           substr($_SESSION['cpPaymentInfo']['method']['variables']['Name'], 0
                            
strrpos($_SESSION['cpPaymentInfo']['method']['variables']['Name'], " "));
  
$LAST_NAME            substr($_SESSION['cpPaymentInfo']['method']['variables']['Name'],  
                            
strrpos($_SESSION['cpPaymentInfo']['method']['variables']['Name'], " ") + 1);
  
$EMAIL                "{$_SESSION['cpPaymentInfo']['method']['variables']['E-mail Address']}";
  
$ADDRESS1             "{$_SESSION['cpPaymentInfo']['method']['variables']['Street Address']}";
  
$CITY                 "{$_SESSION['cpPaymentInfo']['method']['variables']['City']}";
  
$STATE                "{$_SESSION['cpPaymentInfo']['method']['variables']['State']}";
  
$ZIP                  "{$_SESSION['cpPaymentInfo']['method']['variables']['Postal Code']}";
  
$COUNTRY              "{$_SESSION['cpPaymentInfo']['method']['variables']['Country']}";
  
  
// Leave only Numerical Data in Phone Number
  
$PHONE                "";
  for(
$i 0$i strlen($_SESSION['cpPaymentInfo']['method']['variables']['Phone']); $i++)
    if (
is_numeric(substr($_SESSION['cpPaymentInfo']['method']['variables']['Phone'], $i1)))
      
$PHONE .= substr($_SESSION['cpPaymentInfo']['method']['variables']['Phone'], $i1);
  
  
// Continue Variable Setup Again
  
$DAY_PHONE_A          substr($PHONE03);
  
$DAY_PHONE_B          substr($PHONE33);
  
$DAY_PHONE_C          substr($PHONE6);
  
$NIGHT_PHONE_A        substr($PHONE03);
  
$NIGHT_PHONE_B        substr($PHONE33);
  
$NIGHT_PHONE_C        substr($PHONE6);
  
  
// Check if the site is under Testing
  
if ($config['postmode']) {
?>

<form method="post" action="<?php echo $method['form_testing_action']; ?>">
  <input type="hidden" name="test_ipn" value="1" />
<?php
  
} else {
?>

<form method="post" action="<?php echo $method['form_action']; ?>">
<?php
  
}
?>

  <input type="hidden" name="querystring" value="<?php echo $_SERVER['QUERY_STRING']; ?>" />
  <input type="hidden" name="cmd" value="_ext-enter" />
  <input type="hidden" name="business" value="<?php echo $BUSINESS?>" />
  <input type="hidden" name="receiver_email" value="<?php echo $RECEIVER_EMAIL?>" />
  <input type="hidden" name="receiver_id" value="<?php echo $RECEIVER_ID?>" />
  <input type="hidden" name="item_name" value="<?php echo $ITEM_NAME?>" />
  <input type="hidden" name="item_number" value="<?php echo $ITEM_NUMBER?>" />
  <input type="hidden" name="currency_code" value="<?php echo $CURRENCY_CODE?>" />
  <input type="hidden" name="txn_type" value="<?php echo $TXN_TYPE?>" />
  <input type="hidden" name="quantity" value="<?php echo $QUANTITY?>" />
  <input type="hidden" name="custom" value="<?php echo $CUSTOM?>" />
  <input type="hidden" name="invoice" value="<?php echo $INVOICE?>" />
  <input type="hidden" name="shipping" value="<?php echo $SHIPPING?>" />
  <input type="hidden" name="handling" value="<?php echo $HANDLING?>" />
  <input type="hidden" name="tax" value="<?php echo $TAX?>" />
  <input type="hidden" name="amount" value="<?php echo $AMOUNT?>" />
  <input type="hidden" name="return" value="<?php echo $RETURN?>" />
  <input type="hidden" name="cancel_return" value="<?php echo $CANCEL_RETURN?>" />
  <input type="hidden" name="notify_url" value="<?php echo $NOTIFY_URL?>" />
  <input type="hidden" name="redirect_cmd" value="<?php echo $REDIRECT_CMD?>" />
  <input type="hidden" name="first_name" value="<?php echo $FIRST_NAME?>" />
  <input type="hidden" name="last_name" value="<?php echo $LAST_NAME?>" />
  <input type="hidden" name="email" value="<?php echo $EMAIL?>" />
  <input type="hidden" name="address1" value="<?php echo $ADDRESS1?>" />
  <input type="hidden" name="city" value="<?php echo $CITY?>" />
  <input type="hidden" name="state" value="<?php echo $STATE?>" />
  <input type="hidden" name="zip" value="<?php echo $ZIP?>" />
  <input type="hidden" name="country" value="<?php echo $COUNTRY?>" />
  <input type="hidden" name="day_phone_a" value="<?php echo $DAY_PHONE_A?>" />
  <input type="hidden" name="day_phone_b" value="<?php echo $DAY_PHONE_B?>" />
  <input type="hidden" name="day_phone_c" value="<?php echo $DAY_PHONE_C?>" />
  <input type="hidden" name="night_phone_a" value="<?php echo $NIGHT_PHONE_A?>" />
  <input type="hidden" name="night_phone_b" value="<?php echo $NIGHT_PHONE_B?>" />
  <input type="hidden" name="night_phone_c" value="<?php echo $NIGHT_PHONE_C?>" />

Just copy and paste that, replacing the top sections of cpcommerce>payment>paypal>review.php .

And then add    ,'shipping','handling'    to the end of    $restrict = array(    located in cpcommerce>payment>paypal>response.php and cpcommerce>payment>paypal>ipn.php .


This may not be the most efficient way but it gets the job done and should be secure. Note: There is one known bug. If someone orders multiple items, only the name and number of the last item on the list will be displayed. But I don't see anyway of fixing it without rewriting half of cpCommerce, and of course this is still better than just a static name with no number.
« Last Edit: July 22, 2007, 07:51:28 PM by Jenius » Report to moderator   Logged
Jenius
Junior Member
*
Offline Offline

Posts: 25


View Profile WWW
« Reply #3 on: July 22, 2007, 10:54:46 PM »

I figured out a way to display of the item number for each item purchased (if the same item is bought multiple times, it displays it more than once). It doesn't work if more than 5 different items or 3 of the same item is purchased at one time (but these numbers can easily be increased by coping and pasting the pattern). I'm sure there's a much better way of doing this (making it dynamically get the number of items in the cart and quantities so you don't have item limits or zeros at the end and so it's shorter) but I can't figure it out. But in any case, here it is:



In the code I posted above, replace-
Code:
  // Cycle through the contents of the Cart
  foreach ($_SESSION['cpCart'] as $key => $val) {
  // Quantity
  $quantity = $val['standard_quantity'] + $val['sale_quantity'];
  }
 
  // Continue Variable Setup
  $BUSINESS             = "{$method['BUSINESS']}";
  $RECEIVER_EMAIL       = "{$method['BUSINESS']}";
  $RECEIVER_ID          = "{$method['REFERAL_ID']}";
  $ITEM_NAME            = "{$val['name']}";
  $ITEM_NUMBER          = "{$val['id_product']}";


with-
Code:
  $combinednuma = 0;
  $combinednumb = -1;
  $combinednumc = -1;
  $combinednumd = -1;
  $combinednume = -1;
  $combinednumf = -1;
 
  // Cycle through the contents of the Cart
  foreach ($_SESSION['cpCart'] as $key => $val) {
  // Quantity
  $quantity = $val['standard_quantity'] + $val['sale_quantity'];

  if ($combinednume == 0){
    if ($quantity == 1){
      $combinednume = ($val['id_product']);
      $combinednumf = 0;}
    if ($quantity == 2){
      $combinednume = ($val['id_product']).".".($val['id_product']);
      $combinednumf = 0;}
    if ($quantity >= 3){
      $combinednume = ($val['id_product']).".".($val['id_product']).".".($val['id_product']);
      $combinednumf = 0;}
  }
  if ($combinednumd == 0){
    if ($quantity == 1){
      $combinednumd = ($val['id_product']);
      $combinednume = 0;}
    if ($quantity == 2){
      $combinednumd = ($val['id_product']).".".($val['id_product']);
      $combinednume = 0;}
    if ($quantity >= 3){
      $combinednumd = ($val['id_product']).".".($val['id_product']).".".($val['id_product']);
      $combinednume = 0;}
  }
  if ($combinednumc == 0){
    if ($quantity == 1){
      $combinednumc = ($val['id_product']);
      $combinednumd = 0;}
    if ($quantity == 2){
      $combinednumc = ($val['id_product']).".".($val['id_product']);
      $combinednumd = 0;}
    if ($quantity >= 3){
      $combinednumc = ($val['id_product']).".".($val['id_product']).".".($val['id_product']);
      $combinednumd = 0;}
  }
  if ($combinednumb == 0){
    if ($quantity == 1){
      $combinednumb = ($val['id_product']);
      $combinednumc = 0;}
    if ($quantity == 2){
      $combinednumb = ($val['id_product']).".".($val['id_product']);
      $combinednumc = 0;}
    if ($quantity >= 3){
      $combinednumb = ($val['id_product']).".".($val['id_product']).".".($val['id_product']);
      $combinednumc = 0;}
  }
  if ($combinednuma == 0){
    if ($quantity == 1){
      $combinednuma = ($val['id_product']);
      $combinednumb = 0;}
    if ($quantity == 2){
      $combinednuma = ($val['id_product']).".".($val['id_product']);
      $combinednumb = 0;}
    if ($quantity >= 3){
      $combinednuma = ($val['id_product']).".".($val['id_product']).".".($val['id_product']);
      $combinednumb = 0;}
  }
  }
 
  if ($combinednume == -1){
    $combinednume = 0;}
   
  if ($combinednumd == -1){
    $combinednumd = 0;}
   
  if ($combinednumc == -1){
    $combinednumc = 0;}
   
  if ($combinednumb == -1){
    $combinednumb = 0;}
 
  $combinednum = ($combinednuma).".".($combinednumb).".".($combinednumc).".".($combinednumd).".".($combinednume);
 
  // Continue Variable Setup
  $BUSINESS             = "{$method['BUSINESS']}";
  $RECEIVER_EMAIL       = "{$method['BUSINESS']}";
  $RECEIVER_ID          = "{$method['REFERAL_ID']}";
  $ITEM_NAME            = "{$val['name']}";
  $ITEM_NUMBER          = "{$combinednum}";


And the Paypal Payment Method is now un-officially fixed.
« Last Edit: July 22, 2007, 11:01:05 PM by Jenius » Report to moderator   Logged
Tony_1
Intrigued Member
**
Offline Offline

Posts: 87


View Profile
« Reply #4 on: August 13, 2007, 03:52:46 AM »

i totaly got lost.  i'm not a php scripter.
Report to moderator   Logged
Jenius
Junior Member
*
Offline Offline

Posts: 25


View Profile WWW
« Reply #5 on: August 13, 2007, 02:14:58 PM »

Go to this topic here and download the .zip file at the bottom, then replace your current files with the ones there. It contains all the paypal changes listed above plus a few extras.
Report to moderator   Logged
Tony_1
Intrigued Member
**
Offline Offline

Posts: 87


View Profile
« Reply #6 on: August 15, 2007, 04:28:13 AM »

Go to this topic here and download the .zip file at the bottom, then replace your current files with the ones there. It contains all the paypal changes listed above plus a few extras.

thank you.  i should learn but my lifestyle does not let me study. Sad
Report to moderator   Logged
Jenius
Junior Member
*
Offline Offline

Posts: 25


View Profile WWW
« Reply #7 on: August 15, 2007, 08:49:36 AM »

A quick note on product names/IDs in paypal with this code:

Product Name-


If someone purchases more than 1 product, only the name of the last product (in alphabetical order) will show up.
Example- Someone buys products named "AAA" and "ZZZ"; only "ZZZ" will show as the name.


Product IDs-

For product IDs it's a bit more complicated (which is why I'm explaining this in the first place).

All products have there own URL.
Example- http://www.example.com/cpcommerce/product.php?id_product=9

The "9" at the end of the above example is an example of the product ID that I used in this code.

This code, as posted, can handle 5 different products and up to 3 of each of those 5 (but can easily be expanded if you know what you're doing) and each product is seperated by a period.
Example- Someone purchases 2 of product ID# 5 and 1 ID# 10. The output in paypal would look like "Product ID: 5.5.10.0.0.0" .

The zeros at the end are place holders if less than 5 different products are purchased; cpcommerce does not ever actually have a product ID# 0.
« Last Edit: August 15, 2007, 09:08:25 AM by Jenius » Report to moderator   Logged
Pages: [1] Send this topic Print 
cpCommerce Support  |  Version 1.x.x  |  Bug Reports  |  Resolved  |  Topic: paypal bug
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Subproducts are 99% working jongibbins 2 289 February 14, 2008, 05:26:23 AM
by jongibbins
Checking user session: new function gob33 1 209 March 31, 2007, 08:29:27 AM
by cpradio
Modifying Subproducts Telina 2 413 December 04, 2005, 09:26:11 PM
by softnow
Small Bug - Category.listing.php jimbo 0 385 October 28, 2005, 06:44:36 PM
by jimbo
very minor bug marquis 0 409 October 30, 2005, 10:24:22 AM
by marquis

Powered by MySQL Powered by PHP cpCommerce Support | Powered by SMF 1.1.
© 2004, Simple Machines LLC. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!