📄 sp.inc.php
字号:
<?
/**
* in this class,we ignore the Trial checking
*/
class SP_Validater{
//common payment
var $Amount=0;
//subscriptions data
var $SubsAmount=0;
var $SubsPeriod=0;
var $SubsUnit='D';
var $TrialAmount=0;
var $TrialPeriod=0;
var $TrialUnit='D';
var $Currency='USD';
var $product_name='';
var $user1='';
var $user2='';
var $PaymentType='';
var $PayeeAccount='';
var $TestMode=0;
/**
* load gateway setting
*/
function SP_Validater($db)
{
$db->setQuery("select * from gateway where Provider='SP'");
$db->query();
$gateway=$db->loadRow();
$this->PayeeAccount=$gateway['PayeeAccount'];
$this->MD5AccountPassword=$gateway['MD5AccountPassword'];
$this->TestMode=$gateway[TestMode];
}
/**
* load host plan infomation from groups
*/
function LoadClient()
{
global $input,$user,$db;
if(isset($input[uid])) $user->uid=$input[uid];
$plan_id=$input[plan_id];
$info=split('-',$plan_id);
if(!$info[0])
{
die('Data error!');
}
$group_id=$info[0];
$plan_id=$info[1];
$db->setQuery("select * from groups where id='$group_id'");
$db->query();
$row=$db->loadRow();
$periods=split(',',$row[subscr_period]);
$fees=split(',',$row[subscr_fee]);
if($row[subscr_unit]=='D') $scaler=1;
if($row[subscr_unit]=='M') $scaler=30;
if($row[subscr_unit]=='Y') $scaler=365;
$this->PaymentType=$row[payment_type];
$this->SubsUnit=$this->TrialUnit=$row[subscr_unit];
$this->SubsPeriod=$periods[$plan_id]*$scaler;
$this->SubsAmount=$this->Amount=$fees[$plan_id];
$this->product_name=$row[name];
$this->user1=$group_id.'-'.$plan_id;
$this->user2=$user->uid;
}
/**
* load vaild data to verify the IPN Data
*/
function LoadServer($ipn)
{
global $db;
$uid=$ipn->GetVar('user2');
/**
* 1:load this user
*/
$db->setQuery("select * from users where id='$uid'");
$db->query();
if($db->getNumRows()==0)
{
$ipn->SetError('Data error:USER ID '.$uid.' can not be found!');
return false;
}
$row=$db->loadRow();
/**
* if the user has already such a subscription,the payment is from the same subscription!
*/
//if($row[subscr_id]==$ipn->SubsID&&$ipn->SubsID)
if($row[subscr_id]==$ipn->SubsID)
{
$this->PaymentType=$row[payment_type];
$this->SubsUnit=$row[subscr_unit];
$this->SubsPeriod=$row[subscr_period];
$this->SubsAmount=$this->Amount=$row[subscr_fee];
$this->SubsID=$row[subscr_id];
}
/**
* load data from groups,because this is the first subscription created!
*/
else
{
$plan_id=$ipn->GetVar('user1');
$info=split('-',$plan_id);
if(!$info[0])
{
$ipn->SetError('Data error:No Group ID found!');
return false;
}
$group_id=$info[0];
$plan_id=$info[1];
/**
* 1:load host plan infomation
*/
$db->setQuery("select * from groups where id='$group_id'");
$db->query();
if($db->getNumRows()==0)
{
$ipn->SetError('Data error:Group ID '.$group_id.' can not be found!');
return false;
}
$row=$db->loadRow();
$periods=split(',',$row[subscr_period]);
$fees=split(',',$row[subscr_fee]);
$this->PaymentType=$row[payment_type];
$this->SubsID=$ipn->SubsID;
$this->SubsUnit=$row[subscr_unit];
$this->SubsPeriod=$periods[$plan_id];
$this->SubsAmount=$this->Amount=$fees[$plan_id];
}
$this->TrialUnit='D';//no other choices:)
$this->TrialPeriod=0;
$this->TrialAmount=0;
}
/**
* btach function to retrieve vaild data
*/
function GetPayeeAcount()
{
return $this->PayeeAccount;
}
function GetAmount()
{
return $this->Amount;
}
function GetTrialAmount()
{
return $this->TrialAmount;
}
function GetTrialPeriod()
{
return $this->TrialPeriod;
}
function GetSubsID()
{
return $this->SubsID;
}
function GetSubsAmount()
{
return $this->SubsAmount;
}
function GetSubsPeriod()
{
return $this->SubsPeriod;
}
function GetCurrency()
{
return $this->Currency;
}
/**
* Process the payment
*/
function ProcessPayment($ipn)
{
global $db;
$uid=$ipn->GetVar('user2');
$dateinfo=array('D'=>24*60*60,'M'=>30*24*60*60,'Y'=>12*30*24*60*60);
$fee_text="\$$this->Amount/$this->SubsPeriod $this->SubsUnit";
/**
* load the user
*/
$db->setQuery("select * from users where id='$uid'");
$db->query();
$row=$db->loadRow();
$txn_id=$ipn->GetTXNID();
$expire_date=time()>$row[expire_date]?time()+$dateinfo['D']*$this->SubsPeriod:$row[expire_date]+$dateinfo['D']*$this->SubsPeriod;
$plan_id=$ipn->GetVar('user1');
$info=split('-',$plan_id);
$group_id=$info[0];
/**
* this is a subscription,and it is a difrent one:new or upgrade one
*/
//if($row[subscr_id]!=$ipn->SubsID&&$ipn->SubsID)
if($row[subscr_id]!=$ipn->SubsID)
{
$subscr_id=$ipn->SubsID;
$subscr_unit=$ipn->SubsUnit;
$subscr_period=$ipn->SubsPeriod*$scaler;
$subscr_fee=$ipn->SubsAmount;
$db->setQuery("update users set subscr_id='$subscr_id',subscr_unit='$subscr_unit',subscr_period='$subscr_period',subscr_fee='$subscr_fee' where id='$uid'");
$db->query();
}
$db->setQuery("update users set gid='$group_id',expire_date='$expire_date' where id='$uid'");
$db->query();
$descr= mysql_escape_string('Payment for '.$ipn->GetVar('product_name').':'.$fee_text);
$db->setQuery("update $ipn->IPNTable set uid='$uid',descr='$descr' where txn_id='$txn_id'");
$db->query();
}
/**
* cancel the subscription
*/
function ProcessCancelPayment($ipn)
{
global $db;
$uid=$ipn->GetVar('user2');
$dateinfo=array('D'=>24*60*60,'M'=>30*24*60*60,'Y'=>12*30*24*60*60);
$fee_text="\$$this->Amount/$this->SubsPeriod $this->SubsUnit";
/**
* load the user
*/
$db->setQuery("select * from users where id='$uid'");
$db->query();
$row=$db->loadRow();
/**
* this is a subscription,and it is a difrent one:new or upgrade one
*/
$plan_id=$ipn->GetVar('user1');
$info=split('-',$plan_id);
$group_id=$info[0];
if($row[subscr_id]==$ipn->SubsID&&$ipn->SubsID)
{
$subscr_id=$ipn->SubsID;
$subscr_unit=$ipn->SubsUnit;
$subscr_period=$ipn->SubsPeriod;
$subscr_fee=$ipn->SubsAmount;
$db->setQuery("update users set subscr_id='',subscr_unit='',subscr_period='',subscr_fee='' where id='$uid'");
$db->query();
$descr= mysql_escape_string('Cancel for '.$ipn->GetVar('product_name').':'.$fee_text);
$db->setQuery("update $ipn->IPNTable set uid='$uid',descr='$descr' where txn_id='$txn_id'");
$db->query();
}
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -