I wanted to get the userid from paypal after the user have made his payment.
Pay.php
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $merchant_email ?>">
<input type="hidden" name="item_name" value="IPN test">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="0.01">
<input type="hidden" name="notify_url" value="<?php echo $ipn_url ?>">
<input type="hidden" name="return" value="<?php echo $return_url ?>">
<input type="hidden" name="cancel_return" value="<?php echo $cancel_url ?>">
<input type="hidden" name="userid" value="888">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif"
border="0" name="submit" alt="Buy Now">
So I would enable ipn in my paypal account and point to http://www.domain.com/ipn.php?
In ipn.php code
<?php
$userid = $_POST['userid'];
$qry = "INSERT into mypayments(userid) VALUES ('$userid') “;
$result = mysql_query($qry,$db);
?>
Is it correct? How do I get VERIFIED from paypal?
I believe that userid is an incorrect name and will not be returned in your IPN message. I use the optional fields for passing IDs and stuff needed for processing the transaction on my end.
These optional tags are on0, on1, or on3 for the custom field names and os0, ls1, and os2 for the custom field values. These values can go up to on6 and os6.
I would send on0 with a value of "UserID" and os0 the actual ID.
These values will be represented in the IPN as follows:
os0 is represented as option_selection1
os1 is represented as option_selection2
os2 is represented as option_selection3
on0 is represented as option_name1
on1 is represented as option_name2
on2 is represented as option_name3
Here's the info on PayPal's HTML parameters
Use the "custom" variable.
<input type="hidden" name="custom" value="user_id" />
Its a two step process.
PayPal will post an IPN to the url you specified in $ipn_url.
You will then get a VERIFIED response when you post all of the IPN data with an additional cmd=_notify-validate param (details) back to PayPal.
PHP sample here.
Related
I am working a codeigniter project on localhost and In which I am using paypal sandbox payment method for payment.
In which I am facing a problem, The return url is not redirect automatically and also when I click on return merchant button then It is not returning any parameter to my url.
I have set all setting of paypal, I have set the auto return on from paypal account and also set the return url but still i am not getting any response.I am usging this form and parameters.
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr';
<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
<input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="PHPGang Payment">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="userid" value="1">
<input type="hidden" name="credits" value="510">
<input type="hidden" name="amount" value="20">
<input type="hidden" name="cpp_header_image" value="http://112.196.5.114/psychics/component/images/logo.png">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="notify_url" value="http://112.196.5.114/psychics/dashboard/profile/return_url">
<input type="hidden" name="cancel_return" value="http://112.196.5.114/psychics/dashboard/profile/cancel_return">
<input type="hidden" name="return" value="http://112.196.5.114/psychics/dashboard/profile/return_url">
<button type="submit" class="btn btn-success"> Add Funds</button>
</form>
I did not get where is my fault.
Your code is fine, just add below line in your code, clear your browser's cache-cookies and try again:
< input type='hidden' name='rm' value='2'>
NOTE 1: After adding above code, PayPal will return response in POST method.
NOTE 2: Recheck and confirm that auto return must be enable from your PayPal business verified account.
You can check response by adding below line in your return page within PHP tag:
print_r($_REQUEST); OR print_r($_POST);
For more help about PayPal button parameters: check documentation
I'm adding PayPal to my checkout form. Rather than using the API, I just use a form script. However, I'm not getting the response variables from PayPal after the payment has been made. I would like to confirm the amount of money I received to see if the user has paid the amount he should've paid.
Since I dont receive the response variables from paypal, I cannot see whether the user has indeed paid the good amount of money. Am I doing something wrong? I see alot of people have problems with it and none of them had the answer.
My form:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" >
<input type="hidden" name="business" value="seller#seller.com">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="item_name" value="<?php echo $_amount_credits ?> credits">
<input type="hidden" name="item_number" value="<?php echo $_invoice_id ?>">
<input type="hidden" name="amount" value="<?php echo $_total_amount ?>">
<input type="hidden" name="lc" value="NL">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Go back to http://domain.com">
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="return" value="http://domain.com/index.php?payment=success&transaction_id=<?php echo $_GET['tx'] ?>"/>
<input type="hidden" name="cancel_return" value="http://domain.com/index.php?payment=canceled&transaction_id=<?php echo $_GET['tx'] ?>"/>
<input type="submit" class="button blue _quick_order_overview _payment_paypal" name="submit" value="Pay via PayPal">
</form>
You should use Instant Payment Notification (IPN) for this sort of thing. There are lots of good templates for this available on GitHub/Packagist, etc.
IPN will POST transaction data to a listener script you have setup on your server any time a transaction happens on your PayPal account. This would be for payments, refunds, disputes, cleared e-checks, etc. You can automate all sorts of tasks based on the different txn_type's that IPN sends you.
Here is my paypal buy now html code:
<form name="_xclick" action="https://www.paypal.com/ca/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="alex#xumanii.com">
<input type="hidden" name="item_name" value="Bewolf Shooping Cart">
<input type="hidden" name="amount" value="<? echo $grandtotal2;?>">
<input type="hidden" name="add" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="member_id" value="<? echo $info['member_id'];?>">
<input type="hidden" name="return" value="http://www.bewolfclothing.com/thankyou.php">
<input type="hidden" name="notify_url" value="http://www.bewolfclothing.com/notify_paypal2.php">
<input type="hidden" name="cancel_return" value="http://www.bewolfclothing.com/mycart.php">
<input type="hidden" name="undefined_quantity" value="0">
<div class="submit-container"><input class="submit-button" type="submit" name="submit" value="CHECK OUT" /></div>
</form>
In my paypal account, under profile, my selling tools, I have set the AUTO RETURN to ON and I put the thankyou page in there.
After the purchase, it goes to the thankyou page, but the $_REQUEST['tx'] for the paypal transaction ID is not working and the notify_url NEVER gets called.
I searched online and saw that lots of people seem to have trouble with that, but I couldn't find a solution.
notify_url is used to Instant Payment Notification and the url should always be a live URL.
To get the tx ID, you need to
-Auto Return is set to ON
-Valid Return URL
-Payment Data Transfer is set to ON
and in your "http://www.bewolfclothing.com/thankyou.php"
$tx_id = $_GET['tx']; //gives you tx id
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>
Basically I just want to turn off the button after people purchase the art and send them a receipt. I would also like to have a copy of their information. This is what I am passing through my array:
<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="email#mydomain.com" />
<input type="hidden" name="item_name" value="<?php echo $title; ?> (ID:#<?php echo " {$p['id']}" ?>)" />
<input type="hidden" name="item_number" value="<?php echo "{$p['id']}" ?>" />
<input type="hidden" name="amount" value="<?php echo "{$p['price']}" ?>" />
<input type="hidden" name="shipping" value="39.99" />
<input type="hidden" name="return" value="http://mydomain.com/thankyou.php" />
<input type="submit" value=" " class="button" />
</form>
How do I setup a sold field in my database and show/hide my button in php?
IPN, API which do I need to use to make it happen?
Cheers!
I would setup the IPN listener to mark the item's status as sold in it's database table (you are generating that form based on a database?) when the IPN comes back "VERFIFIED" and payment_status = 'Complete'. Then, only generate that form when the item is not sold.
If you don't know how to implement an IPN listener, here is a tutorial: PayPal IPN with PHP