Файл: _rootinc/activeby.inc.php
Строк: 255
<?
class ACTIVEBY
{
private $host = null;
private $cert = null;
private $password = null;
private $log = null;
public $error = null;
private $answer = null;
private $answerArray = null;
private $request = null;
public function init($host,$cert,$password,$log)
{
$this->host = $host;
$this->cert = $cert;
$this->password = $password;
$this->log = $log;
}
private function rest_build_query($array)
{
$data = urldecode( http_build_query($array) );
$data = preg_replace('/[d+]/', '[]', $data);
return $data;
}
private function send($command, $requestData) {
$this->request = $requestData;
$this->request["command"] = $command;
$this->slog("n<<< Send Requestn");
$this->slog($this->request, MODE_CLIENT);
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, "https://".$this->host."/1.0".$command);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($fp, CURLOPT_HEADER, false);
curl_setopt($fp, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fp, CURLOPT_SSLCERT, $this->cert);
curl_setopt($fp, CURLOPT_SSLCERTPASSWD, $this->password);
curl_setopt($fp, CURLOPT_POST, 1);
curl_setopt($fp, CURLOPT_POSTFIELDS, $this->rest_build_query($requestData));
$this->answer = curl_exec($fp);
if (@curl_errno($fp)) {
$this->error = "cURL Error ".@curl_errno($fp).": ".@curl_error($fp); $this->slog($this->error); return false;
}
$this->slog("n>>> Got Responsen");
$this->slog($this->answer, MODE_SERVER);
curl_close($fp);
$this->answerArray = @json_decode($this->answer, true);
if(is_array($this->answerArray)) {
return $this->answerArray;
} else {
if ($this->answer) { $error = $this->answer; } else { $error = "no result"; }
$this->error = "send ($command): $error"; $this->slog($this->error); return false;
}
}
private function slog($str, $mode = MODE_INFO) {
if ($this->log) {
switch($mode) {
case MODE_INFO: $mode = "I"; break;
case MODE_CLIENT: $mode = "C"; break;
case MODE_SERVER: $mode = "S"; break;
}
if (is_array($str)) {
ob_start();
var_export($str);
$str = ob_get_clean();
}
if (is_string($str)) {
$str = explode("n", $str);
}
if (is_array($str)) {
foreach($str as $tmp) {
if (function_exists("posix_getpid")) { $pid = @posix_getpid(); }
else if (function_exists("getmypid")) { $pid = @getmypid(); }
$dt = date("Y-m-d H:i:s");
$tmp = sprintf("%s [%5s] %s: %sn", $dt, $pid, $mode, $tmp);
@error_log($tmp, 3, "./_rootlogs/".date("Ymd")."_activeby.log");
}
}
}
}
public function createAccount($country_id, $email, $company_name, $first_name, $last_name, $middle_name, $fax_area_code, $fax_country_code, $fax_number, $phone_area_code, $phone_country_code, $phone_number, $address, $state, $type, $birthday, $zip, $city, $PassportNumber, $PassportByAndDate, $d60_number, $d60_authority, $UNP, $OKPO, $BankAccount, $BankName, $BankCode, $d60_date) {
$command = "/billing/account";
$requestData = array(
'country_id' => $country_id,
'email' => $email,
'phone_area_code' => $phone_area_code,
'phone_country_code' => $phone_country_code,
'phone_number' => $phone_number,
'birthday' => $birthday,
'fax_area_code' => $fax_area_code,
'fax_country_code' => $fax_country_code,
'fax_number' => $fax_number,
'first_name' => $first_name,
'last_name' => $last_name,
'middle_name' => $middle_name,
'address1' => $address,
'state' => $state,
'type' => $type,
'zip' => $zip,
'city' => $city,
);
if ($type == 1) {
$requestData['additional_attributes'] = array(
array("key" => "Active_PassportNumber", "value" => $PassportNumber),
array("key" => "Active_PassportIssuedBy", "value" => $PassportByAndDate),
array("key" => "Active_AddressStreet", "value" => $address),
array("key" => "Active_AddressHouse", "value" => "")
);
}
if ($type == 2) {
$requestData['company_name'] = $company_name;
$requestData['contact_first_name'] = $first_name;
$requestData['contact_last_name'] = $last_name;
$requestData['contact_middle_name'] = $middle_name;
$requestData['additional_attributes'] = array(
array("key" => "Active_Position", "value" => "Директор"),
array("key" => "Active_d60_number", "value" => $d60_number),
array("key" => "Active_d60_authority", "value" => $d60_authority),
array("key" => "Active_UNP", "value" => $UNP),
array("key" => "Active_OKPO", "value" => $OKPO),
array("key" => "Active_BankAccount", "value" => $BankAccount),
array("key" => "Active_BankName", "value" => $BankName),
array("key" => "Active_BankCode", "value" => $BankCode),
array("key" => "Active_AddressStreet", "value" => $address),
array("key" => "Active_AddressHouse", "value" => ""),
array("key" => "Active_d60_date", "value" => $d60_date)
);
}
if ($type == 3) {
$requestData['company_name'] = $company_name;
$requestData['contact_first_name'] = $first_name;
$requestData['contact_last_name'] = $last_name;
$requestData['contact_middle_name'] = $middle_name;
$requestData['additional_attributes'] = array(
array("key" => "Active_PassportNumber", "value" => $PassportNumber),
array("key" => "Active_PassportIssuedBy", "value" => $PassportByAndDate),
array("key" => "Active_d60_number", "value" => $d60_number),
array("key" => "Active_d60_authority", "value" => $d60_authority),
array("key" => "Active_UNP", "value" => $UNP),
array("key" => "Active_OKPO", "value" => $OKPO),
array("key" => "Active_BankAccount", "value" => $BankAccount),
array("key" => "Active_BankName", "value" => $BankName),
array("key" => "Active_BankCode", "value" => $BankCode),
array("key" => "Active_AddressStreet", "value" => $address),
array("key" => "Active_AddressHouse", "value" => ""),
array("key" => "Active_d60_date", "value" => $d60_date)
);
}
$result = $this->send($command, $requestData);
if (!$result) { return false; }
if ($result["account_id"]) {
return $result["account_id"];
}
else {
$this->error = $command.": no account id"; $this->slog($this->error); return false;
}
}
public function createUser($account_id, $country_id, $email, $first_name, $last_name, $middle_name, $login, $password, $phone_number, $zip) {
$command = "/billing/account/".$account_id."/user";
$requestData = array(
'account_id' => $account_id,
'country_id' => $country_id,
'email' => $email,
'phone_number' => $phone_number,
'first_name' => $first_name,
'last_name' => $last_name,
'middle_name' => $middle_name,
'zip' => $zip,
'login' => $login,
'password' => $password
);
$result = $this->send($command, $requestData);
if (!$result) { return false; }
if ($result["id"]) {
return $result["id"];
}
else {
$this->error = $command.": no user id"; $this->slog($this->error); return false;
}
}
public function registerDomain($domain, $accountId, $promo) {
$command = "/billing/order";
$requestData = array(
'account_id' => $accountId,
'items' => array(
array(
'period_id' => 55403,
'plan_id' => 5516,
'period_duration' => 1,
'domain' => $domain,
'operation' => 'register'
)
),
'payment' => array('method_id' => 0),
'promo_code' => $promo
);
$result = $this->send($command, $requestData);
if (!$result) { return false; }
if ($result["id"] and $result["items"][0]["subscription_id"]) {
$res["order_id"] = $result["id"];
$res["subscription_id"] = $result["items"][0]["subscription_id"];
return $res;
}
else {
$this->error = $command.": no order id or subscription id"; $this->slog($this->error); return false;
}
}
public function renewDomain($domain, $subscriptionId) {
$command = "/billing/subscription/".$subscriptionId."/renew";
$requestData = array(
'subscription_id' => $subscriptionId,
'payment' => array('method_id' => 0),
'period_id' => 55403
);
$result = $this->send($command, $requestData);
if (!$result) { return false; }
if ($result["order_id"]) {
return $result["order_id"];
}
else {
$this->error = $command.": no order id"; $this->slog($this->error); return false;
}
}
}
?>