Jump to content

Recommended Posts

Newbie to PHP, trying to hack an existing shopping cart which uses the following to compute the order total:

 

"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),

 

Since this is the only computation being used, I am assuming the "ROUND" function is causeing the computation to be rounded up.  So, if an order total for example is $18.50, the user is sent over to paypal and the pre-filled paypal charge is turned into $19.00

 

I can't seem to find an alternative to "ROUND"  I tried "ABS" but it just sent an empty total over to paypal.

 

Any *fast* help wouldbe really appreciated!

Thanks!

 

;D

 

Thank you for the fast reply.  I hope you can walk me through making the change?

I am using an opensource cart, and am at a loss for how to solve this without causing errors elsewhere.

Can you give me the exact changes you would make to fix this problem?

I have included the full code here:

 

<?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_total, 2),
"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" => "xxxxxxxx",
"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.'" />';
}

echo '</form>';

}
?>

Thank you... your advice led me here.  I wonder if this could be the culprit?

I am new to PHP, sorry if this is basic.

Please leet me know if this should be changed in some way to change the variable being used in the other page of code.

Thank you so much!!

 

 

/* Product PRICE */
	$my_taxrate = $ps_product->get_product_taxrate($cart[$i]["product_id"], $weight_subtotal);
	$tax = $my_taxrate * 100;

	$price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);

	if( $auth["show_price_including_tax"] == 1 ) {
		$product_price = $price["product_price"] * ($my_taxrate+1);
	} else {
		$product_price = $price["product_price"];
	}

	$product_price = round( $product_price, 2 );
	$product_rows[$i]['product_price'] = $CURRENCY_DISPLAY->getFullValue($product_price);

	/* Quantity Box */
	$product_rows[$i]['quantity_box'] = "<input type=\"text\" title=\"". $VM_LANG->_PHPSHOP_CART_UPDATE ."\" class=\"inputbox\" size=\"4\" maxlength=\"4\" name=\"quantity\" value=\"".$cart[$i]["quantity"]."\" />";

	/* SUBTOTAL CALCULATION */
	$subtotal = $product_price * $cart[$i]["quantity"];

	$total += $subtotal;
	$product_rows[$i]['subtotal'] = $CURRENCY_DISPLAY->getFullValue($subtotal);
	$product_rows[$i]['subtotal_with_tax'] = $CURRENCY_DISPLAY->getFullValue($subtotal * ($my_taxrate+1));

	if (!empty($my_taxrate) && MULTIPLE_TAXRATES_ENABLE=='1') {

		if( $auth["show_price_including_tax"] == 1 ) {
			eval( "\$message = \"".$VM_LANG->_PHPSHOP_INCLUDING_TAX."\";" );
			$product_rows[$i]['subtotal'] .= " ".$message;
		}
		else {
			$product_rows[$i]['subtotal'] .= " (+ $tax% ".$VM_LANG->_PHPSHOP_CART_TAX.")";
		}
	}

Well, the code you jsut posted also uses round with the precision of 2.

 

I think you need to just do some old-fashioned debugging.

 

Start with your fist script above. The amount is comprised of three separate values: order subtotal, tax total, and discount total. The last two are composed of two separate values each. So, I would start by printing all of the individual values to my page and then show the summed values that the code is generating.

 

So, at the bottom of the code you first posted, comment out the mosRedirect line and add this code after the very last closing curly bracket:

 

$discount_total = $db->f("coupon_discount") + $db->f("order_discount");

 

<?php
echo 'Order subtotal: '.$db->f("order_subtotal").'<br><br>';
echo 'Order tax: '.$db->f("order_tax").'<br>';
echo 'Order shipping tax: '.$db->f("order_shipping_tax").'<br>';
echo 'Tax Total: '.$tax_total.'<br><br>';
echo 'Coupon Discount: '.$db->f("coupon_discount").'<br>';
echo 'Order Discount: '.$db->f("order_discount").'<br>';
echo 'Discount Total: '.$discount_total.'<br><br>';
echo 'Order Total: '.$post_variables["amount"].'<br>';
echo 'Shipping: '.$post_variables["shipping"].'<br>';
?>

 

Do the values you get make sense?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.