Using PayPal IPN

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Dynex
Forum Commoner
Posts: 31
Joined: Mon Feb 09, 2009 7:24 pm

Using PayPal IPN

Post by Dynex »

Hey guys, im trying to set up a point purchasing system for an online mmorpg. I am using PayPals IPN system. I have set up and successfully tested the listen but the first part(the actual purchasing and sending order to paypal) is eluding me. Here is what I have so far...
It says there is a problem with the order process on my end.

Code: Select all

<?
include 'includes/header.php'
?>
<table class="text" width="700" style="border: solid 1px #000000;" align="center" cellpadding="5" cellspacing="0" bgcolor="#555555" size="4">
<tr><th>
Because your financial information is so sensitive, we decided not to keep in-house records and shifter the buying process onto a secure, third party: PayPal.
<br>
<br>
<form action="https://www.sandbox.paypal.com/" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="366065">
<table>
<tr><td><input type="hidden" name="on0" value="How many points would you like to buy?">How many points would you like to buy?</td></tr><tr><td><select name="os0">
    <option value="100">100 
    <option value="200">200 
    <option value="400">400 
    <option value="800">800 
    <option value="1000">1000 
</select> </td></tr>
</table>
<input type="image" align="left" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</table>
 
 
 
 
 
 
<?
include 'includes/footer.php'
?>
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: Using PayPal IPN

Post by turbolemon »

Here are some links to helpful PayPal resources which we found useful for integrating with our shopping cart payment system:

How to use PayPal NVP:
https://cms.paypal.com/us/cgi-bin/?cmd= ... PIOverview

Reference:
https://cms.paypal.com/cms_content/US/e ... nGuide.pdf

Code Samples, require PHP with cURL support:
https://cms.paypal.com/cms_content/US/e ... amples.zip

We found the sample to be quite good for basic purposes, though we wrote our own to better fit our implementation.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Using PayPal IPN

Post by Eric! »

The key part you are probably missing is in your BUY NOW buttons. When creating the buttons you go to Step 3 at the bottom and into the Add Advanced Variables you can put in your url's like this:

notify_url=http://yoursite.com/YourIPNScript.php
return=http://yoursite.com/YourThankYouToYourCustomer.htm
rm=1

The rm=1 uses GET and rm=2 uses POST, take your pick. When the button is used it will get Paypal to send the IPN data.

If you want to configure these same URLS for all your paypal purchases you can configure it in your settings and forget the advanced options.

**Instant Payment Notification: In order to use IPN, you have to have it enabled and you have to have a url to your script entered also. (Location: My Account -> Profile Click Profile, then look to Selling Preferences and Instant Payment Notification).

**Auto Return: In order to return the customer to a page on your website after the purchase, you have to have Auto Return set in your profile, and have the url to that page set also. (Location: My Account -> Profile and then look under Selling Preferences and Website Payment Preferences).
Dynex
Forum Commoner
Posts: 31
Joined: Mon Feb 09, 2009 7:24 pm

Re: Using PayPal IPN

Post by Dynex »

Ok so I added those extra variables in and redid the button. I am now trying to run it through sandbox to test it all out but I keep getting an error, any help with sandbox?

Code: Select all

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="7132668">
<table>
<tr><td><input type="hidden" name="on0" value="Points">Points</td></tr><tr><td><select name="os0">
    <option value="100">100 $5.00
    <option value="200">200 $10.00
    <option value="400">400 $20.00
    <option value="800">800 $35.00
    <option value="1000">1000 $45.00
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<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">
</form>
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Using PayPal IPN

Post by Eric! »

What's the error and when are you getting it?
Dynex
Forum Commoner
Posts: 31
Joined: Mon Feb 09, 2009 7:24 pm

Re: Using PayPal IPN

Post by Dynex »

It is happening after I choose which option I want and click the Buy Now button. And it says there is a problem with the sellers website(me) and that they should contact them directly.

These are the extra variables I added:

notify_url=http://classicwars.com/paypal/notify.php
return=http://www.classicwars.com
rm=2


notify.php is my listener.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Using PayPal IPN

Post by Eric! »

It sounds like the button wasn't created properly. What options are you trying to pass along with the buy now? Were these parameters passing properly before adding the advanced variables?

I would just delete all the paypal code and try again from scratch so you get a different hosted_button_id number. As an additional thing to check, you might need to have IPN enabled in your paypal profile.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Using PayPal IPN

Post by califdon »

The PayPal developer's forum http://paypaldeveloper.com/pdn/ is the place to go for quick answers to your integration problems.
Dynex
Forum Commoner
Posts: 31
Joined: Mon Feb 09, 2009 7:24 pm

Re: Using PayPal IPN

Post by Dynex »

Ok so I got it working. Now Im only stuck on how to pass a hidden variable to paypal so they will pass it back to me on my listener. Example. A players account number: 217


Any help on this hidden variable or setting it?

Thanks
Dynex
Forum Commoner
Posts: 31
Joined: Mon Feb 09, 2009 7:24 pm

Re: Using PayPal IPN

Post by Dynex »

Bump o.0

I know where the variables go just not sure how to set them up
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Using PayPal IPN

Post by califdon »

Dynex wrote:Ok so I got it working. Now Im only stuck on how to pass a hidden variable to paypal so they will pass it back to me on my listener. Example. A players account number: 217

Any help on this hidden variable or setting it?

Thanks
PayPal provides several "custom" variables you can use for that purpose, or you can use one of their variables that you don't need for your application, as long as the data type and size fit. The most obvious one is "custom", and there are 2 pairs of name/value optional fields, too. I also use the "invoice" field for something else, since I don't need an invoice number. The one thing you cannot do is make up your own variable field names.

As for your last question, I don't understand what you're asking. I presume you know how to designate an HTML <input> element as type='hidden', so what's the issue?

P.S. We prefer that you do not "bump" posts in this forum.
Dynex
Forum Commoner
Posts: 31
Joined: Mon Feb 09, 2009 7:24 pm

Re: Using PayPal IPN

Post by Dynex »

I know im not supposed to bump, sorry.

And about the hidden field, I mean to say custom fields. Ill look into adding those, the only problem is I cant find where to edit/add these? Do I just add them in manually in html format?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Using PayPal IPN

Post by califdon »

Dynex wrote:And about the hidden field, I mean to say custom fields. Ill look into adding those, the only problem is I cant find where to edit/add these? Do I just add them in manually in html format?
Yes, just put them anywhere within the <form> ... </form> tags. Since they will be hidden, it doesn't matter. I put them at the beginning just to make them easy to find. Each one must have a name= attribute that matches a PayPal variable name (either "custom" or one of the "on1" or "invoice" or whatever you're going to use), a type='hidden' and a value= attribute with whatever value you want to pass (use quotation marks if it's a string).
Dynex
Forum Commoner
Posts: 31
Joined: Mon Feb 09, 2009 7:24 pm

Re: Using PayPal IPN

Post by Dynex »

Ok great thanks, ill look into adding those tonight. That seems exactly what I need and is really easy. I just didnt think paypal would want people just adding to the codes but wat ever.

Thanks again.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Using PayPal IPN

Post by califdon »

Dynex wrote:Ok great thanks, ill look into adding those tonight. That seems exactly what I need and is really easy. I just didnt think paypal would want people just adding to the codes but wat ever.

Thanks again.
PayPal specifically provides the "custom" variable, which can hold up to 255 characters and is described as "User-defined field which will be passed through the system and returned in your merchant payment notification email. This field will not be shown to your subscribers", as well as 6 special "name/value" pairs of option fields:
on0 Optional 64
 
First option field name and label. The os0 variable contains the corresponding value for this option field. For example, if on0 is size, os0 could be large.
 
    *      Optional for Buy Now, Subscribe, and Add to Cart buttons
    *      Not used with Donate or Buy Gift Certificate buttons
 
on1 Optional 64   
 
Second option field name and label. The os1 variable contains the corresponding value for this option field. For example, if on1 is color then os1 could be blue.

 
os0 Optional 64 or 200 See description.
 
Option selection of the buyer for the first option field, on0. If the option field is a dropdown menu or a set of radio buttons, each allowable value should be no more than 64 characters. If buyers enter this value in a text field, there is a 200-character limit.
Note:
 
The option field on0 must also be defined. For example, it could be size.
 
For priced options, include the price and currency symbol in the text of the option selections, as the following sample code shows:
 
<option value="small">small - $10.00</option>
 
Add a corresponding option_select0 and option_amount0 variable for each priced option. Priced options are supported only for Buy Now and Add to Cart buttons. Only one dropdown menu option selection can have priced options.
 
    *      Optional for Buy Now, Subscribe, and Add to Cart buttons
    *      Not used with Donate or Buy Gift Certificate buttons
 
 
os1 Optional 64 or 200
   
Option selection of the buyer for the second option field, on1. If the option field is a dropdown menu or a set of radio buttons, each allowable value should be no more than 64 characters. If buyers enter this value in a text field, there is a 200-character limit.
 
You can specify a maximum of 7 option selections (6 with Subscribe buttons) by incrementing the option selection index (os0 through os6). You can implement up to 5 option selections as dropdown menus and up to 2 option selections as test boxes.

Note: A corresponding option field (on0 through on6) must defined.
 
    *      Optional for Buy Now, Subscribe, and Add to Cart buttons
    *      Not used with Donate or Buy Gift Certificate buttons
The PayPal technical reference can be found at https://cms.paypal.com/us/cgi-bin/?cmd= ... 8A6HF00TZS
Post Reply