amount variable value changes in paypal while payment begins - php

I am using paypal functionality in a sandbox environment.I am implementing very basic functionality of paypal. The problem is that when user buys more than 1 quantity of same product the value of amount in the paypal gets multiplied. I am sure that I am missing some variable to use but can't figure out that. The total amount I am calculating on the server side. e.g if buyer selects 2 quantities of same product, the price get multiplied 2 times and this is the value of amount variable in paypal form. But when form is submitted to paypal, the amount variable's value become the value of item price and final amount in paypal is again multiplied by 2.
I am giving here my paypal form
<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="xyz#exmp.com">
<input type="hidden" name="item_name" value="<?php echo $_SESSION['itemName'];?>">
<input type="hidden" name="quantity" value="<?php echo $quant;?>">
<input type="hidden" name="item_price" value="<?php echo $price;?>">
<input type="hidden" name="amount" value="<?php echo $z?>">
<input type="submit" name="submit" value="pay">
<INPUT TYPE="hidden" NAME="return" value="return website">
<INPUT TYPE="hidden" NAME="cancel_return" value="return website">
</form>
where $quant is the quantity of product, $price is the price of product,
$z is the calculated total amount($quant * $price)
if $quant=2
$price=1000 per unit of product
then $z = 2000
and in paypal website the values become
Item price: 2000.00
Quantity: 2
Amount: 4000
please if any body can help.

According to the Paypal manual there's no variable named item_price.
There's quantity:
Number of items.
And there's amount:
The price or amount of the product, service, or contribution, not
including shipping, handling, or tax
So you should have:
$z = 1000; //price_per_product;
$quant = 2;

Related

Paypal tax_rate variable is not working

I have integrated Paypal standard payment in my php website now i required to send tax in Paypal payment so i have pass tax_rate variable in paypal form, all are working nice but tax is not send in paypal.
My Paypal form code is below.
<form action="<?php echo PAYPAL_URL;?>" name="paypalForm" method="post">
<input type="hidden" name="business" value="<?php echo PAYPAL_EMAIL;?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" id="item_name" value="<?php echo $mainObj->listing_title;?>">
<input type="hidden" name="item_number" id="item_number" value="<?php echo $booking_id;?>">
<input type="hidden" name="custom" value="<?php echo $mainObj->user_id.'__'.$objExtraPostData->message_to_host.'__'.$objExtraPostData->host_call.'__'.$vat.'__'.$mainObj->pay_price.'__'.$guest_invite_id.'__'.$host_invite_id.'__'.$review_guest_invite_id.'__'.$review_host_invite_id; ?>"/>
<input type="hidden" name="amount" id="amount" value="<?php echo $mainObj->pay_price;?>">
<input type="hidden" name="discount_amount" id="discount_amount" value="<?php echo $discount_price;?>">
<input type="hidden" name="tax_rate" value="<?php echo $vat;?>">
<input type="hidden" name="currency_code" value="<?php echo DEFAULT_PAYMENT_CURRENCY_CODE;?>">
<input type="hidden" name="return" value="<?php echo SITE_MOD."nct-paypal/thankyou.php";?>">
<input type="hidden" name="cancel_return" value="<?php echo SITE_MOD."nct-paypal/failed.php";?>">
<input type="hidden" name="notify_url" value="<?php echo SITE_MOD."nct-paypal/notify.php";?>">
</form>
Check if the tax_rate can be used with your payment type. In addition, it might be better when you set your tax rate in your account profile as described beneath.
Transaction-based tax override variable. Set this variable to a percentage that applies to the amount multiplied by the quantity selected during checkout. This value overrides any tax settings set in your account profile. Allowable values are numbers 0.001 through 100. Valid only for Buy Now and Add to Cart buttons. Default – Profile tax settings, if any, apply.

Paypal Payment need transactions details

I have used paypal payment form submission but in response we didn't get payment status and transactions detail we just geting payer_status.
My code is below:
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="currency_code" value="AUD" >
<input type="hidden" name="rm" value="2" >
<input type="hidden" value="" name="custom" id="custom" />
<input type="hidden" name="invoice" value="" >
<input type="hidden" name="item_name" value="">
<input type="hidden" name="a3" value="" >
<input type="hidden" name="p3" value="" >
<input type="hidden" name="t3" value="" >
<input type="hidden" name="src" value="1" >
<input type="hidden" name="sra" value="1" >
<input type="hidden" name="return" value="xx">
<input type="hidden" name="cancel_return" value="xx">
<input type="hidden" name="no_shipping" value="1" >
Let me know any solution to get transaction details.
For getting paypal transaction details do follow steps :
Auto Return should be "ON" for getting transaction detail via paypal account.
a: Login to your paypal account .
b: Then go to your profile -> myselling tool ->website preference
c: Click on the auto return button make it "ON".
d: And give the return url link on this page .(In my case my app return url is success.php)
2.When Payment will be successfully completed then provide $_REQUEST array which contains product id, PayPal transaction ID, PayPal received amount value, PayPal received currency type and PayPal product status.
and write this code to your success.php page.
if (!empty($_REQUEST)) {
$product_no = $_REQUEST['item_number']; // Product ID
$product_transaction = $_REQUEST['tx']; // Paypal transaction ID
$product_price = $_REQUEST['amt']; // Paypal received amount value
$product_currency = $_REQUEST['cc']; // Paypal received currency type
$product_status = $_REQUEST['st']; // Paypal product status
}
I hope this clears up the paypal transactions details.

Passing variable values over to paypal's cart to carry out payment

I have created a basket where a customer can add to and update etc. The product itself is grabbed from the database and displayed in a table in the basket. How do I use Paypal from here? I now want a button called 'pay' that the user can click and then it takes them to Paypal to pay. But I want the details of the items to be reciprocated in the Paypal receipt.
I have signed up to paypals web standard payment. I think I just need the buy button but as mentioned, I am not sure how to get products over to Paypal. I have noticed that the steps are similar for third party carts but the code provided is this:
<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="business" value="seller#dezignerfotos.com">
<input type="hidden" name="item_name_1" value="Item Name 1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="shipping_1" value="1.75">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="2.00">
<input type="hidden" name="shipping_2" value="2.50">
<input type="submit" value="PayPal">
But I dont see how this can relate to my cart. This shows that the cart has 2 items (item_name_1 & item_name_2) but what if the customer has 3? How am I suppose to know how many items the customer has added?
Same issue with the amount - how do I know that an item is going to cost £1.00 or £2.00?
This does not appear to by dynamic depending on what the customer selects? Can somebody explain
You just connect to your database and loop the values from your database to the form's input types.
SELECT * from customer where customer_id = $customer_id
You say that you've already created their shopping cart? I'm not sure how you've stored this, but loop through it, adding these hidden inputs for each item. If for example, your cart was in a PHP array:
$i = 0;
foreach($cart as $item) {
?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $item['name']; ?>">
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $item['cost']; ?>">
<input type="hidden" name="shipping_<?php echo $i; ?>" value="<?php echo $item['shipping']; ?>">
<?php
$i++;
}
unset($i);
Obviously you would need to rename the variables to match how you've stored the values in your cart.

Passing values or variables over to paypal cart

I am developing a website so that a customer can buy gardening products. Currently, a customer can browse products on the website. When they select an individual product, I want them to be able to add to cart using Paypal's custom button. My website is set up so that when a user selects a product, it grabs the information from the database. What do I need to do in order for the product they have added to cart to appear in the Paypal cart? (with its name, and price).
From what I understand, you have to create each individual button for each item on your website. But I do not know what product the customer has selected from the database and my website is set up so that it retrieves the product info from the db.
Hope somebody could help me
A single button can use different products , you must be in a loop. But hidden params would be different.
<input type="hidden" value="Scicssors" name="item_name">
<input type="hidden" value="return.php" name="notify_url">
<input type="hidden" value="10.00" name="amount">
...........................................
There are more than fields required to pass as hidden. You can send these along with form submission button
Refer this link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
You can use a single button for all products. You can change the item_name and amount depending upon the product selected. You can pass userid in item_number field.
When a customer selects the product, query to the database and fetch the product name and amount and update it to the hidden fields.
<?php
$amt = amt from db;
$name = product name from db;
$userid = user's id;
?>
<form name=subs action='https://www.paypal.com/cgi-bin/webscr' method='post'>
<table cellspacing=0 cellpadding=0><tr><td>
<input type="hidden" name="on0" value="user">
<input type="hidden" name="os0" value="<?php echo $user_email; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sales#yoursite.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="add">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="http://yoursite.com/payment-success.php"> //return to this url after payment completed
<input type="hidden" name="cancel_return" value="http://yoursite.com/payment-cancel.php"> //return to this url when payment cancelled
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="custom" value="CustomValue">
<input type="hidden" name="notify_url" value="http://yoursite.com/payment-confirm.php"> //return instant payment notification to this url where you can get the response from paypal and process it
<input type="hidden" name="event" value="add">
<input type="hidden" name="mnt" value="0">
<input type="hidden" name="amount" value="<?php echo $amt; ?>" id="paypalamt"> //the product's amount
<input type="hidden" name="item_number" id="paypalno" value="<?php echo $userid; ?>"> //you can send the customer/user id with this, so that you can retrieve it after payment completion
<input type="hidden" name="item_name" id="itemname" value="<?php echo $name; ?>"> //here you can set your product name
</td></tr>
</form>

Send values of item to paypal cart [duplicate]

I am developing a website so that a customer can buy gardening products. Currently, a customer can browse products on the website. When they select an individual product, I want them to be able to add to cart using Paypal's custom button. My website is set up so that when a user selects a product, it grabs the information from the database. What do I need to do in order for the product they have added to cart to appear in the Paypal cart? (with its name, and price).
From what I understand, you have to create each individual button for each item on your website. But I do not know what product the customer has selected from the database and my website is set up so that it retrieves the product info from the db.
Hope somebody could help me
A single button can use different products , you must be in a loop. But hidden params would be different.
<input type="hidden" value="Scicssors" name="item_name">
<input type="hidden" value="return.php" name="notify_url">
<input type="hidden" value="10.00" name="amount">
...........................................
There are more than fields required to pass as hidden. You can send these along with form submission button
Refer this link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
You can use a single button for all products. You can change the item_name and amount depending upon the product selected. You can pass userid in item_number field.
When a customer selects the product, query to the database and fetch the product name and amount and update it to the hidden fields.
<?php
$amt = amt from db;
$name = product name from db;
$userid = user's id;
?>
<form name=subs action='https://www.paypal.com/cgi-bin/webscr' method='post'>
<table cellspacing=0 cellpadding=0><tr><td>
<input type="hidden" name="on0" value="user">
<input type="hidden" name="os0" value="<?php echo $user_email; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sales#yoursite.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="add">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="http://yoursite.com/payment-success.php"> //return to this url after payment completed
<input type="hidden" name="cancel_return" value="http://yoursite.com/payment-cancel.php"> //return to this url when payment cancelled
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="custom" value="CustomValue">
<input type="hidden" name="notify_url" value="http://yoursite.com/payment-confirm.php"> //return instant payment notification to this url where you can get the response from paypal and process it
<input type="hidden" name="event" value="add">
<input type="hidden" name="mnt" value="0">
<input type="hidden" name="amount" value="<?php echo $amt; ?>" id="paypalamt"> //the product's amount
<input type="hidden" name="item_number" id="paypalno" value="<?php echo $userid; ?>"> //you can send the customer/user id with this, so that you can retrieve it after payment completion
<input type="hidden" name="item_name" id="itemname" value="<?php echo $name; ?>"> //here you can set your product name
</td></tr>
</form>

Categories