I'm currently using a PayPal form to checkout from a website. On shippable items, everything is working fine. The issue I am running into, is the website also offers non-shippable services (downloadable content, streaming videos online). I'm retrieving the correct responses from PayPal when a purchase is successful, only if they pay shipping costs calculated for a non-shippable service. Here is an excerpt from my code:
<form id="paypal-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display: none;">
<?php foreach($checkout as $key => $value): ?>
<input name="item_name_<?php echo $key + 1; ?>" value="<?php echo $value['name']; ?>" type="hidden">
<input name="amount_<?php echo $key + 1; ?>" value="<?php echo $value['amount']; ?>" type="hidden">
<input name="quantity_<?php echo $key + 1; ?>" value="<?php echo $value['quantity']; ?>" type="hidden">
<input name="item_number_<?php echo $key + 1; ?>" value="<?php echo $value['number']; ?>" type="hidden">
<?php endforeach; ?>
<input name="no_shipping" value="2" type="hidden">
<input name="return" value="WEB_SITE/thank-you.html" type="hidden">
<input name="notify_url" value="WEB_SITE/process.html" type="hidden">
<input name="cancel_return" value="WEB_SITE/shopping-cart.html" type="hidden">
<input name="business" value="EMAIL" type="hidden">
<input name="currency_code" value="USD" type="hidden">
<input name="cmd" value="_cart" type="hidden">
<input name="upload" value="1" type="hidden">
<input name="rm" value="2" type="hidden">
<input name="charset" value="utf-8" type="hidden">
</form>
I'm not finding support for the task I'm looking for on this forum or PayPal's. Is what I'm asking for possible?
Okay, after further research and trying new things I found a method that works. Simply using the field "shipping_(n)" and setting the value to "0" overrides the shipping calculation and marks it as $0.00. Thanks everyone for trying. Here is my corrected code:
<form id="paypal-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display: none;">
<?php foreach($checkout as $key => $value): ?>
<input name="item_name_<?php echo $key + 1; ?>" value="<?php echo $value['name']; ?>" type="hidden">
<input name="amount_<?php echo $key + 1; ?>" value="<?php echo $value['amount']; ?>" type="hidden">
<input name="quantity_<?php echo $key + 1; ?>" value="<?php echo $value['quantity']; ?>" type="hidden">
<input name="item_number_<?php echo $key + 1; ?>" value="<?php echo $value['number']; ?>" type="hidden">
<?php if(strpos($value['number'], 'PROGRAMS') !== FALSE): ?>
<input name="shipping_<?php echo $key + 1; ?>" value="0" type="hidden">
<?php endif; ?>
<?php endforeach; ?>
<input name="no_shipping" value="2" type="hidden">
<input name="return" value="WEB_SITE/thank-you.html" type="hidden">
<input name="notify_url" value="WEB_SITE/process.html" type="hidden">
<input name="cancel_return" value="WEB_SITE/shopping-cart.html" type="hidden">
<input name="business" value="EMAIL" type="hidden">
<input name="currency_code" value="USD" type="hidden">
<input name="cmd" value="_cart" type="hidden">
<input name="upload" value="1" type="hidden">
<input name="rm" value="2" type="hidden">
<input name="charset" value="utf-8" type="hidden">
</form>
Related
i have simple paypal checkout form when i post it to paypal with sandbox credential when the paypments success, it gives me nothing like transaction and currency, i did print GET, but there is nothing. i am using codeigniter
below is the form code
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_click">
<input type="hidden" name="business" value="dev1#ferozitech.com">
<input type="hidden" name="item_name" value="test" class="slug">
<input type="hidden" name="item_number" value="2" class="proposalId">
<input type="hidden" name="custom" value="" class="userId">
<input type="hidden" name="amount" value="40" class="amount">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="<?php echo base_url('payment/payment_complete/') ?>">
<input type="hidden" name="cancel_return" value="<?php echo base_url('payment/payment_cancel') ?>">
<input type="image" name="submit" src="<?php echo base_url('images/checkoutpaypal.png'); ?>" alt="PayPal - The safer, easier way to pay online">
</form>
Try this code:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="dev1#ferozitech.com">
<input type="hidden" name="item_name" value="test" class="slug">
<input type="hidden" name="item_number" value="2" class="proposalId">
<input type="hidden" name="custom" value="" class="userId">
<input type="hidden" name="amount" value="40" class="amount">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="lc" value=""/>
<input type="hidden" name="no_note" value="1"/>
<input type="hidden" name="return" value="<?php echo base_url('payment/payment_complete/') ?>">
<input type="hidden" name="cancel_return" value="<?php echo base_url('payment/payment_cancel') ?>">
<input type="hidden" name="notify_url" value="<?php echo base_url('payment/payment_complete/') ?>" />
<input type="image" name="submit" src="<?php echo base_url('images/checkoutpaypal.png'); ?>" alt="PayPal - The safer, easier way to pay online">
</form>
Return url notify_url payment_complete function
print_r($_REQUEST);die;
I'm looking to add a discount code to this Paypal button but don't know how to go about doing it.
Can anyone help or suggest how too, I just need it so a customer can enter a the code and receive 10% off the price
The code is below for the button
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>Please click on the link to pay</p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="<?php echo C_OUR_EMAIL; ?>" />
<input type="hidden" name="first_name" value="<?php echo strfordisp($ofirstname); ?>" />
<input type="hidden" name="last_name" value="<?php echo strfordisp($olastname); ?>" />
<input type="hidden" name="address1" value="<?php echo strfordisp($theorder["oaddress"]); ?>" />
<input type="hidden" name="address2" value="<?php echo strfordisp($theorder["oaddress2"]); ?>" />
<input type="hidden" name="address3" value="<?php echo strfordisp($theorder["oaddress3"]); ?>" />
<input type="hidden" name="city" value="<?php echo strfordisp($theorder["otown"]); ?>">
<input type="hidden" name="zip" value="<?php echo strfordisp($theorder["opostcode"]); ?>" />
<?php $orderdets = mysql_query("select * from c4d_orderitems where orderid='" . $_SESSION["db_order"] . "' and confirm");
$iloop = 1;
while ($orderrow = mysql_fetch_array($orderdets))
{
$itemdesc = $orderrow["itemtypedesc"];
$itemdesc .= " to " . $orderrow["dpostcode"];
$itemprice = $orderrow["cost"] + $orderrow["surcharge"] + $orderrow["insurancecost"];
?>
<input type='hidden' name="item_name_<?php echo $iloop; ?>" value='<?php echo strfordisp($itemdesc); ?>' />
<input type='hidden' name="item_number_<?php echo $iloop; ?>" value='<?php echo $orderrow["itemtype"]; ?>' />
<input type='hidden' name="amount_<?php echo $iloop; ?>" value='<?php
// pctrends
if ((strtoupper($ofirstname)=="PCTRENDSTEST") || (strtoupper($olastname)=="PCTRENDSTEST") || (substr($_SERVER['REMOTE_ADDR'],0,11)=="82.152.55.1"))
echo("0.01");
else echo $itemprice;
?>' />
<input type='hidden' name="quantity_<?php echo $iloop; ?>" value='1' />
<?
$iloop++;
}
?>
<input type="hidden" name="return" value="<?php echo C_SITE_ROOT; ?>stage7.php" />
<input type="hidden" name="cancel-return" value="<?php echo C_SITE_ROOT; ?>order-cancel.php" />
<input type="hidden" name="notify_url" value="<?php echo C_SITE_ROOT; ?>paypal.php" />
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="invoice" value="<?php echo $_SESSION["db_order"]; ?>" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="no-shipping" value="1" />
<input type="hidden" name="button_subtype" value="products" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest" />
<input type="hidden" name="country" value="GB" />
<p class='fmenu'><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></p>
</form>
You must check for the discount-code validity (with AJAX) and make the appropriate calculations to apply the discount to the amount variable (with JavaScript) before to send the payment notification.
The user writes the discount-code insiede the custom variable where you can store whatever you want for your own tracking purposes.
// Check here on keypress with JS and AJAX for discount code validity
<input type="text" name="custom" value="" />
If the discount-code is verified, apply the discount to the amount variable. Something like this:
// Javascript and jQuery
if(verified == true) {
var discounted = $("[name='amount']").val() - ($("[name='amount']").val()/100)*10);
$("[name='amount']").val(discounted);
}
else {
alert("Discount code not found");
}
Then when you send the payment and get the information from paypal (the IPN response) process it like so:
$discountCode = $_POST["custom"];
// ... Discount-code validity check ...
$discountedAmount = $originalAmount - (($originalAmount/100)*10);
// And then check if the paid amount corresponds to the due amount
if($discountedAmount == $_POST["amount"])
For checking out process while redirecting the user https://www.sandbox.paypal.com the paypal does not show more than one type item and only the last (with its quantity) i.e, if user add two types product in his cart and click for checking out process the paypal show only the second type with its quantity but not the first type in billing process. how can i solve the problem?
here is my api code in view file
<form style=" padding:0px;margin:0px;" name="frmOrderAutoSubmit" method="post" >
<input type="hidden" name="upload" value="1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sunymegh#gmail.com">
<?php $cdata = $this->cart->contents() ?>
<?php foreach ($cdata as $items) { ?>
<input type="hidden" name="quantity" value="<?php echo $items['qty']; ?>" />
<input type="hidden" name="item_name" value=" <?php echo $items['name']; ?>"/>
<input type="hidden" name="amount" value="<?php echo $items['price']; ?>"/>
<input type="hidden" name="rm" value="2" />
<input TYPE="hidden" name="address_override" value="0">
<?php } ?>
</form>
You only have one name attribute submitted name="quantity" for example. PayPal uses a format of name="quantity_1".
Where am I going wrong? the company email is correct I tried using the merchant Id but still no joy.....??
<?php $items = unserialize($_SESSION['items']); ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="business" value="cherished4ever#hotmail.co.uk">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="return" value="http://www.cherished4ever.com/">
<?php
$suffix = 1;
foreach($items as $item):
?>
<input type="hidden" name="item_name_<?php echo $suffix; ?>" value="<?php echo $item['name']; ?>">
<input type="hidden" name="amount_<?php echo $suffix; ?>" value="<?php echo $item['price']; ?>">
<?php
$suffix++;
endforeach;
?>
Ok so i have got it working now however I just need some help with the checkout page showing the option name and not the item_name value set as the hidden output:
<select name="amount" style="width:150px;font:9px;margin-top:4px">
<option value="35.00">10 x 10</option>
<option value="55.00">20 x 20</option>
<option value="75.00">30 x 30</option>
</select><br>
Be sure to remember your session_start(); at the top of each page that uses the $_SESSION variable.
For more information, take a look at: http://www.php.net/session_start
On my local machine, when I submit this form, and I do have items inside the $_SESSION['cart'], the sandbox does recognize the items inside it. But when I tried it on a live server, and I submitted the form while there's an item inside $_SESSION['cart'], the sandbox says my cart is empty... Why is that?
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" <?php if(empty($_SESSION['cart'])){echo "onsubmit=\"return false;\"";} ?>>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="<?=$ppemail['email']?>" />
<?php
$i = 1;
foreach($_SESSION['cart'] as $id => $qty):
$product = $myCart->getProduct($id);
?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['ProductName']; ?>">
<input type="hidden" name="item_number_<?php echo $i; ?>" value="<?php echo $product['ProductID']; ?>">
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['ProductOverridePrice']; ?>">
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $qty; ?>">
<?php
$i++;
endforeach;
?>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="shipping_1" value="<?php echo $shipping; ?>">
<input type="hidden" name="return" value="<?php echo $the_class->settings[0]['DomainName'];?>shopping-cart-details.php">
<input type="hidden" name="cancel_return" value="<?php echo $the_class->settings[0]['DomainName'];?>">
<input type="hidden" name="notify_url" value="<?php echo $the_class->settings[0]['DomainName'];?>classes/paypal.php">
<input type="image" src="images/continue-btn.png" name="pay now" value="pay" />
</form>
i found the bug...the table that was at the live server....i meant, one of the field names was small caps..errr