📄 2co.inc.php
字号:
<?
/**
* PP_Validater
*
* @link http://www.yabsoft.com/
* @author Stephen yabziz, <ywyhnchina at 163 dot com>
* @copyright (C) 2005 YABSoft.com
* @version 0.1
* @package IPN
*/
class CO_Validater{
/**
* The payment amount when the payment is instant
*
* @var number
*/
var $Amount=0;
/**
* The below var is subscription
*
* @var string
*/
var $SubsAmount=0;
var $SubsPeriod=0;
var $SubsUnit='D';
var $TrialAmount=0;
var $TrialPeriod=0;
var $TrialUnit='D';
var $Currency='USD';
var $item_name='';
var $item_number='';
var $PaymentType='';
var $PayeeAccount='';
var $BusinissAccount='';
/**
* PP_Validater class constructor
* load gateway setting
*/
function CO_Validater(&$db)
{
$db->setQuery("select * from gateway where Provider='2CO'");
$db->query();
$gateway=$db->loadRow();
$this->PayeeAccount=$gateway['PayeeAccount'];
$this->MD5AccountPassword=$gateway['MD5AccountPassword'];
$this->TestMode=$gateway['TestMode'];
}
/**
* load client infomation from database to fill in payment form
* access from pp_gateway.php
*/
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]);
$this->PaymentType='instant';
$this->Amount=$fees[$plan_id];
$this->item_number=$group_id.'-'.$plan_id;
$this->custom=$user->uid;
}
/**
* load client infomation from database to check against payment gateway
* load vaild data to verify the IPN Data
*/
function LoadServer($ipn)
{
global $db;
$plan_id=$ipn->GetVar('x_invoice_num');
$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];
/**
* load data from groups,because this is the first subscription created!
*/
$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='instant';
$this->SubsUnit=$row[subscr_unit];
$this->SubsPeriod=$periods[$plan_id];
$this->SubsAmount=$this->Amount=$fees[$plan_id];
}
/**
* batch function to retrieve vaild data
*/
function GetPayeeAcount()
{
return $this->PayeeAccount;
}
function GetAmount()
{
return $this->Amount;
}
function GetCurrency()
{
return $this->Currency;
}
/**
* Process web accept payment
*
* @param object $ipn
*/
function ProcessWebAccept(&$ipn)
{
global $db;
$plan_id=$ipn->GetVar('x_invoice_num');
$uid=$ipn->GetVar('x_custom');
$dateinfo=array('D'=>24*60*60,'M'=>30*24*60*60,'Y'=>12*30*24*60*60);
$info=split('-',$plan_id);
if(!$info[0])
{
$ipn->SetError('Data error:No Group ID found!');
return false;
}
$group_id=$info[0];
/**
* load the user
*/
$db->setQuery("select * from users where id='$uid'");
$db->query();
$row=$db->loadRow();
/**
* process the payment subscriptions
*/
$txn_id=$ipn->GetTXNID();
$expire_date=time()>$row[expire_date]?time()+$dateinfo[$this->SubsUnit]*$this->SubsPeriod:$row[expire_date]+$dateinfo[$this->SubsUnit]*$this->SubsPeriod;
$db->setQuery("update users set expire_date='$expire_date',gid='$group_id' where id='$uid'");
$db->query();
$descr= mysql_escape_string('Payment for '.$ipn->GetVar('item_name').":\$$this->SubsAmount/$this->SubsPeriod $this->SubsUnit");
$db->setQuery("update $ipn->IPNTable set uid='$uid',descr='$descr' where txn_id='$txn_id'");
$db->query();
}
/**
* Process Pending payment
*
* @param object $ipn
*/
function ProcessPending(&$ipn,$type='pending')
{
global $db;
$plan_id=$ipn->GetVar('cart_order_id');
$uid=$ipn->GetVar('merchant_order_id');
$dateinfo = array('D'=>24*60*60,'M'=>30*24*60*60,'Y'=>12*30*24*60*60);
$txn_id=$ipn->GetTXNID();
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -