SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    On PayPal's IPN manual, setting it up...

    ...Step 3, where it talks about giving PayPal a "URL" for them to post data, what do they really mean? Do they want me to give them an HTML page, a PHP page??? Or just a URL to a web directory???

  2. #2
    SitePoint Addict
    Join Date
    Jul 2002
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A URL to whatever script is going to process the IPN (which is a "form post").

    Ex: "http://www.mysite.com/ipn.php"
    Pricetack - sell your goods with automatic markdowns

  3. #3
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do they provide the code for this page or do I need to write it?

  4. #4
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, well I found a free PHP script they provide...here's the code they provide for IPN:


    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';

    foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }

    // post back to PayPal system to validate
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

    // assign posted variables to local variables
    $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) {
    // HTTP ERROR
    } else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {
    // check the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment
    }
    else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
    }
    }
    fclose ($fp);
    }
    ?>

    ------------------------

    So do I just upload this onto my server as a PHP file, and then enter the URL into the PayPal website? I don't see where I can write a message to the buyer's address. Sorry if this is a dumb question, thanks...

  5. #5
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jeez, I really need help with this... Is the above thing my IPN script, or something else? I have no idea what the heck I'm supposed to do...feel like such a clueless idiot with this PayPal stuff. Lol...

  6. #6
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi greqc,
    tells us what you want to do with your paypal account so I can give you some directions how and what.

  7. #7
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, here's what I want to do:

    I want to send a confirmation email to my client, after he/she has made the purchase (with my own custom message) and a link to where they can download their product. I'm not even concerned about the link security at this point, I just want to know how I can use PHP to send a confirmation email after someone makes a purchase.

    That's it...thanks...it would be SO AWESOME if you could help me with this...

  8. #8
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sylow...where are you?

  9. #9
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It contains few steps
    1. I assume you have a database which contains your clients
    2. When you are sending them to paypal, use a reference id so paypal can post back the result of payment to your a php script
    3. This php script will check your client database with ref_id and get email address of customer to send an email

    But you can also use
    $item_name = $_POST['item_name'];
    $receiver_email = $_POST['receiver_email'];

    to send emails to your customer. But do it in
    if (strcmp ($res, "VERIFIED") == 0) {
    //HERE
    }


    Now if your php skills is null then you will need more than this help, you might ask in trading forum

  10. #10
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I don't have a database that contains my clients... I assume that the script would have to add clients' info into a database whenever they make an order. Should be a simple script, right?

    Something like this:

    <?
    function db_connect()
    {
    $result = mysql_pconnect("mySQLDB", "user", "password");
    if (!$result)
    return false;
    if (!mysql_select_db("DB_name"))
    return false;
    return $result;
    }
    ?>

    I know some PHP, but don't have much experience in MySQL.

    Also, should quotes be added in between those curly braces (for the email)?

  11. #11
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    sylow, I am about to use Paypal's IPN for a project at work. From your experience does the code that Paypal provides work well? Or is it just a rough example and there's plenty of work that needs to be done with it? I know I'll have to deal with the data once it arrives but as for communicating with their IPN, is their code enough or do I need more?

  12. #12
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So is this basically what I need to use as my IPN page?

    <?php
    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }
    // post back to PayPal system to validate
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
    // assign posted variables to local variables
    $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) {
    // HTTP ERROR
    } else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {
    $message = "Thank you for purchasing the product! \n \n To download your product, click the
    link below:\n LINK here\n \n For support, email me at
    this web page: http://www.html4me.com/contact/contactform.php \n \n Sincerely, Greg Cook"
    $headers = "From: Greg Cook <host@html4me.com>\n";
    mail($payer_email, "Product download", $message, $headers);
    }

    else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
    }
    }
    fclose ($fp);
    }
    ?>

    -------------------------------

    ...or am I missing something? All I want is for an email to be sent to each person that buys the online product, with a link to download his/her product after purchase. Would this work, or am I overlooking something? Thanks...

  13. #13
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bump.

  14. #14
    SitePoint Addict
    Join Date
    Jul 2002
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have configured your Notification URL in your Profile, that should be OK.

    If you set your notify_url in the payment button, you should confirm that receiver_email is your own email address and that the mc_gross/mc_currency is correct (to prevent any farudulent activity).
    Pricetack - sell your goods with automatic markdowns


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
  •