IPN for multiple notify_url

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Freedom35
    Staff Sergeant

    • Dec 2006
    • 43

    IPN for multiple notify_url

    Hi,

    I'm using IPN from paypal to run some of my programs. Currently only one notify_url is sent for every single IPN. Is there a way to send the same IPN from the same paypal button to 2 different notify_url?
    http://www.r2rwealthsecrets.com
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: IPN for multiple notify_url

    Not that i know of, through PayPal. However, you could, however, from the first notify URL (which is, i suppose, in php) try to open a socket to the seconf URL and pass over the necessary info.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    • Freedom35
      Staff Sergeant

      • Dec 2006
      • 43

      #3
      Re: IPN for multiple notify_url

      I found the following php which I think can send to more than one notify_url. But somehow it did not works. What I see is that from Line 5 - 78 it seems to contain some valid code but was "grey" out.Can you help to debug it?

      <?php

      //* Just one variable to set:

      $ppipn = 'ipn-gateway.txt'; // Path to IPN Handler List!!

      ################################################## #######
      # NOTHING BELOW NEEDS TO BE EDITED UNLESS YOU MUST? #
      ################################################## #######

      if (!function_exists('file_get_contents'))
      { // PHP <= 4.2.3
      function file_get_contents($datget)
      { // PHP >= 4.3.0
      $datget = file($datget);
      return $datget[0];
      }
      }

      if (empty($_POST))
      {
      die();
      }

      else
      {
      $paypal = silentPost('www.paypal.com','/cgi-bin/webscr',$_POST,80,2,60);

      if (strcmp ($paypal, 'VERIFIED') == 0)
      {
      multiIPN($_POST,$ppipn);
      }

      else
      {
      die();
      }
      }


      function silentPost($domain,$path,$array=0,$port=80,$mode=1 ,$timeout=30)
      {
      $postdata = '';

      if (!is_array($array)) die();

      foreach ($array as $postkey => $postval)
      {
      if (get_magic_quotes_gpc()) $postval = stripslashes($postval);

      if (!eregi("^[_0-9a-z-]{1,30}$",$postkey) || !strcasecmp ($postkey, 'cmd'))
      {
      unset ($postkey);
      unset ($postval);
      }

      if (!empty($postkey)) $postdata.='&'.$postkey.'='.urlencode($postval);
      }

      if ($mode == 2)
      {
      $postdata = 'cmd=_notify-validate'.($postdata);
      }

      else
      {
      $postdata = substr($postdata, 1, strlen($postdata));
      }

      $socket = fsockopen($domain,$port,$errno,$errstr,$timeout);
      $header = "POST ".$path." HTTP/1.0\r\n";
      $header.= "User-Agent: PHP/".phpversion()."\r\n";
      $header.= "Referer: ".$_SERVER['HTTP_HOST'].
      $_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']."\r\n";
      $header.= "Server: ".$_SERVER['SERVER_SOFTWARE']."\r\n";
      $header.= "Host: ".$domain.":".$port."\r\n";
      $header.= "Content-Type: application/x-www-form-urlencoded\r\n";
      $header.= "Content-Length: ".strlen($postdata)."\r\n";
      $header.= "Accept: */*\r\n\r\n";
      fputs ($socket,$header.$postdata."\r\n\r\n");

      if ($mode == 2)
      {
      while (!feof($socket))
      {
      $ipn = fgets ($socket,1024);
      }

      fclose ($socket);
      return(trim($ipn));
      }

      else
      {
      fclose ($socket);
      }

      }

      function multiIPN($array,$ipntxt)
      {
      $gateways = explode("\r\n",trim(file_get_contents($ipntxt)));

      foreach ($gateways as $gateway)
      {
      if (!stristr($gateway, 'http') && !stristr($gateway, 'https'))
      {
      $gateway = 'http://'.($gateway);
      }

      $gateway = explode('/',trim($gateway));

      if (stristr($gateway[0], 'https'))
      {
      $gateway[1] = 443;
      }

      $ports = explode(':',trim($gateway[2]));

      if (is_numeric($ports[1]))
      {
      $gateway[1] = $ports[1];
      $gateway[2] = str_replace(':'.$ports[1],'',$gateway[2]);
      }

      if (empty($gateway[1]))
      {
      $gateway[1] = 80;
      }

      $urlpath = ($gateway);
      unset($urlpath[0],$urlpath[1],$urlpath[2]);
      sort($urlpath);
      $urldata = '';

      foreach ($urlpath as $httpkey => $httpval)
      {
      $urldata.= '/'.$httpval;
      }

      if (empty($urldata))
      {
      $urldata = '/';
      }

      silentPost($gateway[2],$urldata,$array,$gateway[1]);

      }
      }


      ?>
      http://www.r2rwealthsecrets.com

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #4
        Re: IPN for multiple notify_url

        The above script does excactly what i told you. It receives the IPN value from PayPal, and it then opens sockets to the other sites, to transmit the same values. It is not PayPal that does it, it is your script that repeats the notfication to the third sites.
        Now, as you see, there is a text file, 'ipn-gateway.txt' which is the IPN handler list. Did you create and populate this file ? it should contain all the URLs to be notified . However, though i didn't test it, you have this one line:

        $gateways = explode("\r\n",trim(file_get_contents($ipntxt)));

        where, i think $ipntext is wrong, it should be file_get_contents($ppipn).

        Also, instead of using an external file for the URLs, you can also hardcode them, there is no need to complicate things, unless you need to change the URLs very often.

        In anyway, since the payment verification is already done, WHY do you want to repeat the same procedure directly to the other sites? why don't you simply POST the $_POST array as you recieved it (and verified it) ? You can, if you wish, include a hardcoded key, or a salted hashed key (i.e. based on a hardcoded key and a variable key as time() as salt) to ensure that the transmission to the other sites is real and not sent from a hacker.
        Navaldesign
        Logger Lite: Low Cost, Customizable, multifeatured Login script
        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

        Comment

        • Freedom35
          Staff Sergeant

          • Dec 2006
          • 43

          #5
          Re: IPN for multiple notify_url

          Hi NavalDesign,

          I have created "ipn-gateway.txt" and include the urls to be sent to.

          What you have suggested to me is totally alien for someone with very limited programming skill.

          What I'm doing here is that I'm running phpbb 2.0.22 with paypal subscription mod. This is for my membership subscription. Then I'm running Post Affiliate Pro (PAP) for my affiliate program. All required information will be sent to paypal with only one submit button.

          The problem I'm facing now is that the subscription mod and the PAP required that the IPN to be sent to their respective notify_url. However paypal can only sent to one notify_url.

          As you mentioned, I only need to receive and verified the payment once. It's just that I don't know how to do the $_POST as what you have suggested. Is it possible for you to translate that to layman term?
          http://www.r2rwealthsecrets.com

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #6
            Re: IPN for multiple notify_url

            The script that you are posting above, does excactly that: it posts to ALL the URLs that are included in the ipn-gateways.txt file. So you should have this script in your return page and then it should post to the phpbb mod and to the Affiliate script notify URLs.

            However, i did not test the script, so i can't say if it works ok or not. That requires some time which unfortunately i don't have at this moment.

            It would be also simpler if you took a look to see which fields of the database and in which way the two scripts update, and create a script that will recieve the paypal feedback and update directly all the necessary fields in the Database.
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment

            • Freedom35
              Staff Sergeant

              • Dec 2006
              • 43

              #7
              Re: IPN for multiple notify_url

              I tried the script which did not work. I guess some debugging is required.

              Anyway thanks for your help
              http://www.r2rwealthsecrets.com

              Comment

              • navaldesign
                General & Forum Moderator

                • Oct 2005
                • 12080

                #8
                Re: IPN for multiple notify_url

                In anyway, there is a simple way to go it. Create a small script using the curl library. Set this to be your PayPal return page. The script will send the recieved data to both notify URLs (the one of the PayPal mod and the one of the Affiliate program.

                A possible script could be like this:


                <?php

                // Recieve the paypal data and create the necessary extension to the URLs
                $add = "?";
                while (list ($key, $val) = each ($_GET))
                {
                $add .= "$key=$val&";
                }
                $add = rtrim($add, '&');
                //Change the URLS to be the real ones
                $notify_URL[1] = "http://www.yourdomain.com/path_to/paypalmod_returnpage.php".$add;
                $notify_URL[2] = "http://www.yourdomain.com/path_to/affiliate_returnpage.php".$add;

                // Prepare to POST
                //Initialize the CURL session

                $ch = curl_init();
                $post_data['submit'] = "submit";

                for ($i = 1; $i <= 2; $i++){

                // Set the script to post to the notify URL
                curl_setopt($ch, CURLOPT_URL, $notify_URL[$i] );
                // Indicate the request method (POST)
                curl_setopt($ch, CURLOPT_POST, true );
                // We just send the "submit" value through POST
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
                // Specify that the curl_exec function should return
                // the "success" or "failed" output from the two notify URL scripts.
                // instead of sending it to the browser.
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                // Connect, send data and store in
                // $postResult the output of the notify URL scripts
                $postResult = curl_exec($ch);
                // If there are errors, display them
                if (curl_errno($ch)) {
                print curl_error($ch);
                }
                // If you wish (not this case) display the destination script output
                //echo "$postResult <br>";
                }

                // Close the CURL session
                curl_close($ch);
                ?>


                You can see how it works in http://www.dbtechnosystems.com/post/...23&b=456&c=789

                Please note that the a=123&b=456&c=789 part is only used to show you how the script recieves the data from PayPal, and then it passes it through POST to the two Notify URLs.

                Change the numbers (ONLY the numbers and characters, do NOT touch the ? and & ) to whatever you like to see your own details, as if it were PayPal data.

                In this case these two notify URLs that i created don't do anything else than recieve the POST data and print them in the screen, but when you use the actual notify URLs of your paypal mod and your affiliate script, they will both act as if they had recieved the data directly from PayPal.
                Navaldesign
                Logger Lite: Low Cost, Customizable, multifeatured Login script
                Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                Comment

                • Freedom35
                  Staff Sergeant

                  • Dec 2006
                  • 43

                  #9
                  Re: IPN for multiple notify_url

                  Will this script post back to paypal to confirm verified or invalid IPN? or does it simply post the data from IPN to the two notify_urls?

                  Have tried the script but it does not works. Both programs are not updated with new subscription :(
                  http://www.r2rwealthsecrets.com

                  Comment

                  • navaldesign
                    General & Forum Moderator

                    • Oct 2005
                    • 12080

                    #10
                    Re: IPN for multiple notify_url

                    The script will NOT post back to PayPAl, it will only pass the notification to the two notify URLs.

                    The reason because it doesn't work, is (probably) because it is not even called in action. I mean, if you are using the PayPal mod script and the affiliate script to proceed to PayPal, (real or Sandbox) the scripts include, when sending the user to PayPal, the return page, and by default, this is NOT the above script. How did you try it ?
                    Navaldesign
                    Logger Lite: Low Cost, Customizable, multifeatured Login script
                    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                    Comment

                    • VodaHost
                      General & Forum Administrator

                      • Mar 2005
                      • 12356

                      #11
                      Re: IPN for multiple notify_url

                      naval knows his stuff and always gives valid advice.

                      VodaHost

                      Your Website People!
                      1-302-283-3777 North America / International
                      02036089024 / United Kingdom
                      291916438 / Australia

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

                      Top 3 Best Sellers

                      Web Hosting - Unlimited disk space & bandwidth.

                      Reseller Hosting - Start your own web hosting business.

                      Search Engine & Directory Submission - 300 directories + (Google,Yahoo,Bing)


                      Comment

                      • Karen Mac
                        General

                        • Apr 2006
                        • 8332

                        #12
                        Re: IPN for multiple notify_url

                        I might be wrong here, or in over my head, but, I believe you are trying to use the API to integrate paypal as a shopping cart, and the IPN its talking about or using is the information from the data sent from the store. Paypal sends notice when payment is made and the store or script upon the return from paypal would then need to send the notifications or register the paypal return and the be made to script out the notifications. I dont think you can modify paypal"s to read or do it correctly on the paypal end and make it READABLE or executable on their system.

                        Karen

                        VodaHost

                        Your Website People!
                        1-302-283-3777 North America / International
                        02036089024 / United Kingdom
                        291916438 / Australia

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

                        Top 3 Best Sellers

                        Web Hosting - Unlimited disk space & bandwidth.

                        Reseller Hosting - Start your own web hosting business.

                        Search Engine & Directory Submission - 300 directories + (Google,Yahoo,Bing)


                        Comment

                        • navaldesign
                          General & Forum Moderator

                          • Oct 2005
                          • 12080

                          #13
                          Re: IPN for multiple notify_url

                          Karen, this is not a shopping cart. This is a phpBB forum PayPal subscription payment and an affiliate scipt that both need to recieve the same PayPal notification, in order to update the respective tables in the database.
                          The problem can be solved in three ways:

                          1. Create a script like the above, that will recieve the notiication frpm PayPal and pass it over to both scripts (phpBB mod AND Affiliate script). Then each of these two scripts, will post back to PayPAl to recieve the PayPAl confirmation, and then they will both do what they are supposed to do. The problem is (and that's why i told "How did you test it?") that the subscription payment script, will pass over to PayPal, it's own returnpage, so the PayPal notification does NOT end to my script (and from there to the two others) but only goes to the payment script return page. This can be corrected simply editing the return URL in the scripts code.

                          2. Edit directly the payment return page, so that, after it updates its own tables, it also updates the affiliate script tables. To achieve this, the code of the affiliate scipr must be examined, to see what it does, and copy it's functionalities (by copying the code, or adding a similar code) in the payment mod.

                          3. Edit directly the payment return page, so that after it updates its own tables, it POSTS the PayPal notification to the affiliate script. The same code i posted above, without the loop, which means that it will only work with one notify_URL.
                          Navaldesign
                          Logger Lite: Low Cost, Customizable, multifeatured Login script
                          Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                          DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                          Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                          Comment

                          • Karen Mac
                            General

                            • Apr 2006
                            • 8332

                            #14
                            Re: IPN for multiple notify_url

                            Naval,

                            Thanks.. I think we were saying the same thing, except its a forum, but.. it has to be run as you said, from a script on the forum end, and it would only work IF the payee actually returns to the forum.. they can opt not to do so by simply closing the browser and not clicking the button after they pay, and thats why i said you cant script paypal's ipn to do the notifying or update their database... this is a common issue merchants complain about, and a forum subscription is very similar or the same as accepting paypal as payment method on a store. But then paypal is free so to speak.

                            Karen

                            VodaHost

                            Your Website People!
                            1-302-283-3777 North America / International
                            02036089024 / United Kingdom
                            291916438 / Australia

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

                            Top 3 Best Sellers

                            Web Hosting - Unlimited disk space & bandwidth.

                            Reseller Hosting - Start your own web hosting business.

                            Search Engine & Directory Submission - 300 directories + (Google,Yahoo,Bing)


                            Comment

                            • Freedom35
                              Staff Sergeant

                              • Dec 2006
                              • 43

                              #15
                              Re: IPN for multiple notify_url

                              I have renamed the two notify_url to:
                              $notify_URL[1] = "http://www.r2rwealthsecrets.com/lwtopupresult_paypal_V4.php".$add;
                              $notify_URL[2] = "http://www.r2rwealthsecrets.com/paypal_subscr.php".$add;


                              and saved it as "notify_urls.php"


                              I added the following code to the paypal button (above)

                              $lw_submit_hidden_fields .= '<input type="hidden" name="notify_url" value="http://www.r2rwealthsecrets.com/notify_urls.php">';

                              Then I continue with the subscription and come back to the following page


                              if the subscription went through successfully, I should get the following update which I didn't



                              I also get the following invalid reply from my affiliate script which I didn't get if use the affiliate script alone.




                              P.S. I have also tried adding the following code instead of the one mentioned above but the results is the same as above:
                              $lw_submit_hidden_fields .= '<input type="hidden" name="return" value="value="http://www.r2rwealthsecrets.com/notify_urls.php">';

                              Is this the way to use your script?
                              http://www.r2rwealthsecrets.com

                              Comment

                              Working...
                              X