SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2008
    Location
    Deadwood, SD USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php needed for Paypal IPN?

    Hi;
    I have set up 3 paypal subscription buttons for members of my web site. I need to be know when they have paid a subscription so they can gain instant access to the part of the web site they are paying for.
    What kind of page at my web site do I need to recieve the info send with a paypal IPN?
    I am somewhat experianced with php. Do I need to set up a page that will accept and place the info in a database?
    Thanks.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think paypal have a developer section on their website to help you out here. I know a few years back a friend was working on a site with me and had hours of fun using their sandbox to simulate transactions..

    As far as I'm aware its actually as simple as constructing a url with your details in, allowing the user to click it (or you could redirect them with a meta refresh or header()) and then the paypal server will transmit data back via $_POST. I may be very wrong about this though as I didn't do the coding for it. I just had the basic principle explained to me.

  3. #3
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Dakotakid50, basically how it works is you go into your PayPal account and in the IPN options you give it a URL to a PHP file which will deal with the transaction once it's been confirmed (the user does not see this, it occurs in the background via PayPal's servers), once it's all turned on and setup PayPal will verify the payment and then send some details in a header request to the php file, all you need to do is interpret this and then use the data for your own ends (such as sending an email or adding to a database or something else). The below is the standard IPN script, you just replace the bold text with your PHP code (as in what to do upon each thing occuring), that's about as simple as I can make it, other than that you will need to check the IPN integration guides to learn more about the subject!

    Code PHP:
    <?php
    //set paypal defaults
    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Host: www.paypal.com:443\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    $payment_amount = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];
    if (!$fp) {
    } else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {
    // If things went well, your stuff goes here! The payment was successful.
    // You can use the variables to do whatever you want in this section.
    }
    fclose ($fp);
    }
    ?>

  4. #4
    SitePoint Member
    Join Date
    Oct 2008
    Location
    Deadwood, SD USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys!
    I found paypal developer forum and that code. I didnt know about the sandbox thing, that will be very helpful


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •