php script in paypal form - php

I am writing a php script in Paypal form. I am sending return url using $testUrl variable which will work after successful payment but it is not redirecting to that url.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<select name="amount">
<option value="10">10 SEK</option>
<option value="20">20 SEK</option>
<option value="30">30 SEK</option>
</select>
<?php $testUrl= "http://www.google.com"; ?>
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="3FWC3TJEYANK4" />
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" />
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
<input type="hidden" name="notify_url" value="http://beeurban.ayond.com/wp-content/payment/ipn.php" />
<input type="hidden" name="currency_code" value="SEK" />
<input type="hidden" name="return" value="<?php echo $testUrl ; ?>" />
</form>

The auto return option need to be activate in your paypal account.
See here : Setting PayPal return URL and making it auto return?
Please look at #andrew's answer below : https://stackoverflow.com/a/13468873/1722914

Your problem is that you're using a hosted button. You can't add additional fields to the button code like this when you're using hosted buttons. Everything has to be configured within the button manager in your PayPal account. Your notify_url probably isn't working either, from what I'm seeing, because that would have to be setup in the button manager, too...unless you have the same notify URL setup in your profile under Instant Payment Notification Preferences. Then that would take effect, but what you're passing here would be ignored.
In the button manager, Step 3 - Customized Advanced Features, has an option for "Take customers to this URL when they finish checkout" that you need to enable and fill in your return URL there. You'll also see under "advanced variables" that you can add notify_url there.
Unfortunately, you can't use dynamic values like you're attempting to do with that PHP variable for the return URL. If the return URL is something that can change depending on the order you'll need to use a non-hosted button.
To do that, in Step 2 - Track Inventory, Profit & Loss, you'll need to uncheck the Save button at PayPal box. This will give you different HTML code that will have more fields included, and then you can add your own values for return, notify_url, etc.

http://jream.com/public/lab/paypal_ipn.class.php
this may be helpful in guiding you

Related

Paypal donation return url is giving an empty array

I have been trying to implement paypal donation in my site. The usual form is okay, working fine. But I wanted add a return url where the paypal returns after successfully donations. The paypal returning to that page successfully but I can not get any data of the donation details in return url. Here is the code I wrote for the donation form:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_donations" />
<input type="hidden" name="business" value="myEmail#gmail.com" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="rm" value="2">
<input type="hidden" name="return" value="http://localhost/thankyou.php" id="paypal_return">
<input type="hidden" name="notify_url" value="https://test.org/ipn_route_for_payment" id="ipn_url">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" />
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>
And the following code I wrote in return url:
<?php
print_r($_POST);
print_r($_REQUEST);
I tried with both request and post method but did not get any data. But I am getting IPN notifications.
Note: I tried with live payment too
As comments have mentioned, PDT uses a GET string.
So you would want to make sure that is enabled, and then access the contents of $_GET
Please note that PDT is for informational purposes only. No return is ever guaranteed to happen after a Payments Standard transaction -- the buyer may be shown a receipt and need to click to return for example, or they may close their browser or have it crash.
Absolutely no business logic should be triggered by PDT; its only servicable purpose is to show a slightly more information "Thank you" / "Success" type message to the customer.
Any actual business logic needs to be triggered by an asynchronous IPN or webhook instead.

return facility in paypal button not working

I am trying to send passthrough data in a paypal paynow button and have paypal return that data to my php page when user clicks “return to merchant” button after paying.
For this I am using the “return” facility in the paypal button, together with rm=2 to send all the data back as post. However, I cannot get it to work. Here is my paypal button html:
<form name="paypal2" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="xxx">
<input type="hidden" name="invoice" value="testinvoice_fromcode2">
<input type="hidden" name="custom" value="testcustom_fromcode1">
<input type="hidden" name="on0" value="yes"><!--agreetc-->
<input type="hidden" name="os0" value="<?php echo $aid; ?>">
<input type="hidden" name="on1" value="<?php echo $id; ?>">
<input type="hidden" name="os1" value="<?php echo $agent; ?>">
<input type="hidden" name="return" value=http://www.example.com/Admin/conpanel/privat/phpvendorpaidad.php>
<input type="hidden" name="rm" value="2">
<input id="submit" type="image" src="https://www.paypalobjects.com/en_GB/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_GB/i/scr/pixel.gif" width="1" height="1">
</form>
In the IPN notification, paypal renders:
os0 as option_selection1,
os1 as option_selection2,
on0 as option_name1,
on1 as option_name2,
I know that on0 and os0 are supposed to be used as name value pairs but way back in 2009 when I first wrote this script there were only 2 sets allowed and therefore I used all 4 to carry values and it worked then.
But essentially, I cannot understand why
<input type="hidden" name="return" value=http://www.example.com/Admin/conpanel/privat/phpvendorpaidad.php>
<input type="hidden" name="rm" value="2">
is not working.
I cannot pick up these values in the receiving script, phpvendorpaidad.php, either as
$aid=$_REQUEST['option_selection1'];
or as
$aid=$_REQUEST['os0'];
for example.
Can anyone see what I am doing wrong? Much appreciated.
I also have an IPN listener page that is working normally. Could another way be to build this in to the IPN listener page using javascript to send the form data automatically on page onload?
Is paypal actually POSTing to your return script or using GET? In the latter case, you can see the txn_id and some other info in the query string, but you will NOT get the whole payment detail data.
If you have Auto Return set to On (meaning the user get automatically redirected back to your site, without having to click a button), then paypal with send a GET request and will include only a few items.
var_dump($_REQUEST) and var_dump($_POST) in your script to see what you are getting.
Actually the problem lay in defective if/else logic in my return code, which was set up in 2009 to handle the GET variables that Paypal was sending to the return script in those days. This logic had to differentiate between the POSTed data received from a preceeding form on my server and the GET data received from Paypal. Paypal appears to have chenged since 2009 and no longer sends GET data to the return script but POST data via
<input type="hidden" name="return" value=http://www.example.com/Admin/conpanel/privat/phpvendorpaidad.php>
<input type="hidden" name="rm" value="2">
Once this was corrected the program worked.
However, I was only able to discover the problem thanks to the brilliant suggestion from JBart to var_dump($_REQUEST) (or the more easily read print_r($_REQUEST)). Without this I would still have been floundering. So cheers JBart, would love to buy you a drink if you are in the neighbourhood (NW London)!
And no, I didn't need to extract any variables from the received POSTed array (see my last comment above), just normal '$payment_status = $_POST['payment_status'];'. In this I had misinterpreted another thread on the subject in "How can I get posted data passed along when the user is first redirected through Paypal?"

How to validate PayPal data with IPN when using non-hosted PayPal button

I am rather new to PHP and adding payment gateways
However, I want to learn and am having a go at a small shop with a Paypal buy now button which is linked to a PHP cookies cart
It is working fine and shows a list of the items in the cart, however I am worried it is not secure enough and someone could change the amounts or add their email address so that they receive funds
I would like to integrate the instant payment notification (IPN) : https://www.paypal.com/uk/cgi-bin/webscr?cmd=p/acc/ipn-info-outside
Do I need to do much more than follow the above instructions and make an IPN in the merchant account?
I am a bit confused about what the POST code means and how to integrate it into my button code
Please could someone explain what I need to change in my Paypal button code below so that I can make the payment system secure? I keep breaking it
<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="item_name_1" value="Something Cool">
<input type="hidden" name="quantity_1" value="5">
<input type="hidden" name="amount_1" value="1"-->
<?php
$i = 0;
foreach (json_decode($_COOKIE['cart_items_cookie']) as $key => $value) {
$i++;
echo '<input type="hidden" name="item_name_'.$i.'" value="'.$value->name.'">';
echo '<input type="hidden" name="amount_'.$i.'" value="'.$value->price.'">';
}
?>
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="me#mysite.com">
<input type="hidden" name="item_name" value="Order#21874">
<input type="hidden" name="currency_code" value="GBP">
<!--<input type="hidden" name="amount" value="<?php //echo $_GET['total'];? > "> -->
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/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.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
Any help or point in the right direction much appreciated!
The best thing to do would be to use the Express Checkout API instead of Payments Standard (HTML forms). This requires more programming and working with API calls, however, I have a PayPal PHP class library you can use to make all of the calls very quick and easy for you.
Express Checkout completely hides everything about the payment and it has a lot more features available to it than Standard does.
If you want to stick with Standard, you can build a hosted button by creating the button from within your PayPal account, and make sure to select the option to "Save the button at PayPal." That is what makes it hosted.
Then you'll still get HTML to paste into your site where you want the payment button to show up, but it will only have a few lines, and one of those lines will show a "hosted_button_id".
This secures the button from tampering like you mentioned, but it limits customization you can do with your checkout in general.

Paypal buy now button how to capture price/option dropdown data in ipn listener

I have a paypal pay now button with a dropdown where a user can select 2 different events.
How can i capture what was selected in the dropdown? My current form is not working.
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="TFMANJVCMFZX4">
<input type="hidden" name="option_name1" value="Dinner/Show">
<input type="hidden" name="notify_url" value="http://mysite.com/ipn">
<label>Dinner/Show</label>
<select name="os0" id="paypalDropdown">
<option value="Meal + Event">Meal + Event $15.00 USD</option>
<option value="Event Only">Event Only $10.00 USD</option>
</select>
<input type="hidden" name="currency_code" value="USD">
<input id="paypalButton" type="image" src="https://www.paypalobjects.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.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
To be more specific, i'm using this library - https://github.com/orderly/codeigniter-paypal-ipn and i'm logging the variables and all the option_name and option_selection vars are blank
onchange="myFunction(this)"
this is the entire object, an in JavaScript can be accessed like this
function myFunction(obj) {
var dropDownValue = obj.value;
}
EDIT:
Oops, just read your code.
The select value can be accessed in PHP like this :)
echo $_POST['os0']; // the select fields name
if you have IPN, then PayPal will call the URL you have prepared for this moment and aftre the payment, paypal will send all the data you need. from address and currency to the name of the items he had bought and the price of them. so you can get them at that time.
otherwise you have to write a javascript which catches the selected value and send it via ajax to somewhere else...
Looks like you are trying to use hosted paypal button but have not defined any configuration in your profile.
You might be getting this error message : "PayPal cannot process this transaction because of a problem with the seller's website"
There is no need to capture the values in the form above as this is taken care by configuration on paypal account as below:
Login to your paypal account
Go to Profile-> Selling Preferences -> My Saved Buttons
Edit the sample button (Add a dropdown menu with prices and options e.g Meal + Event $15.00 USD, notify_url etc.)
Save changes
Select the auto generated form code which can be used without any changes
To use the field os0, you must also use the field on0
Where:
on0 = First option field name. If omitted, no variable is passed back to you.
.
-best of luck.

PayPal Buy Now button: Add my own price?

I have a form that a user fills out prior to reaching the PayPal Buy Now button. The form contains information such as the users name and the amount they will be paying (in a hidden field).
I know there probably is a way to pass the name variable to PayPal using the Advanced Variables feature, but is there a way to alter the buttons price?
And can I do this using PHP variables?
Eg: item_name=<?php $myitem ?>
Any advice would be great! Thanks
EDIT: Form as requested
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXX">
<input type="image" src="https://www.paypalobjects.com/en_AU/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.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>
If I understand correctly your question, you have to put the amount hidden field on paypal form.
e.g.
<input type="hidden" name="amount" value="100">
<input type="hidden" name="currency_code" value="USD">
This form will prompt paypal to ask $100 from buyer.
of course you can add your own var there e.g.
<input type="hidden" name="amount" value="<?php echo $amount;?>">
HTH
I cannot even get this working with an unhosted button. It seems Paypal never lets you change the amount. I see it like this :
hosted button : amount is set in the code pointed to by the 'hosted button id'
unhosted button : PayPal encrypts the information, of which amount is part of
so, in either case you cannot change it, or at least, I haven't been able to do this.
Having said that, there is a variable called 'amount' you can use. So, I'm very confused about this.

Categories