Paypal IPN With Paypal..

I'm wondering how to set this up..

Page 1 of 1

6 Replies - 1282 Views - Last Post: 02 November 2010 - 10:36 AM Rate Topic: -----

#1 josh06  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 139
  • Joined: 27-October 06

Paypal IPN With Paypal..

Posted 01 November 2010 - 01:35 PM

Hi everyone,

I am building a website that accepts payment from people via Paypal.
It's sort of like a coupon website. A person buys this coupon / deal on with Paypal and in return
receives the code to use to receive the deal off the person that put it on there.

What I can't get my head around, is how to find out if the person has paid it.
I have been looking at IPN but I don't know where to start really..

I'm not asking for code as I'm pretty sure I can write it. But I just want to know how to find out if someone has actually paid for a deal automatically so that the system can send them an e-mail with their unique code.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Paypal IPN With Paypal..

#2 Dannyboy997  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 64
  • View blog
  • Posts: 258
  • Joined: 17-April 09

Re: Paypal IPN With Paypal..

Posted 01 November 2010 - 01:47 PM

This would be fairly easy to do.

First when you require the api, you should add a row in a table called requests

id(int)(auto increment) (primary Key)
uid(int)
completed(bool)


This would be the column for the table. Now you just have to insert a row inside that table, with the user ID and 0 for completed.

Not sure if there's different versions of the API for PHP. But the one I use has the following:
case 'process':      // Process and order...

This is where you would have that query...

And this:
case 'success':      // Order was successful...

The code in this will only run if the user has successfully paid.
So you would put another query that updates the previous one, but completed to 1.

Hope this makes sense.

Cheers,
Daniel
Was This Post Helpful? 2
  • +
  • -

#3 josh06  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 139
  • Joined: 27-October 06

Re: Paypal IPN With Paypal..

Posted 01 November 2010 - 02:30 PM

This does make sense thank you.
Another thing though, should I run this code when someone clicks 'Pay Now'?
I mean how do I get this code to run after someone has made a payment?

Would I get them to make the payment, then run the IPN code?

Thanks again
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5346
  • View blog
  • Posts: 27,301
  • Joined: 10-May 07

Re: Paypal IPN With Paypal..

Posted 01 November 2010 - 02:45 PM

You should have two files, one is the class file, this will make the secure connection to PayPal's IPN website, the 2nd file will gather the data, do anything that you need to do to verify it from your side, & then pass those values & variables off to PayPal. Then PayPal processes the data & returns their code to your defined website (which was passed to them in an API variable) where you parse & handle the result.
Was This Post Helpful? 0
  • +
  • -

#5 josh06  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 139
  • Joined: 27-October 06

Re: Paypal IPN With Paypal..

Posted 01 November 2010 - 03:21 PM

Ok I'm just trying to get my head around it that's all haha.

So have a file that makes the connection to the IPN site and also transfers the data back to Paypal for processing and my file that saves the data to be used?

I'm just really stuck about implementing it :/
How do I link to the IPN file, through the Pay now button?
They click pay now, pay for it and then I run the IPN script?

I'm really stuck.
Thanks for your help..
Was This Post Helpful? 0
  • +
  • -

#6 Dannyboy997  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 64
  • View blog
  • Posts: 258
  • Joined: 17-April 09

Re: Paypal IPN With Paypal..

Posted 01 November 2010 - 04:59 PM

It does get pretty confusing when there isn't a really good guide on this.

Anyways, what I did on one of my sites (http://motionsharing.com). There's an upgrade link on the site, where you can get more space. You then choose a package. It then has a paypal button that is inside a form. Which sends a request to a file index.php inside the Paypal folder. This folder has the index.php and the class file. The index.php file just rappes up the data and prepairs it for paypal.

<?php
session_start();
// Setup class
require_once('paypal.class.php');  // include the class file
$p = new paypal_class;             // initiate an instance of the class
#$p->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';   // testing paypal url
$p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';     // paypal url



// setup a variable for this script (ie: 'http://www.micahcarrick.com/paypal.php')
$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$amount = $_GET['fprice'];
$plan = $_GET['fplan'];



// if there is not action variable, set the default action of 'process'
if (empty($_GET['action'])) $_GET['action'] = 'process';  

switch ($_GET['action']) {
    
   case 'process':      // Process and order...
   	if ($plan == '1')
   		$splan = 'For 1 Month';
   	if ($plan == '3')
   		$splan = 'For 3 Months';
   	if ($plan == '6')
   		$splan = 'For 6 Months';
   		
   		
   		
      $p->add_field('business', 'youremailhere');
      $p->add_field('cancel_return', $this_script.'?action=cancel');
      $p->add_field('notify_url', $this_script.'?action=ipn');
      $p->add_field('item_name', 'MotionSharing Premium Account '.$splan);
      $p->add_field('amount', amountvariable);
	  $p->add_field('custom', $_SESSION['username']);

      $p->submit_paypal_post(); // submit the fields to paypal
      //$p->dump_fields();      // for debugging, output a table of all the fields
      break;
      
   case 'success':      // Order was successful...
 		
 		
 				
 				//Update the Query...
//This is where you would update Continue.
	//Then Redirect to a success page.

      break;
      
   case 'cancel':       // Order was canceled...

      // The order was canceled before being completed.
 
      header('Location:http://motionsharing.com/order-cancel.php');
      
      break;
      
   case 'ipn':         
      if ($p->validate_ipn()) {
          		 
		 $data = $p->ipn_data;
		
      }
	  
	  
      break;
 }     

?> 




This is the index.php file that sets everything up. It's not that complicated with this code.


Then you place your queries at the appropriate place.

Hope this helps, and makes sense.

Cheers,
Daniel

This post has been edited by Dannyboy997: 01 November 2010 - 05:30 PM

Was This Post Helpful? 1
  • +
  • -

#7 josh06  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 139
  • Joined: 27-October 06

Re: Paypal IPN With Paypal..

Posted 02 November 2010 - 10:36 AM

Ok thank you Danny, I have this code so I'll try implement it
Thanks :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1