Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:19:53+00:00 2026-06-17T09:19:53+00:00

I have a working IPN script. It is updating the data correctly in database

  • 0

I have a working IPN script. It is updating the data correctly in database according to the logged in user. So, Once the payment is successfully made user account will be upgraded as a paid member. And since i am using a paypal subscribe button. So, from the next month billing process will occur automatically.
So, here what i think(I am not sure), Paypal will not interact with my IPN script stored in my server.

So, My question is :-

If my assumption about IPN script is correct then how could i track which user has made a payment for the next billing cycle? (I don’t want to be involved with manual work like tracking user payment information from my Paypal merchant account. I just want to do it through a script. So, once the subscription amount has been deducted from user Paypal account his account on my website will be upgraded as a paid member.)

For the reference what exactly i wanted to update through my ipn script. Below is my IPN script.

<?php

// STEP 1: Read POST data

// reading posted data from directly from $_POST causes serialization 
// issues with array data in POST
// reading raw POST data from input stream instead. 
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
     $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}


// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path 
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
    // error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly

if (strcmp ($res, "VERIFIED") == 0) {
    // check whether 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

    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $item_name=strip_tags($item_name);
    $item_number = strip_tags($_POST['item_number']);
    $payment_status = strip_tags($_POST['payment_status']);
    $payment_amount = strip_tags($_POST['mc_gross']);
    $payment_currency = strip_tags($_POST['mc_currency']);
    $txn_id = strip_tags($_POST['txn_id']);
    $user_id=strip_tags($_POST['custom']);
    $receiver_email = strip_tags($_POST['receiver_email']);
    $payer_email = strip_tags($_POST['payer_email']);
    //if(strcmp($receiver_email, "h_1356964205_per@gmail.com") == 0)
    //{
        /*if($payment_status != "Completed")
        {
            $msg="Transaction with id ".$txn_id." status is not completed..";
            mail("support@example.com","Transaction with the same id already exists in database.",$msg,"From:admin@leadstool.net");
    exit();

        }*/
        include_once('connection.php');
        //$user_id=getfield('id');
        // Query to check the duplicate transaction id.
        $query="SELECT `User_id` FROM `transaction` WHERE `Transaction_id`='".mysql_real_escape_string($txn_id)."'";
        if($query_run=mysql_query($query))
        {
            $num=mysql_num_rows($query_run);
            if($num == 0)
            {
                // Query to check the number of times for subscription.
                $query="SELECT `Transaction_id` FROM `transaction` WHERE `User_id`='".mysql_real_escape_string($user_id)."'";
                if($query_run=mysql_query($query))
                {
                    $num=mysql_num_rows($query_run);
                    if($num>=1)
                    {
                        $type_of_subscription=2;// This 2 will denote the user is rnewing his account
                    } else {
                        $type_of_subscription=1;// Here 1 is denoting that user has subscribed for the 1st time.
                        }
                    $query="SELECT `B_ad_no_paid_user`,`T_ad_no_paid_user` FROM `WebsiteContent` WHERE `Creator_id`='1' ORDER BY `Date_of_update` DESC LIMIT 1";
                    if($query_run=mysql_query($query))
                    {
                        while($rows=mysql_fetch_array($query_run))
                        {
                            $banner_ad_limit=$rows['B_ad_no_paid_user'];
                            $text_ad_limit=$rows['T_ad_no_paid_user'];
                        }
                    }   
                }// Query to check the number of times for subscription ends here.
        //Query to insert the transaction details in database.
        $query="INSERT INTO `transaction` VALUES('".$txn_id."','".$user_id."','".$payment_amount."','".$type_of_subscription."','".$payment_status."','1','".$payer_email."',now())";
        if($query_run=mysql_query($query))
        {
            $query="UPDATE `user` SET `User_type`='1', `Banner_ad_limit`='".$banner_ad_limit."', `Text_ad_limit`='".$text_ad_limit."' WHERE `id`='".mysql_real_escape_string($user_id)."'";
            if($query_run=mysql_query($query))
            {
                $msg="Thank you for subscribing to our service. Your Transaction Id is $txn_id.";
            mail("$payer_email","Subscription confirmation mail",$msg,"From:admin@example.com");
            } else {
                $msg="Thank you! Your transaction is successful with transaction id:- $txn_id. But we are unable to upgrade your profile right now. Please contact admin to resolve the problem.";
                mail("$payer_email","Subscription confirmation mail",$msg,"From:admin@example.com");
                }

        } else {
            $msg="For Transaction with id ".$txn_id." failed to update in database.";
            mail("support@example.com","Unable to update the details in database.",$msg,"From:admin@example.com");
    exit();
            }
        // Query to insert data in database ends here.

            } else {
                $msg="Transaction with id $txn_id already exists in database. Admin please verify the details manually and contact the user. Email id of user is: $payer_email";
                mail("support@example.com","Transaction with the same id already exists in database.",$msg,"From:admin@example.com");
    exit();
        }// Query to check the duplicate transaction id ends here.
        }

    //} else {
        //$msg="Investigate the reason why the registered email id with paypal does not matched with this id $receiver_email";
        //mail("support@example.com","Receiver email address do not matched",$msg,"From:admin@example.com");
    //exit();
        //}

} else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation

    $msg="Dear administrator please verify the reason why the transaction failure occures. The details is:- $res";
    mail("support@example.com","IPN interaction was not verified.",$msg,"From:admin@example.com");
    exit();
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:19:54+00:00Added an answer on June 17, 2026 at 9:19 am

    This is possible using the IPN and notify_url.

    Here is a good tutorial:

    http://www.techrepublic.com/article/handling-recurring-payments-with-paypal-subscriptions-and-ipn/5331883

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have working script that the user completes inputs on a form and when
I'm working with oscommerce and i have problem with Paypal ipn When someone makes
I have working registration script the only problem is that i do not know
I have everything working from the tutorial, replacing it with my data, but it
Well, i have been working on Paypal IPN. I need some information relate to
I have working user registration form. It consist of Zend Form Elements. Now I
I have working (stock) script from node var cluster = require('cluster'); var http =
I'm trying to have working JQuery button menu which will change in attribute data,
I am currently working on a python script that pulls data from a table
I am working with with paypal sandbox. According with that article after IPN verification

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.