/    Sign up×
Community /Pin to ProfileBookmark

PayPal submission code issue!

I’ve built an order form for my company’s website that stores each product from three different product categories in three seperate arrays ($PRODUCTS1, $PRODUCTS2 and $PRODUCTS3). The customer enters a quantity for each product they wish to order, the form displays the subtotal for each product and for the entire order before continuing to the next page where they can complete the order via PayPal. What I’m having trouble with is my paypal ‘buy now’ button logic. I’m trying to carry over the product descriptions, total quantity of items they’re ordering and the total combined price of all items they’re ordering. Currently, only the total quantity is displaying correctly on the paypal order summary page.

No matter how many products they order and regardless of which category they order them from, it always only displays the final product ordered in the paypal “descriptions” section. So, if they order 2 items from $PRODUCTS1, 2 from $PRODUCTS2 and 2 from $PRODUCTS3, only the description of the second item from $PRODUCTS3 is displayed. Also, the total price of the order is correct on the order details page but when the order is submitted to paypal, it’s being multiplied by the quantity of items. So, if the order quantity is 6 and the total is $2000, the paypal summary page displays the quantity as 6 but the total price has changed to $12000.

Here’s my code:

[code=php]
// functions for order form submission result page

function getPayPalBtn($total,$qty,$desc) {
$paypal_email = ‘[email protected]’;
// $desc = ”; // could be based on order, or static
$return_url = ‘http://www.something.com/order_results.php’; // thank you page
$cancel_url = ‘http://www.something.com/order_submit.php’; // if user cancels rather than paying
// could build string of order details (product abbr, qty)
$custom = ”; // up to 256 chars

$str = <<<EOS
<form action=”https://www.paypal.com/cgi-bin/webscr” method=”post”>
<input type=”hidden” name=”cmd” value=”_xclick” />
<input type=”hidden” name=”business” value=”$paypal_email” />
<input type=”hidden” name=”amount” value=”$total” />
<input type=”hidden” name=”quantity” value=”$qty” />
<input type=”hidden” name=”currency_code” value=”CAD” />
<input type=”hidden” name=”item_name” value=”$desc” />
<input type=”hidden” name=”custom” value=”$custom” />
<input type=”hidden” name=”return” value=”$return_url” />
<input type=”hidden” name=”cancel_return” value=”$cancel_url” />
<input type=”image” name=”submit “border=”0″
src=”https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif”
alt=”PayPal – The safer, easier way to pay online” />
</form>
EOS;
return $str;
}

function getOrderInfo() {
global $PRODUCTS1;
global $PRODUCTS2;
global $PRODUCTS3;
$str = ”; $total = 0; $qty = 0;

while ( list($key, $val) = each($_POST) ) {
// Check for valid quantity entries
if ( ( strpos($key, ‘_qty’) !== false ) && is_int((int)$val) && $val > 0 ) {
$pt = strrpos($key, ‘_qty’);
$name_pt = substr( $key, 0, $pt); // product abbr

foreach($PRODUCTS1 as $product) {
list($prod_abbr, $prod_name, $prod_price) = $product;
if ($prod_abbr == $name_pt) {
$sub_tot = $val * $prod_price;
// build string to display order info
$str .= “<p>$val $prod_name at $” . number_format($prod_price, 2) .
‘ each for $’ . number_format($sub_tot, 2) . ‘</p>’;
$qty += $val;
$total += $sub_tot;
$desc = $prod_name;
}
}
foreach($PRODUCTS2 as $product) {
list($prod_abbr, $prod_name, $prod_price) = $product;
if ($prod_abbr == $name_pt) {
$sub_tot = $val * $prod_price;
// build string to display order info
$str .= “<p>$val $prod_name at $” . number_format($prod_price, 2) .
‘ each for $’ . number_format($sub_tot, 2) . ‘</p>’;
$qty += $val;
$total += $sub_tot;
$desc = $prod_name;
}
}
foreach($PRODUCTS3 as $product) {
list($prod_abbr, $prod_name, $prod_price) = $product;
if ($prod_abbr == $name_pt) {
$sub_tot = $val * $prod_price;
// build string to display order info
$str .= “<p>$val $prod_name at $” . number_format($prod_price, 2) .
‘ each for $’ . number_format($sub_tot, 2) . ‘</p>’;
$qty += $val;
$total += $sub_tot;
$desc = $prod_name;
}
}
}
}
if ( $str === ” ) {
$str = ‘<br /><p align=”center”>You didn’t order anything, please <a href=”javascript:history.back()” class=”backlink”>go back</a> and try again.</p><br />’;
} else {
$str = ‘<table width=”100%”><tr><td align=”center”>’ . ‘<h3>Your Order Details</h3><p>’ . $str . ‘</p><p style=”font-weight: bold;”>Total (before taxes and shipping): ‘ . $qty . ‘ items for $’ . number_format($total, 2) . ‘</p>’ . ‘<p style=”font-style: italic;”>** Sales tax and shipping fees will be added to the order at checkout. **</p><br />’ . getPayPalBtn($total,$qty,$desc) . ‘<br />’ . ‘</td></tr></table>’;
}

return $str;
}
[/code]

Any assistance would be greatly appreciated!! ?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @B_Armitage spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...