I keep getting the shopping cart is empty....? - php

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

Related

Paypal different products options

I have paypal legacy code try to debug. I have different products with different price. In my project I found code
<div id="paypal_container" class="payment_container">
<div class="procesor font20 marg_bot20">Pay via PayPal</div>
<form action="<?php $server = base_url(); if (strpos($server,'http://cam.com/') !== false) echo 'https://www.paypal.com/cgi-bin/webscr'; else echo 'https://www.sandbox.paypal.com/cgi-bin/webscr'; ?>" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php if (strpos($server,'http://camm') !== false) echo 'cdd'; else echo 'pptest'; ?>">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="notify_url" value="<?php echo base_url ('paypal/payment'); ?>">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<table>
<tr>
<td class="font20 marg_bot20 inline-block">
<input type="hidden" name="on0" value="Package">Package
</td>
</tr>
<tr>
<td>
<select name="os0" class="input">
<option value="Basic1">Basic $5.00 USD</option>
<option value="Basic2">Basic $25.00 USD</option>
<option value="Basic3">Basic $50.00 USD</option>
<option value="VIP1">VIP1 $75.00 USD</option>
<option value="VIP2">VIP2 150.00 USD</option>
<option value="VIP3">VIP3 300.00 USD</option>
<option value="VIP4">VIP4 $500.00 USD</option>
<option value="VIP5">VIP5 $1,000.00 USD</option>
<option value="VIP6">VIP6 $1,500.00 USD</option>
<option value="Marquis">Marquis $3,000.00</option>
</select>
</td>
</tr>
</table>
<input type="hidden" name="custom" value="<?php echo $custom_pp; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="option_select0" value="Basic1">
<input type="hidden" name="option_amount0" value="5.00">
<input type="hidden" name="option_select1" value="Basic2">
<input type="hidden" name="option_amount1" value="25.00">
<input type="hidden" name="option_select10" value="Basic3">
<input type="hidden" name="option_amount10" value="50.00">
<input type="hidden" name="option_select2" value="VIP1">
<input type="hidden" name="option_amount2" value="75.00">
<input type="hidden" name="option_select3" value="VIP2">
<input type="hidden" name="option_amount3" value="150.00">
<input type="hidden" name="option_select8" value="Marquis1">
<input type="hidden" name="option_amount8" value="200.00">
<input type="hidden" name="option_select4" value="VIP3">
<input type="hidden" name="option_amount4" value="300.00">
<input type="hidden" name="option_select5" value="VIP4">
<input type="hidden" name="option_amount5" value="500.00">
<input type="hidden" name="option_select6" value="VIP5">
<input type="hidden" name="option_amount6" value="1000.00">
<input type="hidden" name="option_select7" value="VIP6">
<input type="hidden" name="option_amount7" value="1500.00">
<input type="hidden" name="option_select9" value="Marquis">
<input type="hidden" name="option_amount9" value="3000.00">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
But when I am redirected to sandbox paypal test page In cart I have proper product selected but price is always 0.01$.
Maybe I need something to add in my test facilitator or something in my html I am not sure how it works?
You can create Add to Cart button with drop down menu for different price.
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/paypal_shopping_cart/?mark=add%20to%20cart
Or, you can refer to the link below for the cart upload command.
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/cart_upload/?mark=add%20to%20cart

Sandbox paypal test account not returning variables

I have two paypal test accounts. One is "testaddabusiness#shop.com" and another is "testaddapersonal#shop.com". They both are for testing my transactions. I followed a tutorial to make a shopping cart integrated with paypal. The problem is it is not returning some of the variables which i need to save in my database table. I have setup the website preference with success.php. It is not returning payment details from paypal.
success.php
<?php
session_start();
include("db/db.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<html>
<title>Success</title>
<body>
<?php
if(isset($_SESSION['cart']) && isset ($_SESSION['login_email'])){
$total=0;
$ships=$_POST['shipment'];
$user=$_POST['name'];
$user_id=$_POST['id'];
$file=$_FILES['file']['name'];
//orders and order details.
$que=mysqli_query($con,"insert into orders(custom_file,date,customerid,ship_days) values('$file',CURRENT_TIMESTAMP(),'$user_id','$ships')");
if($que)
{
$m=move_uploaded_file($_FILES['file']['name'],'./ServerUploadedFiles/'.$user.$file);
$q=mysqli_query($con,"select serial from orders where customerid='$user_id' and date=CURRENT_TIMESTAMP()");
while($row1=mysqli_fetch_array($q,MYSQLI_ASSOC))
{
$order_id=$row1['serial'];
}
foreach($_SESSION['cart'] as $id => $value){
$subtotal=$value['price']*$value['quantity'];
$pid=$value['id'];
$quantity=$value['quantity'];
$color=$value['color'];
$size=$value['size'];
$total+= $subtotal;
$query= mysqli_query($con, "INSERT INTO order_detail(orderid,productid,quantity,price,color,size) VALUES ($order_id, $pid, $quantity, $subtotal, '$color', '$size')");
}
}
//payment details for paypal
$amount=$_GET['amt'];
$currency=$_GET['cc'];
$trx_id=$_GET['tx'];
$insert_payments= mysqli_query($con,"insert into payments(amount,cust_id,trx_id,currency) values('$amount','$user_id','$trx_id','$currency')");
if($amount==$total)
{
echo "<h2>Hello". $user."You have successfully done purchasing process.Please <a href='profile.php'>Go to your account</a>!</h2>";
}
else
{
echo "<h2>Hello". $user."Your payment was not successful.Please <a href='profile.php'>Go to your account</a>!</h2>";
}
}
?>
</body>
</html>
form.php
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" enctype="multipart/form-data">
<?php
$email=$_SESSION["login_email"];
$query=mysqli_query($con,"select * from customers where email='$email'");
while($row=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<input type="hidden" class="input_form" name="id" value="<?=$row["serial"]?>">
<input type="hidden" class="input_form" name="name" value="<?=$row["name"]?>">
<input type="hidden" class="input_form" name="phone" value="<?= $row["phone"] ?>">
<input type="hidden" class="input_form" name="city" value="<?= $row["city"] ?>">
<input type="hidden" class="input_form" name="address" value="<?= $row["address"] ?>">
Download custom size form Provide us your custom size
<input type="file" name="file">
Select shipment interval (optional):<select id="shipment" name="shipment">
<option selected value="7" id="7">7</option>
<option value="6" id="6"> 6 </option>
<option value="5" id="5">5 </option>
<option value="4" id="4">4 </option>
<option value="3" id="3">3 </option>
</select>
<p>Before clicking submit read Terms and Policies carefully..Once ordered would not be restored.</p>
<input type="checkbox" value="I accept the terms and policies by Aada Fashion.">I accept the terms and policies by Aada Fashion.
<?php
}
?>
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="testaddabusiness#shop.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<?php
if(isset($_SESSION['cart'])){
$count=1;
foreach($_SESSION['cart'] as $id => $value){
?>
<input type="hidden" name="item_number_<?php echo $count ?>" value="<?php echo $value['id'] ?>">
<input type="hidden" name="item_name_<?php echo $count ?>" value="<?php echo $value['name'] ?>">
<input type="hidden" name="quantity_<?php echo $count ?>" value="<?php echo $value['quantity'] ?>">
<input type="hidden" name="amount_<?php echo $count ?>" value="<?php echo $value['price'] ?>">
<input type="hidden" name="on1_<?php echo $count ?>" value="<?php echo $value['color'] ?>">
<input type="hidden" name="on0_<?php echo $count ?>" value="<?php echo $value['size'] ?>">
<input type="hidden" name="currency_code" value="USD">
<?php
$count++;
}
}
?>
<input type="hidden" name="return" value="http://abc/WebProject_Adda/success.php">
<input type="hidden" name="cancel_return" value="http://abc/WebProject_Adda/paypal_cancel.php">
<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">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>

Disabling Shipping Cost on Paypal for Non-Shipping Items

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>

paypal order summary missing

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".

Why is the PayPal sandbox telling me my shopping cart is empty?

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

Categories