.

.

How To use Paypal Integration




Using form to Paypal

& for check using action https://www.sandbox.paypal.com/cgi-bin/webscr

<form action="https://www.paypal.com/cgi-bin/webscr"  name="frmPayPal" method="POST">
<?php
$m = 1;
 foreach($this->paypal as $value)
{ ?>
<input type="hidden" name="item_name_<?php echo $m;?>" value="<?php echo $value->flowerid;?>">
<input type="hidden" name="amount_<?php echo $m;?>" value="<?php echo $value->price;?>">
<?php
$m++;
 }?>
 <input type="hidden" name="item_number" value="<?php echo $value->flowerid.','.$userid.','.$sid;?>">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="billing@100innovations.com"> <!--from admin dashboard to enter email by admin-->
<input type="hidden" name="RETURN" value="<?php echo JURI::root(); ?>index.php?option=com_steps&task=frompaypal.success"><!-- return url page after payment-->
<input type="hidden" name="cancel_return" value="<?php echo JURI::root(); ?>index.php?option=com_steps&task=frompaypal.cancel"><!-- return url page after payment after cancel due to any reason for transaction -->
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="notify_url" value="<?php echo JURI::root(); ?>notify_url.php">
<?php
if(isset($_GET['order']))
{
?>
<input id="pay" type="submit" name="Submit" value="Paynow" style="background-color:#09c856">
<?php
}
?>
</form>
Use Notify File which gives all Details by notify_url.php file we can get all details after payment & any query we use only this file which we want to get .we can get all paypal details By Post Method . Use This notify For IPN 

Instant Payment Notification

Instant Payment Notification (IPN) is a message service that automatically notifies merchants of events related to PayPal transactions. Merchants can use it to automate back-office and administrative functions, like fulfilling orders and providing customers with order status.  

check this notify_url.php file

<?php
include('configuration.php');// include config file for joomla
$conf = new JConfig();
$host = $conf->host;
$username = $conf->user;
$pass = $conf->password;
$db = $conf->db;

mysql_connect($host,$username,$pass);
mysql_select_db($db);

foreach ($_POST as $key => $value)
{
    $value = urlencode(stripslashes($value));
    $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i', '${1}%0D%0A${3}', $value); // IPN fix
    $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,$err_num,$err_str,30);
echo('<br>'.$req);


$transid =$_POST['txn_id'];
$status =$_POST['payment_status'];
$amount =$_POST['payment_gross'];
$currency=$_POST['mc_currency'];
       $item_number=explode(',',$_POST['item_number']);
  $userid=$item_number[1];
  $sid= $item_number[2];

if($status=='Completed')
{
$status=1;

}



/*
$item_name = $_POST['item_name'];
$user_id = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$mc_gross =$_POST['mc_gross'];
$gross =$_POST['mc_gross'];
$mc_gross=$mc_gross-(0.30);
$com= getPercentOfCommission();
$comper = $com/100;
$commision=number_format(($com/ 100)*($mc_gross),2);*/
//$fund_ammount=  number_format(($mc_gross)-($commision),2);
/*$fund_ammount = $mc_gross*(1 - $comper) - 0.30;
$commision= number_format($commision+(0.30),2);*/
/**
fund amount calculated by paypal formula
*/

/***/
/*$_SESSION['fund_amt'] = $fund_ammount;
$_SESSION['payer_id'] = $user_id;
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];*/
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp)
{
    echo(' HTTP ERROR');
}
else
{
    fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        echo('<br> res is '.$res);
    if (strcmp ($res, "VERIFIED") == 0)
{

$sql='INSERT INTO dep_paypal(`userid` ,`amount` ,`transid` ,`status` ,`currency`,`session_id`) VALUES  ("'.$userid.'","'.$amount.'","'.$transid.'","'.$status.'","'.$currency.'","'.$sid.'")';



        //$sql = "SELECT * FROM user where user_id='".$user_id."'";
$res = mysql_query($sql);

$sql1 = 'SELECT * FROM dep_cart WHERE  '.'userid = "'. $userid.'" AND '.'sessionid = "' .$sid. '"';

$res = mysql_query($sql1);

$row1 = mysql_fetch_array($res);
$flid=array();

foreach($row1 as $row)
{
 $flid[] = $row->flowerid;

}


$flowerids=implode(',',$flid);//array not store in databas


$sql2 ="UPDATE dep_sender_loved_info SET fid='".$flowerids."' WHERE userid = '".$userid."' AND sessionid ='".$sid."'";

$res = mysql_query($sql2);



    $sql3 ="DELETE FROM #__cart where sessionid = '".$sid."'";

$res = mysql_query($sql3);




/*$user_id = $row['user_id'];

$sqlCheckEmpFund = dbQuery("Select * from user_account_deatils where user_id = '".$user_id."'");
if(dbNumRows($sqlCheckEmpFund)>0)
{
$rowCheckEmpFund = dbFetchArray($sqlCheckEmpFund);
$fund = $rowCheckEmpFund['user_account_balance']+$fund_ammount;
$worker_real_amount = $rowCheckEmpFund['user_account_balance']+$fund_ammount;


$sqlUpdateExists = "Update user_account_deatils set user_account_balance = '".$fund."' where user_id = '".$user_id."' AND user_id = '".$rowCheckEmpFund['user_id']."' AND user_account_id = '".$rowCheckEmpFund['user_account_id']."'";
$resUpdateExists = dbQuery($sqlUpdateExists);

dbQuery("insert project_payment_milestone set transaction_id='".$txn_id."', escrows_commision='".$commision."' ,real_amount='".$gross."',worker_real_amount = '".$worker_real_amount."', paymentTo='".$user_id."', paymentAmount='".$fund_ammount."', payment_status='Deposit', paymentStatus='Paypal', payment_date=NOW()");
}
else
{



$sqlCheckEmpFund = dbQuery("Select * from user_account_deatils where user_id = '".$user_id."'");
$rowCheckEmpFund = dbFetchArray($sqlCheckEmpFund);
$fund = $rowCheckEmpFund['user_account_balance']+$fund_ammount;
$worker_real_amount = $rowCheckEmpFund['user_account_balance']+$fund_ammount;




dbQuery("insert project_payment_milestone set transaction_id='".$txn_id."', escrows_commision='".$commision."' ,real_amount='".$gross."' , worker_real_amount = '".$fund_ammount."', paymentTo='".$user_id."', paymentAmount='".$fund_ammount."', payment_status='Deposit', paymentStatus='Paypal', payment_date=NOW()");


$sqlInsert = "Insert INTO user_account_deatils (user_id,user_account_balance,user_account_created,user_account_status)VALUES('".$user_id."','".$fund_ammount."','".date("Y-m-d g:i:s")."','Yes')";
$resInsert = dbQuery($sqlInsert);

}*/

//$from = "mubarik.galaxyweb@gmail.com";
/*$to = getUserEmail($_POST['item_number']);
$subject = "Fund Successfully Tranfered Into Your Gorilla Accounts";
$message = "<h2>You have successfully Deposited Funds into Your Gorilla Acount.</h2><br />";
$message .= "<h3>You Deposited Funds :: $".$fund_ammount."</h3><br />";
$message .= "<h3>Your Available Balance :: $".checkUserAccountBalance($user_id)."</h3><br />";
$message .= "<br /><br /><br />Thank You";
$header = "From:".$from." \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);*/


    }
    else if (strcmp ($res, "INVALID") == 0)
    {
        $mail_From = "From: $from";
        $mail_To = getUserEmail($_POST['item_number']);
        $mail_Subject = "INVALID IPN";
        $mail_Body = $req;
        foreach ($_SESSION as $key => $value)
        {
            $emailtext .= $key . " = " .$value ."\n\n";
        }
        mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);
    }
}
fclose ($fp);
}
?>



data comes from paypal after payment this

 -- cmd=_notify-validate&mc_gross=3.45&protection_eligibility=Eligible&address_status=confirmed&payer_id=5MM9SHAT2ZATA&tax=0.00&address_street=140+Amy+Joy&payment_date=00%3A17%3A37+Aug+26%2C+2014+PDT&payment_status=Completed&charset=windows-1252&address_zip=76633-2961&first_name=Connie&mc_fee=0.45&address_country_code=US&address_name=Connie+Nelson&notify_version=3.8&custom=&payer_status=verified&business=auyang%40solaris.com.my&address_country=United+States&address_city=China+Spring&quantity=1&verify_sign=A3MYyCx-cQGZQtJqzEL6duABcj5uAspTTcpsjp9SUqT6p6QdvY5SxxYH&payer_email=ben%40solaris.com.my&contact_phone=&txn_id=6LJ63350M33089707&payment_type=instant&last_name=Nelson&address_state=TX&receiver_email=auyang%40solaris.com.my&payment_fee=0.45&receiver_id=CL8THQMPH8SK8&txn_type=web_accept&item_name=Deposite+Funds+To+My+Gorilla+Account&mc_currency=USD&item_number=74&residence_country=US&handling_amount=0.00&transaction_subject=&payment_gross=3.45&shipping=0.00&ipn_track_id=39c88ef73098c







EmoticonEmoticon