📄 mb.inc.php
字号:
<?
/**
* in this class,we ignore the Trial checking
*/
class MB_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 $text='';
var $var1='';
var $var2='';
var $PaymentType='';
var $PayeeAccount='';
var $TestMode=0;
/**
* load gateway setting
*/
function MB_Validater($db)
{
$db->setQuery("select * from gateway where Provider='MB'");
$db->query();
$gateway=$db->loadRow();
$this->PayeeAccount=$gateway['PayeeAccount'];
$this->MD5AccountPassword=$gateway['MD5AccountPassword'];
$this->TestMode=$gateway['TestMode'];
$this->Currency='EUR';//$gateway['Currency'];
}
/**
* 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='D';
$this->SubsPeriod=$periods[$plan_id]*$scaler;
$this->SubsAmount=$this->Amount=$fees[$plan_id];
$this->text=$row[name];
$this->descr=$row[name];
$this->var1=$group_id.'-'.$plan_id;
$this->var2=$user->uid;
}
/**
* load vaild data to verify the IPN Data
*/
function LoadServer($ipn)
{
global $db;
$uid=$ipn->GetVar('var2');
/**
* 1:load this user
*/
$db->setQuery("select * from users where id='$uid'");
$db->query();
$row=$db->loadRow();
if($db->getNumRows()==0)
{
$ipn->SetError('Data error:USER ID '.$uid.' can not be found!');
return false;
}
$plan_id=$ipn->GetVar('var1');
$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];
/**
* 2: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->SubsUnit=$row[subscr_unit];
$this->SubsPeriod=$periods[$plan_id];
$this->SubsAmount=$this->Amount=$fees[$plan_id];
$this->TrialUnit=$row[subscr_unit];
$this->TrialPeriod=0;
$this->TrialAmount=0;
$this->text=$row[name];
if($row[subscr_unit]=='D') $scaler=1;
if($row[subscr_unit]=='M') $scaler=30;
if($row[subscr_unit]=='Y') $scaler=365;
$this->SubsPeriod=$this->SubsPeriod*$scaler;
$this->SubsUnit='D';
}
/**
* 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 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('var2');
$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;
/**
* update the expire date for users
*/
$db->setQuery("update users set gid='$group_id',expire_date='$expire_date' where id='$uid'");
$db->query();
$descr= mysql_escape_string('Payment for '.$this->text.':'.$fee_text);
$db->setQuery("update $ipn->IPNTable set uid='$uid',item_name='$this->text',descr='$descr' where txn_id='$txn_id'");
$db->query();
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -